Commit Graph

8899 Commits

Author SHA1 Message Date
Philip Withnall
954b15218c Merge branch 'mcatanzaro/l10n-time' into 'main'
gsettingsschema: fix l10n=time attribute

Closes #2575

See merge request GNOME/glib!2422
2023-08-16 13:24:18 +00:00
André
9a6ca0ef75
gdbus-codegen: preserve relative indentation in doc comments
This commit also changes the generators for rst, xml and dockbook
to preserve indentation.

Closes #3032
2023-08-14 23:46:09 -03:00
Philip Withnall
c00d7999b1 Merge branch 'th/use-getservbyname-r' into 'main'
gnetworkaddress: use reentrant getservbyname_r() if available

See merge request GNOME/glib!3526
2023-08-14 09:24:51 +00:00
Thomas Haller
f738c7f3db gio: use reentrant getservbyname_r() if available 2023-08-14 09:32:43 +01:00
Thomas Haller
8aa889dbf1 gio: include missing dependency in "gio/gnetworkingprivate.h"
Otherwise, GResolver typedef is unknown.
2023-08-14 09:32:43 +01:00
Thomas Haller
adb3763592 tests: add case for getservbyname() during g_network_address_parse()
Add test cases that result in lookup of the port via
getservbyname().

As the result depends on "/etc/services", it's not reliably the same on
every system. It requires a workaround.
2023-08-14 09:32:43 +01:00
Philip Withnall
065069191c tests: Disable use of ptrace() in tests on BSD and macOS
Commit cf55c31170 added a new test which
uses `ptrace()` to check some `GSubprocess` behaviour. FreeBSD uses
different symbol names for ptrace symbols, and we haven’t tested whether
the test works (and reproduces the failure) on FreeBSD, so skip the test
for now.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-08-14 09:27:07 +01:00
Philip Withnall
73d2658191 Merge branch 'thread-safe-menus_get_interface' into 'main'
gmenuexporter: synchronization in org_gtk_Menus_get_interface.

Closes #3051

See merge request GNOME/glib!3529
2023-08-13 14:21:15 +00:00
Philip Withnall
3ee019c036 Merge branch 'gio-tool-info-translator-comments' into 'main'
gio-tool-info: Move translator comments so they’re visible

See merge request GNOME/glib!3528
2023-08-13 14:18:58 +00:00
André
5fb89dd597
gmenuexporter: synchronization in org_gtk_Menus_get_interface.
Protects the mutation inside org_gtk_Menus_get_interface with
g_once_init_{enter,leave}.

Fixes #3051.
2023-08-13 01:21:49 -03:00
Philip Withnall
65e7a10d2a Merge branch 'macos_ci' into 'main'
interim solution for macOS CI

See merge request GNOME/glib!3503
2023-08-12 22:52:57 +00:00
Philip Withnall
faee7d0858 gio-tool-info: Move translator comments so they’re visible
The tooling won’t pick them up unless they’re directly above the gettext
calls.

Spotted by Piotr Drąg in
ec03755355 (note_1808152).

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-08-12 20:01:36 +01:00
Jonas Ådahl
cf55c31170 gio/tests: Add test case for exit status when being ptraced
The test case will fail with the

    g_assert_false (g_subprocess_get_successful (proc));

assert failing. Without the fix, it'll hit sometimes, but rather
unreliably. When running `meson test --repeat 100`, it'll reproduce
anywhere between the first or much later, but mostly before the 20th
iteration on my system.

Helps: #3071
2023-08-12 19:30:00 +01:00
René de Hesselle
439204ed7d Re-enable macOS CI on a new self-hosted runner
Allow two more tests to fail on macOS for the time being:
https://gitlab.gnome.org/GNOME/glib/-/issues/3069
https://gitlab.gnome.org/GNOME/glib/-/issues/3070
2023-08-11 19:33:19 +02:00
Michael Catanzaro
306d4567d2 Replace setlocale() with uselocale() in GSettings l10n tests
It's not safe to use setlocale() to mutate the locale in a threaded
program. Lots of other tests still do this, and I'm not putting in the
effort to fix them comprehensively in the absense of actual failures on
CI, but I figured it'd be good to fix the tests that I was touching.
2023-08-03 09:45:58 -05:00
Michael Catanzaro
736000e49e Remove setenv() use from GSettings l10n tests
This definitely does not do anything on Linux. I bet it's not needed on
other platforms, either. It's unsafe and may crash; there is no safe way
to mutate the environment in threaded programs.
2023-08-03 09:16:27 -05:00
Michael Catanzaro
92de7298c8 Add test for l10n="time" gschema attribute
This is a copy of the existing test_l10n, modified to use LC_TIME
instead of LC_MESSAGES. It's not safe as each call to g_setenv() or
setlocale() could cause the test to crash; there is no safe way to
change a threaded process's environment, and a threaded process's locale
can only be safely changed using uselocale(), not with setlocale().

The calls to g_setenv() are definitely not needed on Linux. I wonder
whether removing these will break the test on other platforms?

The calls to setlocale() should be replaced by a dance of
uselocale() -> duplocale() -> newlocale() -> uselocale() on Linux. But
this is not portable and this is a cross-platform test. We would have to
make the test platform-specific to do this. macOS and at least FreeBSD
provide these functions via xlocale.h, but this isn't portable.
2023-08-03 09:16:26 -05:00
Michael Catanzaro
34e4c4af77 gsettingsschema: fix l10n=time attribute
It's supposed to be possible to translate settings values using LC_TIME
rather than LC_MESSAGES to determine which translation to use, but
Sebastian Keller noticed that it's not working properly. I've
implemented his proposed solution, which is to actually temporarily
change LC_MESSAGES to match LC_TIME for just as long as necessary to
force gettext to use the desired message catalog.

Fixes #2575
2023-08-03 09:10:58 -05:00
Federico Gallo Herosa
89be3d357d
Fix typos
Fix typo in gio/gappinfo (duplicated word)
Fix typo in gio/gtlsdatabase.c (duplicated word)
Fix typo in gio/gapplication.c (duplicated word, previous words rearranged to improve readability)
Fix typo in glib/tests/gvariant.c (duplicated word)
Fix typo in glib/win_iconv.c (duplicated word)
Fix typo in gio/gschema.dtd (meaning, missing letter)
Fix typo in gio/gdbusintrospection.c (duplicated word)
Fix typo in gio/gdbusintrospection.c (duplicated word).
2023-08-01 15:33:21 -03:00
Philip Withnall
02bc1382b2 gnetworkmonitor: Expand guidelines for metered data use
Clarify how much is too much.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-07-29 15:22:15 +03:00
Philip Withnall
39864716d6 Merge branch 'fix_3050' into 'main'
Strip query sections from file: URIs

Closes #3050

See merge request GNOME/glib!3502
2023-07-28 12:52:36 +00:00
Lukáš Tyrychtr
b504cc0841 gfile: Strip query sections from file: URIs
According to https://url.spec.whatwg.org/#file-state
a file URI can have a fragment and query string, so just ignore them
and don't raise an invalid URI error.

Fixes: #3050
2023-07-28 15:04:49 +03:00
Eric van Gyzen
6b4b4cd889 Fix build race between gio subdirs and gversionmacros.h
I made the kqueue failure 100% reliable with `samu -j1` on FreeBSD,
and therefore confirmed this fixes that problem.  Issue #2929 is
an identical failure on win32, so I assume this fixes that, too,
but I haven't confirmed.

Fixes: #2929
2023-07-25 20:28:20 -05:00
Philip Withnall
9b80774ca7 Merge branch 'fileinfo-filepath' into 'main'
gfileinfo: add file_path methods for language bindings

See merge request GNOME/glib!3461
2023-07-22 05:27:12 +00:00
Jason Francis
04b683c34f gfileinfo: add file_path methods for language bindings
Including some tests by Philip Withnall.
2023-07-21 21:24:50 +01:00
Philip Withnall
b4a6343a5c Merge branch 'mcatanzaro/closure-audit' into 'main'
Audit and fix incorrect use of (closure) in glib

See merge request GNOME/glib!3287
2023-07-21 19:20:07 +00:00
Michael Catanzaro
12e48719af Fix scope annotation on g_file_move_async()
Currently the callback is invalid after the call to g_file_move_async(),
before g_file_move_finish() is called. That is no bueno.
2023-07-21 19:04:37 +01:00
Michael Catanzaro
5d738ddcfe Audit and fix incorrect use of (closure) in glib
Following Emmanuele's instructions for use of introspection annotations:

https://www.bassi.io/articles/2023/02/20/bindable-api-2023/

I have audited all uses of the (closure) annotation in glib and
determined that only a handful are correct. This commit changes almost
all of our use of (closure) annotations to conform to Emmanuele's rules.
2023-07-21 19:03:57 +01:00
Michael Catanzaro
a552bf5694 Merge branch 'revert3356' into 'main'
Revert "build/gmodule-2.0.pc: Move compiler flags from Libs to Cflags"

See merge request GNOME/glib!3504
2023-07-20 15:20:58 +00:00
Philip Withnall
2b391227e6 tests: Fix pkg-config test for multiarch binaries on multiarch systems
The test was passing fine when `bindir` was equal to `multiarch_bindir`,
but not when they differ.

For example, on a Debian system, `gio-querymodules` is installed to
`/usr/lib/x86_64-linux-gnu/glib-2.0/gio-querymodules` rather than
`/usr/bin/gio-querymodules` as it is on (say) Fedora.

This was causing the pkg-config tests to fail on Debian.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #3045
2023-07-20 13:30:34 +01:00
Harald van Dijk
6e29fbec2d
Revert "build/gmodule-2.0.pc: Move compiler flags from Libs to Cflags"
This reverts commit 004f48f4fc.

Per the discussion on #3356, this change was prompted by a
misunderstanding of ldflags/link_args, and it resulted in various other
packages using glib no longer getting symbols exported. This commit
restores the glib 2.76 behaviour.
2023-07-18 18:26:49 +01:00
Corey Berla
a1a00a3071 gdbus-codegen: Error on invalid dbus types
Introduce slightly modified (dbus specific) versions of
variant_is_signature and variant_type_string_scan in order to fail
early on bad type strings.
2023-07-12 15:33:22 -07:00
Philip Withnall
9dd477dd77 Merge branch '3039-android-statx' into 'main'
glocalfileinfo: Fix incorrect use of struct statx.st_mtimensec on Android

Closes #3039

See merge request GNOME/glib!3482
2023-07-04 16:14:33 +00:00
Marco Trevisan (Treviño)
27b7559c91 gdbus-codegen: Define only one marshaller per signature reusing across interfaces
Avoid generating more code than needed, so other than continuing using
the generic glib marshallers when possible, define once the custom ones
we need for each file we generate.

The marshallers are then re-used across all the interfaces defined
without duplicating the code size.
2023-06-30 23:40:03 +02:00
Marco Trevisan (Treviño)
23180d433e gdbus-codegen: Try to reuse default glib marshallers for simpler signals marshallers
If a signal signautre is simple enough we can just reuse the default
marshallers by simply creating a wrapper marshaller
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
c5d9004236 gdbus-codegen: Use direct-access GValue macros for marshallers and GValues
This is the same we're doing in code generated by glib-genmarshaller and
what gmarshal does internally.

Since the generated gdbus C code can be considered private too, this is
safe to do, and will allow faster access to GValue objects.
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
8943ceae6c gdbus-codegen: Generate marshallers for method handlers signals
Get rid completely of the usage of the generic marshaller in gdbus
generated code, using instead specific marshallers.

Code is not yet optimized fully since we may still have duplicated
functions to be generated.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3028
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
6de362fcae gdbus-test-codegen: Add test to check that fd lists can be passed
Add a simple implementation to check that fd-passing works when using
generated code, this is going to be useful to test special marshalling
case.
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
3d313147f0 gio/test-codegen: use valid interface name for FdPassing test
So that it can be ran for real, not only tested for generation
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
7b750972e8 meson/gio: Increase timeout for the codegen python tests
It's adding more stuff, let's ensure it wont timeout for no reason in
some platforms.

As per this mark also it as 'slow'
2023-06-30 22:59:25 +02:00
Marco Trevisan (Treviño)
1cd5c5678a gdbus-codegen: Generate signal marshallers for each interface signal
We relied on g_cclosure_marshal_generic() to easily generate signal
marshallers, but this relies on inspecting each parameter type with ffi
and this implies a performance hit, other than breaking the stack-frame
unwinder used by Linux perf and so by sysprof.

Given that we know the types we work on, it's easy enough to generate
the marshallers ourself.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/3028
2023-06-30 22:17:46 +02:00
Marco Trevisan (Treviño)
51c023f189 tests/codegen: Add checks for signal emission enums
These are checked to be correct by code compilation, but let's ensure we
also have some kind of forma check on the expected syntax.
2023-06-30 22:17:46 +02:00
Marco Trevisan (Treviño)
4b05e06e1c gdbus-codegen: Address more black cleanups 2023-06-30 22:17:46 +02:00
Marco Trevisan (Treviño)
1b345e411f meson: Add all the gdbus-codegen based tests to the proper suite
So it's easier to run them all with --suite=gdbus-codegen
2023-06-30 18:11:18 +02:00
Luca Bacci
2dc0a43bc0 glocalfileinfo: Fix GLocalFileStat getters on MinGW x86
For some reason, `time_t` is defined as being 32 bits wide on that
platform, which causes truncation of the timestamps from `struct stat`.

Avoid that problem by consistently using a 64-bit return value from the
`struct stat` accessors.

Helps: #3039
2023-06-30 15:00:56 +01:00
Marco Trevisan (Treviño)
88d48a7a22 codegen: Use g_signal_emit to emit signals
We were using emit_by_name which implies looking up for the signal name,
while the generated code can easily remember the signal ID and use it
instead, allowing direct access to the signal emission.
2023-06-29 22:20:05 +02:00
Philip Withnall
9845f880ca glocalfileinfo: Delete some redundant code
`_g_stat_has_field (statbuf, G_LOCAL_FILE_STAT_FIELD_ATIME)` will always
return `TRUE` on Windows (since it uses a basic `struct stat`), so the
platform-inspecific code is equivalent to the Windows-specific code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-28 17:49:45 +01:00
Philip Withnall
c3762deb78 glocalfileinfo: Fix incorrect use of struct statx.st_mtimensec on Android
`GLocalFileStat` is a platform-specific abstraction around `struct stat`
or `struct statx`. If `struct statx` is available, it will use that by
preference as it has more features.

`glocalfileinfo.c` was, in some places, incorrectly accessing the fields
of `GLocalFileStat` directly rather than through its `_g_stat_*()`
getters. While it correctly accounted for the platform-specific
differences between `st_mtimensec` and `st_mtim.tv_nsec`, it hadn’t been
updated to deal with `stx_mtime`.

On Android, `st_mtimensec` is defined as a fallback for
`st_mtim.tv_nsec` (even though it doesn’t need to be). This caused GLib
to take the `st_mtimensec` code path rather than the `stx_mtime` code
path, and hence try to dereference `st_mtim` in a `struct statx`.

Fix that by correctly using the `_g_stat_*()` getters consistently.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #3039
2023-06-28 17:32:25 +01:00
Philip Withnall
989b4cb8bd gapplication: Tweak option group description
To match the documented style for all option group descriptions.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #3007
2023-06-28 17:04:59 +01:00
Ondrej Holy
c083a4d1a6 gio-tool-mount: Add option to show progress when unmounting 2023-06-28 15:51:51 +00:00
N.Pranav Krishna
b963bcf8c5 Added Annotations 2023-06-27 16:49:43 +00:00
Christian Hergert
d972ba03b4 listmodel: add documentation about unique instances
This has subtly been required and the original intention, so make it more
discoverable by adding to the documentation.

Fixes #3030
2023-06-21 11:01:52 -07:00
Matthias Clasen
4171fba2fe gapplication: Clarify docs
D-Bus does not support maybe types, therefore
using such types are action parameters in
GApplication does not work.

Fixes: #3027
2023-06-10 08:04:49 -04:00
Philip Withnall
8cad32a118 Revert "tests: Temporarily disable socket test due to a kernel bug"
This reverts commit 1507585869.

This should now be fixed:
https://gitlab.gnome.org/Infrastructure/Infrastructure/-/issues/981#note_1760399.

Fixes: #2879
2023-06-07 12:29:03 +01:00
Maximiliano Sandoval R
389398d444
resolver: Add space in documentations
It is standard practice to put a space in between Returns and Since in docstrings.
2023-06-04 17:33:00 +02:00
Philip Withnall
fbc66b834e Merge branch 'mcatanzaro/#2829' into 'main'
Improve depfile generated by glib-compile-resources

Closes #2829

See merge request GNOME/glib!3460
2023-06-01 09:36:15 +00:00
Michael Catanzaro
3e3a0304f7 Improve depfile generated by glib-compile-resources
glib-compile-resources --dependency-file= currently generates a depfile
with rules that look like this:

foo.xml: resource1 resource2

This means that if any of the files listed in the GResource manifest
foo.xml change, rebuild foo.xml because foo.xml depends on those files.
This is not useful because the XML manifest is not expected to be a
generated dependency and even if it was, changes to the listed files
would not imply any need to regenerate the manifest. What we really do
need to regenerate is the C source file that is generated by
glib-compile-resources after processing the XML manifest and all the
resource files. That is, the rule should look like this:

foo.c: foo.xml resource1 resource2

as suggested by Hans Ulrich Niedermann in the issue report.

Fixes #2829
2023-05-31 14:50:21 -05:00
Jason Francis
c556a4d8f8
gfileinfo: add (type filename) annotation to symlink_target functions 2023-05-31 00:54:38 -04:00
Michael Catanzaro
cc5bb80b9a Fix failure to respect default port of proxy URLs
Currently we require explicitly specifying the port when configuring a
proxy server, which is seriously weird. I take the fact that nobody
reported a bug until 2022 to indicate that almost nobody is using
proxies. Whatever. Let's assume that if no port is provided, the default
port for the protocol should be used instead.

For example, you can now specify in GNOME settings that your proxy server
is https://example.com and it will work. Previously, you had to write
https://example.com:443. Yuck!

This was originally reported as GProxyResolver bug, but nothing is
actually wrong there. It's actually GProxyAddressEnumerator that gets
tripped up by URLs returned by GProxyResolver without a default port.
This breaks GSocketClient.

Fixing this requires exposing GUri's _default_scheme_port() function to
GIO. I considered copy/pasting it since it's not very much code, but I
figure the private call mechanism is probably not too expensive, and I
don't like code duplication.

Fixes #2832
2023-05-30 09:49:43 -05:00
Philip Withnall
1aefcf4e0e Merge branch 'ok/termux-build-issues' into 'main'
gio, tests: adaptations for building with bionic libc from termux

Closes #3008

See merge request GNOME/glib!3443
2023-05-30 13:04:17 +00:00
Philip Withnall
ad464d5563 Merge branch 'main' into 'main'
gio/tests/portal-support: Fix snap test ordering race

Closes #3020

See merge request GNOME/glib!3454
2023-05-30 12:29:06 +00:00
Philip Withnall
0196a36022 Merge branch 'more-atomic-exchange-full' into 'main'
gdataset, gobject: Use atomic compare and exchange full to set pointers

See merge request GNOME/glib!3426
2023-05-30 11:59:40 +00:00
Marco Trevisan (Treviño)
ea904fba1a gresource: Use compare and exchange full to get registered resources 2023-05-30 12:34:41 +01:00
Philip Withnall
28f83c9cf7 gresource: Ensure lazy_register_resources is always accessed atomically
On some platforms, pointer-sized reads are not necessarily atomic, so we
always need to use the correct atomic access primitives.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-30 12:33:48 +01:00
Richard Purdie
c63cf19d9a gio/tests/portal-support: Fix snap test ordering race
When the gnome test runner executes the tests, the test appear to execute in disk
order. This means it sometimes works and sometimes we see breakage in portal-support-snap
and portal-support-snap-classic.

The issue is that some tests create config files but some don't. If they run
in the wrong order, tests see config files they shouldn't and break.

Fix this by deleting the files after each test run, properly cleaning up after
themselves. The cleanup code is based upon gtestutils.c:rm_rf().

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-05-30 12:28:45 +01:00
Guido Günther
b3b23072f3 gactionmap: Add g_action_map_remove_action_entries()
Since we have a convenience method to add actions let's allow to remove
them just as easily. This makes resource cleanup as simple as initially
adding the entries.
2023-05-26 10:30:40 +01:00
Guido Günther
ac840b954f gactionmap: Move declaration of loop var in g_action_map_add_action_entries() 2023-05-25 17:45:17 +02:00
Guido Günther
596fec811d gactionmap: Check for < 0 in g_action_map_add_action_entries()
Assume that all negative values mean `NULL` terminated. Everything else
will cause a disaster anyway.
2023-05-25 17:43:09 +02:00
Philip Withnall
ecbe360a38 Merge branch '3003-glib-compile-schemas-failed' into 'main'
glib-compile-resources: Fix non-ASCII arg parsing on Windows

Closes #3003

See merge request GNOME/glib!3446
2023-05-23 17:16:27 +00:00
Daniyar Tleulin
49537e298c glib-compile-schemas: Fix non-ASCII arg parsing on Windows
When the source directory contains non-ASCII symbols,
argument parsing previously failed on MINGW64.

Fixes: #3003
2023-05-23 16:49:21 +06:00
Daniyar Tleulin
0305d237dd glib-compile-resources: Fix non-ASCII arg parsing on Windows
When the source directory contains non-ASCII symbols,
argument parsing previously failed on MINGW64.

Fixes: #3003
2023-05-23 16:48:41 +06:00
Sonny Piers
0b73d72a44 gio: Add g_file_new_build_filenamev 2023-05-23 10:14:28 +00:00
Øyvind Kolås
786f379d78 gio/tests: avoid shadowing of libc names under bionic libc
Makes the tests compile using clang with meson directly under
termux on android, this build environment does not approve of
overloading libc symbols.

Fixes: #3008

foo
2023-05-22 22:44:52 +02:00
Øyvind Kolås
3050c16aea gio: define hasmntopt ourselves under bionic libc
This is a workaround for build conditions one ends up with under termux,
where the defined __ANDROID_API__ level is lower than what is provided
by gcc installed for it, the libc .so nevertheless contains these symbols
thus enabling the codepaths. This definition is only in use when meson
detected the presence of this symbol in the libc.

Fixes #3008

foo
2023-05-22 22:44:52 +02:00
Carlos Garnacho
4641b02ca2 gio: Add test for local enumerator cancellation
Check that the enumerator is able to cancel if told so.
2023-05-19 11:53:18 +00:00
Carlos Garnacho
99571c42d5 gio: Check cancellable iterating local file enumerator
In the typical `while (g_file_enumerator_next_file ())` patterns,
there is nothing much checking whether the operation was cancelled
on the GIO side. Unless the user checks for the case, this means
local enumerators always run to completion even if cancelled.

Fix this by checking the cancellable state explicitly for local
enumerators, so there are oportunities for bailing out early if
the enumerator is going through a very large directory.
2023-05-19 11:53:18 +00:00
Thomas Haller
cdda194844 gmain: remove unnecessary initialization of *timeout in prepare() callbacks
Note that the prepare callback only has one caller, which pre-initializes
the timeout argument to -1. That may be an implementation detail and not
publicly promised, but it wouldn't make sense to do it any other way in
the caller.

Also, note that g_unix_signal_watch_prepare() and the UNIX branch of
g_child_watch_prepare() already relied on that.
2023-05-18 11:26:33 +02:00
Emmanuele Bassi
20142de034 Ignore g_task_print_alive_task() when introspecting GIO
The `__GTK_DOC_IGNORE__` check is not enough for g-ir-scanner: we need
to check for `__GI_SCANNER__` as well.
2023-05-16 13:33:19 +01:00
Philip Withnall
e02fa2ec90 gfile: Ensure loff_t is defined on FreeBSD
When `copy_file_range()` support was added, I used the definition of
`copy_file_range()` from Linux, which uses `loff_t` to abstract the
different `off*_t` types.

`loff_t` doesn’t exist on FreeBSD, so this doesn’t compile, and was
caught in subsequent asynchronous CI.

Define `loff_t` with a fallback value if it’s not defined, which should
fix this and other uses of `loff_t` in `gfile.c` (for example, if
FreeBSD ever starts declaring `splice()`).

Fixes this CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/2812302

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-15 16:22:35 +01:00
Philip Withnall
8a68b795c1 tests: Fix GIO file size tests as .desktop files have changed size
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-10 09:26:47 +01:00
Arnaud Rebillout
f722f11e57 Rename GTK+ to GTK (mostly comments and documentation)
GTK lost it's '+' suffix back in 2019, according to
<https://mail.gnome.org/archives/gtk-devel-list/2019-February/msg00000.html>

This commit can be re-generated with:

    git grep -l GTK+ \
    | grep -v -e ^NEWS -e ^glib/tests/collate.c \
    | xargs sed -i 's/GTK+/GTK/g'

Most of the changes are in comments and documentation.
2023-05-10 10:56:44 +07:00
Philip Withnall
0e5d9fd249 gfile: Support copy_file_range() for file copies
While it can’t be used in all situations, it is a little bit faster than
`splice()` in some situations, basically if the file system supports
copy on write. In other situations it’s no slower than `splice()`.

See `man copy_file_range` for the situations where it doesn’t work. In
all of these situations, it will return an error, and the GLib code will
fall through and try the existing `splice()` copy code instead.

From my testing of `time gio copy A B` with a 9GB file, the `splice()`
code path takes 22s, and the `copy_file_range()` code path takes 20s.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2863
2023-05-09 14:01:50 +01:00
Philip Withnall
aafa19fc0d tests: Add a test for progress callbacks from g_file_copy()
This wasn’t previously tested.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2863
2023-05-09 14:01:48 +01:00
Philip Withnall
0da948a5d1 gfile: Eliminate a stat() call from the file copy code
The start of the `g_file_copy()` implementation stats the source file to
find all the attributes to copy onto the destination file, so it makes
sense to get it to store the source file size at the same time.

This saves a subsequent `stat()` call on the source FD in the btrfs
reflink or splice code. Every little helps.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-09 13:53:44 +01:00
Philip Withnall
63e1e83c33 Merge branch 'wip/p3732/timeout-seconds-once' into 'main'
add g_timeout_add_seconds_once

