Commit Graph

9169 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
eb78cfeeca gio/tests/fake-document-portal: Test that the app-id matches the request
Ensure that the app-id requiring the document matches the one we want,
so that we can actually test the code in GDesktopAppInfo that does the
mapping
2025-10-16 20:29:32 +02:00
Marco Trevisan (Treviño)
3eb2abb406 fake-document-portal: Fix signature of function callback
We were missing a parameter, as per the generated bindings
2025-10-16 20:29:32 +02:00
Marco Trevisan (Treviño)
352cfe600a gio/gdocumentportal: Use the target name when opening a symlink
When an URI to a symlink is added to the portal, we open it and we send
the FD (of the target) to the portal. This one has no clue about the original
symlink and so it mounts a file that is named like the target.

g_document_portal_add_documents(), however returns a path that contains
the original name and that one is what is sent to the applications when
used via GDesktopAppInfo.

Basically, this is the situation:
  - /tmp/symlink -> /tmp/target
  - An application is launched to open file:/tmp/symlink
  - The portal creates file:/$XDG_RUNTIME_DIR/doc/ID/target
  - Gio converts the path to file:/$XDG_RUNTIME_DIR/doc/ID/symlink

Now, since we can't just pass the symlink to the portal without also
changing the logic there, it's just better to do the conversion ourself,
and so, we use the already-opened fd to figure out the real path of the
opened file, and we return a document file URI that uses the target
basename instead
2025-10-16 20:29:32 +02:00
Marco Trevisan (Treviño)
d81701de56 gio/tests: Add document portal tests
While this can be tested using desktop apps, adding some unit tests
makes simpler to verify the edge cases
2025-10-16 20:29:32 +02:00
Marco Trevisan (Treviño)
ddc324da03 gio/tests/fake-document-portal: Use a sequential ID for docs
It makes things clearer to test
2025-10-16 20:29:32 +02:00
Luca Bacci
b623031e22 glib-compile-resources: print error message when the temp file cannot be created 2025-10-16 13:16:58 +00:00
FeRD (Frank Dana)
9e049b9008 Entity tags: Link to RFC9110 for HTTP ETag reference
The RFC9110 explanation of HTTP ETags is far superior to
the disjoint ramblings found in (now-obsoleted) RFC2616,
and serves as a much better reference for comparison
with GFile entiity tags. Also, link directly to relevant section.
2025-10-02 11:06:41 +00:00
Philip Withnall
5b88afa767 Merge branch 'keep-suffix-name-when-trashing' into 'main'
GLocalFile: keep suffix name when trashing

See merge request GNOME/glib!4838
2025-09-30 16:00:01 +00:00
Philip Withnall
b7d8d88931 Merge branch 'file-equal-docs' into 'main'
gfile: Expand documentation around file equality

See merge request GNOME/glib!4815
2025-09-30 15:29:59 +00:00
wangrong
05012cd1c4 GLocalFile: keep suffix name when trashing
Keeping the suffix name makes it easier to get the correct content-type.
2025-09-26 14:34:16 +08:00
Marco Trevisan
ed36f4c642 Merge branch 'wip/suppress-missing-lock-coverity' into 'main'
gdbus-codegen: Supress coverity warning in skeleton finalization

See merge request GNOME/glib!4825
2025-09-21 13:35:26 +02:00
Carlos Garnacho
592082ef1d gdbus-codegen: Supress coverity warning in skeleton finalization
This commit has the potential to close a thousand Coverity issues.
On generated code from gdbus-codegen, Coverity typically warns on
skeleton->priv->changed_properties_idle_source happening outside
the skeleketon->priv->lock during finalize(), while it's protected
by this mutex in other parts.

Presumably if the object is in finalization, there should be no
other threads poking at it, so the code is actually safe for the
intended use and the warning moot.

To address this, change gdbus-codegen to prefer g_clear_pointer()
with glib >= 2.38 (should be most often the case nowadays) so this
access is reserved to a single line of code, and mark this line of
code with a Coverity code annotation in order to suppress the
warning.
2025-09-21 12:02:58 +02:00
Simon McVittie
67dc482f8a gio/tests: Wait up to 10 seconds for a signal to be received
If the build/test machine is slow, heavily-loaded or otherwise
inconvenienced, it might take a few seconds for the signal to be sent
by the subprocess, received by the message bus, re-broadcasted by the
message bus and received by the test code. Wait a few more seconds
before giving up.

If this test is successful, increasing this timeout will not slow it
down: we stop waiting for the signal as soon as we receive it. This will
only make any difference if the test would have failed.

