Commit Graph

288 Commits

Author SHA1 Message Date
Simon McVittie
b5658723ff backports: Backport G_OPTION_FLAG_NONE, G_OPTION_ENTRY_NULL
These make tables of options a bit clearer to write.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:55:12 +01:00
Simon McVittie
fabcdb3bd8 backports: Backport G_SPAWN_DEFAULT
This makes the absence of flags a bit clearer to write.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:55:12 +01:00
Colin Walters
26375b5308 Merge branch 'pr/ficlone-fixes' into 'master'
fdio: fix fd offset handling with `FICLONE`

See merge request GNOME/libglnx!41
2022-08-01 15:27:34 +00:00
Jonathan Lebon
7a2f26a312 fdio: fix fd offset handling with FICLONE
When using `FICLONE`, the kernel does a full file clone and disregards the
fd offsets. Users of this API however assume that it *is*
offset-sensitive. So we need to verify that the fd offsets are at the
start of the files before we call `FICLONE`. This was done in systemd also
in:

https://github.com/systemd/systemd/commit/c622fbdb8d37

The commit message does not explain this but `ioctl_ficlone(2)` says:

    The `FICLONE` ioctl clones entire files.

(Compare with `FICLONERANGE`, which takes a struct with offsets and the
length).

Similarly, we need to seek to the end of the file descriptors on success
so that we're consistent with the behaviour of the other backends
available (`copy_file_range`, `sendfile` and manual copying). This also
matches what systemd does nowadays:

https://github.com/systemd/systemd/blob/80f967311ac5/src/shared/copy.c#L199
2022-07-29 17:52:43 -04:00
Phaedrus Leeds
c59eb271b5 Merge branch 'wip/smcv/warnings' into 'master'
Fix and enable more compiler warnings

See merge request GNOME/libglnx!35
2022-05-10 18:08:28 +00:00
Phaedrus Leeds
72e532d7ed Merge branch 'wip/smcv/subproject' into 'master'
Improve Meson subproject support

See merge request GNOME/libglnx!34
2022-05-10 17:34:21 +00:00
Simon McVittie
9f033ee2f6 meson: Build with more warnings by default
If we keep this module closer to warnings-clean, then it can be
submoduled into Meson projects that enable warnings by default without
having to override it to a lower warning-level.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:08:15 +01:00
Simon McVittie
7b26e39a1f tests: Make signedness of timestamp agree
This silences a warning from gcc -Wsign-compare. g_get_monotonic_time()
returns a signed int64.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:07:38 +01:00
Simon McVittie
4c51a54c36 tests: Make iterator signedness agree with limit
g_variant_n_children() returns a size_t (or gsize, which is equivalent)
so in principle it could overflow an int, although in practice we are
not going to have that many extended attributes. This silences a
warning from gcc -Wsign-compare.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:06:51 +01:00
Simon McVittie
f65b05f2d5 fdio: Match signedness of length parameter
This is documented as taking a length of -1, but the parameter is
unsigned, so it's more correctly ((gsize) -1). This silences a warning
from gcc -Wsign-compare.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:04:58 +01:00
Simon McVittie
d78121a699 fdio: Make signedness of iterator consistent with limit
gcc -Wsign-compare warns about this. The iteration limit is constant
and small enough that either int or guint would be fine.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:04:00 +01:00
Simon McVittie
2d007fa1c0 fdio, xattrs: Mark unused cancellables as such
These functions take a GCancellable for consistency with other file
APIs, but are not actually cancellable at the moment.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:02:48 +01:00
Simon McVittie
f8b7343a29 console: Mark an unused parameter as such
This signal handler is only called for SIGWINCH, so it doesn't need
to look at its parameter.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-24 11:02:09 +01:00
Simon McVittie
238f7bfc49 fdio: Skip glnx_try_fallocate() if _GNU_SOURCE is not defined
fallocate() is only visible in fcntl.h if _GNU_SOURCE is defined.
Most users of libglnx will want to do that anyway, but it seems nicer
to avoid "implicit declaration of function ‘fallocate’" warnings from
simply including <libglnx.h> into naive code.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:56:41 +01:00
Simon McVittie
4d5b1fcf02 tests: Verify libglnx can work as a subproject
What isn't tested usually doesn't work, and the only way to use libglnx
is as a subproject, so test it like that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:51:53 +01:00
Simon McVittie
96ba9f4d8d tests: Optionally skip building and running the actual tests
If we're building libglnx as a subproject in a larger project, we won't
necessarily want to run these.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:44:13 +01:00
Simon McVittie
c500c362b8 tests: Build libglnx-testlib as a separate static library
One of Flatpak's unit tests uses this, for _GLNX_TEST_SCOPED_TEMP_DIR.
Its API is not really stable, but libglnx is a "copylib" anyway, so
none of it has (or needs) a strictly stable API.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:44:13 +01:00
Simon McVittie
eeea247ade meson: Always build with hidden symbol visibility
This copylib isn't intended to be part of anyone's ABI. In Autotools,
this is typically implemented by doing some ad-hoc compiler checks and
adding -fvisibility=hidden to the global CFLAGS of any library that
pulls in libglnx, but in Meson it's a build system feature.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:44:13 +01:00
Simon McVittie
b76cf458ce meson: Automatically link libglnx-dependent objects to gio-unix
If we don't do this, users of libglnx all have to add this dependency
themselves, otherwise they'll get errors like:

    fatal error: gio/gfiledescriptorbased.h: No such file or directory

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 19:43:25 +01:00
Simon McVittie
c71f7aefa1 Merge branch 'mwleeds/fix-config-h-clean' into 'master'
Add libglnx-config.h to CLEANFILES

