Commit Graph

7702 Commits

Author SHA1 Message Date
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
Philip Withnall
8e9f238667 glocalfilemonitor: Skip event handling if the source has been destroyed
This should prevent unbounded growth of the `event_queue` in the
unlikely case that the `GSource` is removed from its `GMainContext` and
destroyed separately from the `GFileMonitor`.

I’m not sure if that can currently happen, but it could with future
refactoring, so it’s best to address the possibility now while we’re
thinking about this bit of code.

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

Helps: #1941
2022-05-31 12:24:13 +01:00
Benjamin Berg
ee4d93c6fd glocalfilemonitor: Avoid file monitor destruction from event thread
Taking a reference to the GFileMonitor when handling events may cause
object destruction from th worker thread that calls the function. This
condition happens if the surrounding code drops the otherwise last
reference ot the GFileMonitor. The series of events causes destruction
from an unrelated worker thread and also triggers g_file_monitor_cancel
to be called from g_file_monitor_source_handle_event.

For the inotify backend, this results in a deadlock as cancellation
needs to take a lock that protects data structures from being modified
while events are dispatched.

One alternative to this approach might be to add an RCU (release, copy,
update) approach to the lists contained in the wd_dir_hash and
wd_file_hash hash tables.

Fixes: #1941

An example stack trace of this happening is:

Thread 2 (Thread 0x7fea68b1d640 (LWP 260961) "gmain"):
 #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
 #1  0x00007fea692215dc in g_mutex_lock_slowpath (mutex=mutex@entry=0x7fea6911e148 <g.inotify_lock_lock>) at ../glib/gthread-posix.c:1493
 #2  0x00007fea69222062 in g_mutex_lock (mutex=mutex@entry=0x7fea6911e148 <g.inotify_lock_lock>) at ../glib/gthread-posix.c:1517
 #3  0x00007fea6908025a in _ih_sub_cancel (sub=0x1492620) at ../gio/inotify/inotify-helper.c:131
 #4  0x00007fea6907f9da in g_inotify_file_monitor_cancel (monitor=0x14a3550) at ../gio/inotify/ginotifyfilemonitor.c:75
 #5  0x00007fea68fae959 in g_file_monitor_cancel (monitor=0x14a3550) at ../gio/gfilemonitor.c:241
 #6  0x00007fea68fae9dc in g_file_monitor_dispose (object=0x14a3550) at ../gio/gfilemonitor.c:123
 #7  0x00007fea69139341 in g_object_unref (_object=<optimized out>) at ../gobject/gobject.c:3636
 #8  g_object_unref (_object=0x14a3550) at ../gobject/gobject.c:3553
 #9  0x00007fea6907507a in g_file_monitor_source_handle_event (fms=0x14c3560, event_type=<optimized out>, child=0x7fea64001460 "spawned-1", rename_to=rename_to@entry=0x0, other=other@entry=0x0, event_time=<optimized out>) at ../gio/glocalfilemonitor.c:457
 #10 0x00007fea6907fe0e in ih_event_callback (event=0x7fea64001420, sub=0x1492620, file_event=<optimized out>) at ../gio/inotify/inotify-helper.c:218
 #11 0x00007fea6908075c in ip_event_dispatch (dir_list=dir_list@entry=0x14c14c0, file_list=0x0, event=event@entry=0x7fea64001420) at ../gio/inotify/inotify-path.c:493
 #12 0x00007fea6908094e in ip_event_dispatch (event=0x7fea64001420, file_list=<optimized out>, dir_list=0x14c14c0) at ../gio/inotify/inotify-path.c:448
 #13 ip_event_callback (event=0x7fea64001420) at ../gio/inotify/inotify-path.c:548
 #14 ip_event_callback (event=0x7fea64001420) at ../gio/inotify/inotify-path.c:530
 #15 0x00007fea69081391 in ik_source_dispatch (source=0x14a2bf0, func=0x7fea69080890 <ip_event_callback>, user_data=<optimized out>) at ../gio/inotify/inotify-kernel.c:327
 #16 0x00007fea691d0824 in g_main_dispatch (context=0x14a2cc0) at ../glib/gmain.c:3417
 #17 g_main_context_dispatch (context=0x14a2cc0) at ../glib/gmain.c:4135
 #18 0x00007fea691d0b88 in g_main_context_iterate (context=context@entry=0x14a2cc0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4211
 #19 0x00007fea691d0c2f in g_main_context_iteration (context=0x14a2cc0, may_block=may_block@entry=1) at ../glib/gmain.c:4276
 #20 0x00007fea691d0c81 in glib_worker_main (data=<optimized out>) at ../glib/gmain.c:6176
 #21 0x00007fea691f9c2d in g_thread_proxy (data=0x1487cc0) at ../glib/gthread.c:827
 #22 0x00007fea68d93b1a in start_thread (arg=<optimized out>) at pthread_create.c:443
 #23 0x00007fea68e18650 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
2022-05-31 12:24:13 +01:00
Matteo Biggio
ac3fc84ff4 gsocketaddressenumerator: add nullable annotation to the result of next
The returned `SocketAddress` is going to be NULL when the stream of
socket addresses is finished
2022-05-31 11:34:02 +02:00
Philip Withnall
18c0088678 tests: Fix a memory leak when abandoning a file creation time test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 17:45:03 +01:00
Philip Withnall
b7b10cc7e0 tests: Add additional tests for nanosecond precision file timestamps
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #369
2022-05-27 17:45:03 +01:00
nitinosiris
b33ef610de Add functionality to preserve nanosecond timestamps
file copy doesn't preserve nanosecond timestamps

Closes #369
2022-05-27 17:03:35 +01:00
Philip Withnall
7ad6b05458 gfileinfo: Split out a g_file_info_remove_value() helper function
This introduces no functional changes but will make refactoring a bit
easier in the following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 16:56:10 +01:00
Philip Withnall
a20a432100 Merge branch 'nacho/uwp-warnings' into 'main'
win32appinfo: change log level from warning to debug

Closes #2640

See merge request GNOME/glib!2661
2022-05-26 14:29:11 +00:00
TestingPlant
da7a31a052 Rename user data parameters to user_data
The user data parameters in callbacks need to be named user_data to
generate correct closure attributes in the introspection data. This
updates parameters missed in GNOME/glib!2633.
2022-05-22 01:06:37 +00:00
Marc-André Lureau
294b562f34 gio: fix gunixfdlist.h location after move to common gio
Fixes commit 5efb84f24a ("gio: add GUnixFDList on win32")

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2653

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-18 18:19:03 +02:00
Philip Withnall
caf6d99fbe Merge branch 'win32-fd' into 'main'
gio: various unix/fd-related enablement on win32

See merge request GNOME/glib!2656
2022-05-18 14:01:43 +00:00
Philip Withnall
c613d32b92 tests: Add SPDX license headers automatically
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.

This commit was entirely generated using the command:
```
git ls-files gio/tests/*.c | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```

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

Helps: #1415
2022-05-18 09:20:07 +01:00
Philip Withnall
5942cd7984 gio: Add SPDX license headers automatically
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.

This commit was entirely generated using the command:
```
git ls-files gio/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```

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