Signed-off-by: Simon McVittie <smcv@debian.org>
2025-09-19 13:44:37 +01:00
Simon McVittie
73224802b3 gio/tests: Convert the time to wait for expected signal into a constant
No functional change.

Signed-off-by: Simon McVittie <smcv@debian.org>
2025-09-19 13:44:30 +01:00
Simon McVittie
0960e72b07 gio/tests: Avoid a race condition
We have two things happening in parallel:

1. The GDBus worker thread writes out an AddMatch call to the socket,
   the message bus reads that method call from the other end of the
   socket, and the message bus responds by adding the match rule
   for the signal subscription

2. The main thread forks, and the child execs
   gdbus-connection-flush-helper, which sends the signal that we are
   expecting; the message bus receives that signal, and broadcasts it
   to subscribers, if any

Normally (1.) wins the race because exec'ing a child process is more
time-consuming than IPC, and the test passes.

However, it is possible for (2.) to win the race. If so, we will never
receive the expected signal (because it was received by the message bus
before the AddMatch() method call, so at the time it was received, the
test was not yet a subscriber); the test waits until the timeout and
then gives up, and the test fails.

For whatever reason, Debian's s390x buildd seems to be reliably failing
this test since this week, having previously passed. I don't know what
changed. I can (very rarely) reproduce the race condition described
above on a developer-accessible s390x machine by repeatedly running the
/gdbus/connection/flush test in a loop.

Bug-Debian: https://bugs.debian.org/1115617
Signed-off-by: Simon McVittie <smcv@debian.org>
2025-09-19 13:44:23 +01:00
Simon McVittie
ac7275b185 gio/tests: Factor out connection_wait_for_bus() from gdbus-subscribe
Signed-off-by: Simon McVittie <smcv@debian.org>
2025-09-19 13:44:05 +01:00
Lukáš Tyrychtr
4ab0357974 gio-tool-trash: Report error when emptying the trash
This adds error reporting and proper exit code when emptying the trash fails
for some (mainly permission) related error.

Fixes #3785.
2025-09-18 15:11:47 +00:00
Philip Withnall
b961111c97 gfile: Expand documentation around file equality
Prompted by
https://discourse.gnome.org/t/help-on-g-file-equal-and-g-file-attribute-id-file/31268/5.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-09-17 10:51:31 +01:00
Philip Withnall
a8b9c237cf Merge branch 'gdbus-register-error-domain-out-annotation' into 'main'
GDBus: Add `(out)` annotation to quark in g_dbus_error_register_error_domain()

See merge request GNOME/glib!4798
2025-09-16 14:20:58 +00:00
Philip Withnall
3691e4d3d7 Merge branch 'win32-app-info-co-allow-set-foreground-window' into 'main'
GWin32AppInfo: Allow focus-stealing when requested via GAppLaunchContext

See merge request GNOME/glib!4759
2025-09-16 14:19:21 +00:00
Philip Withnall
3d0c3bfae8 Merge branch '3771-keyfile-invalid-escapes' into 'main'
gdesktopappinfo: Error out on more invalid desktop files

Closes #3771

See merge request GNOME/glib!4766
2025-09-16 14:18:58 +00:00
Uwe Korn
2b0f5304bd gio/tests/socket-listener should depend on libdl 2025-09-11 16:04:15 +00:00
Sebastian Dröge
58791ea699 GDBus: Add (out) annotation to quark in g_dbus_error_register_error_domain() 2025-09-11 14:01:27 +03:00
Tobias Stoeckmann
c546ac20d8 tests: Fix clang compilation warnings
With these adjustments, building with clang leads to no warnings:

- The "{ NULL }" statement could be replaced with "{ 0 }" to satisfy
  clang, but this way it's explicitly filling all fields
- Even though "i" is not read with these g_array_binary_search calls,
  it rightfully should be set
2025-09-05 22:34:44 +02:00
Tobias Stoeckmann
48bf508bc1 docs: Fix typos
Typos found with codespell
2025-09-03 21:47:11 +02:00
Tobias Stoeckmann
3d21160b85 docs: Fix typos in comments 2025-09-03 21:33:53 +02:00
Luca Bacci
fc9ce24359 GWin32AppInfo: Add support for focus stealing (unpackaged apps)
...by calling AllowSetForegroundWindow.

See previous commit for more informations.
2025-09-03 17:05:48 +02:00
Luca Bacci
29535c8998 GWin32AppInfo: Add support for focus stealing (packaged apps)
IApplicationActivationManager implements the IForegroundTransfer interface,
which lets us specify if the launched app is allowed to create a window
that steals focus (assuming our process has such ability). By default that
setting is disabled, so launched apps appear in the background and do not
get focus.

See XDG activation (Wayland) and the Startup notification specification (X11)
for equivalent functionality on Unix.

