Commit Graph

358 Commits

Author SHA1 Message Date
Sebastian Wick
14578d856e missing: Add syscall and structs for statx()
They are taken from an older revision of systemd with minimal changes.
2026-03-12 00:41:48 +01:00
Simon McVittie
8eb974e539 Merge branch 'wip/smcv/dup-unref-object' into 'master'
[trivial] local-alloc: Remove duplicate definition of glnx_unref_object

See merge request GNOME/libglnx!67
2026-03-10 17:32:50 +00:00
Colin Walters
287353e5ae Merge branch 'wip/smcv/wpointer-sign' into 'master'
[trivial] tests: Avoid a -Wpointer-sign warning

See merge request GNOME/libglnx!66
2026-03-10 17:11:27 +00:00
Simon McVittie
27f2b28c4f local-alloc: Remove duplicate definition of glnx_unref_object
The same `#define` exists both before and after `glnx_local_obj_unref()`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-05 13:29:31 +00:00
Simon McVittie
f4101e805c tests: Avoid a -Wpointer-sign warning
test_data is an array of (usually) signed char, but
glnx_file_replace_contents_at() takes an array of unsigned bytes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-05 13:24:43 +00:00
Colin Walters
51a1c2a9b6 Merge branch 'wip/various-improvements-1' into 'master'
glnx_fd_reopen, glnx_fd_throw, gcc fanalyzer improvements

See merge request GNOME/libglnx!65
2026-03-03 14:45:27 +00:00
Sebastian Wick
0b0703c3f0 tests: Add comprehensive tests for glnx_fd_reopen
Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-21 01:29:05 +01:00
Sebastian Wick
1ec49dfc9b fdio: Add glnx_fd_reopen
Reopens the specified fd with new flags. This is useful for convert an
O_PATH fd into a regular one, or to turn O_RDWR fds into O_RDONLY fds.
2026-02-21 01:29:05 +01:00
Sebastian Wick
c33f0ed05e glnx-errors.h: add glnx_fd_throw[_*] variants
Similar to the glnx_null_throw variants, this one returns -1 instead of
FALSE or NULL. This is helpful when dealing with functions which return
a fd.
2026-02-18 00:35:43 +01:00
Sebastian Wick
cdce8957b2 backports: Add g_clear_fd 2026-02-18 00:35:43 +01:00
Sebastian Wick
6a556d05d1 lockfile: Assert non-null path in make_lock_file for analyzers
Asserting the value helps the gcc analyzer and avoids a false-positive.
2026-02-17 22:53:31 +01:00
Simon McVittie
de29c5f7d9 errors: Fix URL to an old libgsystem commit
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-05-23 18:09:03 +01:00
Colin Walters
fed928addd Merge branch 'wip/smcv/issue5' into 'master'
fdio: Avoid relying on VLAs or gcc-specific constant folding

Closes #5

See merge request GNOME/libglnx!63
2025-01-06 16:03:35 +00:00
Simon McVittie
cd4b7b53eb fdio: Avoid relying on VLAs or gcc-specific constant folding
Formally, `strlen("x")` is not a constant expression, although gcc can
and does optimize it to a constant expression in simple cases.
clang 19.1.6 warns about this usage.

Replace it with the size of a static array (1 more than the strlen of
its contents), which is unambiguously a constant expression.

Resolves: https://gitlab.gnome.org/GNOME/libglnx/-/issues/5
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-01-06 15:01:43 +00:00
Will Thompson
5544bfdd82 Merge branch 'wip/smcv/issue1' into 'master'
glnx-shutil: Cope with ENOENT even after recursing to create parents

Closes #1

