Commit Graph

203 Commits

Author SHA1 Message Date
Alex Kiernan
460400c19c macros: Add TEMP_FAILURE_RETRY for musl
TEMP_FAILURE_RETRY is glibc specific, add a definition for musl.

See https://github.com/ostreedev/ostree/issues/731

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2019-09-09 14:33:54 +01:00
Jonathan Lebon
8f34033b25 Merge branch 'uchar' into 'master'
missing: Remove unused <uchar.h>

See merge request GNOME/libglnx!6
2019-05-13 18:45:53 +00:00
Simon McVittie
80779a3dec missing: Remove unused <uchar.h>
This doesn't exist on some very old platforms. In the original file
in systemd, it was here for char32_t and char16_t, which we don't use.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-05-02 14:59:59 +01:00
Colin Walters
e16bdc7ef9 Merge branch 'shutil-rm-rf-errprefix' into 'master'
shutil: Prefix error with path in rm_rf()

See merge request GNOME/libglnx!4
2018-12-07 15:07:45 +00:00
Colin Walters
b1cb19b6b2 shutil: Prefix error with path in rm_rf()
First, let's ensure the filename is prefixed consistently.
Second, add the entrypoint as a prefix when recursing.

This is best practice to help debugging.  Motivated by
https://discussion.fedoraproject.org/t/boot-partition-of-silverblue-is-without-space/771/9
2018-12-07 14:55:11 +00:00
Colin Walters
1e9b30838e README: Update Contributing 2018-11-30 16:27:19 -05:00
Colin Walters
13e7b4fdc7 Merge branch 'replace-contents-umask' into 'master'
Fix docs for glnx_file_replace_contents()

See merge request GNOME/libglnx!3
2018-11-30 21:24:41 +00:00
Owen W. Taylor
c2dbe1811b Fix docs for glnx_file_replace_contents()
The docs for `glnx_file_replace_contents[_with_perms]` say that the default mode
is 0666 - umask, but it's actually 0644. Because there's no thread-safe way of
finding out the current umask without grubbing around in /proc/self/status,
simply make the docs reflect reality.
2018-11-30 16:22:51 -05:00
Colin Walters
470af8763f Merge branch 'renameat2-stdio' into 'master'
libglnx.m4: Include stdio.h for renameat2

See merge request GNOME/libglnx!2
2018-07-13 13:00:20 +00:00
Colin Walters
7be25521cf libglnx.m4: Include stdio.h for renameat2
glibc added it upstream:
https://sourceware.org/git/?p=glibc.git;a=commit;h=d6da5cb6a8e0e8a9ce92b7d951a254cf325248d7

But we need the right header.
Ref: https://github.com/flatpak/flatpak/issues/1890
2018-07-11 14:56:32 -04:00
Philip Withnall
e1a78cf2f5 Merge branch 'backport-autoptr-support' into 'master'
Add g_autoptr support for GAsyncResult,GMount,GVolumeMonitor

See merge request GNOME/libglnx!1
2018-05-29 09:28:38 +00:00
Matthew Leeds
00ad6ee739 Add g_autoptr support for GAsyncResult,GMount,GVolumeMonitor 2018-05-28 20:20:52 -07:00
Colin Walters
97b5c08d2f console: Drop newline on glnx_console_lock
This was inherited from some other code; perhaps the idea
was to ensure the console is in a consistent state before starting
a progress bar, but it causes extra newlines which is distracting.
2018-05-08 14:40:12 -07:00
Jonathan Lebon
03e16afa7f missing-syscalls: Use different name for copy_file_range
In glibc 2.27, a wrapper for `copy_file_range` was added[1]. The
function is now always defined, either using a userspace fallback or
just returning `ENOSYS` if the kernel doesn't support it. This throws
off our preprocessor conditionals. Work around this by just renaming our
implementation differently. This is similar to what systemd did[2].