Helps: #1415
2022-05-18 09:18:52 +01:00
Marc-André Lureau
984103b0e7 gio/tests: add gdbus-peer test to win32
Because we can :)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Marc-André Lureau
7886283750 gio/tests: unescape the nonce_file value
The raw value is escaped according to D-Bus rules. This is probablematic
for Windows backslashed paths. We can use URI unescaping, it seems
that's what gdbusaddress.c is doing too.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Marc-André Lureau
e34795b431 gio/gdbusserver: add "unix:" address support on !unix
This is another minor left-over after GNOME/glib!2445.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Marc-André Lureau
18886d43d2 gio/gdbusauth: remove #ifdef G_OS_UNIX around credentials
The AF_UNIX API is available under all platforms since 2.71.1, and
credentials functions returns NOT_SUPPORTED error appropriately,
we can thus remove the special-casing for !unix.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Marc-André Lureau
b5c97b1016 gio/tests: add basic fd-list unit test to unix-fd
To cover win32 support.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Marc-André Lureau
c9b5b1fb94 gio/tests: switch to g_close()
For the better behaviour and portability.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 16:37:39 +02:00
Marc-André Lureau
b8eb64b350 gio/tests: add unix-fd test to win32
The "/unix-fd/scm" test is quite Unix-specific, the next patch is going
to add a portable test.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 16:37:39 +02:00
Philip Withnall
6659f502ca Merge branch 'resources-extraneous-symbol' into 'main'
resources: Hide external data symbol

Closes gtk#4598

See merge request GNOME/glib!2652
2022-05-17 13:58:41 +00:00
Matthias Clasen
6039c1f4e8 resources: Hide external data symbol
Apply --internal to the symbol for the section as well.

Only do this with --external-data, since otherwise gcc
will complain about ignoring the attribute.

This fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4598
2022-05-17 14:04:11 +01:00
Michael Catanzaro
e27ef839d9 Deprecate GDtlsClientConnection validation flags
See !2214 for motivation. It doesn't work properly anymore, and the TLS
versions of these functions were already deprecated. Sadly, I missed the
DTLS versions.

Fixes #2646
2022-05-17 14:03:28 +01:00
Marc-André Lureau
5efb84f24a gio: add GUnixFDList on win32
FDs are not specific to Unix. win32 has APIs to map CRT fd to/from HANDLE.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 14:39:20 +02:00
Ignacio Casal Quinteiro
acb1ce2272 win32appinfo: change log level from warning to debug
There is nothing that the user can do anyway and this dumps
lots of warnings without real need.

Closes #2640
2022-05-17 12:14:21 +02:00
Ignacio Casal Quinteiro
f38d74b233 gtask: use g_strconcat() in g_task_return() only if needed
If the task name is NULL there is no need to allocate the string
since this can be expensive if called very often
2022-05-16 13:25:50 +01:00
Godvin Ouseph
61ad2d7217 Fix typo in gio/meson.build
This broke compiling gtk4 as a subproject on Windows
2022-05-14 15:54:56 +05:30
Marc-André Lureau
277657eacc glib/win32: introduce private g_win32_handle_is_socket()
Used in following commits, including in some GIO experiments.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-12 18:54:11 +02:00
Marc-André Lureau
c4a7ddbf67 gio/tests/unix-fd: rename test
Use a prefix matching the binary, rename the test "scm", as it involves
SocketControlMessage.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-12 18:48:59 +02:00
Marc-André Lureau
18d98e30f9 gio/tests: close leaked fd
Also fixes some of the test on win32, since it won't delete files that
are opened.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-12 18:48:59 +02:00
Marc-André Lureau
a638b2bbd1 gio: include Unix socket headers
This should have been part of #2487.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-12 18:48:59 +02:00
TestingPlant
a5e7156a9b Replace single quotes in gio/tests/codegen.py
This makes the formatting more consistent.
2022-05-12 00:29:44 +00:00
Simon McVittie
816abcbb95 Merge branch 'scan-build-fixes' into 'main'
Add some more assertions to help scan-build out

See merge request GNOME/glib!2646
2022-05-10 16:30:18 +00:00
Philip Withnall
e36f2bb243 gproxyaddressenumerator: Factor out type check
This will help static analysers which think that the type of
`priv->proxy_address` could potentially change between freeing
`dest_hostname` and the `g_return_if_fail()` call below, leading to the
code to continue through to `g_object_new()` and use `dest_hostname`
after freeing it.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-10 16:23:46 +01:00
Philip Withnall
7767978725 gdbusdaemon: Add an assertion to help static analysis of refcounts
This should fix a scan-build warning about the final `name_unref()` here
being a use-after-free.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-10 16:17:38 +01:00
Philip Withnall
86927c39e0 gresource: Assert that resource has correct refcount when unregistering
This should fix a scan-build warning that `resource` is
used-after-freeing in the final `g_resource_unref()` call in
`g_static_resource_fini()`, as `g_resources_unregister_unlocked()` has
already unreffed it.

In reality, each resource has two strong refs on it while active, so the
second unref is correct.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-10 15:53:19 +01:00
Philip Withnall
bd1781a356 build: Stop using Meson features deprecated in Meson <0.60
This clears some Meson warnings.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-06 13:55:28 +01:00
Xavier Claessens
374be41433 meson: Use meson.can_run_host_binaries()
It is not only shorter than `not meson.is_cross_build() or
meson.has_exe_wrapper()` but also handle the case of cross compiling to
a compatible arch such as building for i386 on an amd64.
2022-05-06 13:17:11 +01:00
Philip Withnall
25ab87d8e5 build: Drop checks and workarounds for older Meson versions
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-06 13:01:44 +01:00
Sebastian Dröge
0c6a1af9d6 Merge branch 'gdbus-threading-test-fix-maybe' into 'main'
tests: Reduce wakeup interval in gdbus-threading

See merge request GNOME/glib!2604
2022-04-29 08:05:52 +00:00
Sebastian Dröge
ef8e0035a5 Merge branch 'fix-gdbus-peer-object-manager-test' into 'main'
tests: Use G_TEST_OPTION_ISOLATE_DIRS in gdbus-peer-object-manager

See merge request GNOME/glib!2603
2022-04-29 08:04:33 +00:00
Sebastian Dröge
4f48d4e1bb Merge branch 'scan-build-fixes' into 'main'
Fix various scan-build warnings

See merge request GNOME/glib!2628
2022-04-28 11:07:34 +00:00
Sebastian Dröge
a0aff5404c Merge branch 'scan-build-leak-fix' into 'main'
gopenuriportal: Fix a use-after-free on an error path

See merge request GNOME/glib!2627
2022-04-28 10:44:57 +00:00
Philip Withnall
a17a27bcf1 glocalfileinfo: Remove a redundant store
This fixes a scan-build warning:
```
../../../../source/glib/gio/glocalfileinfo.c:1661:28: warning: Although the value stored to 'mydirname' is used in the enclosing expression, the value is never actually read from 'mydirname' [deadcode.DeadStores]
                           mydirname = g_strdup (dirname),
                           ^           ~~~~~~~~~~~~~~~~~~
```

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

Helps: #1767
2022-04-28 11:22:53 +01:00
Philip Withnall
969eb835dc gopenuriportal: Fix a use-after-free on an error path
`path` was used in building the error message after it had been freed.
Spotted by scan-build.

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

Helps: #1767
2022-04-28 11:22:33 +01:00
Philip Withnall
7f83151ac0 gsocket: Clear address before filling it
This will probably make no functional difference, but will squash two
warnings from scan-build:
```
../../../../source/glib/gio/gsocket.c:503:14: warning: Assigned value is garbage or undefined [core.uninitialized.Assign]
      family = address.storage.ss_family;
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../source/glib/gio/gsocket.c:527:29: warning: Assigned value is garbage or undefined [core.uninitialized.Assign]
       socket->priv->family = address.storage.ss_family;
                            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
```

