Commit Graph

270 Commits

Author SHA1 Message Date
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
Rebecca Turner
a5b76690b1 glnx-fdio: use $TMPDIR if set
As suggested by Colin Walters.
2020-10-01 10:37:47 -04:00
Rebecca Turner
1ea9158c24 glnx-fdio: try $TMPDIR if /var/tmp doesn't exist
`glnx_open_anonymous_tmpfile` attempts to create an fd in `/var/tmp`
regardless of the value of `$TMPDIR`.

This is _usually_ okay, but can fail in some contexts, such as in the
[NixOS][1] build environment, which doesn't have `/var` mapped at all.

To avoid failing in this case, if the inner call to
`glnx_open_anonymous_tmpfile_full` fails, we retrieve the value of
`$TMPDIR` and try calling `glnx_open_anonymous_tmpfile_full` again with
that directory instead.

In the fast path (i.e. where `/var/tmp` exists), functionality is
unchanged.

[1]: https://nixos.org/
2020-09-23 13:33:43 -04:00
Colin Walters
5ef78bb9d9 Merge branch 'err-prefix-xattr' into 'master'
xattrs: Add better error prefixing

See merge request GNOME/libglnx!19
2020-09-10 19:36:38 +00:00
Colin Walters
de5d2ec85c xattrs: Add better error prefixing
Related to
https://github.com/coreos/coreos-assembler/issues/1703

This should help debug things like this in the future.
2020-09-10 18:59:56 +00:00
Colin Walters
84b981a2ef Merge branch 'fix-wrpseudo-grammar' into 'master'
libglnx.m4: Fix grammar in help string

See merge request GNOME/libglnx!17
2020-06-16 20:08:21 +00:00
Colin Walters
cd5a57e8dd Merge branch 'pr/cfr-nfs' into 'master'
glnx-fdio: handle EOPNOTSUPP for copy_file_range

See merge request GNOME/libglnx!18
2020-06-16 19:55:25 +00:00
Jonathan Lebon
7e3a19958e glnx-fdio: handle EOPNOTSUPP for copy_file_range
When using `copy_file_range` to target a source and dest on the same NFS
mount on some older kernel versions, it's possible that we can get
`EOPNOTSUPP` e.g. if the NFS server doesn't support server-side copy.

We hit this in the FCOS release pipeline where we run `ostree
pull-local` to pull content between two repos on the same mount from
inside an OpenShift cluster on top of RHEL7.

Nowadays, it seems like the kernel itself falls back to a more generic
version of `copy_file_range()` at least. Though to be compatible with
older kernels, let's add `EOPNOTSUPP` to the list of errors we interpret
as "cfr possibly available, but can't be done for this specific
operation".
2020-06-16 14:42:13 -04:00
Matthew Leeds
3f38e98a39 libglnx.m4: Fix grammar in help string 2020-06-11 16:28:19 -07:00
Simon McVittie
3c285a7b3a Merge branch 'wip/smcv/const-struct-stat' into 'master'
fdio: Be const-correct for struct stat

See merge request GNOME/libglnx!16
2020-06-09 17:19:36 +00:00
Simon McVittie
dbed5c58db fdio: Be const-correct for struct stat
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>
2020-06-03 17:51:19 +01:00
Simon McVittie
fc9073e7a8 Merge branch 'readme-libgsystem' into 'master'
README: update link to libgsystem

See merge request GNOME/libglnx!15
2020-06-03 16:47:49 +00:00
Simon McVittie
bf851fbe08 Merge branch 'auto-temp-dir-leak' into 'master'
_GLNX_TEST_SCOPED_TEMP_DIR: Fix memory and fd leak

See merge request GNOME/libglnx!14
2020-03-15 18:23:36 +00:00
Simon McVittie
c316e517ab Merge branch 'auto-temp-dir-unused' into 'master'
_GLNX_TEST_SCOPED_TEMP_DIR: Mark variable as G_GNUC_UNUSED

See merge request GNOME/libglnx!13
2020-03-15 18:23:19 +00:00
Will Thompson
70988f0287 README: update link to libgsystem
I was curious.
2019-12-02 16:00:36 +00:00
Simon McVittie
a652ede20b _GLNX_TEST_SCOPED_TEMP_DIR: Fix memory and fd leak
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>
2019-11-11 19:29:28 +00:00
Simon McVittie
bc9c31f785 _GLNX_TEST_SCOPED_TEMP_DIR: Mark variable as G_GNUC_UNUSED
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>
2019-11-11 18:37:38 +00:00
Simon McVittie
5f3d352aa4 Merge branch 'older-glibs' into 'master'
Build successfully on GLib 2.32

See merge request GNOME/libglnx!7
2019-11-11 18:36:08 +00:00
Simon McVittie
3063c69515 Make tests cope with older GLib
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-11-11 18:32:06 +00:00