See merge request GNOME/glib!3383
2023-05-09 12:50:39 +00:00
Philip Withnall
e59e8ebf31 gwin32networkmonitor: Fix returning address of local variable
Something has changed recently which causes this error to now be emitted
when building on Windows msys2-mingw32:
```
../gio/gwin32networkmonitor.c: In function 'win_network_monitor_get_ip_info':
../gio/gwin32networkmonitor.c:92:15: error: storing the address of local variable 'prefix' in '*dest' [-Werror=dangling-pointer=]
   92 |         *dest = (guint8 *) &prefix.Prefix.Ipv4.sin_addr;
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

If `IP_ADDRESS_PREFIX` is defined as a scalar rather than a pointer,
that could explain the problem.

Change the function to always operate on a pointer to avoid any
potential such issues.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-09 12:52:42 +01:00
Peter Eisenmann
e25a4f995f use g_timeout_add_seconds_once()
Use the newly added g_timeout_add_seconds_once() where appropriate.
2023-05-02 13:42:54 +02:00
Philip Withnall
1f044e1cbd Merge branch '2855-test-socket-rename' into 'main'
Rename confusing socket test filenames

Closes #2855

See merge request GNOME/glib!3415
2023-05-02 09:38:25 +00:00
Mike Salmela
dea11643a9 Rename confusing socket test filenames
The gio/tests/socket-client.c doesn't use GSocketClient, which makes the
filename confusing. What the file actually tests is the GSocket. Rename
it to socket-testclient.c
The corresponding GSocket server test file naming doesn't conflict with other
class names, but rename it to socket-testserver.c for consistency.

Closes #2855
2023-04-29 21:48:03 +03:00
Philip Withnall
b38ddf5087 gregistrysettingsbackend: Remove translatable pspec nick/blurb
The file was not listed in `POTFILES.in` (as pointed out by Piotr Drąg
in
fee0a7679a (note_1722885)),
so either it needs to be added to `POTFILES.in` or the translatable
strings need to be removed.

Recent prior art from GTK shows that there’s actually no longer any
point in setting the nick/blurb as no tools use them (and if they did,
it would result in a rubbish user experience). See
https://gitlab.gnome.org/GNOME/gtk/-/issues/4904.

Hence, drop the strings entirely.

See #2991 for tracking this across all of GIO.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2991
2023-04-27 23:33:47 +01:00
Philip Withnall
865cbe3714 gthreadedresolver: Remove some incorrect assertions
If a timeout executes on the same main context iteration as completion
or cancellation of a resolver lookup, `has_returned` will be set
multiple times. That’s fine (the `GCond` will be notified multiple
times, but that’s fine). It was triggering an incorrect assertion, so
remove that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 14:41:26 +01:00
Philip Withnall
7922d3200c Merge branch 'resolver-thread-pool' into 'main'
gthreadedresolver: Switch to using a separate thread pool and support timeouts

See merge request GNOME/glib!3397
2023-04-27 12:46:53 +00:00
Philip Withnall
6c1cbdff63 Merge branch 'task-tracking' into 'main'
gtask: Track pending GTasks if G_ENABLE_DEBUG is defined

See merge request GNOME/glib!3404
2023-04-27 12:46:37 +00:00
Philip Withnall
d231ce0364 Merge branch '2951-reinstate-fileinfo-criticals' into 'main'
Revert "gfileinfo: Temporarily downgrade missing attribute criticals to debugs"

Closes #2951

See merge request GNOME/glib!3379
2023-04-27 11:27:43 +00:00
Philip Withnall
e73c5ed5e1 gresolver: Set timeout on default resolver to 30s
The default for the class is still to have no timeout, but it seems more
practical for most use cases to set a non-infinite timeout on the
default resolver.

If applications have a more specific use case, they can change the
timeout or replace the default resolver.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3397#note_1731387

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
1c4384aec5 tests: Fix cancellation source handling in resolver manual test
If `async_cancel()` was invoked, it would remove the IO watch source,
which would cause the `g_source_remove()` call at the end of `main()` to
warn about an unknown source ID.

Fix that by handling the source as a pointer instead of a handle.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
2ac66413a4 tests: Support --timeout argument in resolver manual test
For testing timeouts.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
ef08e8dd81 gthreadedresolver: Document design of GThreadedResolver
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
c3209f1d84 gthreadedresolver: Re-add cancellation and add timeout support
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
7b18e6205a gthreadedresolver: Switch to using a separate thread pool
Rather than running lookups in the global shared thread pool belonging
to `GTask`, run them in a private thread pool.

This is needed because the global shared thread pool is constrained to
only 14 threads. If there are 14 ongoing calls to
`g_task_run_in_thread()` from any library/code in the process, and then
one of them asks to do a DNS lookup, the lookup will block forever.

Under certain circumstances, particularly where there are a couple of
deep chains of dependent tasks running with `g_task_run_in_thread()`,
this can livelock the program.

Since `GResolver` is likely to be called as a frequent leaf call in
certain workloads, and in particular there are likely to be several
lookups requested at the same time, it makes sense to move resolver
lookups to a private thread pool.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
84074ce757 gthreadedresolver: Centralise GTask return handling in worker threads
This will make it simpler to handle timeouts and cancellation in future,
as all the logic for working out whether to return will all be in one
place, and all the lookup-specific code is now implemented in simple
sync functions which don’t need to care about `GTask`s.

This commit introduces no functional changes, it’s just setting up for
the following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
694394207c gthreadedresolver: Combine closure structs for different lookup types
This introduces no functional changes, but will make a reorganisation of
the code simpler in the next commit.

Rather than dealing with three different closure types, this changes the
code to deal with one which is a tagged union of the three.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
6e499764e4 gthreadedresolver: Port to G_DECLARE_FINAL_TYPE
The class and its header are not public, so this should not be an API or
ABI break.

This just simplifies the code a little and allows for easy extension of
the object’s private data in future commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:23:25 +01:00
Philip Withnall
bf92bae481 gresolver: Add GResolver:timeout property
Without a timeout, some lookup requests can go on forever, typically due
to bugs in underlying systems.

This can have particularly significant effects on the Happy Eyeballs
algorithm in `GSocketClient`, which relies on multiple name lookups as
its first step.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2866
2023-04-27 12:23:25 +01:00
Philip Withnall
06eecda823 gtask: Track pending GTasks if G_ENABLE_DEBUG is defined
Track the `GTask`s which are still alive (not finalised) in a shared
list, and provide a secret debugging function for printing that list.

Too often when debugging apps, I have found that a ‘leaked’ object is
actually still (validly) referenced by an ongoing `GTask` which hasn’t
completed for whatever reason. Or I have found that an operation has
obviously stalled, but there are no pointers available to the `GTask`
which is stalled, because it’s being tracked as a collection of closure
pointers from some `GSource` which is hard to get to in the debugger.

It will be very useful for debugging apps, if there’s a list of all the
still alive `GTask`s somewhere. This is that list.

The code is disabled if `G_ENABLE_DEBUG` is not defined, to avoid every
`GTask` construction/finalisation imposing a global locking penalty.

To use the new list, break in `gdb` while running your app, and call
`g_task_print_alive_tasks()`, or inspect the `task_list` manually:
```
(gdb) print g_task_print_alive_tasks()
16:44:17:788 GLib-GIO 5 GTasks still alive:
 • GTask 0x6100000ac740, gs_plugin_appstream_setup_async, ref count: 1, ever_returned: 0, completed: 0
 • GTask 0x6100000bf940, [gio] D-Bus read, ref count: 2, ever_returned: 0, completed: 0
 • GTask 0x6100000aac40, gs_plugin_loader_setup_async, ref count: 1, ever_returned: 0, completed: 0
 • GTask 0x61000006d940, gs_plugin_loader_job_process_async GsPluginJobRefine, ref count: 1, ever_returned: 0, completed: 0
 • GTask 0x610000118c40, [gio] D-Bus read, ref count: 2, ever_returned: 0, completed: 0
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 12:22:05 +01:00
Philip Withnall
8d527919b4 Merge branch 'update-errfmt-in-gunixconnection-part3' into 'main'
restore error messages in gunixconnection while maintaining older compiler support

See merge request GNOME/glib!3400
2023-04-26 16:27:34 +00:00
James Knight
55e93a8278 gio: switch gunixconnection ngettext with g_dngettext calls
This commit changes the use of `ngettext` with `g_dngettext`. The
project defined `g_dngettext` (with domain support) provides the same
functionality as `ngettext` with a NULL domain provided. The purpose of
this change is to help address a build error for certain compilers that
trigger a `format-nonliteral` error-promoted-warning when using
`ngettext` (see also [1][2]). The benefit of switching to use
`g_dngettext` is that the function is defined with `G_GNUC_FORMAT`. This
provides a hint to GNU GCC compilers to still sanity check these
arguments, but not generate a `format-nonliteral`.

[1]: 4ae8606b6f
[2]: 0ca660315a

Signed-off-by: James Knight <james.d.knight@live.com>
2023-04-25 23:25:38 -04:00
James Knight
0ca660315a Revert "Fix error format in gio/gunixconnection.c (part 2)"
This reverts commit 4ae8606b6f. The idea
for the change [1] was to address a build error for certain compilers
that trigger a `format-nonliteral` error-promoted-warning since these
compilers do not gracefully support `ngettext` usage. The changes
following a pattern from an old commit [2]; however, James Hilliard has
pointed out these changes do not work as intended. A deeper inspection
of the commit showed that the commit was from an old merge request that
was not pulled in, detailing why the changes did not work (see also
[3][4]).

Manipulating the sockets unit test confirms that the format values no
longer get a proper value:

    ...
    ok 9 /socket/address
    ok 10 /socket/unix-from-fd
    ok 11 /socket/unix-connection
    **
    GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting one fd, but got %d
     (g-io-error-quark, 0)
    ...

And reverting this change restores the original functionality:

    ...
    ok 9 /socket/address
    ok 10 /socket/unix-from-fd
    ok 11 /socket/unix-connection
    **
    GLib-GIO:ERROR:../gio/tests/socket.c:1493:test_unix_connection_ancillary_data: assertion failed (err == NULL): Expecting 1 control message, got 0 (g-io-error-quark, 0)
    ...

[1]: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3390
[2]: 44b3d5d80445234041f6c59feb89645f7102c3a4
[3]: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/770
[4]: https://gitlab.gnome.org/GNOME/glib/-/issues/1744

Signed-off-by: James Knight <james.d.knight@live.com>
2023-04-25 23:21:58 -04:00
Philip Withnall
c256af1c2d gthreadedresolver: Add some additional debug prints
These make it a bit easier to track the ongoing resolver tasks, as the
tasks and/or their closures are not tracked in a big list somewhere.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-25 15:35:54 +01:00
Philip Withnall
885eb1d8e5 gtask: Document that g_task_run_in_thread() uses a shared resource
It’s a bad idea to use it without some care for how much it’s being
called in parallel, or dependencies between tasks. If the thread pool
gets exhausted by too many inter-dependent calls to
`g_task_run_in_thread()` then the process will livelock.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-25 15:29:55 +01:00
Marco Trevisan
9308f2c353 Merge branch 'wip/3v1n0/gio-gmodule-visibility-dep' into 'main'
gmodule: Define a gmodule include dependency and use it in gio modules

Closes #2982

See merge request GNOME/glib!3386
2023-04-21 13:58:50 +00:00
James Knight
4ae8606b6f Fix error format in gio/gunixconnection.c (part 2)
Update a series of error messages to use `g_set_error_literal` instead
of `g_set_error`. This should prevent `format-nonliteral` compiler
issues when `-Werror` is configured:

    ../gio/gunixconnection.c: In function ‘g_unix_connection_receive_fd’:
    ../gio/gunixconnection.c:183:9: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
      183 |         nscm);
          |         ^~~~
    ../gio/gunixconnection.c:217:20: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
      217 |                    nfd);
          |                    ^~~
    ../gio/gunixconnection.c: In function ‘g_unix_connection_receive_credentials’:
    ../gio/gunixconnection.c:601:24: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
      601 |                        nscm);
          |                        ^~~~

This is similar to a previous change [1] made to `gunixconnection.c`.

[1]: 44b3d5d80445234041f6c59feb89645f7102c3a4

Signed-off-by: James Knight <james.d.knight@live.com>
2023-04-20 23:41:32 -04:00
Emmanuele Bassi
b8466bb54d Merge branch 'wip/3v1n0/macos-add-desktop-app-info' into 'main'
appmonitor: Skip the test under OSX

See merge request GNOME/glib!3388
2023-04-20 16:52:45 +00:00
Marco Trevisan (Treviño)
d296e94559 appmonitor: Skip the test under OSX
Since commit c0ca3f99 this test is strictly depending on GDesktopAppInfo
that is not defined or available in macos, so skip the test as we do for
windows.

We could have done this at meson level too, but keeping it this way is
probably a better reminder that this should be adapted for such scenario
one day™

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2753753
2023-04-20 16:37:32 +02:00
Marco Trevisan
9f3c4ec940 Merge branch 'old-mac-sdk' into 'main'
gio: fix build on older macOS SDKs

See merge request GNOME/glib!3385
2023-04-20 13:12:06 +00:00
Peter Williams
bb19523a0a gio: fix build on older macOS SDKs
The merge request !2848 added code to automatically detect the module
prefix on macOS, with a test for the Mac #define TARGET_OS_OSX. However,
older versions of the SDK (at least 10.11) don't provide this #define,
leading to build failure. If the #define is missing, fall back to
checking TARGET_OS_MAC. On newer SDKs this symbol is also true for
watchOS, etc., but in those situations TARGET_OS_OSX is available.
2023-04-20 08:54:23 -04:00
Marco Trevisan
aa72638301 Merge branch 'fix-gsocket-receive-from-annotation' into 'main'
gsocket: Explicitly mark size parameter as (in)

See merge request GNOME/glib!3382
2023-04-19 19:19:41 +00:00
Marco Trevisan (Treviño)
fe38a02c62 gmodule: Define a gmodule include dependency and use it in gio modules
Various gio modules include gmodule.h that requires the
gmodule-visibility.h to be already built.

To make this easier, just provide a dependency and use it where we are
building modules that do not depend on libgio_dep (that already includes
that).

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2982
2023-04-19 21:10:29 +02:00
Marco Trevisan
9f111c3416 Merge branch 'valgrind-variable' into 'main'
meson: Add glib_valgrind_suppressions variable to glib pkg-config file

See merge request GNOME/glib!3361
2023-04-17 12:52:28 +00:00
Marco Trevisan (Treviño)
c2e46b3789 meson: cleanup pkg-config variables definitions
Use more readable and shorter syntax
2023-04-17 14:25:52 +02:00
Marco Trevisan (Treviño)
ade79bcb50 meson: Add tests for generated pkg-config files
Ensure things are generated as we expect and avoid we regress on that.
2023-04-17 14:25:52 +02:00
badcel
f510fa0227
gsocket: Explicitly mark size parameter as (in)
The generated gir file marks the size parameter as "out" by default. This is wrong in the context of a caller allocated buffer with a given size. Explicitly marking the size parameter as (in) fixes the issue.
2023-04-15 22:53:05 +02:00
Philip Withnall
da35056247 Merge branch 'registry-settings-root-key' into 'main'
gregistrysettingsbackend: Allow a different root key path

See merge request GNOME/glib!3306
2023-04-14 17:00:01 +00:00
Dario Saccavino
fee0a7679a gregistrysettingsbackend: Allow a different root key path 2023-04-14 17:00:01 +00:00
Philip Withnall
01d5b41afa Revert "gfileinfo: Temporarily downgrade missing attribute criticals to debugs"
This reverts commit 4cad66580b.

Downgrading the criticals was only temporary. Now we’ve branched for
GLib 2.78, the criticals can be reinstated early this cycle, so people
have the maximum time to fix latent bugs in their code.

Fixes: #2951
2023-04-14 17:55:37 +01:00
Philip Withnall
cd118f9af0 Merge branch 'action-group-query-action' into 'main'
actiongroup: Add a compiler warning

See merge request GNOME/glib!3367
2023-04-14 16:32:54 +00:00
Philip Withnall
f2f322005d Merge branch 'update-annotations' into 'main'
Explicitly mark size parameter as (in)

See merge request GNOME/glib!3371
2023-04-14 15:55:38 +00:00
Philip Withnall
58cb296416 Merge branch 'feature/sum_apparent_size_only_for_files_and_symlinks' into 'main'
Align `G_FILE_MEASURE_APPARENT_SIZE` behaviour with `du` from GNU coreutils 9.2

Closes #2965

See merge request GNOME/glib!3358
2023-04-14 15:54:19 +00:00
Philip Withnall
11bdd6fcc4 Merge branch 'wip/jtojnar/wl-are-compiler-flags' into 'main'
build/gmodule-2.0.pc: Move compiler flags from Libs to Cflags

See merge request GNOME/glib!3356
2023-04-14 15:52:56 +00:00
Philip Withnall
088e2a4f5a Merge branch 'socket-nonblock' into 'main'
gsocket/inotify/gwakeup: Use SOCK_NONBLOCK and O_NONBLOCK to avoid fcntl() syscalls where possible

See merge request GNOME/glib!3347
2023-04-14 15:49:52 +00:00
Philip Withnall
1ebfe32c06 Merge branch 'gio-tool-info-strings' into 'main'
gio-tool-info: Fix a duplicate attribute name in the UI

See merge request GNOME/glib!3337
2023-04-14 15:48:43 +00:00
Philip Withnall
5611851eb9 Merge branch 'bsd-libelf-enabled' into 'main'
meson: allow -Dlibelf=enabled without pkg-config

See merge request GNOME/glib!3335
2023-04-14 15:48:20 +00:00
Philip Withnall
56bc6bcad2 Merge branch '1264-gdbus-double-unref' into 'main'
gdbusconnection: Fix double unref on timeout/cancel sending a message

Closes #1264

See merge request GNOME/glib!3291
2023-04-14 14:57:32 +00:00
Philip Withnall
0a84c182e2 gdbusconnection: Improve refcount handling of timeout source
The ref on the timeout source owned by `SendMessageData` was being
dropped just after attaching the source to the main context, leaving it
unowned in that struct. That meant the only ref on the source was held
by the `GMainContext` it was attached to.

This ref was dropped when returning `G_SOURCE_REMOVE` from
`send_message_with_reply_timeout_cb()`. Before that happens,
`send_message_data_deliver_error()` is called, which normally calls
`send_message_with_reply_cleanup()` and destroys the source.

However, if `send_message_data_deliver_error()` is called when the
message has already been delivered, calling
`send_message_with_reply_cleanup()` will be skipped. This leaves the
source pointer in `SendMessageData` dangling, which will cause problems
when `g_source_destroy()` is subsequently called on it.

I’m not sure if it’s possible in practice for this situation to occur,
but the code certainly does nothing to prevent it, and it’s easy enough
to avoid by keeping a strong ref on the source in `SendMessageData`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-04-14 15:37:21 +01:00
Philip Withnall
b84ec21f9c gdbusconnection: Rearrange refcount handling of map_method_serial_to_task
It already implicitly held a strong ref on its `GTask` values, but
didn’t have a free function set so that they would be automatically
unreffed on removal from the map.

This meant that the functions handling removals from the map,
`on_worker_closed()` (via `cancel_method_on_close()`) and
`send_message_with_reply_cleanup()` had to call unref once more than
they would otherwise.

In `send_message_with_reply_cleanup()`, this behaviour depended on
whether it was called with `remove == TRUE`. If not, it was `(transfer
none)` not `(transfer full)`. This led to bugs in its callers.

For example, this led to a direct leak in `cancel_method_on_close()`, as
it needed to remove tasks from `map_method_serial_to_task`, but called
`send_message_with_reply_cleanup(remove = FALSE)` and erroneously didn’t
call unref an additional time.

Try and simplify it all by setting a `GDestroyNotify` on
`map_method_serial_to_task`’s values, and making the refcount handling
of `send_message_with_reply_cleanup()` not be conditional on its
arguments.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-04-14 15:37:21 +01:00
Philip Withnall
08a4387678 gdbusprivate: Use G_SOURCE_REMOVE in a source callback
This is equivalent to the current behaviour, but a little clearer in its
meaning.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-04-14 15:37:21 +01:00
Philip Withnall
d7c813cf5b gdbusprivate: Improve ownership docs for write_message_async()
The ownership transfers in this code are a bit complex, so adding some
extra documentation and `g_steal_pointer()` calls should hopefully help
clarify things.

This doesn’t introduce any functional changes, just code documentation.

Another drive-by improvement in the quest for #1264.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-04-14 15:37:21 +01:00
Philip Withnall
861741ef4b gdbusprivate: Ensure data->task is cleared when it returns
The existing comment in the code was correct that `data` is freed when
the task callback is called, because `data` is also pointed to by the
`user_data` for the task, and that’s freed at the end of the callback.

So the existing code was correct to take a copy of `data->task` before
calling `g_task_return_*()`.

After calling `g_task_return_*()`, the existing code unreffed the task
(which is correct), but then didn’t clear the `data->task` pointer,
leaving `data->task` dangling. That could cause a use-after-free or a
double-unref.

Avoid that risk by explicitly clearing `data->task` before calling
`g_task_return_*()`.

After some testing, it turns out this doesn’t actually fix any bugs, but
it’s still a good robustness improvement.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-04-14 15:36:32 +01:00
Emmanuele Bassi
b94d0c2168 Merge branch '799-app-info-monitor-docs' into 'main'
gappinfo: Clarify one-shot behaviour of GAppInfoMonitor::changed in docs

Closes #799

See merge request GNOME/glib!3346
2023-04-13 21:37:36 +00:00
Emmanuele Bassi
18ae2a3d4e Merge branch '322-proxy-subclass-example' into 'main'
tests: Finish update of gdbus-example-proxy-subclass to new GDBus API

Closes #322

See merge request GNOME/glib!3332
2023-04-13 21:35:13 +00:00
badcel
a89b72389a
Explicitly mark size parameter as (in)
The generated gir file marks the size parameter as "out" by default. This is wrong in the context of a caller allocated buffer with a given size. Explicitly marking the size parameter as (in) fixes the issue.
2023-04-11 20:44:06 +02:00
Joan Bruguera
d901b55128 tests/file: Do not rely on du --bytes behaviour
As explained in the previous commit, GNU Coreutils 9.2 changes the behaviour
of `du --bytes` to only count regular files and symlinks.

The previous commit makes the test pass with GNU Coreutils >=9.2, but the
machine running the tests may have an older version, or perhaps even a
reimplementation such as uutils. So we can't rely on the size returned by `du`
to be the consistent across systems any more.

However, the plus side of the new behaviour is that the size reported by `du`
/ `G_FILE_MEASURE_APPARENT_SIZE` is now well-defined across filesystems
(as the sum of the sizes of regular files & symlinks), so we can hardcode it.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2965
2023-04-08 00:39:25 +00:00
Joan Bruguera
011fe5ebb2 glocalfile: Sum apparent size only for files and symlinks
Since GNU Coreutils 9.2 (commit 110bcd28386b1f47a4cd876098acb708fdcbbb25),
`du --apparent-size` (including `du --bytes`) no longer counts all kinds of
files (directories, FIFOs, etc.), but only those for which `st_size` in
`struct stat` is defined by POSIX, namely regular files and symlinks
(and also rarely supported memory objects).

This aligns the behaviour of GLib's `G_FILE_MEASURE_APPARENT_SIZE` flag
with the new GNU Coreutils `du` and correct POSIX use.

Note that this may be a breaking change for some uses.

Link: https://lists.gnu.org/archive/html/bug-coreutils/2023-03/msg00007.html
Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2965
2023-04-08 00:39:25 +00:00
Dan Yeaw
50851e2706 Fix multiple definition error
Fixes #2966 when compiling with GCC < 9.1 or Clang < 14.0.
2023-04-07 15:22:11 +00:00
Matthias Clasen
e03a96e934 actiongroup: Add a compiler warning
Warn when the boolean return isn't used, since we may not initialize
the out arguments in the FALSE case. Update all internal callers to
use the return value. They were already safe, but users outside GLib
may not be.
2023-04-07 08:44:29 -04:00
Marco Trevisan
9ec6695a72 Merge branch 'drop-gitignore' into 'main'
build: Drop old .gitignore files from test directories

See merge request GNOME/glib!3333
2023-04-05 14:29:13 +00:00
Marco Trevisan
66d9ab7808 Merge branch '2952-pollable-docs' into 'main'
gpollable: Clarify that can_poll() must be called before other methods

Closes #2952

See merge request GNOME/glib!3348
2023-04-05 14:27:07 +00:00
Marco Trevisan
218daa079e Merge branch '2960-debug-controller-docs' into 'main'
gdebugcontrollerdbus: Fix incorrect paragraph on auth in documentation

Closes #2960

See merge request GNOME/glib!3354
2023-04-05 14:24:50 +00:00
Luca Bacci
65e2413dd5 GWin32AppInfo: Fix g_str_has_prefix() check
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2972
2023-04-05 13:50:23 +02:00
Jan Tojnar
004f48f4fc build/gmodule-2.0.pc: Move compiler flags from Libs to Cflags
Previously, `-Wl,--export-dynamic` was in `Libs` key of `gmodule-2.0.pc`,
even though `-Wl` is a compiler flag, rather than a linker one.
This caused issues with API reference builds in evolution-data-server,
which passes the output of `pkg-config --libs` through `--ldflags`
argument of `gtkdoc-scan`, which are forwarded unchanged to `ld`:

    ld: unrecognized option '-Wl,--export-dynamic'

Let’s move the flag to `Cflags` so that the compiler can deal with it.

https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/463
2023-03-31 20:44:14 +02:00
Philip Withnall
224e4e53e2 gdebugcontrollerdbus: Fix incorrect paragraph on auth in documentation
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2960
2023-03-29 14:05:43 +01:00
Philip Withnall
0387c15614 gsocket: Improve wording in a warning message slightly
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-23 14:11:36 +00:00
Philip Withnall
5c65437d73 glib-unix: Add O_NONBLOCK support to g_unix_open_pipe()
Add support for it, but don’t use it anywhere yet — this is an API
addition, but currently doesn’t cause any functional changes. It’ll be
used in the next commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-23 14:11:36 +00:00
Philip Withnall
56c013cb6e inotify: Use IN_NONBLOCK to avoid a fcntl() syscall where possible
The `inotify_init1()` API has supported this flag for a long time
(possibly since it was first introduced, although I haven’t bothered
doing the archaeology).

This saves a syscall when first connecting to inotify.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-23 14:11:36 +00:00
Philip Withnall
e2d06873f9 gpollable: Clarify that can_poll() must be called before other methods
Both `GPollableInputStream` and `GPollableOutputStream` are dynamic
interfaces, in that their implementation on a class may only be
functional if certain prerequisites are met at runtime. For example,
a `GConverterInputStream` is only pollable if its base stream is
pollable, and that’s determined at runtime rather than compile time.

As such, both interfaces have a `can_poll()` method. If that method
returns `FALSE`, the behaviour of all other methods on the interface is
undefined.

That was mentioned in the documentation for `can_poll()`, but not any of
the other documentation for the interfaces, which made it a bit hard to
find.

Mention it more widely.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2952
2023-03-23 12:08:08 +00:00
Philip Withnall
8b0cf41d88 gsocket: Use SOCK_NONBLOCK to avoid a fcntl() syscall where possible
If the libc and kernel support `SOCK_NONBLOCK`, we can specify that in
the `socket()` flags, and avoid a subsequent call to `fcntl()` to set
`O_NONBLOCK`.

For modern Linux distributions, this will save a syscall when creating a
socket.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-23 01:13:49 +00:00
Philip Withnall
afcd0bb900 tests: Add some explanatory comments to appmonitor test
This should split the code up into logical blocks a bit better, and make
it a bit easier to see what the test is doing at a glance.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-22 15:12:52 +00:00
Philip Withnall
e4546614a8 tests: Port appmonitor test from GMainLoop to using GMainContext directly
This makes the exit conditions for each main loop clearer, and
eliminates use of global variables. It introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-22 15:12:52 +00:00
Philip Withnall
666c72c9c5 tests: Fix non-removal of a timeout in appmonitor test
If the first part of the test takes less than 3s (which is normal), the
timeout for it is not removed, and could spuriously fire during the
second part of the test, causing a false failure.