It seems like a reasonable thing to warn about. Initialising the full
union to zero should avoid any possibility of undefined behaviour like
that.

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

Helps: #1767
2022-04-28 10:50:08 +01:00
Philip Withnall
c02890645b tests: Drop redundant store
This fixes a scan-build warning:
```
../../../../source/glib/gio/tests/gdbus-tests.c:146:3: warning: Value stored to 'watch_id' is never read [deadcode.DeadStores]
  watch_id = 0;
  ^
```

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

Helps: #1767
2022-04-28 10:43:13 +01:00
Sebastian Dröge
0c1b7b263e Merge branch 'multicast-memcpy-size' into 'main'
gsocket: Add assertions about socket address sizes for memcpy()

See merge request GNOME/glib!2625
2022-04-27 14:32:16 +00:00
Philip Withnall
49cc9b96f4 gio-tool: Fix a minor memory leak when using gio-set with bytestrings
Tested using:
```sh
touch ~/foo
gio set ~/foo -t bytestring user::test "\x00\x00"
```
(it doesn’t matter that this fails; the bytestring is still decoded)

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

Coverity CID: #1474407
2022-04-27 15:01:08 +01:00
Philip Withnall
ff944776fe gsocket: Add assertions about socket address sizes for memcpy()
These `memcpy()` calls only happen if `g_inet_address_get_family(group)
== G_SOCKET_FAMILY_IPV4`, so the assertions should never fail.

It’s helpful for understanding the code, and for static analysis, to add
the assertions though.

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

Coverity CID: #1486858
2022-04-27 14:47:35 +01:00
Xavier Claessens
199ff2a841 Meson: Fix gio-windows-2.0 override name
The override name must match the pkgconfig name.
2022-04-24 21:29:26 -04:00
Marc-André Lureau
e9f46d3529 gio/tests: fix socket /socket/credentials/unix_socketpair on win32
When I enabled unix socketpair test on win32, I left the existing
g_close(fds[1]), but _g_win32_socketpair() returns native sockets
descriptors that must be closed with closesocket() on win32.

Let GSocket handle the socket pair cleanup.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Marc-André Lureau
89539d9ae0 gio/tests: GStatBuf.st_size is 64 bits on win64
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Philip Withnall
58f54e8303 tests: Reduce wakeup interval in gdbus-threading
When checking that the connection has the expected number of refs, the
test would block on a `GMainContext` iteration for up to 3s before
waking up and failing (if the refcount was still not as expected).

This check was written in the expectation that changing the refcount of
the connection would only happen due to dispatching a source on
`GMainContext` — hence the `GMainContext` would wake up as the refcount
changed.

That’s probably not actually true though. It might be the case that the
connection’s refcount is changed on from the GDBus worker thread, which
would not cause any wakeups on the main thread’s `GMainContext`.

In this case, the `GMainContext` iteration in
`assert_connection_has_one_ref()` would block for the full 3s, and then
wake up and notice the refcount is correct (then the test would
proceed).

That’s fine, apart from the fact that `test_threaded_singleton()` does
this 1000 times. If the slow case is hit on a significant number of
those test runs, the test will take around 3000s to complete, which is
significantly more than meson’s test timeout of 360s. So the test fails
with something like:
```
220/266 glib:gio+slow / gdbus-threading         TIMEOUT 360.07 s

--- command ---
G_TEST_SRCDIR='/builds/GNOME/glib/gio/tests' GIO_MODULE_DIR='' G_TEST_BUILDDIR='/builds/GNOME/glib/_build/gio/tests' /builds/GNOME/glib/_build/gio/tests/gdbus-threading
--- stdout ---
\# random seed: R02S83fe8de22db4d4f376e6d179e2bdd601
1..3
\# Start of gdbus tests
ok 1 /gdbus/delivery-in-thread
ok 2 /gdbus/method-calls-in-thread
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
```

From this log, it can be seen that the sleep is happening on a different
`GMainContext` every other time, so the test *is* making progress.

Assuming this is a correct diagnosis (it’s a lot of guessing), this
commit tries to fix the test by adding a wakeup timeout to the
`GMainContext` in `assert_connection_has_one_ref()`, which will wake it
up every 50ms to re-check the exit condition.