See merge request GNOME/libglnx!33
2022-03-01 19:55:33 +00:00
Phaedrus Leeds
b73a467a97 Add libglnx-config.h to CLEANFILES
This fixes make distcheck for Flatpak (but you have to re-run
autogen.sh).
2022-03-01 11:51:46 -08:00
Colin Walters
88da8ddd60 Merge branch 'wip/noxattr' into 'master'
tests: Don't copy extended attributes when testing pseudo-files

See merge request GNOME/libglnx!32
2022-02-22 14:32:35 +00:00
Simon McVittie
b6ee0e2423 tests: Don't copy extended attributes when testing pseudo-files
It seems that on SELinux systems, files in /proc have extended
attributes that cannot be copied by an unprivileged user.

Signed-off-by: Simon McVittie <smcv@debian.org>
2022-02-22 10:26:39 +00:00
Simon McVittie
983a818936 Merge branch 'wip/reuse' into 'master'
Declare copyright and licensing using REUSE

See merge request GNOME/libglnx!27
2022-02-19 23:00:37 +00:00
Simon McVittie
68191d8274 Update copyright holder for Endless' contributions
Will Thompson reports that all of Endless' IP was transferred to
Endless OS Foundation LLC.

Signed-off-by: Simon McVittie <smcv@debian.org>
2022-02-19 22:57:52 +00:00
Simon McVittie
bc5d289885 CI: Run reuse lint across the tree
Signed-off-by: Simon McVittie <smcv@debian.org>
2022-02-19 22:57:52 +00:00
Simon McVittie
81c6adb0f7 Declare copyright and licensing using REUSE
To fill in some gaps, I've had to make some assumptions:

* trivial changes (such as checking for an additional function or
  header file in libglnx.m4) are assumed to not be copyrightable
* Will Thompson and Matthew Leeds are assumed to be contributing on
  behalf of Endless Mobile Inc.
* files with no explicit licensing information are assumed to be
  under the license found in COPYING

Reference: https://reuse.software/
Signed-off-by: Simon McVittie <smcv@debian.org>
2022-02-19 22:57:48 +00:00
Colin Walters
a29f340fb6 Merge branch 'wip/smcv/copy-pseudo-files' into 'master'
fdio: Use a read/write loop until EOF if st_size is zero

See merge request GNOME/libglnx!31
2022-02-18 14:06:47 +00:00
Phaedrus Leeds
15d4c3aa94 Merge branch 'not-config-h' into 'master'
Include libglnx-config.h instead of config.h

See merge request GNOME/libglnx!24
2022-02-18 13:21:02 +00:00
Phaedrus Leeds
9fe002a0c5 Merge branch 'wip/stdc99' into 'master'
build: Use Meson built-in option c_std instead of -std=gnu99

See merge request GNOME/libglnx!28
2022-02-18 13:10:00 +00:00
Simon McVittie
803adaf488 Merge branch 'disable_copy_file_range_on_EINVAL--I3' into 'master'
Disable copy_file_range on ecryptfs

Closes #3

See merge request GNOME/libglnx!30
2022-01-28 12:17:52 +00:00
Simon McVittie
586bdfe1c3 fdio: Use a read/write loop until EOF if st_size is zero
Some pseudo-files in /proc and /sys list a size of 0 bytes in stat()
results, but do in fact have content. For these pseudo-files, the only
way to find out the true file size is to try read() until EOF, so leave
the max_bytes set to -1.