Instead of relying on source IDs, just use (and explicitly destroy) a
`GSource` for the timeouts.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-22 15:12:52 +00:00
Philip Withnall
c0ca3f995b tests: Fix a FIXME in the appmonitor test
The test thought that calling `g_app_info_get()` was a bit of a hack,
but actually it (or calling another `g_app_info_*()` function) is the
right way to use the `GAppInfoMonitor` API.

See the documentation improvements a couple of commits back for details.

The remaining FIXME higher up in the test should probably be fixed by
getting `g_app_info_monitor_get()` to arm the signal. That requires
changes in `g_app_info_monitor_get()` to call `desktop_file_dir_init()`.
That will have to happen another time.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #799
2023-03-22 15:12:49 +00:00
Philip Withnall
9279f3b0f9 tests: Use g_assert_*() rather than g_assert() in appmonitor tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-22 14:38:04 +00:00
Philip Withnall
0a10851faa tests: Add copyright/licensing header to appmonitor tests
This is put together through git archaeology:
```
git log gio/tests/appmonitor.c
```

The following commits were too trivial to have meaningful copyright:
 - 54047080e9
 - 4e7d22e268
 - f2c1cfe8c7
 - f8f344923e
 - 3ce00b29ec
 - 3468369625
 - e9d9edde82

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2023-03-22 14:36:57 +00:00
Philip Withnall
c62643adc3 gappinfo: Clarify one-shot behaviour of GAppInfoMonitor::changed in docs
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #799
2023-03-22 14:30:39 +00:00
Philip Withnall
4cad66580b gfileinfo: Temporarily downgrade missing attribute criticals to debugs
This partially reverts ed8e86a7d4.

The change to add the criticals (commit ed8e86a7d4) is correct, but
landed too late in the cycle. Let’s downgrade the criticals to debugs
for now, to stop applications seeing a lot of new criticals in their
output. Those criticals are particularly disruptive for command line
applications and unit tests.

Early in the next cycle, the debugs will be re-upgraded to criticals.
This will give applications a whole additional cycle to fix their
ambiguous use of API.

It turned out that a lot of applications have latent bugs around
calling `g_file_info_get_*()` without checking whether an attribute
is set first, and were hence relying on the ‘unknown’ return value
also being an appropriate default for them.

This was compounded by the fact that several non-local GVFS backends
were not setting `GFileInfo` attributes all the time, which caused the
‘missing attribute’ code path to be hit more frequently. For example,
they would only call `g_file_info_set_is_hidden()` with a true value and
never bother with a false one.

It was further compounded by the fact that, while this change landed for
the 2.75.4 release, there did not seem to be extensive integration
testing of that release, and distributions and downstreams went straight
to 2.76.0. That meant we missed the window between 2.75.4 and 2.76.0 to
change, fix or revert this behaviour. GLib relies on distros and
downstreams doing integration testing of unstable releases. We test with
downstream GNOME as part of gnome-build-meta, but do not have the
resources to do integration testing for everybody.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

See: #2907
See: #2932
See: #2934
See: #2945
See: #2948
2023-03-21 15:01:10 +00:00
Philip Withnall
2630b7d2d5 Merge branch '352-file-enumerator-docs' into 'main'
gfileenumerator: Clarify termination condition for next_files_async()

Closes #352

See merge request GNOME/glib!3339
2023-03-21 14:58:45 +00:00
Philip Withnall
a046492a19 gfileenumerator: Add an example of using next_files_async() to the docs
This is written in pseudocode C which omits all the callback boilerplate
for the async calls. This should hopefully make the overall structure of
the loop more obvious.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #352
2023-03-21 14:07:08 +00:00
Owen Taylor
67a9367598 gfileenumerator: Clarify termination condition for next_files_async()
As suggested on #352 by Owen Taylor (commit put together by Philip
Withnall, but in Owen’s name as it’s his wording).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #352
2023-03-21 13:56:52 +00:00
Philip Withnall
2953c08261 gfileinfo: Zero GTimeVal when failing g_file_info_get_modification_time()
Before commit ed8e86a7d4, this function would have silently returned a
zero-valued `GTimeVal` if the correct attributes weren’t present.

That partially regressed in commit ed8e86a7d4, which made it return with
a critical warning, but without zeroing the `GTimeVal`. The critical
warning can be ignored by users (it doesn’t abort the process unless
`G_DEBUG=fatal-criticals` is set), but the change in behaviour of
zeroing the `GTimeVal` could cause bugs.

See: #2907

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-21 12:15:50 +00:00
Philip Withnall
2029d7e900 gpollfilemonitor: Add missing attribute checks for g_file_info_get_size()
Missed from the fixes for #2907.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-21 12:15:50 +00:00
Philip Withnall
4ba3470269 gio: Add some missing file info attribute checks in gio-list and gio-tree
Further fallout from #2907.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2948
2023-03-21 12:15:50 +00:00
Philip Withnall
ec03755355 gio-tool-info: Fix a duplicate attribute name in the UI
`gio info` currently prints ‘display name:’ twice. One of those should
be ‘edit name:’ — this regressed in commit
a374b7c806.

Various translations still have the old string, but some unfortunately
do not, so this is effectively a new translatable string again.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-21 11:31:38 +00:00
Jan Beich
f6c40b1d27 meson: allow -Dlibelf=enabled without pkg-config
gio/meson.build:933:0: ERROR: Dependency "libelf" not found, tried pkgconfig
2023-03-20 14:57:36 +00:00
Colin Walters
8d7c1f9b75 tests: Finish update of gdbus-example-proxy-subclass to new GDBus API
This fixes bug #624696.

Incorporates a more recent change from 1dc774a653 to drop the
`g_type_init()` call, and reformats the indentation a bit.

Fixes: #322
2023-03-20 13:03:04 +00:00
Philip Withnall
3d7e88a77d build: Drop old .gitignore files from test directories
They just listed built files. Since the move to Meson, these are all
kept in a separate build directory, not the source tree, so don’t need
to be ignored.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-20 12:09:02 +00:00
Philip Withnall
9d7c796f1e Merge branch 'fix-monitor-root-directory-fail' into 'main'
inotify: Avoid empty root directory string

See merge request GNOME/glib!3241
2023-03-16 12:12:01 +00:00
Philip Withnall
f535d0915f tests: Add a test for creating a file monitor on the root directory
While we can’t check for any events on it, this at least tests that
creating a file monitor works. It should cover the fix from the previous
commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: !3241
2023-03-15 14:45:10 +00:00
Philip Withnall
1a9be3a1c8 tests: Add a test for D-Bus activating an unknown app with a context
This should catch regressions in the critical warning fixed in the
previous commit.

The launch has to have several conditions:
 - Session bus is running (to avoid the launch happening via the spawn
   codepath)
 - Use a non-existent D-Bus name (to trigger a launch error)
 - Use a launch context (to hit the critical warning code path)
 - Not have a startup ID specified in the platform data — this implies
   having an empty launch context
 - Use an async launch, as that provides an error handling path

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-15 13:50:51 +00:00
Philip Withnall
7cd57b3e85 gdesktopappinfo: Add a missing NULL check
It’s possible for the startup ID to be `NULL` if one wasn’t provided in
the platform data passed to `launch_uris_with_dbus()`.

Passing `NULL` to `g_app_launch_context_launch_failed()` causes a
critical warning.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-14 14:37:14 +00:00
Philip Withnall
764f8426d4 tests: Remove explicit timeout handler from gdbus-auth tests
The timeout runs for the entire duration of the test, which is a
function that Meson’s test harness already provides for us.

Meson’s timeout can be easily adjusted by a factor to allow for running
tests more slowly under valgrind. The timeout in the code cannot, which
leads to spurious failures like
https://gitlab.gnome.org/GNOME/glib/-/jobs/2645271.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-13 11:21:17 +00:00
Philip Withnall
642ee744b8 tests: Fix g_source_remove() of non-existent source in gapplication test
If the timeout callback was executed, it would remove the timeout
source, leaving the `g_source_remove()` call in the main function with a
dangling source ID.

Fixes commit 73205b8bbd.

Spotted in https://gitlab.gnome.org/GNOME/glib/-/jobs/2645271.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-13 11:19:56 +00:00
Luca Bacci
061da06118 GWin32AppInfo: Add NULL string checks
Fixes #2922
2023-03-09 14:29:38 +01:00
Ondrej Holy
1e4a8d3271 Merge branch '2934-false-null-file-attributes' into 'main'
glocalfile: Set various file attributes if their value is FALSE

Closes #2934

See merge request GNOME/glib!3313
2023-03-07 15:33:59 +00:00
Philip Withnall
ff2fad77ef Merge branch 'wip/oholy/lost-and-found-is-hidden' into 'main'
glocalfileinfo: Mark the lost+found dir as hidden again

See merge request GNOME/glib!3310
2023-03-06 17:47:46 +00:00
Philip Withnall
ab3076a242 Merge branch '2932-check-etag-attributes' into 'main'
gfile: Check ETag attribute is present before trying to get it

Closes #2932

See merge request GNOME/glib!3312
2023-03-06 17:42:01 +00:00
Philip Withnall
335d3a4c04 Merge branch 'wip/oholy/is-backup-false' into 'main'
glocalfileinfo: Ensure that is-backup is always set

See merge request GNOME/glib!3311
2023-03-06 17:41:35 +00:00
Philip Withnall
303d79989c gresourcefile: Fix a missing newline in GResourceFile
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-06 16:10:50 +00:00
Philip Withnall
a4e597520a glocalfileinfo: Set is-backup attribute on Windows
Previously it was only being set on non-Windows platforms. For
consistency, always set it on Windows too.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2934
2023-03-06 16:10:50 +00:00
Philip Withnall
8c473c5353 glocalfile: Set various file attributes if their value is FALSE
Following on from #2907, set various boolean attributes if they have
been requested, or are known for sure, and their value is `FALSE`.

Previously the `FALSE` value would have been implicitly returned by the
getter function, but now doing that without the attribute being
explicitly set will trigger a critical warning.

*Don’t* set these attributes if their value is unknown or there was an
error querying it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2934
2023-03-06 16:10:50 +00:00
Ondrej Holy
c965bf23a8 glocalfileinfo: Set is-backup attribute also on Windows
The `is-backup` attribute isn't currently set on Windows. It would
be nice to set such basic attributes on all platforms. Let's set
the attribute to `FALSE` there.
2023-03-06 14:33:39 +01:00
Ondrej Holy
448a163bee glocalfileinfo: Ensure that is-backup is always set
Currently, the `G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP` attribute is set
only when its value is `TRUE`. This is wrong with the latest changes as
the `GLib-GIO-CRITICAL **: 00:54:07.260: GFileInfo created without
standard::is-backup` errors are printed now from the
`g_file_info_get_is_backup` function among others. Let's set this
aattribute also when it is `FALSE`.

Related: https://gitlab.gnome.org/GNOME/glib/-/issues/2934
2023-03-06 14:33:39 +01:00
Ondrej Holy
43066d6960 glocalfileinfo: Mark the lost+found dir as hidden again
The lost+found dir isn't detected as hidden currently. This is regression
caused by the commit 728ad64b. Let's change the code a bit to be sure that
the lost+found dir is marked as hidden again.
2023-03-06 14:10:13 +01:00
Philip Withnall
4e62e55d6d gfile: Check ETag attribute is present before trying to get it
A regression from issue #2907.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2932
2023-03-06 13:02:41 +00:00
Ondrej Holy
406143b072 gfile: Fix file size detection when copying on btrfs
When the `g_file_copy` function is used with files on BTRFS, the
`GLib-GIO-FATAL-CRITICAL: GFileInfo created without standard::size`
error is printed. This is because the `g_file_get_size` function
is used to obtain the file size for the progress callback, but it uses
the wrong `GFileInfo` object that is meant for attributes to be copied
with the file. The file size attribute is missing there obviously. Let's
obtain the file size over the `fstat` call the same way as it is done in
the `splice_stream_with_progress` function to get rid of those errors
and to fix the progress reporting.
2023-03-06 10:30:20 +01:00
Simon McVittie
6c22a5ee2b Merge branch '2925-gdbus-threading-test' into 'main'
gdbusconnection: Explicitly destroy an idle source on cleanup

See merge request GNOME/glib!3296
2023-03-02 12:35:21 +00:00
Philip Withnall
35c9ab144e Merge branch 'main' into 'main'
gio/tests/cxx.cpp: fix missing sentinel for musl

See merge request GNOME/glib!3294
2023-02-23 14:53:20 +00:00
Markus Volk
caab1a41dc gio/tests/cxx.cpp: fix missing sentinel for musl
This fixes:
| ../glib-2.75.3/gio/tests/cxx.cpp: In function 'int main(int, char**)':
| ../glib-2.75.3/gio/tests/cxx.cpp:61:15: error: missing sentinel in function call [-Werror=format=]
|    61 |   g_test_init (&argc, &argv, NULL);

if built with musl libc

Signed-off-by: Markus Volk <f_l_k@t-online.de>
2023-02-23 15:02:26 +01:00
Philip Withnall
7b101588e9 gdbusconnection: Make GDBusMethodInvocation transfer a bit clearer
Add a missing steal call in `schedule_method_call()`. This introduces no
functional changes, but documents the ownership transfer more clearly.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2924
2023-02-23 12:16:05 +00:00
Philip Withnall
d5710deb9d gdbusinterfaceskeleton: Fix a use-after-free of a GDBusMethodInvocation
This `GDBusMethodInvocation` may be shared across threads, with no
guarantee on the strong ref in one thread outlasting any refs in other
threads — so it needs a ref in this helper struct.

This should fix a use-after-free where the `GDBusMethodInvocation` is
freed from `g_value_unset()` after `g_signal_emit()` returns in
`dispatch_in_thread_func()` in one thread; but then dereferenced again
in `g_source_destroy_internal()` from another thread.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2924
2023-02-23 12:16:05 +00:00
Philip Withnall
1f86923766 gdbusinterfaceskeleton: Remove an unnecessary helper struct member
The `GDBusInterfaceSkeleton` is already stored as the source object of
the `GTask` here, with a strong reference.

Storing it again in the task’s data struct is redundant, and makes it
look like the `GDBusInterfaceSkeleton` is being used without holding a
strong reference. (There’s not actually a bug there though: the strong
reference from the `GTask` outlives the data struct, so is sufficient.)

Remove the unnecessary helper struct member to clarify the code a bit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2924
2023-02-23 12:16:05 +00:00
Philip Withnall
81a42f4c59 gsocketclient: Document ownership of connection_attempts better
This introduces no functional changes; just made it while trying to
debug issue #2925.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2925
2023-02-23 12:14:29 +00:00
Philip Withnall
5a69cc22dc gdbusconnection: Explicitly destroy an idle source on cleanup
Otherwise it’s possible for it to hang around in the `GMainContext`
after the “send message” operation has finished. In the best case, this
will cause the `GTask` and `GDBusMessage` to not be freed when the
calling code expects. In the worst case, it could cause use-after-free
problems if it derefs allocations which have since been freed.

I have not seen either of these problems in practice, but it would be
best for the code to eliminate the risk of them altogether by explicitly
destroying the source when the operation is finished.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2925
2023-02-23 12:14:29 +00:00
Philip Withnall
ed7044b5f3 gdbusprivate: Improve docs on message ownership in MessageToWriteData
This doesn’t introduce any functional changes, but should make the code
a little clearer.

Drive-by improvements while trying to debug #1264.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-02-23 12:11:24 +00:00
Philip Withnall
90af20d950 gdbusconnection: Improve docs of message ownership in closures
This introduces no functional changes, but makes it a little clearer how
the ownership of these `GDBusMessage` instances works. The free function
is changed to `g_clear_object()` to avoid the possibility of somehow
using the messages after freeing them.

Basically just some drive-by docs improvements while trying to debug
issue #1264.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1264
2023-02-23 12:11:24 +00:00
Philip Withnall
127c899a2e gdbusconnection: Fix the type of a free function
This didn’t actually cause any observable bugs, since the structures of
`PropertyData` and `PropertyGetAllData` were equivalent for the members
which the free function touches.

Definitely should be fixed though.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-23 12:11:24 +00:00
Philip Withnall
4900ea5215 gdbusconnection: Fix double unref on timeout/cancel sending a message
This appears to fix an intermittent failure seen when sending a D-Bus
message with either of a cancellable or a timeout set.

In particular, I can reliably reproduce it with:
```
meson test gdbus-test-codegen-min-required-2-64 --repeat 10000
```

It can be caught easily with asan when reproduced. Tracking down the
location of the refcount mismatch was a little tricky, but was
simplified by replacing a load of `g_object_ref (message)` calls with
`g_dbus_message_copy (message, NULL)` to switch `GDBusMessage` handling
to using copy semantics. This allowed asan to home in on where the
refcount mismatch was happening.

The problem was that `send_message_data_deliver_error()` takes ownership
of the `GTask` passed to it, but the
`send_message_with_replace_cancelled_idle_cb()` and
`send_message_with_reply_timeout_cb()` functions which were calling it,
were not passing in a strong reference as they should have.

Another approach to fixing this would have been to change the transfer
semantics of `send_message_data_deliver_error()` so it was `(transfer
none)` on its `GTask`. That would probably have resulted in cleaner
code, but would have been a lot harder to verify/review the fix, and
easier to inadvertently introduce new bugs.

The fact that the bug was only triggered by the cancellation and timeout
callbacks explains why it was intermittent: these code paths are
typically never hit, but the timeout path may sometimes be hit on a very
slow test run.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #1264
2023-02-23 12:11:24 +00:00
Simon McVittie
88fd3f0a76 Merge branch 'build-with-llvm-toolchain' into 'main'
Fix building gio/tests/test_resources.o with LLVM ld

Closes #2720

See merge request GNOME/glib!3186
2023-02-22 16:51:05 +00:00
Philip Withnall
0a715be599 Merge branch 'cloexec-other' into 'main'
Close-on-exec flag few missed places

See merge request GNOME/glib!3292
2023-02-22 13:07:35 +00:00
Philip Withnall
ddf85f9d9e Merge branch 'g-win32-app-info-enhancements-2' into 'main'
GWin32AppInfo: Retrieve display name for UWP / Packaged apps

See merge request GNOME/glib!3168
2023-02-22 12:55:24 +00:00
Emmanuele Bassi
4c17e3b122 Merge branch '2907-file-info-docs' into 'main'
gfileinfo: Document required attributes for helper getters

Closes #2907

See merge request GNOME/glib!3261
2023-02-22 12:35:38 +00:00
Luca Bacci
01889cd348 GWin32AppInfo: Retrieve display name of UWP (packaged) apps 2023-02-22 13:24:13 +01:00
Emmanuele Bassi
c669baab4c Merge branch 'live-g-file-test-logging' into 'main'
tests: Remove custom printerr logging from live-g-file

See merge request GNOME/glib!3281
2023-02-22 01:36:10 +00:00
Maciej S. Szmigiero
8f8ebb1bd0 g_mkstemp: Use O_CLOEXEC for race-free setting of the close-on-exec flag
mkstemp-like family of functions also use g_open () under the hood so
they should pass the O_CLOEXEC flag there for race-free setting of the
close-on-exec flag.
2023-02-22 00:38:13 +01:00
Maciej S. Szmigiero
cbc15d6ceb gunixmounts: Use "e" mode flag in setmntent () call for race-free setting of the close-on-exec flag
setmntent () call uses the same mode flag set as fopen (), so it should
also include the "e" mode flag for race-free setting of the close-on-exec
flag.
2023-02-22 00:32:33 +01:00
Luca Bacci
0f0520ffa2 Add VTable definition for IPackage2
Derived from MIT-licensed code:
https://github.com/microsoft/windows-rs/blob/0.43.0/crates/libs/windows/src/Windows/ApplicationModel/mod.rs#L554
2023-02-21 18:01:51 +01:00
Philip Withnall
339aaa3719 Merge branch 'cloexec-audit' into 'main'
Make sure new file descriptors have close-on-exec flag set on them in a race-free way

See merge request GNOME/glib!3283
2023-02-21 12:58:01 +00:00
Maciej S. Szmigiero
0e7bf99ec2 Use "e" mode flag in fopen () calls for race-free setting of the close-on-exec flag
All Unix CRTs examined: glibc, musl, BSDs, Apple libc, Android bionic
ignore unknown fopen () mode flags, so this flag can be added
unconditionally for Unix builds.

Only Windows CRT is intolerant of these, so the single case in
g_dbus_address_connect () where the fopen () call is shared between Unix
and Windows needs appropriate platform-specific handling.

Skipped the call sites in libcharset and xdgmime copylibs.
2023-02-21 12:42:55 +00:00
Maciej S. Szmigiero
3f2e18b07c Use O_CLOEXEC in {g_,}open () calls for race-free setting of the close-on-exec flag
The remaining call sites are either Windows-only, between fork () and
exec () or in xdgmime copylib.

Hope I haven't missed any site.
2023-02-21 12:42:55 +00:00
Maciej S. Szmigiero
dd36ee0abf gtestdbus: Use g_unix_open_pipe_internal () for creating pipes
This attempts to create the pipes with race-free setting of the
close-on-exec flag.
2023-02-21 12:42:55 +00:00
Sebastian Dröge
7c5e930170 Allow passing a NULL item to g_list_store_find_with_equal_func()
The `equal_func` closure can already have all required information
available without the item, and passing the item via the closure instead
of an explicit parameter is more natural for languages that have a
concept of closures that can capture variables.
2023-02-20 10:16:11 +02:00
Maciej S. Szmigiero
3dc77fef24 gsocket: Use accept4 () for race-free setting of the close-on-exec flag
The code was already setting the close-on-exec flag for the new socket,
just in a racy way.
2023-02-19 16:47:13 +01:00
Philip Withnall
5d469dbe5a tests: Remove custom printerr logging from live-g-file
Use `g_test_message()` instead, so that the logs get treated properly
for TAP output.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-16 13:50:15 +00:00
Marius Vollmer
8f02681f6e gdbus: Never buffer reads during server authentication
Otherwise, the content of the buffer is thrown away when switching
from reading via a GDataInputStream to unbuffered reads when waiting
for the "BEGIN" line.

(The code already tried to protect against over-reading like this by
using unbuffered reads for the last few lines of the auth protocol,
but it might already be too late at that point.  The buffer of the
GDataInputStream might already contain the "BEGIN" line for example.)

This matters when connecting a sd-bus client directly to a GDBus
client.  A sd-bus client optimistically sends the whole auth
conversation in one go without waiting for intermediate replies.  This
is done to improve performance for the many short-lived connections
that are typically made.
2023-02-15 14:33:15 +00:00
Philip Withnall
bde724e5ac Revert "Revert "tests: Temporarily disable socket test due to a kernel bug""
This reverts commit 27bee8fe5d.

Inevitably, despite testing the CI multiple times before merging commit
27bee8fe, the CI is now failing again in the `socket` test due to (what
I continue to assume is) the kernel regression:

https://gitlab.gnome.org/martinpitt/glib/-/jobs/2585332

In order to unblock development on `main` expediently, I guess I’ll just
revert the revert.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Reopens: #2879
2023-02-15 13:23:13 +00:00
Philip Withnall
27bee8fe5d Revert "tests: Temporarily disable socket test due to a kernel bug"
This reverts commit 1507585869.

Maybe it works now? It will work as soon as the CI host kernel is
updated.

Fixes: #2879
2023-02-13 19:35:30 +00:00
Philip Withnall
438bd5cfa1 gutils: Make g_find_program_for_path() a proper private API
It’s not meant to be exposed publicly yet (we’re not ready to stabilise
it), but it was incorrectly decorated with `GLIB_AVAILABLE_IN_2_76`.

We can’t remove the decorator and use it that way, as it’s called in
libgio, so we have to expose it using `GLIB_PRIVATE_CALL()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2876
2023-02-13 16:12:07 +00:00
Philip Withnall
728ad64b44 glocalfileinfo: Ensure boolean file attributes are set
Don’t just set them when they’re true and rely on their non-presence
being evaluated to `FALSE`. That means that they erroneously don’t get
returned in `g_file_info_list_attributes()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
7082f03dbf gio-tool-info: Add missing attribute check
`g_file_info_get_is_hidden()` should not be called without checking the
attribute is set first, just as with the calls higher up in this code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
ed8e86a7d4 gfileinfo: Add critical warnings for helper getters
As documented in a previous commit, these functions should not be called
without the right attributes being present in the `GFileInfo`. Add
critical warnings to make this more obvious.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
8cee721df8 gfileinfo: Remove erroneous GFileType casts from returns
Looks like copy/paste errors.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-08 10:00:43 +00:00
Philip Withnall
2f862993cc gfileinfo: Fix some minor documentation typos
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-08 09:57:51 +00:00
Philip Withnall
937c6f15cd gfileinfo: Document required attributes for helper getters
It doesn’t make sense to (for example) call `g_file_info_get_name()` if
the `GFileInfo` doesn’t contain `G_FILE_ATTRIBUTE_STANDARD_NAME`, given
that building the `GFileInfo` is typically a static process and entirely
under the control of the programmer.

By being this restrictive, we avoid having to return ‘unknown’ values
for some of these standard APIs, particularly the numeric ones such as
`g_file_info_get_size()`. If APIs like that were to work correctly in
the face of a `GFileInfo` without `G_FILE_ATTRIBUTE_STANDARD_SIZE`
specified, they’d have to be able to return a value to indicate the
attribute is missing. Returning `0` or `G_MAXSIZE` to indicate that
would be ambiguous.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2907
2023-02-08 09:54:54 +00:00
Eli Schwartz
740440774a
fix underspecified dependencies on generated headers
Since gmodule-visibility.h is now a custom target and produced at
buildtime, it might not always exist in time for use in other source
files. This was the case for gio-inotify.

Add it as an additional source file to ensure in-time generation.
2023-02-06 23:00:04 -05:00
wangrong
2643961845 inotify: Avoid empty root directory string
When gio monitors a directory, it will delete the extra "/" at the end
of the directory string, but when the directory is "/", this will cause
the modified directory string to be empty, and eventually the
monitoring will fail. The solution is to delete only if the directory
string length is greater than 1.
2023-02-03 08:38:51 +00:00
Philip Withnall
622e1d8c83 Merge branch 'wip/ernestask/converter-null-out' into 'main'
gio: converter: Forbid null out arguments

See merge request GNOME/glib!3245
2023-02-02 22:39:57 +00:00
Ernestas Kulik
e0976efee9 gio: converter: Forbid null out arguments
Currently, inbuf_size and outbuf_size are not documented as not
nullable, but they are expected to be so, which might lead to unexpected
crashes. Moreover, outbuf itself is also expected to not be null, so
this commit adds the appropriate GI annotations and early returns on
failed preconditions.
2023-02-02 21:25:56 +02:00
Marco Trevisan
155e44652e Merge branch 'gstring-free-warning' into 'main'
Make g_string_free (_, FALSE) warn on unused result

See merge request GNOME/glib!3226
2023-02-01 16:28:02 +00:00
Philip Withnall
bd5e57ef17 tests: Fix a few minor leaks in gdbus-example-peer
One leak spotted by the Coverity, the others found via valgrind.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1504322
2023-01-31 11:44:44 +00:00
Alex Richardson
c434743111 Fix build of gio/ttests/est_resources2.o with LLVM objcopy
LLVM objcopy's --strip-all is more aggressive that GNU objcopy --strip-all
and will remove everything that is not actually used. In this case we
see the following error:
`error: 'gio/tests/test_resources.o': Symbol table has link index of 5 which is not a valid index`