This polling approach has been taken because it doesn’t seem feasible to
make sure that every `g_object_ref()`/`g_object_unref()` call on a
`GDBusConnection` causes the main context to wake up.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 14:39:43 +01:00
Philip Withnall
77416fc023 tests: Use g_assert_*() rather than g_assert() in gdbus-peer-object-manager
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:29:19 +01:00
Philip Withnall
20c3ab9e51 tests: Use G_TEST_OPTION_ISOLATE_DIRS in gdbus-peer-object-manager
This might fix a recent test failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/1929015. Unfortunately
there’s not much debug information in the logs to go on, and I can’t
reproduce it locally. All I have is:
```
192/272 glib:gio / gdbus-peer-object-manager    FAIL     0.43 s (killed by signal 11 SIGSEGV)

--- command ---
GIO_MODULE_DIR='' G_TEST_BUILDDIR='/builds/GNOME/glib/_build/gio/tests' G_TEST_SRCDIR='/builds/GNOME/glib/gio/tests' /builds/GNOME/glib/_build/gio/tests/gdbus-peer-object-manager
--- stdout ---
\# random seed: R02Seee9b7325ecd7c19249a3412397aed9b
1..2
\# Start of gdbus tests
\# Start of peer-object-manager tests
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:29:19 +01:00
Marc-André Lureau
2a925f273b gio/tests: DuplicateHandle() is inappropriate for SOCKET 2022-04-07 11:22:55 +00:00
Sebastian Dröge
86a24bb19a Merge branch 'wip/pwithnall/converter-stream-debugging' into 'main'
tests: Remove an incorrect assertion in converter-stream

See merge request GNOME/glib!2591
2022-04-06 13:15:01 +00:00
Jason Francis
a85246af3b gio: Add g_list_store_find_with_equal_func_full()
Fixes: #2447
2022-04-05 18:34:39 +01:00
Philip Withnall
aec5d17d77 tests: Remove an incorrect assertion in converter-stream
While the assertion always turned out to be true on Linux, it frequently
caused spurious test failures on FreeBSD.

After some remote debugging, I *think* the cause is as written up in the
comment in the code in this commit. However, I cannot be certain, as the
more debugging messages I added, the harder the failure was to
reproduce; and I don’t have access to a FreeBSD machine.

This fixes failures like:
```
Bail out! GLib-GIO:ERROR:../gio/tests/converter-stream.c:1043:test_converter_pollable: assertion failed (error == NULL): Resource temporarily unavailable (g-io-error-quark, 27)
```

It’s succeeded 1000 times in a row on the FreeBSD CI now; previously
it was failing one time in three:
https://gitlab.gnome.org/GNOME/glib/-/jobs/1936395.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-05 18:19:23 +01:00
Philip Withnall
82ad0510d2 tests: Don’t exit gdbus-method-invocation test early on connection close
There’s (deliberately) a bit of race in implementing/handling
`CloseBeforeReturning()` in `gdbus-method-invocation.c`. If the server
closes the D-Bus connection early, the client may exit with `SIGTERM` if
`GDBusConnection:exit-on-close` is set. We don’t want that, as the test
is trying to check that the default handling of a D-Bus method return
after a connection has closed works.

See https://gnome.pages.gitlab.gnome.org/-/glib/-/jobs/1935191/artifacts/_build/meson-logs/testlog.txt

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-05 14:43:16 +01:00
Philip Withnall
bae0a3c751 Merge branch 'badcel/gunixfdlist-only-unix' into 'main'
GUnixFDList: Include only in unix build

See merge request GNOME/glib!2585
2022-04-05 12:12:19 +00:00
Philip Withnall
259c86909f Merge branch 'fix-trashing-sandboxed-directories' into 'main'
Fix trashing sandboxed directories

Closes #2629

See merge request GNOME/glib!2583
2022-04-05 11:58:33 +00:00
badcel
c9874f817b
GUnixFDList: Include only in unix build 2022-04-04 20:30:22 +02:00
Loic Le Page
c6a5021f48 Fix redefinition of local variable in gio/gdbusobjectmanagerclient.c 2022-04-04 17:39:59 +01:00
Loic Le Page
5223863922 Fix redefinition of local variable in gio/gdbusserver.c 2022-04-04 17:39:59 +01:00
Loic Le Page
af69d438ed Fix unused variable and remove finalize vfunc in gio/tests/gdbus-example-proxy-subclass.c
G_GNUC_UNUSED does perfectly its job with gcc compiler but the warning
still remains with msvc compiler.

Once the unused variable removed, the finalize vfunc can be removed as
it's doing the same job as the parent function.
2022-04-04 17:39:59 +01:00
Loic Le Page
4e3f704d49 Fix global variable name hidden by local variables in gio/tests/pollable.c 2022-04-04 17:39:58 +01:00
Loic Le Page
25ab7f1e74 Fix global variable name hidden by local variables in gio/tests/proxy.c 2022-04-04 17:39:42 +01:00
Loic Le Page
13710c3699 Fix global variable name hidden by local variables in gio/tests/resolver.c 2022-04-04 17:39:42 +01:00
Matthias Clasen
724df43616 Fix trashing sandboxed directories
We must not open the fd with O_PATH|O_NOFOLLOW,
since the portal rejects that combination. Leaving
out O_NOFOLLOW is fine in this case - we know it
is a directory, we just received EISDIR.

Fixes: #2629
2022-04-04 10:26:13 -04:00
Philip Withnall
6c31ef6f18 Merge branch 'cleanup-warnings-split-8' into 'main'
Cleanup warnings split 8

See merge request GNOME/glib!2497
2022-04-01 15:13:32 +00:00
Loic Le Page
e372ed3413 Fix cast pointer to int warning in gio/tests/socket.c 2022-04-01 15:10:50 +02:00
Loic Le Page
7bd79b112d Fix non-initialized variable in gio/tests/socket-client.c 2022-04-01 15:10:50 +02:00
Loic Le Page
027e3769ee Fix global variable name hidden by local variables in gio/tests/socket-server.c 2022-04-01 15:10:50 +02:00
Loic Le Page
7178e10cd5 Fix redefinition of local variable in gio/tests/testfilemonitor.c 2022-04-01 15:10:50 +02:00
Loic Le Page
c324ce5c2a Fix redefinition of local variable in gio/gactiongroupexporter.c 2022-04-01 15:10:50 +02:00
Loic Le Page
3214a0f333 Fix redefinition of local variable in gio/gapplicationimpl-dbus.c 2022-04-01 15:10:50 +02:00
Loic Le Page
0c1619227c Fix redefinition of local variable in gio/gdbus-tool.c 2022-04-01 15:10:50 +02:00
Loic Le Page
4bcb7bc631 Fix redefinition of local variable in gio/gdbusauth.c 2022-04-01 15:10:50 +02:00
Loic Le Page
eb157bfa1b Fix redefinition of local variable in gio/gdbusauthmechanismsha1.c 2022-04-01 15:10:41 +02:00
Loic Le Page
bf68e8606b Fix non-initialized variable and remove obsolete usage of inet_addr in gio/gsocket.c 2022-04-01 00:18:40 +01:00
Loic Le Page
7bde242707 Fix redefinition of local variable in gio/gsocks5proxy.c 2022-04-01 00:18:40 +01:00
Loic Le Page
bd5d867320 Fix global variable name hidden by local variables in gio/gthreadedresolver.c 2022-04-01 00:18:40 +01:00
Loic Le Page
49d0c5a90b Fix redefinition of local variable in gio/gtlscertificate.c 2022-04-01 00:18:40 +01:00
Loic Le Page
84dabcf274 Fix global and local variables hidden by local variables and non-initialized variables in gio/gwin32appinfo.c 2022-04-01 00:18:40 +01:00
Loic Le Page
155657de3e Fix redefinition of local variable in gio/gwin32file-sync-stream.c 2022-04-01 00:18:40 +01:00
Philip Withnall
f8302d29f1 Merge branch 'wip/smcv/simplify-openpty-linking' into 'main'
tests: Call openpty (if available) without using dlsym

See merge request GNOME/glib!2562
2022-03-31 15:09:46 +00:00
Loic Le Page
6888f9e17e Fix too small array definition in gio/gdummyfile.c (no room for the '\0') 2022-03-31 13:10:26 +01:00
Loic Le Page
5ec3a425d2 Fix non-initialized variable in gio/gfile.c 2022-03-31 13:10:25 +01:00
Loic Le Page
397ccd833b Fix global variable name hidden by local variables in gio/gfileinfo.c 2022-03-31 13:10:25 +01:00
Loic Le Page
cbdddf82c0 Fix global variable name hidden by local variables in gio/gio-tool-info.c 2022-03-31 13:10:25 +01:00
Loic Le Page
72cc5b3910 Fix global variable name hidden by local variables in gio/gio-tool-list.c 2022-03-31 13:10:25 +01:00
Loic Le Page
71de9553ca Fix global variable name hidden by local variables in gio/gio-tool-mount.c 2022-03-31 13:10:25 +01:00
Loic Le Page
c0dabdd8df Fix global variable name hidden by local variables in gio/gio-tool-save.c 2022-03-31 13:10:25 +01:00
Loic Le Page
781231d556 Fix global variable name hidden by local variables in gio/gio-tool-trash.c 2022-03-31 13:10:25 +01:00
Loic Le Page
a30ae2497d Fix redefinition of local variable in gio/giomodule.c 2022-03-31 13:10:25 +01:00
Loic Le Page
94264e6190 Fix redefinition of local variable in gio/giowin32-private.c 2022-03-31 13:10:25 +01:00
Sebastian Dröge
1fc402b33b Merge branch '2614-bye-bye-gamin' into 'main'
gio: Remove fam file monitor support

Closes #2614

See merge request GNOME/glib!2570
2022-03-23 16:45:04 +00:00
Philip Withnall
6aa210e6af gio: Remove fam file monitor support
libgamin was last released in 2007 and is dead
[upstream](https://gitlab.gnome.org/Archive/gamin). Distributions may
still ship it (although Fedora no longer does), but we want people to
use inotify on Linux since it’s actively supported.

BSDs use kqueue. Windows uses win32filemonitor.

FAM might still be used on some commercial Unix distributions, but there
are no contributors from those distributions, and certainly no CI for
them to prevent regressions.

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

Fixes: #2614
2022-03-23 15:41:54 +00:00
Philip Withnall
2759dd71be gio: Remove remaining references to fen file monitor
It used to exist on Solaris, but GLib’s support for it was mostly
removed in 2015 in commit 21ab660cf8.

Remove the final few references.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-23 15:40:41 +00:00
Marc-André Lureau
517bd62840 gio/win32: TIME_CREATED_USEC is u32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-23 19:34:32 +04:00
Philip Withnall
f9ef3bec68 gthreadedresolver: Only declare private test APIs on Unix
They’re only defined on Unix anyway. `GThreadedResolver` has an entirely
different code path for handling DNS replies on Windows.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:41:08 +00:00
Philip Withnall
e8e8aebcbe resolver: Add SRV support to manual resolver test
This allows for tests like:
```
resolver -t SRV _http._tcp.mxtoolbox.com
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
33204fe127 tests: Add tests for parsing specific DNS record types
Success and failure tests. This massively increases test coverage for
parsing DNS records, although it doesn’t get it to 100%.