Hit this when trying to build on F28, which rebased to glibc 2.27.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f
[2] 5187dd2c40
2018-05-04 14:52:04 -04:00
Aurelien Jarno
0c82203cd4 Include sys/mman.h when checking for memfd_create
glibc 2.27 added support for memfd_create. Unfortunately flatpak-builder,
or rather the included libglnx library, also has such a function to
wrap the corresponding syscall. It correctly tries to detect it in
the configure script to disabled the wrapper in case glibc provides
it. However it doesn't work due to a missing include.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=890722
2018-02-19 10:34:45 +01:00
Jonathan Lebon
6f1ee5db14 console: make stdout_is_tty() public
Share its static var goodness with clients. This will be used in
rpm-ostree from various places which sometimes do use a `GLnxConsole`
and sometimes don't, so it's more convenient to make it its own
function.
2018-01-10 17:58:14 +00:00
Colin Walters
96b1fd9578 console: Avoid rendering too quickly
For TTYs, it slows things down pointlessly. For non-TTYs like Jenkins jobs, it
creates a ton of output that obscures useful information.
2017-12-12 15:31:45 -05:00
Colin Walters
985ed1c861 console: Drop unused current_text/current_percent
The idea was clearly to avoid useless updates, but we never actually *set* these
values. Drop the code for now to avoid confusion, I'll reimplement this in a
better way.
2017-12-12 15:24:42 -05:00
Colin Walters
bb7dd4dd08 console: Limit progress bar to 20 columns max
IMO, it looks bad to have a really big progress bar. I personally usually work
on a 27" monitor with maximized terminals.
2017-12-12 15:24:42 -05:00
Colin Walters
a8f96bd5f7 console: Add an "n items" API
It's often really useful to see the counts, not just the percentage.
2017-12-12 15:24:42 -05:00
Colin Walters
31ef1961ec fdio: Include libgen.h again for dirname()
rpm-ostree at least uses `dirname()` and relied on the `#include <libgen.h>`
that we had previously.
2017-12-12 14:22:39 -05:00
Ray Strode
03b48a3934 fdio: implement glnx_basename from scratch
At the top of glnx-fdio.h there's this comment:

/* When we include libgen.h because we need
 * dirname() we immediately undefine
 * basename() since libgen.h defines it as
 * a macro to the XDG version which is really
 * broken. */

and then it does #undef basename to try to
gain access to non-default basename implementation.

The problem is that this trick doesn't work on
some systems:

./libglnx/glnx-fdio.h: In function 'glnx_basename':
./libglnx/glnx-fdio.h:46:11: error: 'basename'
undeclared (first use in this function)
   return (basename) (path);

Anyway, basename() is like 3 lines of code to
implement, so this commit just does that instead
of relying on glibc for it.
2017-11-14 10:05:23 -05:00
Will Thompson
016ea9168b errors: don't use 'static inline' on varargs functions
This caused GCC 6.3.0 -Winline to complain:

    ../../../ext/libglnx/glnx-errors.h:169:1: warning: function
        ‘glnx_throw_errno_prefix’ can never be inlined because it uses
        variable argument lists [-Winline]
     glnx_throw_errno_prefix (GError **error, const char *fmt, ...)
     ^~~~~~~~~~~~~~~~~~~~~~~
    ../../../ext/libglnx/glnx-errors.h:169:1: warning: inlining failed
        in call to ‘glnx_throw_errno_prefix’: function not inlinable
        [-Winline]
2017-11-02 17:14:06 +00:00
Colin Walters
b36606b366 missing-syscall: #include config.h
Followup to previous commit; this helps me build libostree
with `-Werror=undef`.
2017-11-02 11:30:53 -04:00
Will Thompson
4577dc826a Add missing configure check for copy_file_range
Without this, including glnx-missing-syscall.h raises this warning:

    ../ext/libglnx/glnx-missing-syscall.h:121:6: warning: "HAVE_DECL_COPY_FILE_RANGE" is not defined [-Wundef]
     #if !HAVE_DECL_COPY_FILE_RANGE
          ^~~~~~~~~~~~~~~~~~~~~~~~~
2017-11-02 14:55:17 +00:00
Colin Walters
d15a379007 tree-wide: Some new style porting
Use decl-after-stmt where applicable.
2017-10-24 08:43:26 -04:00
Colin Walters
771d7a01d1 tree-wide: Use glnx_autofd and glnx_close_fd()
Port to `glnx_autofd` tree wide, and add one missed `glnx_close_fd()` use in the
tmpfile code.
2017-10-16 18:06:53 -04:00
Colin Walters
e627524af9 fdio: Avoid ?: syntax for fstatat_allow_noent()
`g-ir-scanner` is unaware of this GNUC extension and complains.
Saw that while building ostree.