See merge request GNOME/libglnx!62
2024-12-06 13:57:01 +00:00
Simon McVittie
e6151ffbc0 Add a test for glnx_shutil_mkdir_p_at with an unusable parent
This is a slight generalization of the reproducer contributed by Will
Thompson: as well as exercising the case where the parent is a dangling
symlink (reproducing GNOME/libglnx#1), this also exercises the case where
the parent is a non-directory non-symlink (in this case a regular file).

Reproduces: GNOME/libglnx#1
Co-authored-by: Will Thompson <wjt@endlessos.org>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-06 13:29:50 +00:00
Simon McVittie
2eb4bcc282 glnx-shutil: Cope with ENOENT even after recursing to create parents
If we try to create `link/content` where `link` is a dangling symlink,
recursing to create `link` will succeed (mkdirat fails with EEXIST,
which is explicitly ignored), but then mkdirat for `link/content` will
still fail. Fail gracefully instead of crashing out with an assertion
failure.

Resolves: GNOME/libglnx#1
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-06 13:29:50 +00:00
Simon McVittie
f44d944233 tests: Run each shutil test in a temporary directory
Otherwise it could potentially race with tests in other executables that
also want to create `./test`, or interfere with other test-cases in the
same executable that expect `./test` to be nonexistent or empty.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-06 13:29:50 +00:00
Will Thompson
b345955140 Merge branch 'wip/smcv/meson-bool' into 'master'
build: Use a boolean default for a boolean option, rather than a string

See merge request GNOME/libglnx!60
2024-12-05 11:39:21 +00:00
Simon McVittie
f92968a8d2 build: Use a boolean default for a boolean option, rather than a string
Meson 1.1.0 officially deprecates string defaults for boolean options,
but boolean defaults worked in many older Meson versions, going back to
at least 0.49.x.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-05 11:35:45 +00:00
Simon McVittie
87f2768fab Merge branch 'wip/smcv/glib-unix' into 'master'
glnx-backports: Include `<glib-unix.h>`

See merge request GNOME/libglnx!59
2024-08-23 13:53:06 +00:00
Simon McVittie
8ed45a1a22 glnx-backports: Include <glib-unix.h>
When compiling with GLib older than 2.80.x, we provide a compatibility
backport of g_closefrom() and g_fdwalk_set_cloexec(), but when compiling
with newer GLib, we rely on GLib to provide those.

The intended scope of libglnx (Linux only) is narrower than the scope
of `<glib-unix.h>` (any Unix platform), so we can safely include
`<glib-unix.h>` unconditionally. This provides least-astonishment by
having `#include <libglnx.h>` with newer GLib always provide a superset
of the functionality it provides with older GLib.

This would have avoided needing
https://github.com/flatpak/flatpak/pull/5737.

Fixes: 6ada39c3 "backports: Add a backport of g_closefrom(), g_fdwalk_set_cloexec()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-13 14:55:37 +01:00
Simon McVittie
b38235ac2d Merge branch 'wip/smcv/issue4' into 'master'
build: Fix function detection when using -Werror=return-type

Closes #4

See merge request GNOME/libglnx!57
2024-04-20 14:59:03 +00:00
Simon McVittie
d56b85b61c Merge branch 'wip/smcv/pid-format' into 'master'
backports: Add a fallback definition for G_PID_FORMAT

See merge request GNOME/libglnx!55
2024-04-19 09:45:44 +00:00
Simon McVittie
ed4c1fbbc4 Merge branch 'wip/smcv/g-steal-fd-old-glib' into 'master'
backports: Avoid warnings for g_steal_fd when targeting older GLib

See merge request GNOME/libglnx!56
2024-04-19 09:45:29 +00:00
Simon McVittie
284b75d31b build: Fix function detection when using -Werror=return-type
Recent versions of openSUSE default to using -Werror=return-type for
package builds, which results in all of these function checks
incorrectly detecting the function as not being available.

Co-authored-by: Peng Yi
Resolves: https://gitlab.gnome.org/GNOME/libglnx/-/issues/4
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-04-19 10:29:07 +01:00
Simon McVittie
e31547a6e0 backports: Avoid warnings for g_steal_fd when targeting older GLib
flatpak-builder does this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-07 10:41:09 +00:00
Simon McVittie
f57d443926 backports: Add a fallback definition for G_PID_FORMAT
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-22 12:45:22 +00:00
Colin Walters
202b294e60 Merge branch 'wip/smcv/closefrom' into 'master'
Fixes for g_closefrom() backport

See merge request GNOME/libglnx!54
2024-02-09 21:00:45 +00:00
Simon McVittie
e4beedc0f6 backports: Use glnx-missing.h to provide missing syscalls
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 16:54:27 +00:00
Simon McVittie
1e6efc7846 missing: Add flags for close_range()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 16:54:24 +00:00
Simon McVittie
debdea2907 missing: Add a wrapper for close_range()
This is not the same as systemd's, because systemd's disagrees
with glibc on the signedness of the arguments
(https://github.com/systemd/systemd/issues/31270).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 16:54:14 +00:00
Simon McVittie
9d66aa7375 missing: Add syscall number for close_range()
Taken from systemd, but replacing assert_cc with G_STATIC_ASSERT.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 16:54:03 +00:00
Simon McVittie
f2ff19d7c8 build: Really check for close_range() as intended
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 16:50:04 +00:00
Colin Walters
c2c6c9502a Merge branch 'wip/smcv/closefrom' into 'master'
backports: Add a backport of g_closefrom(), g_fdwalk_set_cloexec()

See merge request GNOME/libglnx!53
2024-02-09 15:43:34 +00:00
Simon McVittie
6ada39c384 backports: Add a backport of g_closefrom(), g_fdwalk_set_cloexec()
These will be new API in GLib 2.79.2.

The only code change in the implementation, other than the _glnx
wrappers, was to use `close()` instead of `g_close (fd, NULL)` in a
context where it must be async-signal safe.

The test-case needed some more adjustments to be backwards-compatible
with GLib from the distant past.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 15:29:52 +00:00
Colin Walters
b415d04688 Merge branch 'pr/fix-lsetxattrat' into 'master'
glnx-xattrs: Fix invalid argument to lsetxattr()

See merge request GNOME/libglnx!52
2024-01-10 16:12:28 +00:00
Jonathan Lebon
79b809ae68 glnx-xattrs: Fix invalid argument to lsetxattr()
We weren't passing the right path argument here.

This bug would've been quickly noticed if the function were actually
used but I still did at least a global GitHub search which didn't return
any users.
2024-01-09 16:48:32 -05:00
Simon McVittie
c1e954e82a Merge branch 'build-testing-helper' into 'master'
build: Make tests depend on the helper required by one of them

See merge request GNOME/libglnx!51
2023-12-14 17:07:20 +00:00
Andre Klapper
aff1eea9b6 DOAP: Replace non-existing d-d-l mailing list with GNOME Discourse URL 2023-09-18 11:06:20 +02:00
Simon McVittie
1bd99c1b51 build: Make tests depend on the helper required by one of them
This allows doing:

    meson setup _build
    meson test -C _build

without an intervening `meson compile` step. Previously, this would have
failed in `tests/testing` because `testing-helper` was never compiled.

For a project this small, there's no real need to distinguish precisely
which tests need the helper: we can have a simpler build by just
assuming that they all do, like Autotools would.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-29 19:51:50 +01:00
Simon McVittie
54ad67db3f Merge branch 'wip/smcv/disable-crash-reporting' into 'master'
testutils: Add a backport of g_test_disable_crash_reporting()

See merge request GNOME/libglnx!50
2023-08-29 18:47:47 +00:00
Simon McVittie
c02eb59916 Merge branch 'wip/denittis/strv_equal' into 'master'
backports: Add g_strv_equal from GLib >= 2.60

See merge request GNOME/libglnx!48
2023-07-28 13:55:34 +00:00
Simon McVittie
30b89b830d testutils: Add a backport of g_test_disable_crash_reporting()
When testing something that is expected to fail or crash, it's useful
to disable core dump reporting.

This is a slightly simplified version of GNOME/glib!3510: because
libglnx isn't portable to non-Linux, we can assume that <sys/prctl.h>,
prctl() and <sys/resource.h> are always available, so we don't need
to check for them in the build system.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-28 14:50:13 +01:00
Ludovico de Nittis
52f66d482b backports: Add g_strv_equal from GLib >= 2.60
This is a very useful utility function that allows you to compare two
strings arrays.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2023-03-01 09:42:00 +01:00
Will Thompson
07e3e49d3e Merge branch 'wip/smcv/steal-fd' into 'master'
backports: Add g_steal_fd, from GLib >= 2.70

See merge request GNOME/libglnx!47
2023-02-27 11:24:28 +00:00
Simon McVittie
ea18312ed0 backports: Add g_steal_fd, from GLib >= 2.70
This is essentially the same as glnx_steal_fd, so make glnx_steal_fd an
alias for it.

The unit test is taken from GLib, slightly modified to avoid g_close()
and also test the old name glnx_steal_fd().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-08 11:17:41 +00:00
Colin Walters
4e44fd9c17 Merge branch 'wip/smcv/memdup2' into 'master'
backports: Add a backport of g_memdup2()

See merge request GNOME/libglnx!46
2022-11-01 20:33:37 +00:00
Simon McVittie
5275410e6c tests: Add a simple test for g_memdup2, from GLib
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-28 12:07:45 +01:00
Simon McVittie
8a29325374 backports: Add a backport of g_memdup2()
g_memdup2() replaces g_memdup(), which is prone to integer overflow on
64-bit systems if copying a very large object with an
attacker-controlled size.

The original version in GLib is extern, but it seems simple enough to
inline a backport.

Related: https://gitlab.gnome.org/GNOME/glib/-/issues/2319
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-28 12:07:45 +01:00