It should now be useful enough to do more fuzzing on, without
immediately getting trivial failures from the fuzzer.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
0d42af06e0 gthreadedresolver: Treat query and answer counts as unsigned
They can’t be negative.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
08dee06b59 gthreadedresolver: Limit length of each record to its stated rdlength
Rather than limiting them to the full length of the answer, which may
include subsequent records.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
023fab80f9 gthreadedresolver: Add error checking to all record parsing
This should catch all kinds of invalid records, and correctly report
them as errors.

Heavily based on work by Patrick Griffis in !2134.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
81193c5aac gthreadedresolver: Don’t warn on unrecognised record types
Otherwise the code isn’t forwards-compatible, and may be DOSed by
servers returning unknown records, if `G_DEBUG=fatal-warnings` is
enabled for some reason.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
51f70fe62e tests: Add tests for invalid DNS response header parsing
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
2a7b4db243 gthreadedresolver: Expose g_resolver_record_type_to_rrtype()
So that it can be used in the tests.

It’s not part of the public, documented, supported API.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
8b73d7bbf9 gthreadedresolver: Handle error returns from dn_expand() in headers
It is possible for `dn_expand()` to fail; if so, it’ll return `-1`,
which will mess up subsequent parsing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Philip Withnall
263ca69da8 gthreadedresolver: Check header length when parsing response
Otherwise we could read off the end of an invalid response.

oss-fuzz#42538
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-22 12:40:12 +00:00
Patrick Griffis
5cdacced3f tests: Add basic test framework for GResolver DNS parsing
Split out from https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2134
by Philip Withnall so it can be used in advance of HTTPS DNS record
support landing.

Reworked to no longer use test fixtures, as it’s simple enough to build
the response header in each test.

The tests are built on Unix only, as they test the parsing code in
`g_resolver_records_from_res_query()`, which is Unix-specific. The
Windows DNS APIs provide much more structured results which don’t need
parsing.
2022-03-22 12:40:12 +00:00
Philip Withnall
2e940e125f Merge branch 'w32-skips' into 'main'
Various win32 tests skip & fixes

See merge request GNOME/glib!2540
2022-03-21 12:19:24 +00:00
Simon McVittie
1726e150f4 tests: Call openpty (if available) without using dlsym
The SONAME of libutil varies between architectures, so the logic to find
the SONAME of libutil was only correct for native builds (Linux on
Linux), not for cross-builds. The regular expression was also not
sufficiently broad to match the SONAME used on the alpha architecture,
which is apparently libutil.so.1.1.

Instead of screen-scraping the output of ldconfig and using that to
dlopen the library that contains openpty, it seems more reliable to
emit a link-time reference to openpty and let the linker do its job.
It's also less code.

Bug-Debian: https://bugs.debian.org/1007946
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-03-19 14:10:51 +00:00
Philip Withnall
c53129911c Merge branch 'power-profile-monitor-docs' into 'main'
gpowerprofilemonitor: Tweak wording of documentation to make more sense

See merge request GNOME/glib!2534
2022-03-18 11:34:47 +00:00
Sebastian Dröge
73f918b376 Merge branch 'gdbus-method-invocation-leak' into 'main'
gdbusmethodinvocation: Fix a leak on an early return path

See merge request GNOME/glib!2557
2022-03-18 09:25:28 +00:00
Marc-André Lureau
e38e92e37b gio/tests/codegen: skip tests that require /dev/stdout on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:20:14 +04:00
Marc-André Lureau
b3d6946c27 tests/socket: skip a test if AF_UNIX is not supported on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:16:38 +04:00
Marc-André Lureau
e014b9272a gio/tests: skip filemonitor tests on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:16:38 +04:00
Marc-André Lureau
cfc47558fc tests: enable defaultvalue and debugcontroller on win32
The test still requires dbus-daemon.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:16:38 +04:00
Marc-André Lureau
e9d9edde82 tests: skip appmonitor test on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:16:14 +04:00
Philip Withnall
a7750cd020 tests: Add unit tests for GDBusMethodInvocation
These should cover everything to do with returning a value or error from
a `GDBusMethodInvocation` object.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-17 19:17:41 +00:00
Philip Withnall
7143457076 gdbusmethodinvocation: Drop redundant quote from warning message
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-17 19:05:56 +00:00
Philip Withnall
76f5460107 gdbusmethodinvocation: Fix dead code for type checking GetAll
`property_info` is only ever set for `Get` and `Set` calls, not for
`GetAll`, as it only represents a single property. So this code was
never reachable.

Move it out so that it is reachable.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-17 19:05:56 +00:00
Philip Withnall
a3b8846e54 gdbusmethodinvocation: Fix a leak on an early return path
When doing an early return from `g_dbus_method_invocation_return_*()`
due to passing in the wrong type (or no return value when one was
expected), the parameters were not correctly sunk and were leaked.

Fix that. A unit test will be added in a following commit.

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

Coverity CID: #1474536
2022-03-17 19:04:42 +00:00
Philip Withnall
4ef27174af tests: Use g_strv_contains() rather than a home-grown version
The public `g_strv_contains()` API didn’t exist at the time this code
was originally written. Now, happily, it does.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-17 16:28:41 +00:00
Philip Withnall
e4d77f7e89 gdbusconnection: Use g_strv_contains() rather than a home-grown version
The public `g_strv_contains()` API didn’t exist at the time this code
was originally written. Now, happily, it does.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-17 16:24:08 +00:00
Philip Withnall
9b77b75f2d Merge branch 'w32-contenttype' into 'main'
Various contenttype-related test fixes on win32

See merge request GNOME/glib!2499
2022-03-17 15:14:14 +00:00
Philip Withnall
96279325b7 Merge branch 'cleanup-warnings-split-6' into 'main'
Cleanup warnings split 6

See merge request GNOME/glib!2495
2022-03-17 15:13:14 +00:00
Philip Withnall
1756dde873 Merge branch '2312-codegen-test-leak-fix' into 'main'
tests: Fix a leak in gdbus-test-codegen test

Closes #2312

See merge request GNOME/glib!2546
2022-03-17 15:12:08 +00:00
Michael Catanzaro
69a1867d51 gtlsconnection: fix typo in docs
Grrr, copy/paste error detected.
2022-03-16 10:38:34 +00:00
Philip Withnall
96caca2b7a tests: Explicitly close stream in converter-stream
When the test has finished writing all the expanded content into the
socket, explicitly close the output stream, which should make the input
stream readable and non-blocking.

The code intended to do this before, but only as a side-effect of
dropping its last reference to `right`. If another reference was being
held to `right` somewhere else, it wouldn’t end up being closed, which
would lead to failures like
https://gitlab.gnome.org/GNOME/glib/-/jobs/1890000:
```
(/var/tmp/gitlab_runner/builds/Ff4WDDRj/0/GNOME/glib/_build/gio/tests/converter-stream:56570): GLib-GIO-DEBUG: 12:56:23.280: GSocketClient: Connection successful!
Bail out! GLib-GIO:ERROR:../gio/tests/converter-stream.c:1042:test_converter_pollable: assertion failed (error == NULL): Resource temporarily unavailable (g-io-error-quark, 27)
stderr:
```