Support for focus-stealing can be set in GAppLaunchContext subclasses like
GdkAppLaunchContext, see gdk_app_launch_context_set_timestamp [1].

[1] https://docs.gtk.org/gdk4/method.AppLaunchContext.set_timestamp.html
2025-09-03 17:05:48 +02:00
Luca Bacci
8168e68716 GWin32AppInfo: Add support for startup-notification-id
GdkAppLaunchContext for Wayland / X11 fetch an opaque token
from the compositor.

On Windows, the system doesn't give you any token. Instead,
the token is implicit, and you can pass that to other
processes via dedicated APIs like AllowSetForegroundWindow.

Due to that, we use an internal format for startup-notify-id
that lets us check what to pass to activated apps.
2025-09-03 17:05:32 +02:00
Philip Withnall
5c42d4f82c gdesktopappinfo: Error out on more invalid desktop files
Currently, the `GDesktopAppInfo` constructors return an error if
validity checks for the `Exec=` line, or other lines, fail. However,
they were ignoring the validity checks done at the `GKeyFile` level, for
invalid UTF-8 or string escaping.

It seems consistent to error out for those too, rather than pretending
that the key file line wasn’t set at all (i.e. treating it like `NULL`).

Spotted by Daniel Kondor.

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

Fixes: #3771
2025-09-02 17:50:49 +01:00
Niveditha Rau
f607ae6511 glocalfile: Disable faccessat()-based query_exists on Solaris 2025-09-01 13:56:21 -07:00
Kleis Auke Wolthuizen
e506d16efa gio: gmemorymonitorpsi: Replace GRegex with g_str_has_prefix()
Using g_str_has_prefix() and simple pointer arithmetic is easier and
more efficient.

No functional change.
2025-08-30 13:31:38 +00:00
Emmanuele Bassi
e13fe685cf docs: Fix links to GioUnix types
Now that Unix-specific types have been moved to the GioUnix, we need to
fix the various links in our documentation.
2025-08-29 18:00:50 +01:00
Zhou Qiankang
9c1226223c tests/gio: skip Unix socket-mock tests on Windows
Signed-off-by: Zhou Qiankang <wszqkzqk@qq.com>
2025-08-19 21:31:13 +08:00
Rafael Girão
ce3a5dbbbe glib: respect symlinks when updating mimeapps.list
In the case where mimeapps.list is a symlink, gio-issued updates would
overwrite the file, destroying the symlink in the process.

Instead, this approach recursively follows mimeapps.list symlinks
and overwites the contents of the final file instead.

Closes #3579
2025-08-18 13:44:23 +00:00
Philip Withnall
30aff12d89 gmemorymonitorpoll: Hold a weak ref from a source callback to the monitor
It’s possible for the dispatch of the timeout source to race with the
finalisation of the `GMemoryMonitorPoll`, given that the timeout is run
in the GLib worker thread.

Protect against that by holding a thread-safe weak ref on the
`GMemoryMonitor` in the callback data.

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

Fixes: #3758
2025-08-12 13:24:52 +01:00
Niveditha Rau
365c5bcfd1 Disable GMemoryMonitorPsi on Solaris
PSI doesn’t exist in the Solaris kernel, so this `GMemoryMonitor`
implementation can never be chosen at runtime on Solaris.
2025-08-12 08:31:04 +00:00
Tobias Stoeckmann
b8f9743a4d systemtap: Use correct formatters/types
Try to avoid casting variables to potentially smaller types to fit
defined probes. This can truncate values and lead to wrong results.

Also make sure that signedness matches.

Since GType can be even 128 bit on CHERI architecture, cast all these
various types used based on platform to uintmax_t which SystemTap
properly processes.
2025-08-08 23:15:38 +02:00
Antoine Jacoutot
ff47c01818 glocalfile: Disable faccessat()-based query_exists on OpenBSD 2025-08-07 11:28:25 +00:00
Khalid Abu Shawarib
7a38cbc1dc gio/filenamecompleter: Use platform-specific directory separator 2025-08-05 17:36:41 +03:00
Khalid Abu Shawarib
48f8812cca gio/tests/filenamecompleter: Add a basic test 2025-08-05 17:36:00 +03:00
Khalid Abu Shawarib
f9592306c9 gio/filenamecompleter: Add more specifics to documentation
Also remove redundant things like asking a user to free a string,
as it is already covered by transfer type annotations.
2025-08-05 17:36:00 +03:00
Philip Withnall
da19665880 Merge branch 'gdbuserror-docs' into 'main'
gdbuserror: Reformat docs to fully use gi-docgen and match style guide