copy_file_range() and sendfile() don't work for such files in some
kernel versions (see <https://lwn.net/Articles/846403/>), so skip the
fast-paths and use a read() and write() loop. For pseudo-files, we
expect to be able to copy the whole content in one read() in any case.

Signed-off-by: Simon McVittie <smcv@debian.org>
2022-01-28 11:41:47 +00:00
Olaf Leidinger
24231a956a Fall back if copy_file_range fails with EINVAL
Although EINVAL usually indicates a programming error, ecryptfs (and
possibly other stacked filesystems) returns EINVAL for attempts to
copy_file_range() or sendfile() between files on that filesystem.

Resolves: https://gitlab.gnome.org/GNOME/libglnx/-/issues/3
2022-01-28 10:44:59 +00:00
Colin Walters
ef502aabf7 Merge branch 'pr/cov-fix' into 'master'
xattrs: Fix possible double-free in `get_xattrs_impl`

See merge request GNOME/libglnx!29
2021-08-04 15:32:52 +00:00
Jonathan Lebon
82e5b7dd56 xattrs: Fix possible double-free in get_xattrs_impl
When we free `xattr_name`, we need to transfer ownership away to avoid
potential for a double-free if we hit `ENOTSUP` on the next iteration.

Reported-by: Seth Arnold <seth.arnold@canonical.com>
2021-08-03 16:39:01 -04:00
Simon McVittie
a4dcfe8d2f build: Use Meson built-in option c_std instead of -std=gnu99
This silences a Meson warning.

Signed-off-by: Simon McVittie <smcv@debian.org>
2021-07-02 14:19:15 +01:00
Colin Walters
b7a2d4dc59 Merge branch 'console-staticanalysis-fix' into 'master'
console: Pacify `gcc -fanalyzer`

See merge request GNOME/libglnx!26
2021-06-28 15:02:42 +00:00
Simon McVittie
c306703c6f Include libglnx-config.h instead of config.h
This avoids colliding with a config.h generated by a parent Meson
project.

In the Meson build system, we generate libglnx-config.h by doing our
own checks, so we want to avoid it colliding.

In the Autotools build system, we assume that the parent project will
generate its own config.h that contains the results of LIBGLNX_CONFIGURE,
and create a forwarding header libglnx-config.h in the $(top_builddir)
(so that it is next to config.h).

Note that after updating libglnx in an Autotools non-recursive-Make
project (libostree, flatpak, flatpak-builder) it will be necessary to
re-run autogen.sh.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-28 15:53:32 +01:00
Simon McVittie
1f02e4313a glnx-lockfile.h: Remove unused inclusion of config.h
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-28 15:53:08 +01:00
Colin Walters
59c02f9939 Merge branch 'wip/smcv/rewinddir' into 'master'
glnx-dirfd: Add a rewinddir() wrapper

See merge request GNOME/libglnx!25
2021-06-28 14:07:14 +00:00
Colin Walters
62f8ed6c8e console: Pacify gcc -fanalyzer
It's not smart enough to follow the conditionals here to see
that `textlen > 0` implies `text != NULL`.  But the cost of an additional
check is probably nil, so let's be robust to future code refactoring.
2021-06-28 10:05:09 -04:00
Simon McVittie
a0750a00b1 glnx-dirfd: Add a rewinddir() wrapper
This is useful in the same situations rewinddir() is. My use-case right
now is to remove some of the files from a directory, then go back through
the directory removing symlinks that pointed to those files.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-22 15:59:05 +01:00
Colin Walters
4c9055ac08 Merge branch 'pr/glnx-no-chown' into 'master'
glnx_file_copy_at: Add GLNX_FILE_COPY_NOCHOWN

See merge request GNOME/libglnx!22
2021-02-09 22:30:19 +00:00
Jonathan Lebon
1345882d6a glnx_file_copy_at: Add GLNX_FILE_COPY_NOCHOWN
In some contexts, we may want to copy a root-owned file but we're not
running as root so we can't `fchown` it. (The case I'm interested in is
actually a bit more obscure than this: running in a supermin VM as root,
and wanting to copy a file we created onto a 9p mount where we don't
have perms to `fchown`).

Add a `GLNX_FILE_COPY_NOCHOWN` to handle this case.
2021-02-09 16:24:10 -05:00
Colin Walters
900caea698 macros: Fix casting for C++ compatibility
Prep for more work on porting rpm-ostree to use cxx-rs.
2020-12-06 23:26:49 +00:00
Colin Walters
a8b4418954 glnx_strjoina: Cast to result for C++ compatibility
Prep for using C++ in rpm-ostree (temporarily).
2020-11-22 23:03:04 +00:00
Colin Walters
efcacc4c5f fdio: Fix compilation via C++
I may use https://cxx.rs/ in rpm-ostree, which means we
need our dependencies' headers to build in C++ mode.
2020-11-22 19:11:31 +00:00
Alexander Larsson
493d399b19 Merge branch 'replace-increasing-mtime' into 'master'
Add GLNX_FILE_REPLACE_INCREASING_MTIME

See merge request GNOME/libglnx!21
2020-11-03 11:22:04 +00:00
Alexander Larsson
013417ea72 Add GLNX_FILE_REPLACE_INCREASING_MTIME
This make replaced files have a strictly increasing st_mtime. The main
usecase I have for this is to ensure the summary file mtime increases
because the flatpak tests are failing due to the python httpd used
in the tests rely on st_mtime for the http If-Modified-Since header.

For the tests this breaks all the time since we're just doing a lot of
summary updates. However, I can see this accidentally happening in the
wild too, so i think its proper to always ensure the new summary is
"newer", even though it means it will be timestamped slightly in the
future. In practice this will not happen regularly, and the times it
*does* happen we really do need it.
2020-11-03 11:44:52 +01:00
Colin Walters
1dd01d5ef1 Merge branch 'tmpfile-dir' into 'master'
glnx-fdio: try $TMPDIR if /var/tmp doesn't exist

See merge request GNOME/libglnx!20
2020-10-02 17:45:01 +00:00