Commit Graph

318 Commits

Author SHA1 Message Date
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
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
Simon McVittie
e701578c6f Merge branch 'wip/smcv/assert-true-false' into 'master'
backport-testutils: Add g_assert_true(), g_assert_false()

See merge request GNOME/libglnx!44
2022-10-10 18:29:50 +00:00
Will Thompson
2290411e93 Merge branch 'wip/smcv/strtok-r' into 'master'
tests: Ensure saveptr is NULL before first call to strtok_r()

See merge request GNOME/libglnx!45
2022-10-10 15:34:53 +00:00
Simon McVittie
416744a265 tests: Ensure saveptr is NULL before first call to strtok_r()
The standards-conformant behaviour is that the contents of saveptr
are ignored when the first argument is non-NULL, but the man page notes
that some older implementations required saveptr to be NULL in that
situation, and the gcc 4.8 provided by the Steam Runtime warns about this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-10 15:35:11 +01:00
Simon McVittie
a91959e0d4 backport-testutils: Add g_assert_true(), g_assert_false()
These were only added in 2.38, and some projects with particularly
ancient dependencies (like the Steam Runtime, based on a 2012 version
of Ubuntu) still avoid depending on that version.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-10 15:27:56 +01:00
Will Thompson
8f2e676d9b Merge branch 'wip/smcv/warnings' into 'master'
build: Explicitly disable warnings for non-ISO C features

See merge request GNOME/libglnx!42
2022-10-10 13:43:00 +00:00
Simon McVittie
f1e85346d2 Merge branch 'wip/smcv/2-74-constants' into 'master'
backports: Backport new NONE/DEFAULT constants from GLib 2.74

See merge request GNOME/libglnx!39
2022-10-10 13:40:37 +00:00
Simon McVittie
15070ab54e Merge branch 'wip/smcv/null-option-entry-ifndef' into 'master'
backports: Use #ifndef instead of GLIB_CHECK_VERSION

See merge request GNOME/libglnx!43
2022-10-10 13:39:54 +00:00
Simon McVittie
5bb5b7c71e backports: Backport new NONE/DEFAULT constants from GLib 2.74
These enums were not originally defined with a zero-valued constant
(or in the case of GApplicationFlags, the constant always existed but
its name was inappropriate for GObject-Introspection), and the
corresponding constants were added in GLib 2.74 to make them more
self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-10 14:38:25 +01:00
Simon McVittie
2e46d5b145 Merge branch 'wip/smcv/testing-helpers' into 'master'
Backport g_test_skip_printf(), etc.

See merge request GNOME/libglnx!38
2022-10-10 13:36:44 +00:00
Simon McVittie
cdef2bb414 backports: Use #ifndef instead of GLIB_CHECK_VERSION
As Will Thompson pointed out on !37, G_OPTION_ENTRY_NULL is a macro in
GLib, so we can test for it with `#ifndef` rather than a version guard.
This is a little bit nicer for parent projects that might already have
their own backport of it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-10 14:34:25 +01:00
Simon McVittie
0b5d4a079b Merge branch 'wip/smcv/g-info' into 'master'
backports: Backport g_info()

See merge request GNOME/libglnx!40
2022-10-10 13:30:41 +00:00
Simon McVittie
5e072816e8 Merge branch 'wip/smcv/easy-constants' into 'master'
Add backports of straightforward constants

See merge request GNOME/libglnx!37
2022-10-10 13:30:24 +00:00
Simon McVittie
45108f1852 build: Explicitly disable warnings for non-ISO C features
libglnx is intentionally not portable to non-Unix platforms or to
compilers that do not implement gcc/clang extensions, so it's
counterproductive to warn about these extensions, even if libglnx is used
by a parent project that generally (for the parts that don't use
libglnx) wants to be portable to any ISO C compiler.

Suggested by Will Thompson on !36.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-10 14:09:29 +01:00
Simon McVittie
f780507d5b Merge branch 'wip/smcv/warnings' into 'master'
build: Reduce default warning level from 3 to 2

See merge request GNOME/libglnx!36
2022-10-10 13:01:03 +00:00
Simon McVittie
c52b73d4ae Backport most of the test convenience helpers from GLib's GTest
This includes a test (who tests the tests themselves?). Run
as `${build}/tests/testing --tap` with semi-modern GLib, or
`${build}/tests/testing --verbose` with GLib < 2.38, to check that the
output is as reasonable as possible given the limitations of the GLib
version in use.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:59:24 +01:00
Simon McVittie
5a60c0bca5 Move assertion/test utilities to a separate header
A lot of recent convenience APIs can easily be backported, but they'll
clutter glnx-backports.h. In preparation, split these out.

Another reason to separate these is that when we start adding backports
of test utilities that need implementation code in the libglnx static
library, we'll want their implementations to be in a separate
translation unit, so that they don't get linked into production
executables, only into tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:56:36 +01:00
Simon McVittie
9a0e6fd004 testlib: Be compatible with ancient GLib by using glnx_close_fd
This is an enabler for testing a backport of GTest helpers
(g_test_skip(), etc.) in the oldest environment that I have conveniently
available (Steam Runtime 1 'scout' with GLib 2.32).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:56:30 +01:00
Simon McVittie
29681b4b77 backports: Backport G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED
These are convenient for the same reasons as G_SOURCE_REMOVE and
G_SOURCE_CONTINUE.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-19 10:55:12 +01:00
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
Simon McVittie
c5e1b295bc backports: Backport g_info()
The rest of the g_log() wrappers have been there since time immemorial,
but g_info() was initially omitted. It's useful for projects like Flatpak
that want to have two levels of off-by-default logging, which map nicely
to info and debug.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-27 16:37:57 +01:00
Simon McVittie
af02572e6b build: Reduce default warning level from 3 to 2
Warning level 2 is -Wall -Wextra, and warning level 3 adds -Wpedantic
(warnings about use of non-ISO extensions). libglnx is intentionally
using non-ISO features, so -Wpedantic is counterproductive.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-27 13:57:19 +01: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