While we're here, fix up a few other things:

 - Tell the compiler the stat buffer is unused (I didn't see
   a warning, just doing this on general principle)
 - Return from `glnx_throw_errno_prefix()` directly; we do
   preserve errno there, let's feel free to rely on it.
2017-10-11 17:07:54 -04:00
Jonathan Lebon
b923a950af tests: drop unused variable 2017-10-11 20:03:12 +00:00
Jonathan Lebon
5362f6bc3f fdio: allow NULL for fstatat_allow_noent stbuf
Often, the caller doesn't actually care about the details of the stat
struct itself, but just whether the entry exists or not. It does work
to just pass `NULL` directly to glibc in a quick test, but given that
the argument is tagged as `__nonnull` and that the documentation does
not explicitly specify this is supported, let's do this safely.
2017-10-06 21:45:55 +00:00
Colin Walters
97cd6a6c1d Add glnx_fd_close() and glnx_autofd
I'd like to have the checks for `EBADF` as well as the
"assign to -1" in more places.  The cleanup function we
had for `glnx_fd_close` is actually what we want.

Let's rename the cleanup macro to `glnx_autofd` to better match
other autocleanups like `g_autofree`.

Then we can use `glnx_fd_close()` as a replacement for plain Unix `close()`. I
left the `glnx_close_fd` macro, but it's obviously confusing now with the
former. We'll eventually remove it.
2017-10-06 10:14:57 -04:00
Colin Walters
dea16cd8be fdio: Squash compiler warning from previous commit
Oops.
2017-10-05 14:45:40 -04:00
Colin Walters
b72906dbe0 fdio: Generate tmpname for RENAME_EXCHANGE fallback
I was using this in rpm-ostree and glanced at the code. This was clearly the
intent, but isn't a full fix. See code comments for more details.
2017-10-02 10:09:02 -04:00
Colin Walters
dd5fd9c1e5 missing: Sync from latest systemd, add memfd_create()
Planning to use memfd_create() in flatpak and rpm-ostree, which both use
bubblewrap, and want to pass read-only data via file descriptor to the
container. Passing via `O_TMPFILE` requires `O_RDWR` (read and write),
and passing via a pipe would require buffering.

The systemd `missing.h` has grown enormously; I only cherry-picked the bits for
memfd.
2017-10-01 09:51:14 -07:00
Philip Withnall
e30154431d shutil: Fix assertion failure in glnx_shutil_mkdir_p_at()
If the directory for @dfd is deleted after being opened,
glnx_shutil_mkdir_p_at() would fail with an assertion failure. Fix that,
and make it return an ENOENT error instead.

Add a unit test.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Colin Walters <walters@verbum.org>
Reviewed-by: Jonathan Lebon <jlebon@redhat.com>

https://github.com/ostreedev/ostree/issues/1215
2017-09-26 15:08:04 +01:00
Colin Walters
32a4293101 lockfile: Use an initialized member rather than explicit init
This makes us more friendly to being embedded in a GObject or
the like that's fully zero-initialized, rather than relying on the special
`-1` value for the fd.

Calls to `glnx_release_lock_file()` become idempotent, so it's easy to call it
unconditionally in an object finalizer.
2017-09-25 15:36:23 -04:00
Jonathan Lebon
292cfc807e macros: use size_t for glnx_strjoina len
This was in my workspace for a while.
`strlen` returns a `size_t` and `alloca` expects a `size_t`.
2017-09-25 11:55:43 -04:00
Colin Walters
5ee2f1be7a fdio: Open target dirname for glnx_file_copy_at()
Particularly if `AT_FDCWD` is used, we need to open
in the target dir, otherwise we can get `EXDEV` when trying
to do the final link.

(Theoretically we can cross a mountpoint even with fd-relative
 though this is a lot less likely)
2017-09-25 11:53:40 -04:00
Philip Withnall
56e7e728ab dirfd: Fix typo in documentation for glnx_ensure_dir()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-09-21 20:20:47 +01:00
Colin Walters
e5856ca293 build-sys: Fix make dist
The libostree Travis builds use make dist.
2017-09-17 09:04:57 -04:00
Colin Walters
c2bcca04ba tests: Add macro for auto-error checking
Having our tests forced into a `goto out` style is seriously annoying
since we can't write tests like we write production code.  Add
a macro that checks for the error being NULL.