Fix this by only removing debug symbols instead of all unused symbols and
sections.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2720
2023-01-28 10:46:50 +00:00
Alex Richardson
6d93568e36 Fix building gio/tests/test_resources.o with LLVM ld
Unlike GNU ld which has a default target architecture, ld.lld is always a
cross-linker and has the same behaviour for all targets. If you don't tell
ld.lld what the target architecture is it can't infer the right ELF flags
for the resulting object file.
```
$ ~/cheri/output/sdk/bin/ld -r -b binary gio/tests/test5.gresource -o gio/tests/test_resources.o -v
LLD 14.0.0 (compatible with GNU linkers)
ld: error: target emulation unknown: -m or at least one .o file required
```

As you can see from the error message it can't infer the target
architecture (you need a least one valid .o file or the -m flag).
If you use the compiler instead of directly invoking the linker it will
pass the appropriate flags:
```
$ ~/cheri/output/sdk/bin/clang -r -Wl,-b,binary gio/tests/test5.gresource -o gio/tests/test_resources.o -v
clang version 14.0.0 (https://github.com/CTSRD-CHERI/llvm-project.git ff66b683475fc44355b2010dbcbe1202d785e6f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/alexrichardson/cheri/output/sdk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/home/alexrichardson/cheri/output/sdk/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o gio/tests/test_resources.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/home/alexrichardson/cheri/output/sdk/bin/../lib -L/lib -L/usr/lib -r -b binary gio/tests/test5.gresource
❯ file gio/tests/test_resources.o
gio/tests/test_resources.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
```

This works for most architectures, but ones that need additional metadata
sections to encode the used ABI, etc. will require a different approach
using .incbin. However, that is a change for another MR.

Partially fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2720
2023-01-28 10:46:50 +00:00
Sergey Bugaev
c121118bc4 tests: Silence a warning
In case the OS does not support epoll and kqueue, we get the warning:

gio/tests/pollable.c: In function ‘test_pollable_unix_nulldev’:
gio/tests/pollable.c:266:7: warning: unused variable ‘fd’
[-Wunused-variable]
  266 |   int fd;

Get rid of it.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:58:56 +03:00
Sergey Bugaev
bccff754b6 Use g_string_free_and_steal () more
Now that there is g_string_free_and_steal (), we can use it instead of
the older g_string_free (_, FALSE). Make sure to use its return value
while doing so, as opposed to manually accessing string->str, to avoid
compiler warnings and make the intent more explicit.

This is all done in preparation for making g_string_free (_, FALSE) warn
on unused return value much like g_string_free_and_steal (), which will
happen in the next commit.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:55:27 +03:00
Marco Trevisan
5e40004bdb Merge branch 'gstrdup-inline' into 'main'
gstrfuncs: Add inline version of g_strdup()

See merge request GNOME/glib!3209
2023-01-26 18:38:37 +00:00
Marco Trevisan
2cbc90cc1e Merge branch '2901-gio-executable-docs' into 'main'
gappinfo: Document that g_app_info_get_executable() should not be spawned

Closes #2901

See merge request GNOME/glib!3240
2023-01-26 16:41:16 +00:00
Marco Trevisan (Treviño)
23da6bade0 {glib,gio}/cxx: Add more tests for C++ inline funcs
These could behave differently in C++ so let's ensure this is not the
case.
2023-01-26 16:52:36 +01:00
Marco Trevisan
452e9957a4 Merge branch 'leak-suppressions' into 'main'
Add a few suppressions to glib.supp and fix a minor bug in gapplication test

See merge request GNOME/glib!3223
2023-01-26 15:40:22 +00:00
Philip Withnall
ac30b7d824 Merge branch 'leak-fix' into 'main'
tests/desktop-app-info: fix stack-use-after-scope

See merge request GNOME/glib!3187
2023-01-26 15:36:22 +00:00
Philip Withnall
c53f9c0d37 gappinfo: Document that g_app_info_get_executable() should not be spawned
Spawning a process correctly is a lot more complicated than just bunging
an argument onto the return value from this function.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2901
2023-01-26 14:54:35 +00:00
Marc-André Lureau
f50a4f8501 tests/desktop-app-info: fix stack-use-after-scope
Fix the tests, by allocating the structure.

==121338==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe44018610 at pc 0x00000040ff71 bp 0x7ffe440178f0 sp 0x7ffe440178e8
READ of size 8 at 0x7ffe44018610 thread T0
    #0 0x40ff70 in test_launch_uris_with_terminal ../gio/tests/desktop-app-info.c:1393
    #1 0x7efd97b831e8 in test_case_run ../glib/gtestutils.c:2947
    #2 0x7efd97b831e8 in g_test_run_suite_internal ../glib/gtestutils.c:3037
    #3 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #4 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #5 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #6 0x7efd97b84189 in g_test_run_suite ../glib/gtestutils.c:3136
    #7 0x7efd97b842c5 in g_test_run ../glib/gtestutils.c:2248
    #8 0x4055bc in main ../gio/tests/desktop-app-info.c:1901
    #9 0x7efd9564a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
    #10 0x7efd9564a5c8 in __libc_start_main_alias_1 (/lib64/libc.so.6+0x275c8)
    #11 0x4059f4 in _start (/home/elmarco/src/gnome/glib/build/gio/tests/desktop-app-info+0x4059f4)

Address 0x7ffe44018610 is located in stack of thread T0 at offset 128 in frame
    #0 0x404d1f in main ../gio/tests/desktop-app-info.c:1823

  This frame has 6 object(s):
    [48, 52) 'argc' (line 1821)
    [64, 72) 'path' (line 1870)
    [96, 104) 'argv' (line 1822)
    [128, 144) '<unknown>' <== Memory access at offset 128 is inside this variable
    [160, 176) '<unknown>'
    [192, 288) 'supported_terminals' (line 1825)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-01-24 23:43:20 +04:00
Philip Withnall
1507585869 tests: Temporarily disable socket test due to a kernel bug
There’s a kernel bug on the CI machines which is causing this test to
fail all the time and it’s getting my goat.

The test can be re-enabled later (by reverting this commit) when the
kernel on the CI VM host is fixed. I don’t know when that’s going to
happen.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2879
2023-01-24 11:46:25 +00:00
Philip Withnall
73205b8bbd tests: Explicitly remove a timeout handler in gapplication test
Otherwise if, for whatever reason, the `app` loses its D-Bus name,
`g_application_quit()` is called from `name_was_lost()` before it’s
called from `quit_already()`, and then `quit_already()` does an invalid
read on `app`.

If the name was not meant to be lost at this point in the test, the
subsequent `g_assert_false (name_lost)` will catch that, so this change
shouldn’t cause the test to pass unnecessarily.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-24 11:25:34 +00:00
Philip Withnall
e23ea40aaa gwin32: Fix two minor string leaks
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2891, #2892
2023-01-23 11:50:34 +00:00
Marco Trevisan (Treviño)
6a4f6c593c gsettings: Skip tests in the proper way
This will make TAP happier in reporting what's wrong
2023-01-20 14:10:08 +01:00
Marco Trevisan (Treviño)
04e8c8c719 gio/tests/gsettings: Write subprocess stdout as test message
This won't confuse the meson TAP parser.
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
ed8810216a gio/tests: Use default log writer to stderr for launched processes
We don't want to bother TAP parser with subprocess messages when using
verbose logging, so let's just use stderr by default.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
d4088e7f2a gio: Use 'cpp' suite for C++ tests
That's what we use for all the tests, so be consistent.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
1594cf77eb meson: Use exitcode protocol for some c++ and gobject definition tests
In all these cases we don't really care about running the test file,
while building and basic execution it is relevant.

Also they don't support TAP at all.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
58031feb17 meson: Use 'tap' test protocol by default
Meson supports tap protocol results parsing, allowing us to track better
the tests that are running (and the ones that are actually skipped) without
manually parsing the test output.

However this also implies that using the verbose mode for a test doesn't
show its output by default (unless there are failures).
2023-01-17 21:08:48 +01:00
Philip Withnall
438006899e Merge branch 'document-gtask-brokenness' into 'main'
GTask: Document issues

See merge request GNOME/glib!3203
2023-01-16 14:43:20 +00:00
Marco Trevisan
dabb650ad4 Merge branch 'settings-action-per-desktop-default' into 'main'
gsettings: Support per-desktop overrides in GSettingsAction

See merge request GNOME/glib!3193
2023-01-16 13:30:53 +00:00
Matthias Clasen
f999481ec2 GTask: Document issues
We may not be able to fix GTasks broken design,
but at least we should document it and not let
users stumble into this bear trap without warning.

Helps: #1346
2023-01-16 08:19:23 -05:00
Emmanuele Bassi
5d0db7f0b8 Merge branch 'fix-closure-annotations' into 'main'
Fix a couple of `closure` annotations

See merge request GNOME/glib!3198
2023-01-14 08:58:28 +00:00
Marco Trevisan (Treviño)
45ec0aa81e tests/gsettings: Check that per-desktop settings are used by GAction's 2023-01-14 04:17:51 +01:00
banjiuqingshan
d9a1d7524f gio/tests/file.c: Fix expectations when running as root
Includes tweaks by Philip Withnall.
2023-01-13 22:21:07 +00:00
Philip Withnall
f85e4e341f gsettings: Slightly simplify g_settings_action_get_state()
This introduces no functional changes.

Suggested by Christian Persch.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-13 22:14:56 +00:00
Sebastian Dröge
79fd6fd6a0 Fix a couple of closure annotations 2023-01-13 18:06:23 +02:00
Philip Withnall
e9fc91550f Merge branch 'badcel/revert-update-closure-annotations' into 'main'
Revert "Rename user data parameters to user_data"

Closes #2827