This is a bit of a guess (I’m not sure it’ll fix the intermittent test
error, as I haven’t been able to reproduce that locally), but it’s worth
a try.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-14 17:59:37 +00:00
Philip Withnall
8cff531520 tests: Isolate directory access for gdbus-connection-flush test
When multiple tests were run in parallel, this would race on its access
to `~/.dbus-keyrings` to authenticate with the D-Bus server, since the
keyring directory was not appropriately sandboxed to the unit test.

Use `G_TEST_OPTION_ISOLATE_DIRS` to automatically isolate each unit
test’s directory usage.

This should hopefully fix the failure seen in
https://gitlab.gnome.org/GNOME/glib/-/jobs/1849524, where the following
was in the log for a test executed in parallel:
```
GDBus-DBUS_COOKIE_SHA1: Deleted stale lock file '/home/user/.dbus-keyrings/org_gtk_gdbus_general.lock'
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-12 00:03:05 +00:00
Philip Withnall
a3c768732d tests: Isolate directory access for gdbus-non-socket test
When multiple tests were run in parallel, this would race on its access
to `~/.dbus-keyrings` to authenticate with the D-Bus server, since the
keyring directory was not appropriately sandboxed to the unit test.

Use `G_TEST_OPTION_ISOLATE_DIRS` to automatically isolate each unit
test’s directory usage.

This should hopefully fix the failure seen in
https://gitlab.gnome.org/pwithnall/glib/-/jobs/1879558.
```
228/266 glib:gio / gdbus-non-socket             FAIL     8.64 s (killed by signal 6 SIGABRT)
…
--- stderr ---
GDBus-DBUS_COOKIE_SHA1: Deleted stale lock file '/home/user/.dbus-keyrings/org_gtk_gdbus_general.lock'
**
GLib-GIO:ERROR:../gio/tests/gdbus-non-socket.c:253:test_non_socket: assertion failed (error == NULL): Exhausted all available authentication mechanisms (tried: EXTERNAL, DBUS_COOKIE_SHA1) (available: EXTERNAL, DBUS_COOKIE_SHA1) (g-io-error-quark, 0)
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-11 23:56:18 +00:00
Philip Withnall
404d5d40e0 tests: Ensure timeout source is removed in gdbus-auth test
If the whole set of tests takes more than 5 seconds, the failure timeout
from the first test could still trigger, causing an incorrect failure.

Ensure the timeout is removed at the end of each test.i