This doesn't fully solve the problem since the test functions are
still forced into `void` returns; at some point I may extend
GLib to have `g_test_add_err_func()`.
2017-09-13 10:57:30 -04:00
Colin Walters
667d8aa721 tree-wide: Use our own syscall wrappers or error prefixing
Followup to similar commits in the ostree stack recently.
2017-09-13 10:34:21 -04:00
Colin Walters
0428fd87ff dirfd: Extend tmpdir API to support optional cleaning
We have a use case in libostree's staging dirs where we try to reuse
them across multiple ostree txns, but we want the fd-relative bits
here.

Extend the tmpdir API to make deletion optional. While here, also extend the API
to support checking for errors when deleting for projects like libostree that
want to do so consistently.

Also while here, add a change to set the fd to `-1` after clearing to be extra
defensive.
2017-09-13 10:28:25 -04:00
Colin Walters
b59bb2be7c fdio: Add gtk-doc for stbuf parameter of glnx_file_copy_at()
Spotted in ba5e1cf9f5
2017-09-12 11:09:29 -04:00
Colin Walters
673f48f6ca fdio: Use O_TMPFILE + rename-overwrite for regfile copies
I was working on rpm-ostree unified core, and hit the fact that
`glnx_file_copy_at()` had the same bug with `fsetxattr()` and files whose mode
is <= `0400` (e.g. `000` in the case of `/etc/shadow`) that libostree did a
while ago.  Basically, Linux currently allows `write()` on non-writable open files
but not `fsetxattr()`.  This situation is masked for privileged (i.e.
`CAP_DAC_OVERRIDE`) code.

Looking at this, I think it's cleaner to convert to `O_TMPFILE` here,
since that code already handles setting the tmpfile to mode `0600`.  Now,
this *is* a behavior change in the corner case of existing files which
are symbolic links.  Previously we'd do an `open(O_TRUNC)` which would follow
the link.

But in the big picture, I think the use cases for `open(O_TRUNC)` are really
rare - I audited all callers of this in ostree/rpm-ostree/flatpak, and all of
them will be fine with this behavior change. For example, the ostree `/etc`
merge code already explicitly unlinks the target beforehand. Other cases like
supporting `repo/pubring.gpg` in an ostree repo being a symlink...eh, just no.

Making this change allows us to convert to new style, and brings all of the
general benefits of using `O_TMPFILE` too.
2017-09-12 11:05:59 -04:00
Colin Walters
9d995a3620 fdio: Support taking ownership of tmpfile fd
While reading a strace I noticed a double close in the tests; this was because
we were missing an assignment to `-1` in the tests. However, let's make
supporting this clearer by explicitly supporting the fd being `-1` while still
setting the `initialized` variable to `FALSE`. We also add the `EBADF` assertion
checking.
2017-09-12 09:43:05 -04:00
Colin Walters
806bb46e05 fdio: Use O_EXCL for anonymous tmpfiles
I noticed while reading the manpage for `linkat()` that `O_TMPFILE`
supports `O_EXCL` to mean exactly what we're doing with the anonymous
tmpfile API.

Change the code to start using it; this required refactoring the internals since
we had a check to be sure the caller wasn't passing `O_EXCL` for the
non-anonymous path which we want to keep.

Presumably the storage system could do smarter things if it knows a file will
always be anonymous, e.g. it doesn't need to journal its data.
2017-09-12 09:42:47 -04:00
Colin Walters
627d4e2f15 fdio: Add glnx_fstatat_allow_noent()
This is a very common pattern in both ostree/rpm-ostree. Make a better API for
this. I thought a lot about simply zeroing out `struct stat` but that feels
dangerous; none of the values have seem obviously `cannot be zero`.
2017-09-07 16:05:26 -04:00
Jonathan Lebon
47d8163293 test-libglnx-xattrs.c: appease -Wunused-variable 2017-08-25 11:02:37 -04:00
Colin Walters
7100ebbc68 dirfd: New tmpdir API
Basically all of the ostree/rpm-ostree callers want to both create and open, so
let's merge `glnx_mkdtempat()` and `glnx_mkdtempat_open()`.

Second, all of them want to do `glnx_shutil_rm_rf_at()` on cleanup, so we do the
same thing we did with `GLnxTmpfile` and create `GLnxTmpDir` that has a cleanup
attribute.

The cleanup this results in for rpm-ostree is pretty substantial.
2017-08-18 16:01:38 -04:00