See merge request GNOME/glib!3111
2023-01-11 14:58:31 +00:00
Philip Withnall
b494b83405 gsettings: Support per-desktop overrides in GSettingsAction
Due to an oversight (I guess), per-desktop default values (which come
from override files such as this one:
https://github.com/endlessm/gnome-shell/blob/master/data/00_org.gnome.shell.gschema.override)
were not checked when getting a GSettings value via a `GSettingsAction`.

Per-desktop default values are correctly returned via all other
GSettings query paths (see calls to
`g_settings_schema_key_get_translated_default()`).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-10 20:57:03 +00:00
Simon McVittie
cabe1370ed Merge branch 'fix-glib-compile-schemas-typo' into 'main'
glib-compile-schemas: Fix typo in comparison function

See merge request GNOME/glib!3188
2023-01-09 17:12:12 +00:00
badcel
fc70f2c057
Do not name callback parameters "user_data"
Calling a callback parameter "user_data" implicitly adds the "closure" attribute in the documentation which is wrong for callbacks.
2023-01-09 14:12:16 +01:00
Philip Withnall
9d5bcc9491 glib-compile-schemas: Fix typo in comparison function
This caused schemas and override files to be sorted incorrectly.

Fixes a regression introduced in commit 861e82efbc.

Spotted by John Wudrick in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3155#note_1635044.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-09 12:20:10 +00:00
badcel
19a02d7d14
Revert "Rename user data parameters to user_data"
This reverts commit da7a31a052. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
2023-01-09 13:09:26 +01:00
Emmanuele Bassi
684d9aa0c3 build: Don't overwrite build variables
We cannot use `gvisibility_h` for different visibility header files; you
never know when you're going to refer to the variable again, and
projects might end up needing to retrieve the variable contents—like,
for instance, gobject-introspection using glib as a subproject.
2023-01-08 00:33:14 +00:00
Philip Withnall
73fa684e30 Merge branch 'ptr-array-sort-values' into 'main'
garray: Add g_ptr_array_sort_values[_with_data]() wrappers

See merge request GNOME/glib!3155
2023-01-06 12:09:37 +00:00
Marco Trevisan (Treviño)
861e82efbc gio: Use g_ptr_array_sort_values()
Cleanup some code using GPtrArray sorting with functions that were taking
pointer to pointers arguments.
2023-01-06 11:46:01 +00:00
Philip Withnall
d333b06644 Merge branch 'g-win32-app-info-enhancements' into 'main'
GWin32AppInfo: Fixes for UWP (packaged) apps activation

See merge request GNOME/glib!3167
2023-01-05 17:51:06 +00:00
Luca Bacci
86fccfcb70 GWin32AppInfo: Prefer file activation over URI activation for file URI's
(...unless file:// URI's are actually supported by the target app)

References:

 [1] - https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-uri-activation
 [2] - https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-file-activation
2023-01-05 17:50:15 +01:00
Luca Bacci
02417db370 GWin32AppInfo: Pass only one item to ActivateForProtocol()
IApplicationActivationManager::ActivateForProtocol() only uses the first
item from the IShellItemArray. When we have to activate multiple URI's,
call ActivateForProtocol() repeatedly in a loop, each time with one URI.

References:

 [1] - IApplicationActivationManager::ActivateForProtocol method [MSDN]
       https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iapplicationactivationmanager-activateforprotocol
2023-01-05 17:46:50 +01:00
Luca Bacci
7bbbb1ee42 GWin32AppInfo: Create IShellItemArray object inside launch_uwp_internal()
The IShellItemArray object is only used in launch_uwp_internal(),
so do not make callers bother with that.
2023-01-05 17:42:03 +01:00
Maxim Mikityanskiy
a56bc06f16 glocalfileinfo: Don't reset mtime tv_sec when setting tv_usec
Fix a regression that appeared after adding support for nanosecond
timestamps to set_mtime_atime(). User-visible effect: when copying a
file from a gvfs MTP mountpoint to the local filesystem, the file's
mtime is set to 0.

This behavior happens when setting G_FILE_ATTRIBUTE_TIME_MODIFIED first,
then G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC. Setting the second attribute
ends up in set_mtime_atime() with mtime_usec_value set, and mtime_value
== NULL. When mtime_value is NULL, the tv_sec part of the timestamp
should be fetched by lazy_stat(), but set_mtime_atime() fails to assign
it properly, and tv_sec stays at 0, leading to losing the main part of
the timestamp.

Fix the issue by setting times_n[1].tv_sec to the value fetched from
lazy_stat().

Fixes: b33ef610de ("Add functionality to preserve nanosecond timestamps")
Fixes: 15cb123c82 ("glocalfileinfo: don't call both utimes and utimensat")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
2023-01-02 03:55:43 +02:00
Alynx Zhou
b16201390b codegen: Check parameter before calling its interface method 2022-12-30 13:44:20 +00:00
Philip Withnall
8463155b21 gdesktopappinfo: Drop an unnecessary NULL check
`search_token` cannot be `NULL` at this point (guaranteed by all the
current call sites of `desktop_file_dir_unindexed_search()`), so remove
an unnecessary `NULL` check.

Add an assertion to make the nullability clear.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1502196, #1502193
2022-12-29 15:57:53 +00:00
Philip Withnall
0c640cf671 Merge branch 'md' into 'main'
codegen: Support markdown suitable for gi-docgen

See merge request GNOME/glib!3171
2022-12-29 12:42:12 +00:00
Guido Günther
4cb945d780 codegen: Support markdown suitable for gi-docgen 2022-12-29 12:42:12 +00:00
Philip Withnall
46d3a016f3 Merge branch 'write_info_file_fail' into 'main'
GLocalFile: add error handle for trash info file writing

See merge request GNOME/glib!3170
2022-12-29 12:33:55 +00:00
wangrong
95c4312941 GLocalFile: add error handle for trash info file writing 2022-12-29 12:33:55 +00:00
wangrong
333e9fc0ba GLocalFile: Delete redundant error saving statement 2022-12-29 12:29:39 +00:00
Michael Catanzaro
d246d09e5b gproxyresolver: allow implicit ports in URIs
If the port is not specified, then a default port should be assumed.
This is how everybody expects URIs to work and it's how GProxyResolver
should work too.

We already have lots of tests to ensure this works as expected; however,
the documentation currently does not allow it. Change the documentation
to match reality.

Fixes #2832
2022-12-22 15:37:27 -06:00
Michael Catanzaro
1c3f992f11 Revert "gsimpleproxyresolver: Make explicit that a port is needed for HTTP/HTTPS"
This reverts commit eb12afed6f

Instead, let's allow use of URIs without ports specified, which
indicates that a default port should be used.
2022-12-22 15:37:27 -06:00
Philip Withnall
a0ea1d7093 Merge branch 'g-win32-app-info-enhancements' into 'main'
GWin32AppInfo: Check for local file path first

Closes #2843

See merge request GNOME/glib!3160
2022-12-22 15:02:42 +00:00
Luca Bacci
3c2b15fb15 GWin32AppInfo: Fix use-after-free 2022-12-22 15:14:29 +01:00
Luca Bacci
b0b16cf06e GWin32AppInfo: Check for local file path first
When launching a registered handler we compose the command-line
string using the registered command-line template. Applications
expect files in their command-line as local paths rather than
complete URI strings.

For example,

  "Program.exe" "%1"

Should expand to

  "Program.exe" "C:\file.dat"

Rather than

  "Program.exe" "file:///C:\file.dat"

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2843
2022-12-22 15:13:10 +01:00
Philip Withnall
1abd7507be gmenuexporter: Fix warning of unused n_items when building with G_DISABLE_ASSERT
Spotted in https://gitlab.gnome.org/GNOME/glib/-/jobs/2461358

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-21 12:33:58 +00:00
Philip Withnall
9e2ad88455 Merge branch 'search-app-prefix-strstr' into 'main'
gdesktopappinfo: Group search results by both categories and match types

See merge request GNOME/glib!3107
2022-12-21 11:42:35 +00:00
Alynx Zhou
0e612effbe tests: Update search tests for desktop-icon-info
Because we now put substring match in the next group of prefix match,
the test cases should also be updated.
2022-12-20 09:59:09 +08:00
Alynx Zhou
f81a9d226b gdesktopappinfo: Group search results by both categories and match types
Substring matches can have too much unwanted results, while prefix
matches is more accurate but cannot handle some special cases, this
commit combines them by adding a match_type member, then sort and group
result with both categories and match types.

For the same category, prefix matched results will be put in the first
group and substring matched results will be put in the second group.
2022-12-20 09:59:09 +08:00
Philip Withnall
d3a26bb4de Merge branch 'activation-token' into 'main'
gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key

Closes #2709

See merge request GNOME/glib!3090
2022-12-19 13:05:57 +00:00
Ilya Fedin
627f2738e0 gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key
See:
 * https://gitlab.freedesktop.org/xdg/xdg-specs/-/blob/master/desktop-entry/desktop-entry-spec.xml#L1061-1068
 * https://wayland.app/protocols/xdg-activation-v1
 * https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/xdg-activation/x11-interoperation.rst

Fixes: #2709
2022-12-19 12:45:02 +00:00
Philip Withnall
abd76e0286 Merge branch 'ghash-keys+values-arrays' into 'main'
ghash: Add APIs to get (and steal) hash table keys and values as GPtrArray

See merge request GNOME/glib!3130
2022-12-16 18:32:10 +00:00
Philip Withnall
a8826215b0 Merge branch 'fix-cancellable-connect-race' into 'main'
GCancellable: Ensure it is always cancelled on connect callback

See merge request GNOME/glib!2764
2022-12-16 18:11:03 +00:00
Marco Trevisan (Treviño)
3cad948f46 gdbusdaemon: Simplify name listing code using only arrays 2022-12-16 18:45:37 +01:00
Marco Trevisan (Treviño)
52900ed6b0 gdbusobjectskeleton: Get the ifaces via array instead of list 2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
036dabcff9 gdbus-tool: Steal set values passing the ownership to an array 2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
1eb7f3177d gdbusobjectmanagerclient: Simplify g-name-owner changes code
We can avoid further copies and unneeded ref/unrefs.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
0e56d2f5db gdbusmessage: Get message headers keys as arrays
We eventually need to return them as an array anyways.
Sadly we can't just reuse such memory because each element is a pointer and
not a guchar, but still we can be cheaper in various operations.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
1e699edf0e gdbusaddress: Use simpler hash table keys as arrays
We don't really need the lists overhead here, so let's just use the simpler
forms.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
5d5d12112b gdbusaddress: Use simpler hash table keys as arrays
We don't really need the lists overhead here, so let's just use the simpler
forms.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
e733a3db10 gdbusconnection: Avoid copying connection registered set values twice 2022-12-16 18:45:36 +01:00
Alex Richardson
994f96fb2b tests/gdbus-method-invocation: Fix missing g_variant_new() argument
I noticed this when running the test on an Arm Morello system where varargs
have bounds. g_variant_new() was trying to read an integer using va_arg(),
but since there was no argument it resulted in a bounds errors there.
On most other architectures this will just read whatever value is contained
in the next argument register and is not something that ASan can detect, so
it never resulted in test failures.
2022-12-16 10:28:50 +00:00
Marco Trevisan (Treviño)
cdda03a690 GCancellable: Ensure it is always cancelled on connect callback
When a cancellable is cancelled when we call g_cancellable_connect we
used to immediately call the provided callback, while this is fine we
actually had race in case the cancellable was about to be reset or in
the middle of a cancellation.

In fact it could happen that when we released the mutex, another thread
could reset the cancellable just before the callback is actually called
and so leading to call it with g_cancellable_cancelled() == FALSE.

So to handle this, make disconnect and reset function to wait for
connection emission to finish, not to break their assumptions.

This can be tested using some "brute-force" tests where multiple threads
are racing to connect and disconnect while others are cancelling and
resetting a cancellable, ensuring that all works as we expect.
2022-12-15 19:30:43 +01:00
Philip Withnall
8a60c22bb4 Merge branch '861-dbus-menu-model-robustness' into 'main'
gmenumodel: disallow exporting large menus on the bus

Closes #861

See merge request GNOME/glib!3133
2022-12-14 16:18:07 +00:00
Lars Uebernickel
89a7bbcf6e gmenumodel: disallow exporting large menus on the bus
This solves problems with validating untrusted inputs from D-Bus, where
invalid numbers of added and removed menu entries, and positions, could
be specified.

Original patch from
https://bugzilla.gnome.org/show_bug.cgi?id=728733#c7, tweaked by Philip
Withnall to add a few code comments and make
`G_MENU_EXPORTER_MAX_SECTION_SIZE` public so callers can check their
inputs against it if they want. Also tweaked to use `g_warning()` instead
of the nonexistent `g_dbus_warning()`.

Fixes: #861
2022-12-14 15:42:14 +00:00
Philip Withnall
a2c8a8c630 tests: Release GApplication a little later to avoid assertion failures
If it takes one more `GMainContext` cycle than expected for the
`activate` signals to be handled, the `GApplication` under test can be
released too early, and the test will fail due to not seeing a high
enough value of `n_activations`.

Hopefully avoid that by moving the release to a low priority idle
callback.

This fix is only hopeful because I’ve only been able to reproduce the
failure on FreeBSD CI and not locally.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2835
2022-12-14 09:33:18 +00:00
Marco Trevisan
a9e8b3f7e4 Merge branch '2837-test-timeouts' into 'main'
tests: Increase a timeout in contexts test

Closes #2837

See merge request GNOME/glib!3122
2022-12-13 14:57:44 +00:00
Philip Withnall
cad9256c3d tests: Increase a timeout in contexts test
The timeout is just to stop the test hanging forever, so there’s no need
for it to be so short. It’s caused at least one spurious CI failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/2445023.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2837
2022-12-13 14:07:58 +00:00
Philip Withnall
3c15df01c8 Merge branch 'wip/3v1n0/desktop-app-info-fail-on-not-existent' into 'main'
gdesktopappinfo: Fail early if trying to launch an invalid executable and always use desktop Path and context $PATH

See merge request GNOME/glib!3042
2022-12-13 13:01:09 +00:00
Marco Trevisan (Treviño)
511d1cad02 gdesktopappinfo: Fail early if trying to launch an invalid executable
GDesktopAppInfo never failed in the most simple of the cases: when a
desktop file or a command line app info was pointing to an invalid
executable (for the context).

The reason for this is that we're launching all the programs using
gio-launch-desktop which will always exist in a sane GLib installation,
and thus our call to execvp won't ever fail on failure.

This was partially mitigated by not allowing to create a desktop app
icon using a non-existent executable (even if not fully correctly) but
still did not work in case a custom PATH was provided in the launch
context.

To avoid this, use g_find_program_for_path() to find early if a program
that we're about to launch is available, and if it's not the case return
the same error that g_spawn_async_with_fds() would throw in such cases.

While this is slowing a bit our preparation phase, would avoid to leave
to the exec function the job to find where our program is.

Add tests simulating this behavior.
2022-12-12 15:58:13 +01:00
Marco Trevisan (Treviño)
da8aa0b66d desktop-app-info: Use launch context PATH and desktop Path to find terminals
We used to launch applications with terminals using the normal program
finder logic that did not consider the context path nor the desktop file
working dir. Switch to g_find_program_for_path() to find terminals so we
can ensure that both conditions are true.

Update tests to consider this case too.
2022-12-12 15:58:13 +01:00
Marco Trevisan (Treviño)
e41e3dc601 gdesktopappinfo: Take in account the desktop Path to find executables
Desktop files can provide the executable working path and that can be
used to pick the file to launch.

So take it in account.
2022-12-12 15:58:13 +01:00
Philip Withnall
191e89878d tests: Add basic GApplicationCommandLine unit tests
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-09 10:45:21 +00:00
Philip Withnall
c0eef5e226 gapplication: Validate types of well-known platform data keys
The platform data comes from the parent process, which should normally
be considered trusted (if we don’t trust it, it can do all sorts of
other things to mess this process up, such as setting
`LD_LIBRARY_PATH`).

However, it can also come from any process which calls `CommandLine`
over D-Bus, so always has to be able to handle untrusted input. In
particular, `v`-typed `GVariant`s must always have their dynamic type
validated before having values of a static type retrieved from them.

Includes unit tests.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
eb0d9e709a gapplication: Document that command line options must be validated
They come from an external process, so they must be validated.

In particular, it’s always easy to forget to validate the type of a
`GVariant`, and just try to get the stored value using a well-known
type; but that’s a programming error if the `GVariant` actually stores a
different type. Always check the variant type first if loading from a
`v`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
83c11637ba gfdonotificationbackend: Validate actions before activating them
These actions are activated as a result of receiving the `ActionInvoked`
signal from `org.freedesktop.Notifications`. As that’s received from
another process over D-Bus, it’s feasible that it could be malformed.
Without validating the action and its parameter, assertions will be hit
within the `GAction` code.

While we should be able to trust whatever process owns
`org.freedesktop.Notifications`, it’s possible that’s not the case, so
best validate what we receive.

Includes unit tests.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
08012bd3e0 tests: Add stub tests for GFdoNotificationBackend
This test is fairly pointless, but puts the infrastructure in place for
adding more tests for `GFdoNotificationBackend` in upcoming commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
3987f41f8c gfdonotificationbackend: Don’t remove notification if invoking action fails
Invoking an action on a notification should remove it (by default,
unless the `resident` hint is set, but GLib doesn’t currently support
that).

If, somehow, an invalid action is invoked on the notification, that
shouldn’t cause it to be removed though, because no action has taken
place. So change the code to do that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-09 10:45:21 +00:00
Philip Withnall
da634e7a25 gapplication: Validate actions activated over D-Bus
As with the previous commit, the arguments to `ActivateAction` have to
be validated before being passed to `g_action_group_activate_action()`.
As they come over D-Bus, they are coming from an untrusted source.

Includes unit tests for all D-Bus methods on `GApplication`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
dbe4531e86 gactiongroupexporter: Validate actions activated or changed over D-Bus
The action name, parameter and new state are all controlled by an
external process, so can’t be trusted. Ensure they are validated before
being passed to functions which assert that they are correctly typed and
extant.

Add unit tests.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
5fd101eccc tests: Move a helper function around in the actions test
This will be used in an upcoming commit.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1904
2022-12-09 10:45:21 +00:00
Philip Withnall
c27b02ace7 Merge branch 'gio-thumbnail-sizes' into 'main'
file-info: Add a set of attributes for large thumbnails

Closes #621

See merge request GNOME/glib!2918
2022-12-08 09:04:45 +00:00
Matthias Clasen
f0606d5421 file-info: Add a set of attributes for large thumbnails
Some applications (eg., gnome-photos) really want a large thumbnail,
if one can be created. Simply falling back to a smaller one (probably
created by an old nautilus), without giving the application a chance
to create a bigger thumbnail, is undesirable because they will appear
fuzzy.

Therefore, at separate attribute sets for all the thumbnail sizes
that are supported in the spec: normal/large/x-large/xx-large.

The old attribute will now return by default the biggest available, as
it used to be, but also including the x-large and xx-large cases.

Co-Authored-by: Marco Trevisan <mail@3v1n0.net>

Fixes: #621
2022-12-08 05:21:19 +01:00
Chris Talbot
eb12afed6f gsimpleproxyresolver: Make explicit that a port is needed for HTTP/HTTPS 2022-12-06 13:37:47 +00:00
Marco Trevisan
6599cf95ae Merge branch 'wip/pwithnall/dbus-system-bus-address' into 'main'
gdbusaddress: Use runstatedir rather than localstatedir

See merge request GNOME/glib!3101
2022-12-06 00:24:17 +00:00
Philip Withnall
7b9dcb70c4 gunixmounts: Include configured localstatedir+runstatedir in system FS list
In case they differ from the defaults, we probably want to ignore them
when listing filesystems which are interesting to the user.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-02 21:53:18 +00:00
Philip Withnall
b7b9f89417 gdbusaddress: Use runstatedir rather than localstatedir
This reworks commit 20e1508e6e, for two
reasons:
 - Upstream dbus.git now does the same (although this isn’t yet reflected
   in the online version of the D-Bus Specification); see
   https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/209.
 - It allows local-prefix (e.g. jhbuild) builds of GLib to build in a
   custom prefix while still interacting with system services using the
   system-wide `/run` directory. To do so, pass `-Druntime_dir=/run` to
   meson configure.

As documented in the `NEWS` file in
https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/209, it’s only
valid to use `/run` – rather than `/var/run` – for D-Bus if the two
paths are interoperable. i.e. `/var/run` should be a symlink to `/run`,
and the D-Bus daemon should be configured to put its socket there.

This commit deliberately doesn’t introduce a special `system_socket`
configure option for specifying where the D-Bus system socket lives, as
that would only be useful for a distribution which sets `runstatedir` to
something other than `/var/run` or `/run`, which seems unlikely. We
could add such an option in future, though, if a distribution comes
forward with such a requirement.

See discussion on
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3095#note_1605502.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-02 21:53:18 +00:00
Philip Withnall
f4c9b42084 Merge branch 'use-socklen-t' into 'main'
gsocket: use socklen_t in more places to fix build under cygwin

See merge request GNOME/glib!3105
2022-12-02 21:24:52 +00:00
Christoph Reiter
60ab0737df gsocket: fix -Wsign-compare warnings when socklen_t is signed
under cygwin socklen_t is signed which leads to warnings like:

warning: comparison of integer expressions of different signedness:
‘long unsigned int’ and ‘socklen_t’ {aka ‘int’} [-Wsign-compare]

In both cases we compare against some small fixed sizes, so cast them
to socklen_t.
2022-12-02 21:17:42 +01:00
Christoph Reiter
e31c6accc5 gsocket: use socklen_t in more places to fix build under cygwin
cygwin defines socklen_t as int, unlike everywhere else where it is uint32_t (afaics),
so signed vs unsigned.

The recently added -Werror=pointer-sign in 4353813058
makes the build fail under cygwin now with something like:

error: pointer targets in passing argument 5 of ‘getsockopt’ differ in signedness [-Werror=pointer-sign]

This changes guint to socklen_t where needed for getsockname, getpeername and getsockopt.
2022-12-02 21:17:22 +01:00
Alynx Zhou
6dd5f2515f gdesktopappinfo: Use strstr instead of g_str_has_prefix for search
Fixes: #1152
2022-12-02 19:19:47 +00:00
Jason Francis
acfeb65633
gsocketcontrolmessage: add nullable annotation to deserialize return 2022-11-29 17:46:16 -05:00
Philip Withnall
5218765de2 Merge branch 'form-default-gdbusaddress' into 'main'
gdbusaddress: Form default system dbus path using meson definitions

See merge request GNOME/glib!3095
2022-11-28 18:36:47 +00:00
Roman Stratiienko
20e1508e6e gdbusaddress: Form default system dbus path using meson definitions
This is useful for systems where rootfs doesn't contain /var directory,
e.g. on Android.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2022-11-28 19:57:59 +02:00
Sonny Piers
29da935c28 Fix doc typo in g_dbus_connection_signal_subscribe 2022-11-28 11:33:09 +00:00
Philip Withnall
24e1bfba16 Merge branch 'snap-portal-support' into 'main'
portal: Check for snap plugs before accessing portals

See merge request GNOME/glib!3020
2022-11-24 19:49:07 +00:00
Marco Trevisan (Treviño)
92fae633a0 gio/tests: Add tests for flatpak infos
Support testing flatpak infos, we do it by faking /.flatpak-info file in
case we're building in test mode.
2022-11-24 20:03:39 +01:00
Marco Trevisan (Treviño)
e6eebfd9c3 gportalsupport: Force use /usr/bin/snapctl to get snap connection status
Do not search in path for snapctl to avoid it to be potentially
overridden by changing the PATH env variable.

Still allow testing by using an ifdef to check if we're building for the
test files or not.
2022-11-24 20:03:39 +01:00
Marco Trevisan (Treviño)
94ebd9f041 gio/tests/sandbox: Use test portal utils to create fake snap.yaml 2022-11-24 20:03:39 +01:00
Marco Trevisan (Treviño)
b1a2b64e94 gio/tests: Add tests for portal support functions
Test all the snap cases and the unknown sandbox one.

We need to use different test processes as we initialize the portal
type early enough that it can't be changed later.
2022-11-24 20:03:39 +01:00
Robert Ancell
216d7ba042 portal: Check for snap plugs before accessing portals
This is of particular use in the gsettings backend, which is currently using
dconf for all snaps.
Fully confined snaps should use the keyfile backend, as Flatpaks do.

Co-Authored-by: Marco Trevisan <mail@3v1n0.net>
2022-11-24 20:00:18 +01:00
Marco Trevisan (Treviño)
0e4dff445f gsandbox: Mark classic snaps as UNKNOWN sandbox type
Classic snaps are just a kind of packages with no sandbox at all, so
there's no point to mark them as sandboxed.

In this way we can just do IO checks once without having to multiply
them.

Co-Authored-by: Robert Ancell <robert.ancell@canonical.com>
2022-11-24 20:00:18 +01:00
Philip Withnall
66499d2199 Revert "build: Don’t define redundant built-in variables in pkgconfig calls"
This reverts commit 7e3e591d43.

The freedesktop SDK, which is used by gnome-build-meta, only has Meson
0.63. Bumping GLib’s Meson dependency to 0.64 means that, at the moment,
GLib is not buildable in gnome-build-meta and hence can’t be tested in
nightly pipelines against other projects, etc.

That’s bad for testing GLib.

It’s arguably bad that we’re restricted to using an older version of
Meson than shipped by Debian Testing, but that’s a separate discussion
to be had.

Revert the Meson 0.64 dependency until the freedesktop SDK ships Meson ≥
0.64. This also means reverting the simplifications to use of
`gnome.mkenum_simple()`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3077#note_1601064
2022-11-24 12:10:03 +00:00
Philip Withnall
b4231844a2 Revert "build: Use fs.copyfile() instead of configure_file()"
This reverts commit 19353017a7.

The freedesktop SDK, which is used by gnome-build-meta, only has Meson
0.63. Bumping GLib’s Meson dependency to 0.64 means that, at the moment,
GLib is not buildable in gnome-build-meta and hence can’t be tested in
nightly pipelines against other projects, etc.

That’s bad for testing GLib.

It’s arguably bad that we’re restricted to using an older version of
Meson than shipped by Debian Testing, but that’s a separate discussion
to be had.

Revert the Meson 0.64 dependency until the freedesktop SDK ships Meson ≥
0.64. This also means reverting the simplifications to use of
`gnome.mkenum_simple()`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3077#note_1601064
2022-11-24 12:09:55 +00:00
Philip Withnall
b646b1cab7 Revert "meson: Use gnome.mkenum_simple()"
This reverts commit 756b424cce.

The freedesktop SDK, which is used by gnome-build-meta, only has Meson
0.63. Bumping GLib’s Meson dependency to 0.64 means that, at the moment,
GLib is not buildable in gnome-build-meta and hence can’t be tested in
nightly pipelines against other projects, etc.

That’s bad for testing GLib.

It’s arguably bad that we’re restricted to using an older version of
Meson than shipped by Debian Testing, but that’s a separate discussion
to be had.

Revert the Meson 0.64 dependency until the freedesktop SDK ships Meson ≥
0.64. This also means reverting the simplifications to use of
`gnome.mkenum_simple()`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3077#note_1601064
2022-11-24 12:06:10 +00:00
Marco Trevisan (Treviño)
660242af07 tests/sandbox: Use isolated-directories
So we don't have to bother to manually remove the created artifacts.
2022-11-24 05:38:32 +01:00
Robert Ancell
4ba188c906 portal: Rename function to not be flatpak specific
It will also read snap information
2022-11-24 05:38:32 +01:00
Simon McVittie
a241226f2e Merge branch 'gdbus-tests-isolate-dirs' into 'main'
tests: Add G_TEST_OPTION_ISOLATE_DIRS to almost all gdbus tests

See merge request GNOME/glib!3088
2022-11-23 17:20:44 +00:00
Xavier Claessens
756b424cce meson: Use gnome.mkenum_simple()
Meson now uses find_program() to get glib-mkenum from glib instead of
from system. That was already fixed at least in >=0.60 which is our
current minimum requirement.
2022-11-23 08:02:34 -05:00
Xavier Claessens
6dd5c5002a Merge branch 'wip/pwithnall/meson-0.64' into 'main'
build: Bump Meson dependency to 0.64.0

See merge request GNOME/glib!3077
2022-11-23 11:48:51 +00:00
Philip Withnall
fd27c8dc6e tests: Add G_TEST_OPTION_ISOLATE_DIRS to almost all gdbus tests
This is a spiritual follow-up to commit 8cff531520, which
added `G_TEST_OPTION_ISOLATE_DIRS` to the `gdbus-connection-flush` test
to avoid its D-Bus cookie lock file from being erroneously deleted by
other tests running in parallel.

The same failure mode could affect any of the other D-Bus tests which
connect to a bus. As an easy fix, enable `G_TEST_OPTION_ISOLATE_DIRS`
for all of them.

The only test it’s not (yet) enabled for is `gdbus-address-get-session`
as that messes around with `XDG_RUNTIME_DIR` to test finding the session
bus. It might be possible to use `G_TEST_OPTION_ISOLATE_DIRS` with it,
but that would take longer than I have right now.

In any case, the more tests (which try to connect to a bus) that this is
enabled for, the lower the chances of spurious test failure due to them
conflicting over shared resources.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-23 11:15:20 +00:00
Philip Withnall
19353017a7 build: Use fs.copyfile() instead of configure_file()
Because Meson complains about using `configure_file(copy: true)`.

Includes improvements by Xavier Claessens.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-23 10:40:32 +00:00
Philip Withnall
7e3e591d43 build: Don’t define redundant built-in variables in pkgconfig calls
This is deprecated since Meson 0.62.0, since Meson does this
automatically for us.

This fixes a Meson configure warning.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-23 10:39:58 +00:00
Marco Trevisan
291ca47bd5 Merge branch 'wait-for-nothing' into 'main'
tests: Remove a manual timeout from desktop-app-info test

See merge request GNOME/glib!3083
2022-11-22 17:58:04 +00:00
Marco Trevisan
8fba287c81 Merge branch 'wip/pwithnall/2777-zerosize' into 'main'
gio: Change content type of zero-sized files to application/x-zerosize

Closes #2777

See merge request GNOME/glib!3053
2022-11-22 17:52:47 +00:00
Philip Withnall
ebfbd9c56a tests: Remove a manual timeout from desktop-app-info test
It sometimes fails under valgrind, and is pointless: if the test is
wedged, it’s better to catch that with the timeout at the level of
`meson test`, which can be tailored (using `-t`) to the test environment
and wrapper.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2961#note_1600072

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-22 16:11:49 +00:00
Philip Withnall
0781e12f45 tests: Add additional assertions to gsubprocess test
This should quell a scan-build warning about passing `NULL` to
`strlen()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-18 16:34:06 +00:00
Philip Withnall
5f51cc844c gapplicationcommandline: Fix a minor typo in the documentation
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
fec865cb0c gapplicationcommandline: Add a missing transfer annotation
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
73f445b099 tests: Add some missing error checks to actions test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
b836ed5c13 tests: Stop using GMainLoop in actions test
Instead, iterate the `GMainContext` directly. This allows tests on
asynchronously returned values to be done in the actual test function,
rather than a callback, which should make the tests a little clearer.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
19eee4bc41 gtestdbus: Use g_timeout_add_seconds() rather than g_timeout_add()
This makes the code a little easier to understand and allows the kernel
a little bit more leeway in scheduling the callback, which is fine
because we don’t need high accuracy here.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
e8c068db50 gnotificationbackend: Fix a GDBusConnection leak
`g_notification_backend_new_default()` adds a reference on
`backend->dbus_connection` (if non-`NULL`), but nothing ever unreffed
that.

Fix that by adding a dispose method.

In practice this is not really a problem, because the notification
backend is held alive by a `GApplication`, which lives as long as the
process. It’ll be a problem if someone is to ever add unit tests for
`GNotificationBackend`s though. So let’s fix it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
683c7d05a3 gnotification: Fix a couple of minor typos in a documentation comment
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
18574d1ba9 gnotification: Improve docs around GVariant ownership
Add a few missing introspection annotations too.

This doesn’t change any of the ownership handling behaviour, just
documents what’s there. What’s there seems to be correct, to the extent
that I can see.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 10:12:05 +00:00
Philip Withnall
af6bf2dc02 ggtknotificationbackend: Fix a minor typo in a comment
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-15 17:59:36 +00:00
Philip Withnall
716189c4c7 gfdonotificationbackend: Improve internal docs around floating GVariants
The code is correct, but from a quick read-through it wasn’t entirely
clear to me how it handled floating `GVariant`s in object state or the
`parameter` argument.

Add an assertion and some comments to hopefully clarify things a little.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-15 17:59:36 +00:00
Philip Withnall
d470e7227a gaction: Improve documentation around floating GVariants
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-15 17:59:36 +00:00
Philip Withnall
4748db5fd3 gaction: Improve docs formatting for g_action_parse_detailed_name()
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-15 17:59:36 +00:00
Philip Withnall
5ac06ac8ea gaction: Add missing annotations to g_action_parse_detailed_name()
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-15 17:59:36 +00:00
Philip Withnall
55c1fc7dfc Merge branch 'wip/smcv/hidden-inotify' into 'main'
gio: Use hidden symbol visibility in static libraries

Closes #2811

See merge request GNOME/glib!3069
2022-11-14 13:21:51 +00:00
Alexander Kanavin
a9fa7589c6 tests: Work around Meson bug with using exe_wrapper
Do not use can_run_host_binaries() as it returns true even though
custom_target() does not currently correctly wrap target-built
tool binaries with exe_wrapper so they can be run on the host.

See https://github.com/mesonbuild/meson/issues/11029
2022-11-14 13:01:47 +00:00
Simon McVittie
c1ee1a99bc gio: Use hidden symbol visibility in static libraries
Building GLib 2.75.0 on Linux adds various inotify-related internal
symbols to the ABI, which doesn't seem to have been intentional.
I went through the other libraries in the build system, and it looks
as though the BSD kqueue backend would have the same problem.

GNU symbol visibility probably doesn't do anything for gio/win32, but
for completeness I've set that to use hidden symbols too, on the basis
that it'll be easier to get this right if we're consistent.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2811
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-14 12:36:22 +00:00
Xavier Claessens
b65d6f497d gio: Fix missing visibility header dependency 2022-11-12 10:20:49 -05:00
Philip Withnall
9b68c31b38 tests: Add a missing g_task_return_boolean() in gdbus-server-auth tests
Otherwise the task never returned a value.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/385

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-10 14:25:47 +00:00
Philip Withnall
fe89940572 gtask: Emit a debug message if a GTask is finalised without returning
This typically indicates a bug in the program, where a GTask has been
created, but a bug in the control flow has caused it to not return a
value.

There is one situation where it might be legitimate to finalise a GTask
without returning: if an error happens in your *_async() start function
after you’ve created a GTask, but before the async operation returns to
the main loop; and you report the error using g_task_report_*error()
rather than reporting it using the newly constructed GTask.

Another situation is where you are just using GTask as a convenient way
to move some work to another thread, without the complexity of creating
and running your own thread pool. GDBus does this with
g_dbus_interface_method_dispatch_helper(), for example.

In most other cases, it’s a bug. Emit a debug message about it, but not
a full-blown warning, as that would create noise in the legitimate
cases.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2022-11-10 14:25:47 +00:00
Ray Strode
4a00ac91c6 tests: Shorten internal codegen test timeout
the gio dbus codegen test has 10 test cases in it.
Each test case is given 100 seconds to complete.

That is far longer than they should need.

Furthermore, the entire test is only given 60s
to complete.

This commit makes the internal timeout more consistent
with the external timeout, by giving each of the 10
test cases 6 seconds instead of 100s.
2022-11-08 13:08:53 -05:00
Philip Withnall
e2b9e28ece Merge branch 'wip/3v1n0/meson-fix-tests-binary-dependencies' into 'main'
test/meson: Add tests dependencies on built programs, libraries and modules

See merge request GNOME/glib!3015
2022-11-08 12:30:53 +00:00
Philip Withnall
42c9e8218b gio: Change content type of zero-sized files to application/x-zerosize
That’s what xdgmime uses for zero-sized files (see `XDG_MIME_TYPE_EMPTY`).

Historically, GLib explicitly used `text/plain` for empty files, to
ensure they would open in a text editor. But `text/plain` is not really
correct for an empty file: the content isn’t text because there is no
content. The file could eventually become something else when written
to.

Text editors which want to be opened for new, empty files should add
`application/x-zerosize` to their list of supported content types.

Users who want to set a handler for `application/x-zerosize` on their
desktop should use
```sh
gio mime application/x-zerosize  # to see the current handler
gio mime application/x-zerosize org.gnome.gedit.desktop  # to set it
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2777
2022-11-07 13:21:28 +00:00
Philip Withnall
5af339aedf gio: Check __APPLE__ in a few places instead of HAVE_COCOA
`HAVE_COCOA` should be used only in the places where we’re actually
depending on the Cocoa toolkit. It should not be used as a general way
of detecting building on a Darwin-based OS such as macOS.

Conversely, there are a few places in the code where we do want to
specifically detect the Cocoa toolkit (and others where we specifically
want to detect Carbon), so keep `HAVE_COCOA` and `HAVE_CARBON` around.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2802
2022-11-07 11:30:32 +00:00
Philip Withnall
7b52ccbfc4 Revert "gio, glib: Use G_OS_DARWIN for code that is for such environments"
This reverts commit 476e33c3f3.

We’ve decided to remove `G_OS_DARWIN` in favour of recommending people
use `__APPLE__` instead. As per the discussion on #2802 and linked
issues,
 * Adding a new define shifts the complexity from “which of these
   platform-provided defines do I use” to “which platform-provided
   defines does G_OS_DARWIN use”
 * There should ideally be no cases where a user of GLib has to use
   their own platform-specific code, since GLib should be providing
   appropriate abstractions
 * Providing a single `G_OS_DARWIN` to cover all Apple products (macOS
   and iOS) hides the complexity of what the user is actually testing:
   are they testing for the Mach kernel, the Carbon and/or Cocoa user
   space toolkits, macOS vs iOS vs tvOS, etc

Helps: #2802
2022-11-07 11:30:32 +00:00
Michael Catanzaro
24f2cfba25 gtask: don't use g_task_set_static_name() unless allowed
Need to check GLIB_VERSION_MIN_REQUIRED before inlining use of something
newer.

Fixes #2805
2022-11-03 19:06:40 -05:00
Simon McVittie
32b0dd24e3 Add a SPDX LicenseRef for the license historically used for tests
Some of GLib's unit tests are under an apparently GLib-specific
permissive license, vaguely similar to the BSD/MIT family but with the
GPL's lack-of-warranty wording. This is not on SPDX's list of
well-known licenses, so we need to use a custom license name prefixed
with LicenseRef if we want to represent this in SPDX/REUSE syntax.

Most of the newer tests seem to be licensed under LGPL-2.1-or-later
instead.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-02 12:34:19 +00:00
Philip Withnall
7ee767213b Merge branch 'mcatanzaro/#2799' into 'main'
gproxyresolver: lookup_finish() should better parallel lookup_async()

Closes #2799

See merge request GNOME/glib!3045
2022-11-02 09:47:32 +00:00
Xavier Claessens
f6edb52bda Merge branch 'wip/3v1n0/some-meson-fixmes' into 'main'
meson: Handle various build system FIXME's

See merge request GNOME/glib!3012
2022-11-01 23:36:04 +00:00
Michael Catanzaro
7f85fd126b gproxyresolver: lookup_finish() should better parallel lookup_async()
In g_proxy_resolver_lookup_async() we have some error validation that
detects invalid URIs and directly returns an error, bypassing the
interface's lookup_async() function. This is great, but when the
interface's lookup_finish() function gets called later, it may assert
that the source tag of the GTask matches the interface's lookup_async()
function, which will not be the case.

As suggested by Philip, we need to check for this situation in
g_proxy_resolver_lookup_finish() and avoid calling into the interface
here if we did the same in g_proxy_resolver_lookup_async(). This can be
done by checking the source tag.

I added a few new tests to check the invalid URI "asdf" used in the
issue report. The final case, using async GProxyResolver directly,
checks for this bug.

Fixes #2799
2022-11-01 13:40:35 -05:00
Matthias Clasen
13e48ff963 tests: Tweak the task tests
Tweak the g_task_set_name test to use a non-literal string,
so we don't test g_task_set_static_name twice.
2022-11-01 11:48:52 +00:00
Matthias Clasen
525e3953ef tests: Add a test for g_task_set_static_name()
The test checks that the original string
is returned by g_task_get_name().
2022-11-01 11:48:46 +00:00
Matthias Clasen
99c7d60869 gtask: Add g_task_set_static_name()
Similar to g_source_set_static_name, this avoids
strdup overhead for debug-only information in
possibly hot code paths.

We also add a macro wrapper for g_task_set_name that
uses __builtin_constant_p to decide whether to use
g_task_set_name or g_task_set_static_name.
2022-11-01 11:48:38 +00:00
Matthias Clasen
794ee60306 gdbusconnection: Set a name on all sources
We already set names on most sources, this
one was just forgotten. This lets us set
a static name, and prevents g_task_attach_source
from setting a non-static one.
2022-11-01 11:48:33 +00:00
Matthias Clasen
01f2c5aec9 gtask: Don't overwrite source names
Only set a name in g_task_attach_source
if the source does not already have one.

Including a new test by Philip Withnall.
2022-11-01 11:48:08 +00:00
Robert Ancell
bfd7074dfc gio: Fix formatting 2022-11-01 10:20:36 +00:00
Robert Ancell
5a83f384d1 Fix meson formatting 2022-11-01 10:20:36 +00:00
Robert Ancell
568763e776 gio: Create a sandbox checking function 2022-11-01 10:20:36 +00:00
Marco Trevisan (Treviño)
c490e3c522 gio/tests/meson: Add resource plugin as test dependency 2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
407c45ddaf gio/tests/meson: Add fake-service-name as gdbus-names dependency
It uses a fake name owner that we didn't depend on
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
ed013f9550 gio/tests/meson: Make giomodule test to depend on built modules
These are loaded dynamically so we need to ensure they're available at
test time
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
ff195b6e0d gio/tests/meson: Add dbus-launch as dependency of gdbus-address-get-session 2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
fd2b4e4ca4 gio/tests/meson: Add glib-compile-schemas as dependency for gsettings test 2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
0525a32c09 gio/tests/meson: Add fake-document-portal as dependency of dbus-appinfo
It uses the portal, but it doesn't depend on it.
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
cb85b26dd2 gio/tests/meson: Add gdbus-connection-flush-helper as dependency of connection tests 2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
01349e8e7f gio/tests/meson: Add gdbus-testserver prog as dependency of GDbus tests
Most gdbus tests launch the gdbus-testserver binary, so add it as
dependency of such tests.
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
caf75d8f9c gio/tests/meson: Add basic-application as prerequisite of gapplication
It's currently commented code, but in any case it's better to build it
earlier
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
97b0e96577 gio/tests/meson: Add gsubprocess-testprog as gsubprocess dependency
It launches such binary, so add it as prerequisite.
2022-11-01 01:56:20 +01:00
Marco Trevisan (Treviño)
e1e4084ecb gio/tests/meson: Add appinfo-test and apps as appinfo tests dependency
We need to make sure that such binaries are built and available at test time
or we may fail some tests requiring them (directly or through desktop file).

As per this, and because now generated desktop files are available both
at build and install time, don't skip some tests we were used to, but
actually enforce they are running.
2022-11-01 01:56:10 +01:00
Marco Trevisan (Treviño)
a1a0a9d75a gio/meson: Make possible for test to depend on extra programs
We have some test programs on which some tests depend on, for example
appinfo-test is a tool that is used by the desktop-app-info tests.

So test can now have an 'extra_programs' key where the extra program
names can be included.

This could have been handled manually via 'depends', but this allows
to avoid repeating code and be sure that all is defined when extra
programs targets are checked.
2022-11-01 01:56:09 +01:00
Philip Withnall
176f66502d tests: Reduce an unnecessary sleep from desktop-app-info test
`g_app_info_launch_default_for_uri_async()` has already returned by this
point, so waiting a long time is not really going to help.

Wait for 3× as long as the successful case took, which should allow for
long enough to catch true negatives, with a bit of variance.

On my system, this means waiting for about 14ms, rather than the 100ms
which this previous slept for. This speeds the test up by about 5%.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-01 00:33:40 +00:00
Marco Trevisan (Treviño)
e9cbcfff80 gio/tests/meson: Always generate desktop files for local builds
We were generating .desktop files with different content when installed
tests were enabled, and thus making impossible to test some cases
because there was no built file until installed.

To avoid this, always generate both versions of desktop files while
install only the one containing the install path prefix if needed.
2022-11-01 01:31:49 +01:00
Marco Trevisan (Treviño)
359c705fc6 gio/tests/meson: Make desktop-app-info depend on gio-launch-desktop
We actually use it to launch applications so it has to be built at test
time
2022-11-01 01:31:49 +01:00
Philip Withnall
cbf17c9422 Merge branch 'wip/3v1n0/support-can-fail-tests' into 'main'
meson, ci: Support tests that can fail under certain conditions

See merge request GNOME/glib!2987
2022-10-31 14:28:02 +00:00
Marco Trevisan (Treviño)
be665cdce0 glib,gio/tests: Mark some spawn tests as flaky under windows
It a may fail at times, but it generally works:

 See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2346261
 See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2346262
2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
3c56d661d8 meson: Use test setup environment instead of repeating it everywhere 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
3e227fb528 glocalfileinfo: Define errsv only if it's used 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
b30430970a tests: Mark should_fail tests as can_fail
Even if they are expected to fail, we should not use an inverse logic
for treating their return codes.
2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
8d5ae3ae83 ci: Mark failing mingw tests as can-fail and do not ignore test failures 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
54a9e797fe ci: Mark failing windows tests as can-fail and do not ignore test failures 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
b9e085537d meson: Expose library build type as global variables
Given that it can be computed using an error-prone strings comparisons it
is better to provide a variable everywhere, so that we don't have the
risk of comparing values that are always false.
2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
914bb06ab4 gio: mark codegen test as can-fail in freebsd
See: https://gitlab.gnome.org/GNOME/glib/-/issues/2764
2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
62dca6c1cf meson, ci: Support tests that can fail under certain conditions
We have tests that are failing in some environments, but it's
difficult to handle them because:
 - for some environments we just allow all the tests to fail: DANGEROUS
 - when we don't allow failures we have flacky tests: A CI pain

So, to avoid this and ensure that:
 - New failing tests are tracked in all platforms
 - gitlab integration on tests reports is working
 - coverage is reported also for failing tests

Add support for `can_fail` keyword on tests that would mark the test as
part of the `failing` test suite.
Not adding the suite directly when defining the tests as this is
definitely simpler and allows to define conditions more clearly (see next
commits).

Now, add a default test setup that does not run the failing and flaky tests
by default (not to bother distributors with testing well-known issues) and
eventually run all the tests in CI:
 - Non-flaky tests cannot fail in all platforms
 - Failing and Flaky tests can fail

In both cases we save the test reports so that gitlab integration is
preserved.
2022-10-31 14:08:29 +01:00
Marco Trevisan
4339df0583 Merge branch 'portal-support-missing-guards' into 'main'
portal: Fix broken header guard

See merge request GNOME/glib!3035
2022-10-31 12:31:01 +00:00
Robert Ancell
0239417935 portal: Fix broken header guard
This wouldn't have caused an issue with the current header contents, but could have triggered a future bug.
2022-10-31 12:08:41 +01:00
Marco Trevisan (Treviño)
dd422a0588 gio/tests/win32-streams: Avoid doing sign casting when we can
the offset can be just an unsigned parameter so that we don't have to cast
the sizeof (DATA) result.
2022-10-31 12:02:57 +01:00
Philip Withnall
9f10881574 Merge branch 'wip/smcv/autofd' into 'main'
gstdio: Silence "Not available before" warnings for inline functions

Closes #2796

See merge request GNOME/glib!3026
2022-10-27 21:55:09 +00:00
Marco Trevisan
d0b3021f7f Merge branch 'nirbheek/gmodule-suffix-deprecation' into 'main'
Improve g_module_open(), deprecate G_MODULE_SUFFIX

Closes #520 e #1413

See merge request GNOME/glib!2950
2022-10-27 16:27:42 +00:00
Nirbheek Chauhan
958d0f9b9b tests: Fix resources test on macOS
The content type detection is not very specific on macOS.
2022-10-27 20:26:53 +05:30
Nirbheek Chauhan
d941558ee9 Improve g_module_open(), deprecate G_MODULE_SUFFIX
G_MODULE_SUFFIX is deprecated now because you will get the wrong
results using it most of the time:

1. The suffix on macOS is usually 'dylib', but it's 'so' when using
   Autotools, so there's no way to get the suffix correct using
   a pre-processor macro.
2. Prefixes also vary in a platform-specific way. You may or may not have
   a 'lib' prefix for the name on Windows and on Cygwin the prefix is
   'cyg'.
3. The library name itself can vary per platform. For instance, you may
   want to load foo-1.dll on Windows and libfoo.1.dylib on macOS. This
   is for libraries, not modules, but that is still a use-case that
   people use the GModule API for.

g_module_build_path() does take care of (2) on Cygwin, but it
fundamentally cannot handle the possibility of multiple options for
the module name, since it does not do any I/O. Hence, it is also
deprecated.

Instead, g_module_open() has been improved so that it takes care of
all this by searching the filesystem for combinations of possible
suffixes and prefixes on each platform. Along the way, the
documentation for it was also improved to make it clearer what it
does.

Closes https://gitlab.gnome.org/GNOME/glib/-/issues/520

Closes https://gitlab.gnome.org/GNOME/glib/-/issues/1413
2022-10-27 20:26:53 +05:30
Simon McVittie
a62dd272d8 tests: Test that we can include all headers with an old MAX_VERSION
In principle we could script this so that each max-version.c is compiled
26 times, once per possible MAX_VERSION, but I haven't implemented
that here: just pinning to the oldest possible version is sufficient to
reproduce #2796.

These aren't included in the installed-tests, since they don't really
do anything at runtime (the important thing is that they compile
without warnings).

Reproduces: #2796
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-27 14:50:48 +01:00
Maxime Gervais
ae65753b16 Add kgx (gnome console) known terminals lists 2022-10-27 00:21:39 +02:00
Simon McVittie
65016fddd9 Replace all uses of G_VA_COPY with Standard C va_copy
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-26 18:07:55 +01:00
Marco Trevisan
b9e68b0bd4 Merge branch 'support-xdg-terminal-exec' into 'main'
Add support for xdg-terminal-exec for handling desktop applications using 'Terminal=true'

See merge request GNOME/glib!2839
2022-10-26 17:03:12 +00:00
Max Gautier
dd9bc7cf59 gio: test xdg-terminal-exec usage 2022-10-26 18:41:26 +02:00
Max Gautier
22e1b9bcc0 gio: add xdg-terminal-exec as a known terminal
Allow users to select their terminal of choice by using the
xdg-terminal-exec wrapper.

It is a temporary temporary solution while waiting for the
xdg-default-apps specification
(https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/54), in
accordance with this comment:
https://gitlab.gnome.org/GNOME/glib/-/issues/338#note_1076172
2022-10-26 18:41:26 +02:00
Max Gautier
b64347d279 gio: add support for terminal with no option
Introduce support for terminals executing commands without an option,
i.e., the command is passed directly as argument to the terminal emulator.
This is needed for xdg-terminal-exec.
2022-10-26 18:41:26 +02:00
Max Gautier
eb2d1d8fc8 gio: Refactor the known terminals search
Get rid of multiple conditionals branch by using a loop and storing the
options needed by particular terminal emulators directly in an array.
Remove intermediate variable term_argv as we don't need it.

Advantages:
- simpler logic, less branching
- the terminal emulator list is more readable, by virtue of being
  condensed in one array. Launch options to execute a terminal program
  are also more explicitly specified
- the logic become independent from the order
- one less allocation
2022-10-26 18:15:26 +02:00
Xavier Claessens
b8a0ffa1b9 meson: Add missing install tags 2022-10-26 11:55:56 -04:00
Marco Trevisan (Treviño)
e955cd4842 gio: Install empty glib gio modules dir on install
This requires to keep the relative path around not to have to play with
paths too much at python level.
2022-10-26 17:39:23 +02:00
Philip Withnall
010d831e0e Merge branch 'fix-desktop-app-info-leak' into 'main'
gio/gdesktopappinfo: Free the wrapped argv array on launch failure

See merge request GNOME/glib!3008
2022-10-26 09:28:08 +00:00
Marco Trevisan (Treviño)
dafd6602dc gio/gdesktopappinfo: Free the wrapped argv array on launch failure
We create an array that we never free, ensure this is the case.
The previous commit gives CI a chance to check this with valgrind job.

Found as part of another review:
 - https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2839#note_1524922
2022-10-25 14:33:25 +02:00
Marco Trevisan (Treviño)
37e61d66c3 gio/tests/desktop-app-info: Add test to check failure on launch as manager
Trying to use invalid Fd's numbers so that this would fail early.
2022-10-25 14:33:25 +02:00
Marco Trevisan (Treviño)
6bbc72d2c4 gio/tests/desktop-app-info: Add a TestLaunchContext to improve SN testing
Add a custom launch context implementation so that we can test the
startup notification code better.
2022-10-25 14:33:25 +02:00
Marco Trevisan (Treviño)
ec67c7dbf2 desktop-app-info: Run test without display, they work with no issue 2022-10-25 14:31:02 +02:00
Marco Trevisan (Treviño)
d4a31897ab tests/desktop-app-info: Check if launched signal is emitted 2022-10-25 14:31:02 +02:00
Marco Trevisan (Treviño)
836fd0563d meson: Remove unneeded install_tag's on headers
Meson is able to handle this automatically when we're installing in the
include-dir prefix.
2022-10-24 21:09:49 +02:00
Marco Trevisan (Treviño)
6dd222e753 meson: Cleanup include-dir paths, use base path without repetitions
Avoid setting the subdir all the times, just use the global definition
plus the specific module subdir
2022-10-24 21:09:09 +02:00
Marco Trevisan (Treviño)
341895a19e glib, gmodule, gobject: Add generated headers to the lib dependency
This requires changing them from being generated sources at compile time
to custom targets, but it also ensures that they are actually there when
needed, in fact currently we may instead try to compile files that requires
them without having been generated yet.

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2346914 (glib)
See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2344802 (gmodule)
See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2345205 (gobject)
2022-10-23 18:04:56 +02:00
Simon McVittie
662661a8d0 Merge branch 'wip/pwithnall/macos-file-info-test-fixed' into 'main'
build: Mark the g-file-info test as succeeding

See merge request GNOME/glib!3004
2022-10-21 18:56:12 +00:00
msizanoen1
9151fe94cb gio: remove pointless use of g_unix_socket_address_abstract_names_supported with unix:tmpdir=
There's no point in checking for
g_unix_socket_address_abstract_names_supported now that unix:tmpdir=
always use non-abstract sockets.
2022-10-21 22:09:06 +07:00
msizanoen1
c0a1a3b384 gio/gdbusserver: use non-abstract socket for unix:tmpdir=
This implements https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/350
for GDBus's server implementation.

Abstract sockets belong to the network namespace instead of the mount
namespace. As a result, mount namespace-based sandboxes (e.g. Flatpak)
cannot restrict access to abstract sockets (and therefore GDBus's
unix:tmpdir= server addresses), at least for applications with network
access permission, which may result in sandbox escapes unless the
application running the GDBus server explicitly check that the connecting
process is not in a sandbox. As of the time of writing, no known
applications using GDBusServer does this.

Fix this by always using non-abstract sockets for unix:tmpdir=, which is
allowed by the DBus specification.
2022-10-21 22:08:11 +07:00
Philip Withnall
d0eaccccad build: Mark the g-file-info test as succeeding
Previously it was marked as failing on macOS, but commit
ed3998b390 seems to have fixed that. yay!

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1392
2022-10-21 15:48:33 +01:00
Ross Burton
ed3998b390 gio/tests/g-file-info: don't assume million-in-one events don't happen
The access and creation time tests create a file, gets the time in
seconds, then gets the time in microseconds and assumes that the
difference between the two has to be above 0.

As rare as this may be, it can happen:

$ stat g-file-info-test-50A450 -c %y
2021-07-06 18:24:56.000000767 +0100

Change the test to simply assert that the difference not negative to
handle this case.

This is the same fix as 289f8b, but that was just modification time.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2022-10-20 14:41:56 +01:00
Philip Withnall
e6fa40bf99 Merge branch 'wip/3v1n0/add-darwin-os' into 'main'
meson: Define G_OS_DARWIN when compiling under OSX or iOS

See merge request GNOME/glib!2981
2022-10-20 11:41:48 +00:00
Philip Withnall
5b01b47c34 Merge branch 'gicon-introspect-vfuncs' into 'main'
gicon: Add introspection for to_tokens / from_tokens vfunc's

See merge request GNOME/glib!2937
2022-10-20 11:39:04 +00:00
Marco Trevisan (Treviño)
476e33c3f3 gio, glib: Use G_OS_DARWIN for code that is for such environments
While we preserved the COCOA/CARBON cases when specific libraries are
needed.
2022-10-20 03:37:21 +02:00
Philip Withnall
4b6cc2d87b Merge branch 'gtask-bitfields-fix' into 'main'
gtask: Use unsigned bit-field struct values to avoid warnings

See merge request GNOME/glib!2979
2022-10-19 11:32:25 +00:00
Ray Strode
8f85fa163b tests: Check for public.text not text/plain on OSX
The "content type" on OSX is a Uniform Type Identifier not a MIME
type, so make sure to use the right format in the empty file test.
2022-10-18 16:02:49 -04:00
Ray Strode
9d0d30c9d2 tests: Don't run du on osx
The du command that ships on OS X doesn't understand
--bytes, so don't try to use du on that platform.
2022-10-18 16:02:02 -04:00
Marco Trevisan (Treviño)
4398d140c7 gtask: Use unsigned bit-field struct values to avoid warnings
In recent Clang we may get a build warning as per:

  ../gio/gtask.c: warning: implicit truncation from 'int' to a
    one-bit wide bit-field changes value from 1 to -1
    [-Wsingle-bit-bitfield-constant-conversion]

This is because we use gboolean (and thus a signed type) for bit-fields.
Now, this is not an issue in practice for the way we're using them, but
still better to mute such compiler warns in the right way.
2022-10-18 21:28:00 +02:00
Ray Strode
11ca3da091 Merge branch 'halfline/test-case-pipe-confusion' into 'main'
tests/desktop-app-info: Make sure scripts writes to the right end of the pipe

See merge request GNOME/glib!2969
2022-10-18 17:57:52 +00:00
Marco Trevisan
2c90a563ae Merge branch 'unix-streams-fixes' into 'main'
tests: Fix race condition on cancellation in unix-streams test

See merge request GNOME/glib!2963
2022-10-18 16:30:19 +00:00
Marco Trevisan
337763bcf3 Merge branch 'always-sniff-xdg-mime' into 'main'
glocalfileinfo: Ensure we always sniff some data to get the content type

Closes #2742

See merge request GNOME/glib!2887
2022-10-18 16:27:25 +00:00
Ray Strode
04c8a6bc61 Revert "tests: Temporarily disable desktop-app-info terminal test on FreeBSD"
Since we no longer require /proc for the desktop-app-info test, we can
run it on FreeBSD again.

This reverts commit 3235eee0e2.
2022-10-18 12:15:10 -04:00
Ray Strode
4657e9bf60 tests/desktop-app-info: Use named pipe instead of /proc
Freebsd doesn't always have /proc mounted, so relying on
/proc for the tests isn't ideal.

This commit changes the desktop-app-info tests to use
mkfifo instead of /proc/../fd/.. to relay terminal
arguments.

Might help with this error message I'm seeing in CI:

/tmp/bin-path-H1UQT1/gnome-terminal: cannot create /proc/38961/fd/6: No such file or directory
2022-10-18 12:15:10 -04:00
Marco Trevisan (Treviño)
846e68befd glocalfileinfo: Ensure we always sniff some data to get the content type
In case the XDG database is not initialized yet we may try to sniff a
0-length data, making our content-type routines to mark non-empty files
as `application/x-zerosize`.

This is wrong, so in case the sniff size is not set, let's just
try to read the default value. To avoid false-application/x-zerosize
results (that are not something we want as per legacy assumptions).

See: https://bugzilla.gnome.org/show_bug.cgi?id=755795

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2742
2022-10-18 17:46:38 +02:00
Marco Trevisan
baa766295d Merge branch 'fix-desktop-app-info' into 'main'
tests: Fix minor race in desktop-app-info terminals test

See merge request GNOME/glib!2968
2022-10-18 14:44:42 +00:00
Emmanuele Bassi
52917f57ca Merge branch 'wip/pwithnall/2781-desktop-app-info-proc-bsd' into 'main'
tests: Temporarily disable desktop-app-info terminal test on FreeBSD

See merge request GNOME/glib!2972
2022-10-18 12:33:20 +00:00
Marc-André Lureau
d95cf75bf0 gio/module: ignore module leak
A module must exist forever after it is loaded. If it's not referenced
anywhere, as with some gio tests, ASAN will report direct leaks. Silence
those.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-18 14:31:31 +04:00
Philip Withnall
3235eee0e2 tests: Temporarily disable desktop-app-info terminal test on FreeBSD
It’s often (but not always) failing on the CI machines with a timeout
which looks like the FD sharing via `/proc` isn’t reliably working.

Disable this test (but not the whole `desktop-app-info` test suite) on
FreeBSD until someone who has access to a FreeBSD machine can debug it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2781
2022-10-18 10:35:17 +01:00
Marc-André Lureau
3967d1da56 Revert "gio/module: fix leak when there is no cache"
This reverts commit ad0fd6c5d9.

The type system actually keeps a weak reference on the module/plugin.
g_type_module_unuse() documentation is explicit "Once a #GTypeModule is
initialized, it must exist forever."

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-18 10:53:38 +04:00
Philip Withnall
1c42e2da25 tests: Fix minor race in desktop-app-info terminals test
The implementation of `g_desktop_app_info_launch_uris()` will spawn the
exec file once for each URI unless the desktop file has a placeholder in
its Exec line which supports multiple URIs at once.

The fake terminal doesn’t have such a placeholder, so the fake terminal
script is spawned twice in quick succession, once for each URI. Since it
was making two separate printf calls (one to print the output to the
pipe, and one to terminate it with a newline), it’s possible that two
invocations of the script could interleave their printf calls, resulting
in pipe input along the lines of `URI1 URI2 newline newline` rather than
`URI1 newline URI2 newline`.

This would cause the test to fail.

Fix that by making the script atomic by moving the newline into the
first printf call.

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2339109:
```
\# Fake 'nxterm' terminal created as: /tmp/bin-path-R6GWT1/nxterm
\# 'nxterm' called with arguments: '-e true nxterm-argument /tmp/bin-path-R6GWT1-e true nxterm-argument /tmp/test_desktop-app-info_CO92T1/desktop-app-info/launch-uris-with-terminal/nxterm/.dirs/data'
Bail out! GLib-GIO:ERROR:../gio/tests/desktop-app-info.c:1294:test_launch_uris_with_terminal: assertion failed (g_strv_length (output_args) == 4): (7 == 4)
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-17 17:40:53 +01:00
Philip Withnall
eef6ea9b3b Merge branch '2726-fuse-remote' into 'main'
glocalfile: Support marking fuse.sshfs filesystems as remote

Closes #2726

See merge request GNOME/glib!2966
2022-10-17 16:17:30 +00:00
Philip Withnall
bcb5eee0ea glocalfile: Support marking fuse.sshfs filesystems as remote
This requires checking the type of a filesystem using `/proc/mounts`
rather than `statfs()`, since `statfs()` doesn’t give the subtype of the
mount. So it only returns `fuse` rather than `fuse.sshfs`.

This commit changes the output of `gio info -f ./path/to/local/sshfs/mount`
from `filesystem::remote: FALSE` to `filesystem::remote: TRUE`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2726
2022-10-17 16:05:58 +01:00
Philip Withnall
be9e268c6a tests: Use g_assert_*() rather than g_assert() in unix-streams
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-17 13:03:26 +01:00
Philip Withnall
0c1fa95827 tests: Fix race condition on cancellation in unix-streams test
The cancellable may be cancelled just after the operation succeeds in a
different thread. So instead of checking whether the cancellable is
cancelled, check whether the operation returned a `CANCELLED` error, and
*then* assert that the cancellable is cancelled.

This should fix
https://pwithnall.pages.gitlab.gnome.org/-/glib/-/jobs/2338552/artifacts/_build/meson-logs/testlog.txt:
```
ok 1 /unix-streams/basic
Bail out! GLib-GIO:ERROR:../gio/tests/unix-streams.c:149:main_thread_skipped: assertion failed (err == (g-io-error-quark, 19)): err is NULL
stderr:
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-17 13:02:02 +01:00
Philip Withnall
09459fa44d gthreadedresolver: Comment on name expansion for SRV targets
See the commit contents. This clarifies the existing code’s behaviour
and doesn’t change it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2622
2022-10-17 12:46:01 +01:00
Marc-André Lureau
ad0fd6c5d9 gio/module: fix leak when there is no cache
GIOModule is a helper object, we keep it around when there is a cache,
but we should free it otherwise.

Found thanks to ASAN.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 14:32:15 +04:00
Marc-André Lureau
60b8916fee tests/gmenumodel: fix various leaks
Found thanks to ASAN.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 14:11:36 +04:00
Philip Withnall
292c117b98 Merge branch 'w32-tests' into 'main'
Various win32 test fixes

See merge request GNOME/glib!2952
2022-10-17 09:53:44 +00:00
Marc-André Lureau
30e7a00017 tests/contenttype: icon name text/plain doesn't have text-x-generic on win32
The g_content_type_get_icon() function for win32 can lookup the
DefaultIcon associated with .txt and return a different result.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 11:01:00 +04:00
Marc-André Lureau
f23d8a9087 gio/locafileinfo: fix set_mtime_atime on win32
Use a similar behaviour as the utime()/posix implementation and query
the current times to allow modifying only usec/nsecs parts.

Fixes tests/g-file-info on win32.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:52:11 +04:00
Marc-André Lureau
c3494ce5dc tests/file-thumbnail: make it work with win32 paths
On Win32, we get paths with mixed \\ and /, use GFile to resolve and
normalize the paths before comparing.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:43:59 +04:00
Philip Withnall
4bc284fca6 Merge branch 'wip/smcv/deprecated-prop-followup' into 'main'
Run tests with G_ENABLE_DIAGNOSTIC=1

See merge request GNOME/glib!2889
2022-10-15 21:31:29 +00:00
Philip Withnall
1e9cf21b30 Merge branch 'desktop-app-info-terminal-tests' into 'main'
tests/desktop-app-info: Add tests to verify if launching with terminal works

See merge request GNOME/glib!2884
2022-10-14 15:30:04 +00:00
Philip Withnall
6fab8a8cd9 Merge branch 'macos-gio-modules' into 'main'
giomodule: Automatically detect modules on macOS

See merge request GNOME/glib!2848
2022-10-14 15:29:04 +00:00
Xavier Claessens
4e44cea486 gdbus example: Every DLL must have its own visibility macro 2022-10-13 20:53:56 -04:00
Xavier Claessens
8733d172a3 Do not define GIO_COMPILATION for executables
It must only be defined when building libgio. This requires some
workaround to allow include of some gio private headers.

When GIO_COMPILATION is not defined we cannot include individual gio
headers. We workaround that by defining __GIO_GIO_H_INSIDE__ in some
places. Also gdbusprivate.h is not an installed header, so it's fine to
include it directly.
2022-10-13 20:53:56 -04:00
Xavier Claessens
90fcbc7dfc giomodules: g_io_module_* must always be exported
Those symbols are not used by GIO itself but by external modules.
2022-10-13 20:53:56 -04:00
Xavier Claessens
e5565f6635 Rename all visibility macros 2022-10-13 20:53:56 -04:00
Xavier Claessens
dcfc9f689e Fix symbol visibility macros on Windows
There is currently no `dllimport` attribute on any of our function,
which prevents MSVC to optimize function calls.

To fix that issue, we need to redeclare all our visibility macros for
each of our libraries, because when compiling e.g. GIO code, we need
dllimport in GLIB headers and dllexport in GIO headers. That means they
cannot use the same GLIB_AVAILABLE_* macro.

Since that's a lot of boilerplate to copy/paste after each version bump,
this MR generate all those macros using a python script.

Also simplify the meson side by using `gnu_symbol_visibility : 'hidden'`
keyword argument instead of passing the cflag manually.

This leaves only API index to add manually into glib-docs.xml when
bumping GLib version. That file cannot be generated because Meson does
not allow passing a buit file to gnome.gtkdoc()'s main_xml kwarg
unfortunately.
2022-10-13 20:53:56 -04:00
Piotr Brzeziński
af83c6571e giomodule: Automatically detect modules on macOS
Makes use of relocatable prefixes, allowing gio to find modules
automatically without needing to set the GIO_EXTRA_MODULES env var.
2022-10-14 05:21:09 +05:30
Philip Withnall
c16f524034 Merge branch 'static' into 'main'
tests: skip shared libs if default_library=static

See merge request GNOME/glib!2867
2022-10-12 16:19:02 +00:00
Alyssa Ross
1dc8d69edb tests: skip shared libs if default_library=static
Otherwise, the build will fail when the toolchain is static-only, even
with -Ddefault_library=static.  I talked to a Meson developer in their
IRC channel, who told me that the correct fix was to ensure that
shared_library is only used if default_library != static.
2022-10-12 16:49:39 +01:00
Philip Withnall
057a9e5773 Merge branch 'test-actions-parallel-fix' into 'main'
tests/desktop-app-info: Use unique temporary paths for action files

See merge request GNOME/glib!2885
2022-10-12 14:41:27 +00:00
Philip Withnall
5d504709ab Merge branch 'more-gio-thumbnail-sizes' into 'main'
glocalfileinfo: Add support for xx-large and x-large thumbnails

Closes #2767

See merge request GNOME/glib!2941
2022-10-12 13:43:07 +00:00
Philip Withnall
e90733a457 Merge branch 'atomic-older-cplusplus' into 'main'
gatomic: fix the atomic compare_and_exchange macros on older C++ standard versions

See merge request GNOME/glib!2864
2022-10-12 09:56:19 +00:00
Marco Trevisan (Treviño)
3f1724d832 tests/desktop-app-info: Add tests to verify if launching with terminal works
Simulate launching applications using terminals by creating scripts on
the fly that are named as the terminals that we support, ensuring that
these are called with the arguments that we expect.

Related to: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2839
2022-10-11 21:46:01 +02:00
Marco Trevisan (Treviño)
e7a68531b3 glocalfileinfo: Add support for xx-large and x-large thumbnails
Co-Authored-by: António Fernandes <antoniof@gnome.org>

Closes: #2767
2022-10-11 20:58:58 +02:00
Marco Trevisan (Treviño)
9bb1410c54 gio/tests: Add file-thumbnail tests
Check if thumbnails are created in the path we expect and that we can
retrieve their information, but also that we try to get the biggest size
available when multiple are available.
2022-10-11 20:58:58 +02:00
Marco Trevisan
cf4d8a3bdc Merge branch 'osx-declaration-mixes-fix' into 'main'
gosxcontenttype: Do not mix declarations with code

Closes #2759

See merge request GNOME/glib!2909
2022-10-11 13:24:57 +00:00
Marco Trevisan (Treviño)
60587d5965 tests/file: Include config.h so tests checking HAVE_* definitions are ran
We have tests depending on HAVE_UTIMES and HAVE_UTIMENSAT that were
currently not compiled because these were always undefined
2022-10-11 14:37:12 +02:00
Marco Trevisan (Treviño)
b1d4b4bb3b glocalfileinfo: Avoid getting unused type values 2022-10-11 14:24:17 +02:00
Jared Wahlstrand
15cb123c82 glocalfileinfo: don't call both utimes and utimensat
also split us precision and ns precision code to make this cleaner
2022-10-11 14:10:28 +02:00
Marco Trevisan
db259b5925 Merge branch 'atime' into 'main'
tests: skip g-file-info test if atime unsupported

See merge request GNOME/glib!2866
2022-10-10 15:32:06 +00:00
Philip Withnall
1d2ea6518c Merge branch 'fix-unix-streams-error-leak' into 'main'
tests/unix-streams: Free the cancelled error on cancelled cancellable

See merge request GNOME/glib!2892
2022-10-10 12:02:56 +00:00
Marco Trevisan (Treviño)
5a6ce16142 gicon: Do not mark g_icon_to_string() as to_tokens() invoker
That's not strictly true as they've different signature, and this leads
to some introspection and documentation errors.
2022-10-06 17:25:13 +02:00
Marco Trevisan (Treviño)
c3ebf6cdca gicon: Add virtual invokers for equal() and serialize() 2022-10-06 17:25:13 +02:00
Marco Trevisan (Treviño)
7ea5e4c293 gicon: Force g_icon_hash argument to be Gio.Icon for bindings 2022-10-06 17:25:13 +02:00
Marco Trevisan (Treviño)
19cfc55847 gicon: Add introspection for to_tokens / from_tokens vfunc's
The GIconIface virtual functions were not introspectable as they use
complex parameters that GI isn't able to compute alone.

So provide introspection metadata to the two function pointers
definitions.

GIcon::from_tokens is a static virtual function so it won't actually
work until GI support for it [1] is merged.

[1] https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/361
2022-10-06 17:25:10 +02:00
Peter Williams
7f7171e68a gio: properly guard use of utimensat()
Closes #2766.
2022-09-21 11:56:33 -04:00
Simon McVittie
25d21edb32 gio/tests: Disable deprecation warnings where necessary
The defaultvalue test sets all properties, even the deprecated ones.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-21 11:19:31 +01:00
Simon McVittie
88e160dfe4 tests: Move common test environment variables to top level
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-21 11:19:28 +01:00
Marco Trevisan
87b4771d1f Merge branch 'install-tag-2' into 'main'
meson: Set install_tag remaining installed files

See merge request GNOME/glib!2905
2022-09-21 10:05:18 +00:00
Xavier Claessens
a73ca336aa meson: Set install_tag on remaining installed files 2022-09-20 11:30:12 -04:00
Xavier Claessens
c00df192ee meson: Set install_tag on installed tests files
This could be done automatically by Meson, this commit can be reverted
when we have that Meson PR in our CI:
https://github.com/mesonbuild/meson/pull/10829
2022-09-20 11:30:02 -04:00
Marco Trevisan (Treviño)
5fc8a476c8 gosxcontenttype: Do not mix declarations with code
Fixes: #2759
2022-09-20 15:41:08 +02:00
Marco Trevisan
7b53edbf26 Merge branch 'local-output-stream-prevent-double-fd-close' into 'main'
glocalfileoutputstream: Do not double-close an fd on unlink error

See merge request GNOME/glib!2901
2022-09-20 13:19:04 +00:00
Marco Trevisan
51cf76ebb0 Merge branch 'kjellahl/gio-launch-desktop-clang' into 'main'
gio-launch-desktop: Fix the G_STATIC_ASSERT expressions for clang

Closes #2740

See merge request GNOME/glib!2898
2022-09-19 15:04:21 +00:00
Marco Trevisan
65abaa76c5 Merge branch 'task_get_cancellable_nullable' into 'main'
gio: make g_task_get_cancellable return value (nullable)

See merge request GNOME/glib!2899
2022-09-19 15:02:39 +00:00
Marco Trevisan
22f0522c10 Merge branch 'mcatanzaro/gtype-criticals' into 'main'
Replace most GObject warnings with criticals

See merge request GNOME/glib!2852
2022-09-19 14:35:12 +00:00
Marco Trevisan (Treviño)
2401e1a090 glocalfileoutputstream: Do not double-close an fd on unlink error
In case we fail unlinking a file we could close again an FD that has
been already just closed. So avoid this by unsetting it when closing.

Coverity CID: #1474462
2022-09-16 15:11:47 +02:00
Jason Francis
9cd9787c52
gio: make g_task_get_cancellable return value nullable 2022-09-16 01:27:12 -04:00
Kjell Ahlstedt
37dba1c425 gio-launch-desktop: Fix the G_STATIC_ASSERT expressions for clang
The clang compiler requires the static_assert expression to be an integral
constant expression. `"text"` is not, but `sizeof "text"` is.

Fixes #2740
2022-09-15 12:55:18 +02:00
Marco Trevisan (Treviño)
1cbe7a6734 meson: Build C++ tests for the currently supported C++ standard versions
We've various macros definitions that are depending using C++ features
that may not work in all the standard versions, so recompile the cxx
tests that we have in all the ones we want to support.
2022-09-15 01:18:40 +02:00
Alyssa Ross
7c74fe4c1d
tests: skip based on g_file_info_has_attribute
Per review request.  Matches the style for the newly introduced skip
check in test_g_file_info_access_time.
2022-09-14 13:21:53 +00:00
Alyssa Ross
7162b3c496
tests: skip g-file-info test if atime unsupported
For example, g_file_query_info will not be able to determine access
time for files on ZFS with atime=off.
2022-09-14 13:21:39 +00:00
Marco Trevisan (Treviño)
c8e2d4a38d unix-streams: Ensure we get cancelled errors if the cancellable is cancelled 2022-09-13 16:30:12 +02:00
Marco Trevisan (Treviño)
d40ef833e3 tests/unix-streams: Free the cancelled error on cancelled cancellable
Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-13 16:29:20 +02:00
Marco Trevisan (Treviño)
02de235059 tests/desktop-app-info: Use unique temporary paths for action files
desktop-app-info test may fail when repeated with multiple concurrent
processes because the actions test relies on checking the existence of
in the shared build directory, so by doing something like:

  meson test -C _build desktop-app-info -t 0.3 --repeat 80

We may end up in timeout errors, because we are waiting for files that
have been already deleted by other processes.

To avoid this, let's rely on writing the files on `$G_TEST_TMPDIR` env
variable, that is always set and unique, given that we're using the
G_TEST_OPTION_ISOLATE_DIRS test option.
2022-09-13 02:44:25 +02:00
Xavier Claessens
a1c78d63ef meson: Set install_tag on all tools
Those tools are not needed at runtime for typical applications,
distributions typically package them separately.

This makes `meson install --tag runtime` skip installation of those
tools. Omitting `--tag` argument will still install them, as well as
with `--tag bin,bin-devel`.

See https://mesonbuild.com/Installing.html#installation-tags.
2022-09-12 09:50:31 -04:00
Luca Bacci
24572c93c2 Merge branch 'g-win32-app-info-fixes' into 'main'
GWin32AppInfo: Add missing g_spawn_close_pid

See merge request GNOME/glib!2881
2022-09-08 14:12:05 +00:00
Emmanuele Bassi
07a08d5cf5 Merge branch 'coverity-build-fix' into 'main'
gioenumtypes: Only define GLIB_DISABLE_DEPRECATION_WARNINGS if needed

See merge request GNOME/glib!2879
2022-09-07 14:07:45 +00:00
Marco Trevisan (Treviño)
07c808ad90 gioenumtypes: Only define GLIB_DISABLE_DEPRECATION_WARNINGS if needed 2022-09-07 15:31:38 +02:00
Matthias Clasen
1f4188f0ab Merge branch 'fgets-error-ignore' into 'main'
gio-tool-mount: Return early on fgets EOF

Closes #2737

See merge request GNOME/glib!2870
2022-09-06 17:22:15 +00:00
Andy Holmes
1eb1a47a50
GActionGroup: Fix ownership transfer annotation for query_action()
The `(transfer none)` behaviour for `parameter_type` and `state_type`
parameters is implicit with the `const` attribute, but was incorrectly
determined to be `(transfer full)` in the GIR.

Add explicit `(transfer none)` annotations for these two parameters.
2022-09-04 17:29:39 -07:00
Emmanuele Bassi
bafd025811 Merge branch 'ebassi/gcc-12-fixes' into 'main'
Fix array-bounds compiler warnings with GCC 12

See merge request GNOME/glib!2873
2022-09-02 23:17:25 +00:00
Marco Trevisan (Treviño)
221f22b6e1 gdesktopappinfo: Unref the GDBus call results
On our GDBus call callback wrapper we were completing the gdbus call but
ignoring the returned value, that was always leaked.

Fix this.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 21:21:34 +02:00
Marco Trevisan (Treviño)
026a69905e gdesktopappinfo: Unref GDBus call result GVariant if no callback is set
When launching URIs via dbus we may ignore the callback if one was not
provided, however in such case we were also leaking the return value for
the gdbus call.

Unref it properly.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 21:21:34 +02:00
Marco Trevisan (Treviño)
e268ff39b6 gio/tests/gdbus-peer: Unref cached property GVariant value
Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 21:21:34 +02:00
Marco Trevisan (Treviño)
1da208cddc gio/tests/gdbus-proxy-threads: Unref GVariant's that we own
This test is leaking various GVariant's that we are supposed to unref,
leading the valgrind CI job to complain about.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 20:26:06 +02:00
Marco Trevisan
88d4b3b365 Merge branch 'fix-doc-portal-add-leak' into 'main'
documentportal: Fix small leak in add_documents with empty URI list

Closes #2733

See merge request GNOME/glib!2871
2022-09-02 18:24:48 +00:00
Sebastian Keller
27203e48c9 documentportal: Fix small leak in add_documents with empty URI list
When called with an empty URI list (or only inaccessible files),
g_document_portal_add_documents would not call g_variant_builder_end,
leaking the memory allocated by the variant builder.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/2733
2022-09-02 19:48:36 +02:00
Marco Trevisan (Treviño)
511627b735 tests/dbus-appinfo: Add test case for flatpak opening an invalid file
We were testing the case in which we were opening an actual file, and so
potentially using a fd-list, however we were missing the case in which a file
was not existent.

And in such case we are incidentally hitting a leak now.
2022-09-02 19:48:36 +02:00
Emmanuele Bassi
e08c954693 Fix check before a memcpy
The search_total_results address is always going to be non-zero, so the
check will always evaluate to true, and GCC is kind enough to point this
out to us.

The appropriate fix is checking if the size of the search results array
is larger than zero, and if so, copy them into the total results array.
2022-09-02 12:59:22 +01:00
Luca Bacci
e112bdb247 GWin32AppInfo: Add missing g_spawn_close_pid 2022-09-02 12:35:17 +02:00
Marco Trevisan
2ef66ba386 Merge branch 'main' into 'main'
gio-launch-desktop: replace static_assert with G_STATIC_ASSERT

Closes #2713

See merge request GNOME/glib!2858
2022-08-31 15:06:27 +00:00
Marco Trevisan (Treviño)
a0e71ff86f gio-tool-mount: Return early on fgets EOF
As per commit a5390002 we're exiting with error in case fgets failed,
however it could also fail because of EOF (like on ^D), so in such case
we can just return early treating it as a non-error.

Otherwise still exit with error.

Fixes: #2737
2022-08-30 16:33:29 +02:00
Matthias Clasen
56236d708f Merge branch 'use-cloexec-epoll' into 'main'
gio-unix: Use EPOLL_CLOEXEC by default

See merge request GNOME/glib!2868
2022-08-27 16:37:11 +00:00
Luca Bacci
e1e9bc9429 Merge branch 'g-win32-app-info-launch-uris-async' into 'main'
GWin32AppInfo: Implement launch_uris_async

Closes gtk#4400

See merge request GNOME/glib!2760
2022-08-27 14:11:10 +00:00
Luca Bacci
53515197df GWin32AppInfo: Instantiate ApplicationActivationManager out-of-process
This is recommended on MSDN
2022-08-26 11:33:22 +02:00
Luca Bacci
d12cf95836 GDesktopAppInfo: Tidy up code a bit
* Remove an unneeded field from LaunchUrisData and add annotations
* Rename local GError* variables to local_error
* Use g_set_object
* Fix indentation
2022-08-26 11:33:22 +02:00
Luca Bacci
361b4a8fc9 GAppInfo: Clarify that GAppInfo launch methods can spawn multiple instances
...of the application if many URI's are provided. This is important to note
because the GAppLaunchContext signals may be emitted multiple times during
a single launch operation.
2022-08-26 11:33:22 +02:00
Luca Bacci
42a76e1631 GWin32AppInfo: Check for task cancellation
We cannot cancel a spawn operation, but sometimes we have to
spawn the target application mutiple times (e.g. in case the
target app only supports one URI in its command-line, but we
were given multiple URI's), in that case continuously check
the cancellation status before attempting any spawn operation
2022-08-26 11:33:22 +02:00
Luca Bacci
cff3e660c1 GWin32AppInfo: Emit GAppLaunchContext signals for all code paths 2022-08-26 11:33:09 +02:00
Colin Walters
426fab1eca gio-unix: Use EPOLL_CLOEXEC by default
First, there's no reason not to use the new `epoll_create1` system call,
which quickly obsoleted `epoll_create` which has an obsolete and
unused size argument.

But more specifically, it offers `EPOLL_CLOEXEC` which we want
to use for general hygeine - there's no reason to potentially
leak this file descriptor to forked processes.

(GLib itself carefully closes file descriptors when forking child
 processes, but it may be linked with other software that doesn't;
 notably in my case for example the Rust standard library does not
 do this and hence relies more on the application code using
 `O_CLOEXEC` and variants)

This is just a drive-by fix; I saw the system call when I was using
`strace` to debug something else in rpm-ostree.
2022-08-26 04:10:22 -04:00
Luca Bacci
f0ff6a6af0 GWin32AppInfo: Add g_win32_app_info_launch_uris_impl utility function
This utility function will be called by both launch_uris and
launch_uris_async, passing a from_task parameter respectively
as NULL and non-NULL. The from_task parameter will be needed
to know whether GAppLaunchContext signals should be emitted
directly (from_task == NULL) or scheduled for emission on the
main thread (from_task != NULL).
2022-08-16 12:29:18 +02:00
Marco Trevisan
813ce7f0b5 gio-launch-desktop: preserve static_assert message 2022-08-15 17:02:06 +00:00
Owen Rafferty
c850a06ea2
gio-launch-desktop: replace static_assert with G_STATIC_ASSERT 2022-08-15 01:41:50 -05:00
Luca Bacci
bf13a5e0a4 GWin32AppInfo: Implement launch_uris_async
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4400
2022-08-12 18:33:20 +02:00
Michael Catanzaro
0ffe86a1f7 Replace most GObject warnings with criticals
All of these warnings indicate programmer error, so critical is most
appropriate here.

Exceptions: deprecation warnings are just warnings. Also, warnings that
are worded with uncertainty can remain warnings rather than criticals.
2022-08-09 13:18:47 -05:00
Marco Trevisan (Treviño)
bcddc56c41 gtlscertificate: Update reference to G_TLS_CERTIFICATE_NO_FLAGS
G_TLS_CERTIFICATE_FLAGS_NONE was removed as part of commit aa65fc2537.
2022-08-06 01:33:15 +02:00
Marco Trevisan
a4f60709d5 Merge branch 'mcatanzaro/tls-exporter' into 'main'
Expose tls-exporter channel binding

See merge request GNOME/glib!2853
2022-08-05 22:01:37 +00:00
Michael Catanzaro
9d37075a00 Expose tls-exporter channel binding
Required for glib-networking#191
2022-08-05 16:02:09 -05:00
Marco Trevisan
6965f6457e Merge branch 'iss2588' into 'main'
gio-tool: -d option to delete attribute

Closes #2588

See merge request GNOME/glib!2845
2022-08-05 19:21:58 +00:00
Luca Bacci
d3ae4cc809 GWin32AppInfo: Ensure COM is initialized when activating UWP apps
Using the Application Activation Manager coclass. Its threading model
is marked as 'both', so it can be instantiated in any apartment type
without marshaling.
2022-08-04 21:35:08 +02:00
Luca Bacci
cdb8e5e9c5 Fix warnings in GCancellable test 2022-08-03 20:38:59 +02:00
Luca Bacci
a1737ece06 Fix GCancellable tests for Windows 64bit
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2703
2022-08-03 20:33:46 +02:00
Luca Bacci
0cb43a4965 Merge branch 'g-win32-app-info-launched-signal-actually-report-pid' into 'main'
GWin32AppInfo: Fix PID reporting in launched signal

See merge request GNOME/glib!2299
2022-08-02 14:51:26 +00:00
Luca Bacci
45bdeeddff GWin32AppInfo: Actually report the GPid in the GAppLaunchContext::launched signal
We need to pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_async,
otherwise the returned child_pid will always be 0.
2022-08-02 16:38:32 +02:00
codeboybebop
ece66f11fc gio-tool: -d option to delete attribute
gio tool has support for deleting attributes of the file. To delete attribute user
should specify type '--type="unset"'. This is not mentioned in help and therefore not
intuitive. By adding '-d' option, we make this process more obvious.

closes #2588
2022-07-31 13:19:50 -05:00
Emmanuele Bassi
a9394bd68e Implement GFileIface.set_display_name() for resource files
Resource files cannot be renamed, and GFileIface.set_display_name() is
mandatory.

Fixes: #2705
2022-07-30 20:06:07 +01:00
madmurphy
b295c53769 gfileinfo: Implement xattr attribute removal
Fixes: #1187
2022-07-26 07:58:32 +00:00
Emmanuele Bassi
8f68c1e646 Rename G_MARKUP_PARSE_FLAGS_NONE
The prefix for GMarkupParseFlags enumeration members is G_MARKUP; this
means that G_MARKUP_PARSE_FLAGS_NONE gets split into
GLib.MarkupParseFlags.PARSE_FLAGS_NONE by the introspection scanner.

The `/*< nick=none >*/` trigraph attribute is a glib-mkenum thing, and
does not affect the introspection scanner; it would also only affect the
GEnumValue nickname, which is not used by language bindings to resolve
the name of the enumeration member. Plus, GMarkupParseFlags does not
have a corresponding GType anyway.
2022-07-25 22:30:22 +01:00
Emmanuele Bassi
aa65fc2537 Rename G_TLS_CERTIFICATE_FLAGS_NONE
The prefix is G_TLS_CERTIFICATE, not G_TLS_CERTIFICATE_FLAGS. Having
G_TLS_CERTIFICATE_FLAGS_NONE leads to a FLAGS_NONE nick in the GType,
and a FLAGS_NONE member name in the introspection data.
2022-07-25 22:30:22 +01:00
Emmanuele Bassi
09234b50fe Introduce G_APPLICATION_DEFAULT_FLAGS
Enumeration members should either have the name of the type as their
prefix, or they should all have the same prefix.

The "default flags" enumeration member for GApplicationFlags is
unfortunately named G_APPLICATION_FLAGS_NONE, while every other member
of the same type has a G_APPLICATION prefix. The result is that the nick
name of the enumeration member is "flags-none", and that language
bindings will have to use something like
Gio.ApplicationFlags.FLAGS_NONE.

To fix this API wart, we can deprecate the FLAGS_NONE member, and add a
new DEFAULT_FLAGS.
2022-07-25 22:30:22 +01:00
Simon McVittie
94e05f7f28 gio-launch-desktop: Only replace fds that point to the Journal
If stdout is the Journal but stderr is not, then we probably only want
to redirect stdout, or vice versa.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 10:21:35 +01:00
Philip Withnall
30c840a755 Merge branch 'wip/smcv/gio-launch-desktop-sd-journal' into 'main'
Bring back gio-launch-desktop, use it to redirect stdout/stderr to the Journal

Closes #2682

See merge request GNOME/glib!2819
2022-07-24 23:31:27 +00:00
Philip Withnall
9c1b2399ec Merge branch 'iss2542' into 'main'
gio-tool: Flatten the outputed string

Closes #2542

See merge request GNOME/glib!2834
2022-07-24 23:13:06 +00:00
Simon McVittie
f736414825 gio-launch-desktop: Don't alter stdout/stderr if not already the Journal
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:54 +02:00
Simon McVittie
763643ceaa gio-launch-desktop: Redirect stdout, stderr to systemd Journal
This prevents a launched process's output from being mixed up with the
output of the parent process, which can lead to the wrong program being
blamed for warning messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:54 +02:00
Simon McVittie
ae15c800ce Install gio-launch-desktop in a non-PATH location
This is an internal helper executable, which users shouldn't invoke
directly (see glib#1633).

When building for a single-architecture distribution, we can install
it as ${libexecdir}/gio-launch-desktop.

When building for a multiarch distribution, installing it into an
architecture-specific location and packaging it alongside the GLib
library avoids the problem discussed in glib#1633 where it would either
cause a circular dependency between the GLib library and a common
cross-architecture package (libglib2.0-bin in Debian), or require a
separate package just to contain gio-launch-desktop, or cause different
architectures' copies to overwrite each other.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
8157668eac gdesktopappinfo: Don't trust $GIO_LAUNCH_DESKTOP if setuid
gio-launch-desktop was removed before checking GIO for potentially
unsafe environment variable references, so reverting its removal brought
this one back. If a setuid program is using GAppInfo then something is
probably already horribly wrong, but let's be careful anyway.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
e4e21f20e2 gio-launch-desktop: Fix a compiler warning
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
6620d28333 gio-launch-desktop: Add SPDX-License-Identifier
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
6751392934 tests: Avoid using deprecated meson.build_root
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
d0967c1d4a Revert "gdesktopappinfo: Use sh rather than gio-launch-desktop"
A shell one-liner was enough to set GIO_LAUNCHED_DESKTOP_FILE_PID,
but ideally we also want to do the equivalent of sd_journal_stream_fd()
to set up its standard output and standard error streams.

Ideally we would call sd_journal_stream_fd() in a process that will
exec the real program, otherwise it will report the wrong process ID
in the Journal, but we can't easily do that in a forked child when
using posix_spawn() for subprocesses.

This reverts commit 2b533ca99a.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Philip Withnall
206be0a8a1 Merge branch 'wip/smcv/multiarch-triggers' into 'main'
gio: Optionally install trigger executables to architecture-specific paths

See merge request GNOME/glib!2818
2022-07-24 22:57:34 +00:00
codeboybebop
a374b7c806 gio-tool: Flatten the outputed string
Replacing new line in outputed atributes with " ↵ "

closes: #2542
2022-07-24 15:59:43 -05:00
Simon McVittie
32b226d1b1 gdbus: Allow cross-namespace connections to Linux session and system buses
The dominant implementations of the well-known session and system
message buses are the reference implementation from the dbus project
(dbus-daemon) and the sd-bus-based reimplementation dbus-broker, both
of which have correct implementations for EXTERNAL authentication with
an unspecified authorization identity.

This makes it reasonably safe to assume that the well-known message
buses can cope with the unspecified authorization identity, even if we
cannot make the same assumption for custom servers such as the ones
used in ibus and gvfs (which might have been started with an older
GLib version before upgrading GLib in-place).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 14:07:02 +01:00
Simon McVittie
e0a0749268 gdbusauthmechanismexternal: Optionally send empty authorization identity
When using a GDBus client in a non-trivial user namespace, the result of
geteuid() can differ from the uid in the namespace where the server is
running. This would result in connection attempts being rejected, because
the identity that the client claims to have does not match the identity
that the server derives from its credentials.

RFC 4422 allows us to send an empty authorization identity, which means we
want to authenticate as whatever identity the server can derive from our
out-of-band credentials. In particular, this resolves the authentication
failure when crossing between different Linux user namespaces.

Because D-Bus does not have a way to represent an empty initial response
as distinct from the absence of an initial response, we cannot use the
initial-response optimization (RFC 4422 §4.3.a) in this case, and must
fall back to waiting for the server to send a challenge.

Unfortunately, GDBus versions older than glib!2826 did not implement
the server side of this protocol correctly, and would respond to the
missing initial response in a way that breaks the SASL state machine
(expecting a response without sending a challenge), causing client and
server to deadlock with each waiting for the other to respond. Until
fixed versions of GDBus are widespread, we can't rely on having a server
that can cope with this, so gate it behind a flag, which can be set for
connections that are known to cross non-trivial namespace boundaries.

Originally inspired by
<1ed4723d38>,
and based on earlier work by Giuseppe Scrivano (in which the
cross-namespace behaviour was unconditional, rather than gated by a
flag).

Co-authored-by: Giuseppe Scrivano <giuseppe@scrivano.org>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 13:46:26 +01:00
Simon McVittie
0c087d121f gio: Optionally install trigger executables to architecture-specific paths
In Debian-style multiarch (libdir = lib/x86_64-linux-gnu or similar),
Red-Hat-style multilib (libdir = lib64 or lib) and Arch-style multilib
(libdir = lib or lib32), we have to run a separate version of
gio-querymodules to discover 32- or 64-bit modules on x86. Installing
modules in the directory used for each word size needs to trigger
recompilation of the correct modules list.

Debian, Fedora and Arch currently all have patches to facilitate this:
Debian moves gio-querymodules into ${libdir}/glib-2.0 and provides a
compat symlink in ${bindir}, while Fedora and Arch rename one or both
of the gio-querymodules executables to give it a -32 or -64 suffix.

We can avoid the need for these patches by making this a build option.
Doing this upstream has the advantage that the pkg-config metadata for
each architecture points to the correct executable and is in sync with
reality.

I'm using Debian's installation scheme with a separate directory here,
because the word-size suffix used in Fedora and Arch only works for the
common case of 32- and 64-bit multilib, and does not cover scenarios
where there can be more than one ABI with the same word size, such as
multiarch cross-compilation or alternative ABIs like x32.

Now that we have this infrastructure, it's also convenient to use it for
glib-compile-schemas. This works with /usr/share, so it only needs to
be run for one architecture (typically the system's primary
architecture), but using /usr/bin/glib-compile-schemas for the trigger
would result in either primary and secondary architectures trying to
overwrite each other's /usr/bin/glib-compile-schemas binaries, or a
circular dependency (the GLib library would have to depend on a
common package that contains glib-compile-schemas, but
glib-compile-schemas depends on the GLib library). Installing a
glib-compile-schemas binary in an architecture-specific location
alongside each GLib library bypasses this problem.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 11:19:37 +01:00
Philip Withnall
55928d6ac0 Merge branch 'more-atomic-ops' into 'main'
Use atomic exchange operations more

See merge request GNOME/glib!2759
2022-07-23 11:35:08 +00:00
Philip Withnall
8d3dac8f83 Merge branch 'wip/smcv/gdbus-sasl' into 'main'
GDBus: improve interoperability of SASL handshake

See merge request GNOME/glib!2826
2022-07-20 13:01:49 +00:00
Simon McVittie
0c24039874 tests: Add a test for GDBusServer with various simulated clients
Instead of using a GDBusConnection, this does the handshake at a lower
level using specific strings in the SASL handshake, to verify that we
will interoperate with various clients including sd-bus, libdbus and
older versions of GDBus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 19:39:41 +01:00
Simon McVittie
3f532af65c gdbusauth: Represent empty data block as DATA\r\n, with no space
This is an interoperability fix. The reference implementation of D-Bus
treats "DATA\r\n" as equivalent to "DATA \r\n", but sd-bus does not,
and only accepts the former.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 17:53:40 +01:00
Giuseppe Scrivano
b51e3ab09e GDBusServer: Accept empty authorization identity for EXTERNAL mechanism
RFC 4422 appendix A defines the empty authorization identity to mean
the identity that the server associated with its authentication
credentials. In this case, this means whatever uid is in the
GCredentials object.

In particular, this means that clients in a different Linux user
namespace can authenticate against our server and will be authorized
as the version of their uid that is visible in the server's namespace,
even if the corresponding numeric uid returned by geteuid() in the
client's namespace was different. systemd's sd-bus has relied on this
since commit
1ed4723d38.

[Originally part of a larger commit; commit message added by smcv]

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 17:53:32 +01:00
Giuseppe Scrivano
a7d2e727ee GDBusServer: If no initial response for EXTERNAL, send a challenge
Sending an "initial response" along with the AUTH command is meant
to be an optional optimization, and clients are allowed to omit it.
We must reply with our initial challenge, which in the case of EXTERNAL
is an empty string: the client responds to that with the authorization
identity.

If we do not reply to the AUTH command, then the client will wait
forever for our reply, while we wait forever for the reply that we
expect the client to send, resulting in deadlock.

D-Bus does not have a way to distinguish between an empty initial
response and the absence of an initial response, so clients that want
to use an empty authorization identity, such as systed's sd-bus,
cannot use the initial-response optimization and will fail to connect
to a GDBusServer that does not have this change.

[Originally part of a larger commit; commit message added by smcv.]

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 16:26:24 +01:00
Giuseppe Scrivano
764f071909 gdbusauth: empty DATA does not need a trailing space
This is an interoperability fix. If the line is exactly "DATA\r\n",
the reference implementation of D-Bus treats this as equivalent to
"DATA \r\n", meaning the data block consists of zero hex-encoded bytes.
In practice, D-Bus clients send empty data blocks as "DATA\r\n", and
in fact sd-bus only accepts that, rejecting "DATA \r\n".

[Originally part of a larger commit; commit message added by smcv]

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
Co-authored-by: Simon McVittie <smcv@collabora.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 16:11:20 +01:00
Simon McVittie
937f9a61cd gioenums: G_IO_ERROR_NO_SUCH_DEVICE is new in 2.74
This attribute will produce "deprecation" warnings when using it in
code that does not want dependencies on newer GLib versions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 12:02:12 +01:00
Philip Withnall
c3a80a7142 Merge branch 'non-registered-extension-point' into 'main'
Add missing extension point register for various settings backends

See merge request GNOME/glib!2813
2022-07-15 21:25:58 +00:00
Ryan Hope
7c4e6032c6 Add tests for GMemorySettingsBackend and GNullSettingsBackend 2022-07-15 22:07:03 +02:00
Ryan Hope
924da751c2 gio: Ensure extension points are registered when creating Settings backends
Add missing call to _g_io_modules_ensure_extension_points_registered() to
GRegistryBackend, GNullSettingsBackend, and GNextstepSettingsBackend
2022-07-15 21:36:09 +02:00
Ryan Hope
04255e4565 Add missing extension point register for for GMemorySettingsBackend
Using GMemorySettingsBackend before any other GSettingsBackend would
cause the following error: "Tried to implement non-registered extension
point gsettings-backend". This is due to a missing call to
_g_io_modules_ensure_extension_points_registered() in the GMemorySettingsBackend
type definition which registers the gsettings-backend extension point.
2022-07-15 21:36:03 +02:00
James Hilliard
d0b9ebbaac meson: fix build without cpp toolchain
We don't need a cpp toolchain for building glib so lets just
automatically disable tests requiring one when not available.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-07-15 12:58:41 -06:00
Marco Trevisan (Treviño)
399f46f8bf giomodule: Use g_once_init_enter/leave to register extensions and load dirs
There's no much change in behavior, but let's take advantages of the tools
we already have to handle these cases.
2022-07-13 00:47:31 +02:00
Marco Trevisan
c752b63143 Merge branch 'wait-for-async-uri-handler-called' into 'main'
gio/tests/desktop-app-info: Wait until the callback is called

See merge request GNOME/glib!2809
2022-07-12 15:46:14 +00:00
Marco Trevisan (Treviño)
ecaa5b5b7a gio/tests/desktop-app-info: Wait until the callback is called
The test was flacky because we were only relying on the presence of a
file, while the callback could have not been called yet, while ensure
for both assumptions to be true before stop iterating the loop.
2022-07-12 17:33:15 +02:00
Philip Withnall
e2639ce56e gsocketclient: Fix passing NULL to g_task_get_cancellable()
Fix a regression from commit abddb42d14, where it could pass `NULL` to
`g_task_get_cancellable()`, triggering a critical warning. This could
happen because the lifetime of `data->task` is not as long as the
lifetime of the `ConnectionAttempt`, but the code assumed it was.

Fix the problem by keeping a strong ref to that `GCancellable` around
until the `ConnectionAttempt` is finished being destroyed.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2687
2022-07-12 16:07:23 +01:00
Marco Trevisan (Treviño)
a5390002fc gio-tool-mount: Exit with error in case we can't read from stdin
It's a fatal situation so we can just exit without caring much.
2022-07-06 16:05:33 +02:00
Philip Withnall
59fc26cbaa gio: Add some missing license and copyright headers
These headers have all been written manually, by looking through the git
log for each file and noting the copyright of each significant
contribution.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-07-05 12:30:46 +01:00
Philip Withnall
41691cc4c8 Merge branch 'more-spdx' into 'main'
Add more SPDX license headers

See merge request GNOME/glib!2706
2022-07-05 11:06:49 +00:00
Marco Trevisan
777f0975f9 Merge branch 'content-type-locking' into 'main'
gcontenttype: Fix a potential use-after-free of xdgmime data

See merge request GNOME/glib!2786
2022-06-30 15:01:41 +00:00
Philip Withnall
ecec522835 gcontenttype: Clarify some ownership transfers
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-30 14:21:37 +01:00
Philip Withnall
45d4c52501 gcontenttype: Fix a potential use-after-free of xdgmime data
While `gio_xdgmime` is unlocked, the data which `type` points to in the
xdgmime cache might get invalidated, leaving `type` as a dangling
pointer. That would not bode well for the `g_strdup (type)` call to
insert a new entry into the `type_comment_cache` once `gio_xdgmime` is
re-acquired.

This was spotted using static analysis, and the symptoms have not
knowingly been seen in the wild.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1474702
2022-06-30 14:21:18 +01:00
Philip Withnall
bd56345f23 Merge branch 'move_assert-msg-test' into 'main'
Convert tests/assert-msg-test* to glib/tests/assert-msg-test*

Closes #1434

See merge request GNOME/glib!2767
2022-06-28 10:41:59 +00:00
Philip Withnall
164d3759fb Merge branch 'mcatanzaro/#2597' into 'main'
Avoid crashing when GProxyResolver returns weird results, and related fixes

Closes #2597

See merge request GNOME/glib!2742
2022-06-28 10:33:33 +00:00
Emmanuel Fleury
5699b7b169 Fix some coding style issues in python tests pointed out by black and flake8 2022-06-28 11:19:21 +01:00
Michael Catanzaro
8e29865112 gproxyresolver: add asserts to ensure error is set
This will catch buggy implementations of GProxyResolver before they are
able to return bogus results to higher level code. In particular, if
g_proxy_resolver_lookup() returns NULL, it'd better set an error to
explain why.
2022-06-27 15:10:25 -05:00
Michael Catanzaro
1738fad172 proxyaddressenumerator: set error parameter more thoughtfully
It doesn't make sense for a proxy resolver to return NULL without an
error on the first call. Whereas a DNS resolver would do this to
indicate that a query completed successfully but found no results, a
proxy resolver should return "direct://" instead. Therefore, if we are
going to return NULL, we ought to have an error as well. Let's make sure
this actually happens by adding some fallback errors just in case
GProxyResolver feeds us weird results.

Additionally, we should not return any errors except
G_IO_ERROR_CANCELLED after the very first iteration. This is an API
contract of GSocketAddressEnumerator. Let's add some checks to ensure
this.

Note that we have inadequate test coverage for GProxyAddressEnumerator.
It's tested here only via GSocketClient. We could do a bit better by
testing it directly as well. For example, I've added tests to see what
happens when GProxyResolver returns both a valid and an invalid URI, but
it's not so interesting here because GSocketClient always uses the valid
result and ignores the error from GProxyAddressEnumerator.

Fixes #2597
2022-06-27 15:10:05 -05:00
Michael Catanzaro
6f83f45db4 gsimpleproxyresolver: ensure default proxy is valid
It should be either a valid URI, or NULL. Passing empty strings or other
invalid URIs is no bueno.
2022-06-27 14:23:51 -05:00
Michael Catanzaro
8a1f087a31 gsimpleproxyresolver: default_proxy should be consistently nullable
Currently it's nullable in g_simple_proxy_resolver_new(), but not in
g_simple_proxy_resolver_set_default_proxy() nor the property. Fix these.
2022-06-27 14:23:51 -05:00
Michael Catanzaro
4667f5980a proxy-test: fix check for simple:// URI scheme
This has no practical impact, since it's only a test, and none of the
test code would have hit this bug, but the GTestProxyResolver's check to
see if the URI scheme is simple:// currently only compares the first
four bytes of the string, so it's actually only checking for the "simp"
and would match anything else after that, e.g. "simpleton://". This is
surely not intended.
2022-06-27 14:23:51 -05:00
Philip Withnall
087272777b tests: Fix incorrect basename comparison in gsubprocess test
This was causing intermittent failures on macOS, depending on whether
the tmpdir ended with a `/` or `/some-dir`. `g_strrstr()` is not the
right function to use to extract a basename from a path, for this
reason.

When it failed, the macOS test was failing with:
```
ok 16 /gsubprocess/env
Bail out! GLib-GIO:ERROR:../gio/tests/gsubprocess.c:1507:test_cwd: assertion failed (basename == tmp_lineend_basename): ("/T\n" == "/\n")
```

The test now passes reliably, which means that it can be removed from
the list of expected failures on macOS.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1392
2022-06-27 15:02:55 +01:00
Philip Withnall
6d381c9668 Merge branch 'getfsent_lock' into 'main'
Add lock in _g_get_unix_mount_points() around *fsent() functions

See merge request GNOME/glib!1717
2022-06-27 11:20:49 +00:00
Rozhuk Ivan
f43cf34151 [PATCH] Add lock in _g_get_unix_mount_points() around *fsent() functions 2022-06-25 19:22:06 +03:00
Rozhuk Ivan
02d0d6497b [PATCH] _g_get_unix_mount_points(): reduce syscalls inside loop 2022-06-25 19:01:30 +03:00
Philip Withnall
059a5fd4da tests: Skip various default handler tests on macOS
They are not currently supported by `gosxappinfo.m`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:43:18 +01:00
Philip Withnall
dbdc9ca995 gosxappinfo: Correctly return an error from create_from_commandline()
Creating a `GAppInfo` from a commandline isn’t currently supported on
macOS, but the implementation was incorrectly returning `NULL` without
setting the `GError`.

This was being caught by the new tests in `gio/tests/file.c`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:27:45 +01:00
Philip Withnall
a98bd895d5 tests: Fix a path comparison in the file tests
On macOS the comparison was failing as one of the paths had a trailing
slash while the other didn’t.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:27:45 +01:00
Marco Trevisan (Treviño)
bfd77693ce gresource: Use atomic pointer exchange operations to nullify and check 2022-06-23 20:01:12 +02:00
Marco Trevisan (Treviño)
9c32cfbaaa gfileattribute: Do atomic addition before checking the old value on ref
So we avoid working on a value that is not been updated yet.
2022-06-23 20:01:12 +02:00
Marco Trevisan (Treviño)
576e5f2f87 cancellable: Use more atomic exchanges operations
We used to do get and set atomic operations pair, but these may be
unsafe in some cases as threads may rely on data that is changed in
in between them, however this is not a problem if we do exchange the
pointers.

So just use exchange ops, in this way we can avoid lock/unlock mutex
dances
2022-06-23 20:01:12 +02:00
Marco Trevisan (Treviño)
e7269a26e4 gio/tests: Ensure that a cancellable hangs if reset from cancellable callback 2022-06-23 20:01:12 +02:00
Marco Trevisan (Treviño)
e218371f19 gio/tests: Ensure that cancellable is cancelled when emitting the signal
Use a race between threads resetting and cancelling a cancellable and
ensure that when we call the callback the cancellable is cancelled
2022-06-23 20:01:12 +02:00
Marco Trevisan (Treviño)
62192925b6 gio/tests: Add tests for cancellable pollfd and cancellation callbacks 2022-06-23 20:01:12 +02:00
Philip Withnall
191923ce61 Merge branch 'wip/smcv/none-flags' into 'main'
Add a NONE or DEFAULT member to most flags-sets

See merge request GNOME/glib!2576
2022-06-23 16:09:38 +00:00
Philip Withnall
5655af6ada Merge branch 'more-async-gfile' into 'main'
gfile (and GAppInfo): Add some missing async APIs and ensure async calls always use them

See merge request GNOME/glib!2717
2022-06-23 11:49:55 +00:00
Simon McVittie
879b9cd669 gregex: Add G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:39 +01:00
Simon McVittie
0d4e401ede gmarkup: Add G_MARKUP_PARSE_FLAGS_NONE
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:27 +01:00
Simon McVittie
cc528f6c2e giomodule test: Don't pass a magic number to g_test_trap_subprocess()
This worked, but seems like bad style.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:19 +01:00
Simon McVittie
de8672fe0b gtestutils: Add G_TEST_SUBPROCESS_DEFAULT, G_TEST_TRAP_DEFAULT
This makes calls to test subprocesses with default behaviour more
self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:13 +01:00
Simon McVittie
f59e02a143 gioenums: Add G_TLS_CERTIFICATE_FLAGS_NONE
This makes the absence of flags (in other words, a valid certificate)
more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:05 +01:00
Simon McVittie
7045260c22 gsignal: Add G_CONNECT_DEFAULT
This makes calls to g_signal_connect_data() and g_signal_connect_object()
with default flags more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:46:45 +01:00
Marco Trevisan
cb0cc996ee Merge branch 'test-suite-fixes' into 'main'
tests: Various fixes for TAP output of tests

See merge request GNOME/glib!2749
2022-06-22 18:48:59 +00:00
Marco Trevisan (Treviño)
5b04d23fc4 gfile: Make g_query_default_handler_async really Async
Despite the name, the call was still doing blocking operations when
looking for app handlers via GAppInfo. Now it's possible to use fully
async calls.

Together with previous commit, the API is now fully async.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
8a880e1379 GAppInfo: Make g_app_info_launch_default_for_uri_async fully async
Despite the name, we still used blocking calls to get the default app
for URI, now that we have an async implementation of the API to get the
default implementation for URI scheme, we can remove the blocking calls.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
8aee5fc628 GAppInfo: Add async API to get default Application for URI scheme
Make possible to fetch the default application for URI scheme in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
73b29e8f6e gio/tests: Add test case for g_app_info_launch_default_for_uri
We did not check whether this function worked before, so add a simple
test case for it, providing some test functions to make it possible to
reply the same behavior
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
eee15225c7 GDesktopAppInfo: Ignore flushing the session bus when there's not
In some cases (such as in our CI tests) we may not have any dbus session
set after launching, but we always assumed so.

In case we have not a session bus set, we only have to return early.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
6fef60b65c GDesktopAppInfo: Ensure that URI scheme is a valid argument 2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
c87602451c gfile: Use async API to get the default GAppInfo for type
In both callbacks of g_file_query_default_handler_async() we were
actually using I/O blocking APIs making it not fully async.

Now that such API is provided, we can use it.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
44dbd43170 GAppInfo: Add async API to get default Application for content type
Make possible to fetch the Application for default content type in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
abae8c1f05 gio/tests: Add test cases for g_file_query_default_handler[_async]
Simulating having default handlers, however this is tested only in unix
as windows may behave differently, so let's just skip it for now.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
22e951e6ac gfile: Add Async API to create a temporary directory and return as GFile
While it's possible to create a directory synchronously via
g_dir_make_tmp(), there's no such API that performs it asynchronously.

So implement it using GFile, using a thread to perform such task.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
fa24391529 gfile: Add API to create a new temporary file asynchronously
Make possible to create a new gfile with a temporary name in async
way, using the same API of g_file_new_tmp().
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
2a05fd0cb0 gioerror: Rely on GFileError to compute GIOErrorEnum from errno
Avoid re defining cases for GIoErrorEnum when we already handle them
through GFileError, so remove code duplication and just rely on
g_file_error_from_errno() to compute the file error and then use
g_io_error_from_file_error() to get the possible IOError.

In case it's something not handled as GFileError, we can use the same
logic as before.

This is now a safe change to do as we have covered all the supported
cases in tests.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
b64fd312da gerror: Add an utility function to get the GIO Error from GFileError
When GIO functions are using GLib file utils functions we expect to
return a GIO Error, so provide a way to map such error values.
2022-06-22 20:07:25 +02:00
Emmanuele Bassi
55a5a82655 Merge branch 'tls-certificate-refs' into 'main'
gtlscertificate: Hold a ref on the root certificate when building chains

See merge request GNOME/glib!2761
2022-06-21 12:09:22 +00:00
Philip Withnall
75a39114d8 tests: Fix non-TAP output from socket test
This was breaking strict TAP parsers, such as Meson’s.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
8dde15a5b3 tests: Fix gengiotypefuncs.py helper script
It seems this script has potentially never worked properly under Python
3. It’s supposed to list all the `_get_type()` functions it can find in
the GIO headers, but since the regex string passed to `re.search()` was
not a Python regex, nothing was matching.

Fix that, and do another few small cleanups to the script.

This makes the `defaultvalue` test not skip all the types.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
f977ddf34f tests: Fix non-TAP output from debugcontroller test
When running under a strict TAP parser this was previously producing
problematic non-conforming output.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
2c75c392eb gtlscertificate: Hold a ref on the root certificate when building chains
This is unlikely to be a bug in practice, as the certificate pointed to
by `root` should have a ref held on it as the issuer of another
certificate in the chain.

However, we can’t guarantee that’s how the `GTlsCertificate`
implementation behaves, so keep a temporary ref on `root` until it’s no
longer needed.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1489985
2022-06-21 12:11:27 +01:00
Olivier Crête
1cc685abc4 gio: Don't bundle gtrace in static builds
They're already in the libglib.a file and it prevents the build
from completing.
2022-06-20 16:09:51 -04:00
Michael Catanzaro
f95ca6cb71 xdgmime: fix double free
We free xdg_dirs[i] twice, but fail to free xdg_dirs itself.

Also, since free() is NULL-safe, there is no need for the second check
here.

Discovered in: https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/16#note_1432025
2022-06-17 08:49:03 -05:00
Philip Withnall
594a70bf5f Merge branch 'gvdb-as-wrap' into 'main'
build: Move gvdb to a subproject

See merge request GNOME/glib!2733
2022-06-16 09:29:43 +00:00
Philip Withnall
b3f49d08a6 build: Move gvdb to a subproject
Rather than carrying the copylib around inside GLib, which is a pain to
synchronise and affects our code coverage statistics.

This requires updating the CI images to cache the new subproject,
including updating the `cache-subprojects.sh` script to pull in git
submodules.

It also requires adding `gioenumtypes_dep` to be added to the
dependencies list of `libgio`, since it needs to be build before GVDB as
it’s pulled in by the GIO headers which GVDB includes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2603
2022-06-16 10:12:07 +01:00
Marco Trevisan (Treviño)
e5841beba6 gioerror: Map ENOSYS to G_IO_ERROR_NOT_SUPPORTED
If a wrong syscall is used, we can assume that such feature is not
supported at higher level.
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
587f5f25d0 gioerror: Map ENETDOWN to G_IO_ERROR_NETWORK_UNREACHABLE 2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
3d6f843097 gioerror: Map ENOMSG, EBADMSG and ENODATA to G_IO_ERROR_INVALID_DATA 2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
19417b1a67 gioerror: Map ENFILE to G_IO_ERROR_TOO_MANY_OPEN_FILES
ENFILE stands for "Too many open files in system", so we can definitely
group it together with EMFILE ("Too many open files").
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
6bc6b7ef30 gioerror: Map ETXTBSY to G_FILE_ERROR_BUSY
It's a busy text file, but we don't care much about specifics so we
can just return the generic busy error.
2022-06-15 20:44:10 +02:00
Marco Trevisan (Treviño)
d2ca48ad97 gioerror: Add G_IO_ERROR_NO_SUCH_DEVICE to map ENODEV 2022-06-15 20:43:56 +02:00
Marco Trevisan (Treviño)
9e09894414 gioerror: Handle EMLINK error as too-many-links error
This used to be a FreeBSD only error but it's actually defined also in
linux.
2022-06-15 20:41:53 +02:00
Marco Trevisan (Treviño)
35c6c5c663 tests: Add unit test for GIOErrorEnum conversion functions 2022-06-15 20:41:52 +02:00
Marco Trevisan (Treviño)
04718a9692 gfile: Implement interface API to make symbolic links asynchronously
The interface was ready for this API but it was not provided.

So implement this, using a thread that calls the sync API for now.

Add tests.

Helps with: GNOME/glib#157
2022-06-15 19:49:38 +02:00
Marco Trevisan (Treviño)
fe9e35624a gfile: Check that using NULL symlink_value as a programmer error
And also ensure that a null strings gives an error.
2022-06-15 19:49:38 +02:00
Philip Withnall
56d371942e gsocketclient: Fix still-reachable references to cancellables
`GSocketClient` chains its internal `GCancellable` objects to ones
provided by the caller in two places using `g_cancellable_connect()`.
However, it never calls `g_cancellable_disconnect()`, instead relying
(incorrectly) on the `GCancellable` provided by the caller being
short-lived.

In the (valid) situation where a caller reuses one `GCancellable` for
multiple socket client calls, or for calls across multiple socket
clients, this will cause the internal `GCancellable` objects from those
`GSocketClient`s to accumulate, with one reference left each (which is
the reference from the `g_cancellable_connect()` closure).

These `GCancellable` instances aren’t technically leaked, as they will
all be freed when the caller’s `GCancellable` is disposed, but they are
no longer useful and there is no bound on the number of them which will
hang around.

For a program doing a lot of socket operations, this still-reachable
memory usage can become significant.

Fix the problem by adding paired `g_cancellable_disconnect()` calls.
It’s not possible to add a unit test as we can’t measure still-reachable
memory growth before the end of a unit test when everything has to be
freed.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2670
2022-06-14 11:15:18 +01:00
Benjamin Otte
7a4ec897bc listmodel: Recommend implementing properties
"item-type" and "n-items" should ideally be implemented by listmodels,
so document that.
2022-06-09 17:08:42 +02:00
Benjamin Otte
51840393b2 liststore: Add tests for n-items property 2022-06-09 17:08:42 +02:00
Benjamin Otte
6b62d63d36 liststore: Add "n-items" property 2022-06-09 17:08:42 +02:00
Benjamin Otte
9b55841d78 liststore: Use g_object_class_install_properties()
Not very useful yet, but future commits add more properties.
2022-06-08 15:45:27 +02:00
Philip Withnall
3b87740e3e tests: Fix defined-but-not-used variables if HAVE_OPENPTY is undefined
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-07 19:12:46 +01:00
Philip Withnall
14f4b38fb1 tests: NULL-initialise some variables to help scan-build
Dynamically, these will only ever be used after they’ve been initialised
due to correct checking of `use_udp` throughout the test. However,
that’s a global variable and the static analyser is assuming it might
change value. So help it out by NULL-initialising the variables so they
can never be used uninitialised.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-07 11:04:25 +01:00
Simon McVittie
36da11550c Merge branch 'leak-fixes' into 'main'
tests: Various small test fixes for valgrind

See merge request GNOME/glib!2711
2022-06-01 17:23:02 +00:00
Michael Catanzaro
05755f2fbd Merge branch '2639-xdgmime-fix' into 'main'
xdgmime: Fix broken file:// content type lookups for webkitgtk

Closes #2639

See merge request GNOME/glib!2708
2022-06-01 15:24:02 +00:00
Philip Withnall
33f36af489 tests: Remove an unnecessary timeout in gnotification test
This is a fallback timeout to abort the test if the expected number of
messages aren’t seen in time. However, when running the test under
valgrind it will take longer and sometimes spuriously trigger the
timeout.

There’s no point in having an abort timeout inside the test: the test
runner (Meson) already provides one for us, which we can adjust with a
multiplier when running under valgrind.

So removes the timeout from within the test. This should fix the
gnotification test under valgrind.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-01 15:20:38 +01:00
Philip Withnall
4282f22102 tests: Fix leaks in new GDateTime file info tests
From b7b10cc7e0. My fault!

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-01 15:19:59 +01:00
Philip Withnall
972df061a7 Merge branch 'wip/pwithnall/fix-pollable-test' into 'main'
tests: Fix a potential race condition in pollable test

See merge request GNOME/glib!2702
2022-06-01 13:15:32 +00:00
Philip Withnall
7ec351e3f4 xdgmime: Fix broken file:// content type lookups for webkitgtk
This re-applies a chunk from commit e63262d49d which was
accidentally lost when upstreaming the commit to xdgmime (as
https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/10).

The upstreamed commit was then re-backported to GLib as a1bfe899ab,
without the missing chunk.

The missing chunk is potentially causing incorrect content type results
for `file://` URIs when used from webkitgtk.

Thanks to Stephen Jung and Michael Catanzaro for investigating.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2639
2022-06-01 14:02:53 +01:00
Philip Withnall
26409f19cd Add SPDX license headers for LGPL-2.1-or-later to various files
These have all been added manually, as I’ve finished all the files which
I can automatically detect.

All the license headers in this commit are for LGPL-2.1-or-later, and
all have been double-checked against the license paragraph in the file
header.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-06-01 12:44:23 +01:00
Christopher Nielsen
d785405268 credentials: macos: check for existence of LOCAL_PEERPID
- Fixes build errors for macOS 10.7 and earlier, where this is not supported
2022-05-31 17:08:08 -04:00
Philip Withnall
c1f8865689 Merge branch 'benzea/fix-inotify-race' into 'main'
glocalfilemonitor: Avoid file monitor destruction from event thread

Closes #1941

See merge request GNOME/glib!2561
2022-05-31 12:18:38 +00:00
Philip Withnall
95c1d656e2 tests: Fix a potential race condition in pollable test
This may have been causing an intermittent failure of the pollable test
on BSD, where updating the readable status of a socket takes a bit
longer than on Linux.

```
GLib-GIO-DEBUG: 16:06:41.235: GSocketClient: Starting application layer connection
GLib-GIO-DEBUG: 16:06:41.235: GSocketClient: Connection successful!
Bail out! GLib-GIO:ERROR:../gio/tests/pollable.c:73:check_source_readability_callback: assertion failed (readable == expected): (0 == 1)
```

I have not debugged the test on BSD, though, so this is only a guess.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/2022087

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 13:14:15 +01:00
Philip Withnall
4daa3ca33e tests: Remove global variables from pollable test
This should make each unit test a bit more self-contained and easier to
verify that they’re independent.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 13:12:06 +01:00
Philip Withnall
ac322a1205 tests: Use g_assert_*() rather than g_assert() in pollable
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 12:57:46 +01:00
Philip Withnall
e5a691e84a tests: Add a test for GFileMonitor deadlocks
This test is opportunistic in that it’s not possible to detect whether
the race condition has been hit (other than by hitting a deadlock).

So the only approach we can take for testing is to loop over the code
which has previously been known to cause a deadlock a number of times.

The number of repetitions is chosen from running the test with the
deadlock fix reverted.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1941
2022-05-31 12:24:13 +01:00