We don't modify this struct (if non-NULL), so it can be const. In
particular, this is helpful if calling glnx_file_copy_at() from
nftw() to implement the equivalent of `cp -a --reflink=auto`.
Signed-off-by: Simon McVittie <smcv@collabora.com>
This doesn't really matter, since it only happens when our process is
about to exit anyway, but it makes it easier to use AddressSanitizer
and similar tools.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Otherwise, clang diagnoses it as unused. It is - deliberately - only
allocated and cleaned up, with no other use.
Signed-off-by: Simon McVittie <smcv@collabora.com>
If you're building on a really old GLib, you might not have GTask,
GSubprocess or g_markup_parse_context_unref(), among others. This gets
libglnx compiling (and apparently working) on GLib versions as old
as 2.32.
Signed-off-by: Simon McVittie <smcv@collabora.com>
This will be necessary if targeting GLib versions older than 2.34,
such as GLib 2.32 in Ubuntu 12.04 and the Steam Runtime.
Signed-off-by: Simon McVittie <smcv@collabora.com>
This is useful if you need the file to be on a particular filesystem.
In particular, flatpak wants this to make tempfiles on /tmp for things
we need to write during flatpak run, such as the libseccomp output fd.
We've had "flatpak run" stop working in low disk situations without this,
so its nice to be able to fix it.
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>
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.
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.
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
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
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.
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.
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.
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]