See merge request GNOME/glib!4715
2025-08-05 13:20:06 +00:00
Philip Withnall
d6ba42a489 gdbuserror: Reformat docs to fully use gi-docgen and match style guide
https://developer.gnome.org/documentation/guidelines/devel-docs.html#writing-api-references

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3250
2025-08-05 13:57:40 +01:00
Luca Bacci
12543df16f Tests: do not set a timeout in Python tests
The Meson test harness handles that for us.

With a custom timeout, meson test -t is not useful (which is
surprising for users) and interactive debugging sessions may
terminate unexepectedly.
2025-08-04 10:47:50 +02:00
Philip Withnall
2326db507d tests: Add a missing poll condition to socket-listener test
It’s possible for the server communications to finish one main context
iteration before all of the client communications, depending on how the
kernel queues socket connection messages.

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

```
GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL
not ok /socket-listener/accept/multi-simultaneously - GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-31 00:11:25 +01:00
Michael Catanzaro
364f33c168 Merge branch '3739-socket-listener-keeps-on-giving' into 'main'
gsocketlistener: Fix accepting multiple connections in a single GMainContext iteration

Closes #3739

See merge request GNOME/glib!4717
2025-07-28 02:04:34 -05:00
Philip Withnall
8b82fb34c9 gsocketlistener: Fix infinite blocking when accepting connections
As the new comments in the code try to explain, this fixes infinite
blocking which could happen when calling
`g_socket_listener_accept_async()` multiple times in parallel, with more
parallel calls than there are pending incoming connections on any of the
`GSocket`s in the `GSocketListener`.

The way `g_socket_listener_accept_async()` works is to create a set of
`GSocketSource`s when it’s called, one for each of the `GSocket`s in the
`GSocketListener`. Those sources are attached to the main context,
polling for `G_IO_IN` (indicating that the socket has a pending incoming
connection to accept).

When one of the socket sources polls ready, `g_socket_accept()` is
called on it, and a new connection is created.

If there are multiple pending `g_socket_listener_accept_async()` calls,
there are correspondingly multiple `GSocketSource` sources for each
`GSocket` in the `GSocketListener`. They will all poll ready in a single
`GMainContext` iteration. The first one to be dispatched will
successfully call `g_socket_accept()`, and subsequent ones to dispatch
will do likewise until there are no more pending incoming connections.
At that point, any remaining socket sources polling ready in that
`GMainContext` iteration will call `g_socket_accept()` on a socket which
is *not* ready to accept, and that will block indefinitely, because
`GSocket` has its own blocking layer on top of `poll()`.

This is not great.

It seems like a better approach would be to disable `GSocket`’s blocking
code, because `GSocketListener` is using `poll()` directly. We only need
one source of poll truth. So, do that.

Unfortunately, that’s complicated by the fact that
`g_socket_listener_add_socket()` allows third party code to provide its
own `GSocket`s to listen on. We probably can’t unilaterally change those
to non-blocking mode, so users of that API will get what they ask for.
That might include blocking indefinitely. I’ve adjusted the
documentation to mention that, at least.

The changes are fairly simple; the accompanying unit test is less
simple. Shrug. It tests for the scenario fixed by this commit, plus the
scenario fixed by the previous commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3739
2025-07-25 16:36:33 +01:00
Philip Withnall
5ccce023de gsocketlistener: Fix a use-after-free when accepting sockets
The changes in commit 30ccfac9cf were not quite correct. The code is
structured so that a single reference to a `GTask` (and hence its
`AcceptSocketAsyncData` task data) is shared across the multiple
`GSocketSource`s which are created for a pending `accept_async()` call.

Setting `returned_yet` to true to short-circuit the remaining
`accept_ready()` dispatches in a given `GMainContext` iteration would
have worked, were it not for the fact that the code then immediately
dropped the last reference it had to the `GTask`, potentially freeing
the structure which contained `returned_yet`. Because of the async
nature of `GTask`, the exact timing of finalisation could vary.

This also meant that the other `GSocketSource`s were not destroyed until
an unknown time later.

Improve on that by explicitly destroying the other `GSocketSource`s as
soon as the first one returns an accepted socket. This causes
`GMainContext` to skip dispatching them, even within the same
`GMainContext` iteration. It also means the separate `returned_yet`
member is unnecessary.

This should fix the immediate issue seen in #3739. However, while
testing it I found a further issue which will be fixed in a following
commit, before I add a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3739
2025-07-25 16:04:44 +01:00
Philip Withnall
0558fc541e gsocketlistener: Factor out code to add sockets to internal structures
This introduces no functional differences, just makes some upcoming
changes clearer.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3739
2025-07-25 16:04:37 +01:00