This will hopefully fix the CI failure seen here:
https://gitlab.gnome.org/pwithnall/glib/-/jobs/1879558.
```
204/266 glib:gio / gdbus-auth                   FAIL     9.21 s (killed by signal 5 SIGTRAP)
…
ok 1 /gdbus/auth/client/EXTERNAL
Bail out! GLib-GIO-FATAL-ERROR: Timeout waiting for client
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-11 23:47:22 +00:00
Loic Le Page
7a50259345 Fix redefinition of local variable in gio/glib-compile-schemas.c 2022-03-09 17:19:02 +01:00
Loic Le Page
9380a8cdb0 Fix redefinition of local variable in gio/glocalfilemonitor.c 2022-03-09 17:19:02 +01:00
Loic Le Page
d0dfc76554 Fix redefinition of local variable and non-initialized variable in gio/glocalfileoutputstream.c 2022-03-09 17:18:03 +01:00
Philip Withnall
bed82b807f tests: Re-enable address sanitizer for gdbus-test-codegen
Now that the leaks are fixed, this test can be run under the sanitizer
again.

This is a partial revert of commit
f378352051.

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

Helps: #2312
2022-03-09 14:21:22 +00:00
Philip Withnall
9499aeb8bf tests: Wait for signal unsubscriptions in gdbus-test-codegen
When destroying `GDBusProxy`s in a custom `GMainContext`, the context
must be iterated enough after finalisation of the proxies that any
pending D-Bus traffic, and the signal subscription data, can be freed.

See the documentation for `g_dbus_connection_signal_unsubscribe()`.

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

Fixes: #2312
2022-03-09 14:21:20 +00:00
Marc-André Lureau
b0c53559c0 tests: skip check anything is octet-stream
Like on Mac, the contenttype database can't say that much yet.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
7fa4999457 tests: skip test_tree on win32
Currently it simply crashes, because types == NULL.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
5f1bae1594 gio/tests: fix test_icon on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
452d64a03b tests: use Windows mime type for executable
According to https://stackoverflow.com/a/43916291/1277510

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
b60b0ec72d gio: relax g_content_type_is_a on win32
This is quite gross, but it looks like the whole content-type code on
Windows is similar. Pass test_subtype.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
ab0c00bd7e gio/tests: fix various content type guesses on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
529e091bb5 gio/tests: fix content type guess for directory on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
9d852bc6f3 gio: implement simple directory type detection
Use a logic similar to what is done for Unix, based on trailing path
separator.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:30 +04:00
Marc-André Lureau
b3379557af gio: return '*' content type on win32 from unknown mime
This fixes test_unknown.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-09 11:41:20 +04:00
Philip Withnall
0239ae7122 tests: Fix a leak in gdbus-test-codegen test
The `ay` property has type `string` (see the generated code) since it’s
not been annotated to force accepting a `GVariant`.

This means the GObject property machinery expects a string, and calls
`g_strdup()` on the passed-in pointer, rather than sinking the
`GVariant`.

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

Helps: #2312
2022-03-08 20:08:43 +00:00
Emmanuele Bassi
618d6873fd Merge branch 'wip/pwithnall/ci-fixes' into 'main'
Various unit test fixes

See merge request GNOME/glib!2538
2022-03-07 09:24:10 +00:00
Philip Withnall
4d237daf32 tests: Add more debug output to gdbus-threading test
It periodically hangs due to the `GDBusConnection` having more than 1
ref (and never losing them), so there’s potentially a leaking ref
somewhere:
```
(/builds/alexander.klauer/glib/_build/gio/tests/gdbus-threading:17767): GLib-GIO-DEBUG: 13:18:12.268: refcount of 0x55fe85b1a260 is not right, sleeping
\# GLib-GIO-DEBUG: refcount of 0x55fe85b1a260 is not right, sleeping
```

Add some more debug output to try and track the problem down.

See: https://gitlab.gnome.org/alexander.klauer/glib/-/jobs/1865968

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-04 19:53:04 +00:00
Philip Withnall
54ee8e5414 tests: Add more debug output to converter-stream test
It’s periodically failing on FreeBSD and I can’t reproduce the failure
locally nor work out what it is from the logs:
```
Bail out! GLib-GIO:ERROR:../gio/tests/converter-stream.c:1041:test_converter_pollable: assertion failed (res != -1): (-1 != -1)
stderr:
**
GLib-GIO:ERROR:../gio/tests/converter-stream.c:1041:test_converter_pollable: assertion failed (res != -1): (-1 != -1)
```

Add some more debug output to get the value of `error`, in the hope that
will provide some insight.

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

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-04 19:51:17 +00:00
Emmanuele Bassi
0c4c8d1005 Merge branch '2611-revert-option-changes' into 'main'
Revert "gapplication: Expose zero-valued numbers in handle-local-options"

Closes #2611

See merge request GNOME/glib!2536
2022-03-04 19:21:21 +00:00
Philip Withnall
141d3f68d3 tests: Mark network-address test as expected to succeed on macOS
Commit 13c4b9579b seems to have fixed
`network-address` so that it’s reliable everywhere, including on macOS.

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

Helps: #1392
2022-03-04 19:07:02 +00:00
Philip Withnall
23e935a342 Revert "gapplication: Expose zero-valued numbers in handle-local-options"
This reverts commit 1ed67a9c44.

It turns out that including options, with their default values, in the
`handle-local-options` signal, which weren’t set on the command line,
breaks some applications.

In particular, it breaks Inkscape, which is the application this commit
was originally meant to fix (a different problem).

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

Fixes: #2611
Breaks: #2329
See: !1953
2022-03-04 18:16:12 +00:00
Philip Withnall
3bef2760e9 Merge branch 'docs' into 'main'
docs: mark macros, flags, enums with percent sign

Closes #2589

See merge request GNOME/glib!2470
2022-03-04 16:21:55 +00:00
Gabor Karsay
7e64004db0 docs: mark macros, flags, enums with percent sign 2022-03-04 16:21:55 +00:00
Philip Withnall
f08324e014 Merge branch 'w32-tests-spawn' into 'main'
Various spawn-related test fixes on win32

See merge request GNOME/glib!2485
2022-03-04 16:16:39 +00:00
Philip Withnall
674dc5171c gpowerprofilemonitor: Tweak wording of documentation to make more sense
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-04 12:18:34 +00:00
Sebastian Dröge
420238e0c4 Merge branch 'debug-controller-unused' into 'main'
gdebugcontrollerdbus: Mark a variable as G_GNUC_UNUSED

See merge request GNOME/glib!2519
2022-03-03 14:54:28 +00:00
Sebastian Dröge
8091727b27 Merge branch 'wip/pwithnall/macos-tests' into 'main'
tests: Stop ignoring test failures on macOS

See merge request GNOME/glib!2505
2022-03-03 14:53:38 +00:00
Philip Withnall
c1293acb27 gtask: Document that task name is set by g_task_set_source_tag()
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-03 12:42:28 +00:00
Xavier Claessens
218ac195df meson: Add schemasdir and giomoduledir to gio dependency
This allows applications to get their value regardless whether glib is a
subproject or pkgconfig:

  gio_dep = dependency('gio-2.0')
  giomoduledir = gio_dep.get_variable('giomoduledir')
  schemasdir = gio_dep.get_variable('schemasdir')
2022-02-23 08:24:00 -05:00
Philip Withnall
dbd11f3d3b Merge branch 'wip/pwithnall/revert-2517' into 'main'
Revert "meson: Add schemasdir and giomoduledir to gio dependency"

See merge request GNOME/glib!2524
2022-02-23 12:17:29 +00:00
Philip Withnall
7f8c09cd07 Merge branch 'wip/pwithnall/network-address-test-fixes' into 'main'
tests: Remove threads from mock-resolver/network-address test

See merge request GNOME/glib!2520
2022-02-23 12:03:28 +00:00
Philip Withnall
590a2c9af8 Revert "meson: Add schemasdir and giomoduledir to gio dependency"
This reverts commit 5aa03882ca.

It fails to compile on newer Meson versions with
`--fatal-meson-warnings` due to:
```
WARNING: Project targeting '>= 0.52.0' but tried to use feature introduced in '0.54.0': variables arg in declare_dependency.
gio/meson.build:833:0: ERROR: Fatal warnings enabled, aborting
```

That happens regardless of the fact that we’ve correctly limited the use
of the `variables` argument to only when building with Meson ≥ 0.56.
Unfortunately Meson can’t statically detect that the argument is
conditional.

Bumping GLib’s Meson dependency is too much work right now, so this MR
unfortunately has to be reverted.
2022-02-23 11:51:13 +00:00
Marc-André Lureau
0f85eefb8b gio: fix OOB string access if filename is empty
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-02-22 23:55:57 +04:00
Philip Withnall
68dc5d5fbc Merge branch 'meson-gio-var' into 'main'
meson: Add schemasdir and giomoduledir to gio dependency

See merge request GNOME/glib!2517
2022-02-22 18:22:52 +00:00
Xavier Claessens
5aa03882ca meson: Add schemasdir and giomoduledir to gio dependency
This allows applications to get their value regardless whether glib is a
subproject or pkgconfig:

  gio_dep = dependency('gio-2.0')
  giomoduledir = gio_dep.get_variable('giomoduledir')
  schemasdir = gio_dep.get_variable('schemasdir')
2022-02-22 08:54:07 -05:00
Philip Withnall
00faa84f77 Merge branch 'giomodule' into 'main'
meson: Set GIO_EXTRA_MODULES in devenv

See merge request GNOME/glib!2518
2022-02-22 13:38:58 +00:00
Philip Withnall
13c4b9579b tests: Remove threads from mock-resolver/network-address test
`mock-resolver.c` is a mock implementation of `GResolver` used in the
`network-address` tests. It returns resolver results, and implements
timeouts, as directed by the test calling it.

In particular, it allows the IPv4 and IPv6 resolver results to be
returned using independent delays. This allows code paths which deal
with IPv4 and IPv6 results being returned at different times to be
tested, as the ‘Happy Eyeballs’ spec mandates various hard-coded
timeouts for returning the best results it can in a reasonable
timeframe.

Previously, `mock-resolver.c` implemented the timeouts by handling
`lookup_by_name()` in a `GTask` worker thread, and calling `g_usleep()`
for the timeout. This seemed to cause occasional CI failures, such as
https://gitlab.gnome.org/GNOME/glib/-/jobs/1843454, where a resolver
error would be returned rather than the expected results:
```
ok 52 /network-address/happy-eyeballs/ipv4-error-ipv6-first
\# GLib-GIO-DEBUG: IPv4 DNS error: IPv4 Broken
(/var/tmp/gitlab_runner/builds/Ff4WDDRj/0/GNOME/glib/_build/gio/tests/network-address:18428): GLib-GIO-DEBUG: 09:03:08.587: IPv4 DNS error: IPv4 Broken
Bail out! GLib-GIO:ERROR:../gio/tests/network-address.c:586:got_addr: assertion failed (error == NULL): IPv4 Broken (g-io-error-quark, 24)
stderr:
**
GLib-GIO:ERROR:../gio/tests/network-address.c:586:got_addr: assertion failed (error == NULL): IPv4 Broken (g-io-error-quark, 24)
```

While I’ve been unable to reproduce these failures locally, I suspect
they might be down to thread spawning occasionally taking long enough on
a CI runner to change the ordering of the timeouts, such that the ‘Happy
Eyeballs’ algorithm returns a different set of results from what the
test expects.

So, this commit rewrites part of `mock-resolver.c` to implement timeouts
in the main thread, rather than in a worker thread. That should
eliminate the delays in spawning threads, and should mean that the
timeout sources in `mock-resolver.c` are attached to the same
`GMainContext` as those from the ‘Happy Eyeballs’ algorithm which are
monitoring them, so a total order over the timeouts can be guaranteed.

Of course, I might be completely wrong since this is just a guess and I
can’t properly test it since I can’t reproduce the failure. Worth a try.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-22 11:25:21 +00:00
Philip Withnall
bb2d79e6a8 tests: Use g_assert_*() rather than g_assert() in network-address.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-22 11:25:21 +00:00
Philip Withnall
a57706887e tests: Fix memory leaks in network-address test
The test results weren’t being freed.

This makes the `network-address` test clean under memcheck for me.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-22 11:25:21 +00:00
Philip Withnall
cd9ed612a7 gdebugcontrollerdbus: Mark a variable as G_GNUC_UNUSED
It’s not used when compiling with `G_DISABLE_ASSERT`. This fixes the CI
build failure here: https://gitlab.gnome.org/GNOME/glib/-/jobs/1843082
```
[461/1229] Compiling C object 'gio/6ae6c9e@@gio-2.0@sha/gdebugcontrollerdbus.c.o'.
FAILED: gio/6ae6c9e@@gio-2.0@sha/gdebugcontrollerdbus.c.o
cc -Igio/6ae6c9e@@gio-2.0@sha -Igio -I../gio -I. -I../ -Iglib -I../glib -Igobject -I../gobject -Igmodule -I../gmodule -I/usr/include/libmount -I/usr/include/blkid -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -Werror -std=gnu99 -g -D_GNU_SOURCE -fno-strict-aliasing -DG_ENABLE_DEBUG -DG_DISABLE_ASSERT -Wduplicated-branches -Wimplicit-fallthrough -Wmisleading-indentation -Wunused -Wno-unused-parameter -Wno-cast-function-type -Wno-pedantic -Wno-format-zero-length -Wno-variadic-macros -Werror=format=2 -Werror=init-self -Werror=missing-include-dirs -Werror=pointer-arith -Wstrict-prototypes -Wno-bad-function-cast -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes -fPIC '-DG_LOG_DOMAIN="GLib-GIO"' -DGIO_COMPILATION '-DGIO_MODULE_DIR="/usr/local/lib64/gio/modules"' '-DLOCALSTATEDIR="/usr/local/var"' -fvisibility=hidden -MD -MQ 'gio/6ae6c9e@@gio-2.0@sha/gdebugcontrollerdbus.c.o' -MF 'gio/6ae6c9e@@gio-2.0@sha/gdebugcontrollerdbus.c.o.d' -o 'gio/6ae6c9e@@gio-2.0@sha/gdebugcontrollerdbus.c.o' -c ../gio/gdebugcontrollerdbus.c
../gio/gdebugcontrollerdbus.c: In function ‘authorize_cb’:
../gio/gdebugcontrollerdbus.c:345:32: error: unused variable ‘priv’ [-Werror=unused-variable]
  345 |   GDebugControllerDBusPrivate *priv = g_debug_controller_dbus_get_instance_private (self);
      |                                ^~~~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-22 09:35:40 +00:00
Xavier Claessens
0071abc187 meson: Set GIO_EXTRA_MODULES in devenv
This makes GIO find the fam module within "meson devenv" without having
to install it on the system.
2022-02-21 13:22:54 -05:00
Simon McVittie
6517bbfbc3 glocalfileinfo: Always define _g_stat_mtim_nsec, etc.
If these struct members aren't available, we can be more like an
abstraction layer by falling back to yielding 0.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-21 16:58:08 +00:00
Simon McVittie
3c12ddce81 Merge branch '1929-dbus-auth-locking' into 'main'
gdbusauthmechanismsha1: Don’t delete a stale lock file if it’s changed

Closes #1929

See merge request GNOME/glib!2511
2022-02-21 13:48:54 +00:00
Philip Withnall
36112f9b83 tests: Stop ignoring test failures on macOS
Test failures were previously ignored on macOS because there are 12
tests which consistently fail (and have not yet been fixed, because
there are no regularly active macOS maintainers for GLib; you could help
here!).

However, this means that new test failures can’t be spotted.

So, explicitly mark those 12 tests as `should_fail` on macOS, and then
make other test failures cause failure of the CI run.

We can track the process of fixing those 12 tests on #1392 and #1251.

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

Helps: #1392
2022-02-20 15:01:59 +00:00
Philip Withnall
5180c7de1e tests: Make debugcontroller and defaultvalue depend on dbus-daemon
As they use `g_test_dbus_*()`, they depend on dbus-daemon, so move them
to the part of the Meson file which lists those tests.

This disables them running on platforms which don’t have `dbus-daemon`
available. Arguably, this should be done by returning an error from
`g_test_dbus_up()` and then calling `g_test_skip()`, so the test is
correctly recorded as having been skipped. But that’s a fix for another
time.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 15:01:38 +00:00
Philip Withnall
ae903744ee Merge branch 'environment-test-fixes' into 'main'
tests: Fix various small memory leaks

See merge request GNOME/glib!2509
2022-02-20 12:09:00 +00:00
Philip Withnall
c60a0a45de tests: Fix a memory leak in the tls-certificate test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
a4ce8399cd tests: Fix memory leaks in the g-file-info-filesystem-readonly test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
d007fdb079 tests: Fix a memory leak in the resources test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
9434e4a40c tests: Use g_assert_*() rather than g_assert() in resources.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
cb18e6b969 Merge branch 'empty-argv' into 'main'
Various minor fixes for empty argv handling

See merge request GNOME/glib!2466
2022-02-20 09:36:41 +00:00
Philip Withnall
01a432d6ff glocalfileinfo: Add missing _g_stat_*() methods for win32
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 13:50:19 +00:00
Philip Withnall
648f9efce0 tests: Remove extra debugging from gdbus-connection-flush
Having compared the debug output, it doesn’t show anything unusual
happening that can’t already be seen from other output, for this test.

This is a partial revert of 8fd71dccc5. The debugging output it added to
other tests may still be useful.

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

Helps: #1929
2022-02-18 13:24:13 +00:00
Philip Withnall
693e4efeba tests: Use g_assert_*() rather than g_assert() in gdbus-connection-flush.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 13:22:16 +00:00
Philip Withnall
dc0eb5e49a gdbusauthmechanismsha1: Don’t delete a stale lock file if it’s changed
The retry loop for acquiring the lock for the authentication cookie file
currently tries to acquire the lock for 0.5s, then gives up, assumes the
lock file is stale, and deletes it.

That’s great if the lock file *is* stale because it’s been left there by
a crashed process.

It’s not so great if the lock file just happens to have been there every
time this process checked, because the cookie file is highly contested
while (for example) running lots of parallel unit tests.

Check for that situation by comparing the mtime of the lock file and
continuing to retry if it’s changed.

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

Fixes: #1929
2022-02-18 13:17:19 +00:00
Philip Withnall
10e5c21102 Merge branch 'desktop-app-info-leak' into 'main'
gdesktopappinfo: Fix a leak when launching URIs over D-Bus

See merge request GNOME/glib!2510
2022-02-18 12:06:13 +00:00
Philip Withnall
3583526c2d Merge branch 'disable-assert-fix' into 'main'
gresource-tool: Fix unused-but-set-variable warn with G_DISABLE_ASSERT

See merge request GNOME/glib!2506
2022-02-18 10:38:44 +00:00
Philip Withnall
5046dd8679 Merge branch 'fix-style-check' into 'main'
codegen: Reformat parser.py according to black

See merge request GNOME/glib!2508
2022-02-18 10:38:05 +00:00
Philip Withnall
f6aafcd028 gdesktopappinfo: Fix a leak when launching URIs over D-Bus
If any platform data is set, the temporary `GVariantDict` was being
leaked.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 10:35:10 +00:00
Philip Withnall
d551e81812 Merge branch 'fix-compile-resources-leak' into 'main'
glib-compile-resources: Fix a memory leak of the compiler option

See merge request GNOME/glib!2501
2022-02-18 10:34:25 +00:00