Commit Graph

1883 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
63873c0eb1 application: Unset the registered state after shutting down
An application that has been shut down is still marked as registered
even if its implementation has been already destroyed.

This may lead to unguarded crashes when calling functions that have
assumptions for being used with registered applications.

So, when an application is registered, mark it as unregistered just
before destroying its implementation and after being shut down, so that
we follow the registration process in reversed order.

Added tests
2021-04-27 17:11:10 +02:00
Emmanuel Fleury
59acf6950c Fix missing initializer warning in gio/tests/gdbus-example-server.c
gio/tests/gdbus-example-server.c:280:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  280 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
f587095cfc Fix signedness warning in gio/tests/socket-common.c
gio/tests/socket-common.c: In function ‘socket_address_from_string’:
gio/tests/socket-common.c:50:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
   50 |   for (i = 0; i < G_N_ELEMENTS (unix_socket_address_types); i++)
      |                 ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
bac08a4b26 Fix several missing initializer warnings in gio/tests/gdbus-example-subtree.c
gio/tests/gdbus-example-subtree.c:76:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
   76 | };
      | ^
gio/tests/gdbus-example-subtree.c:190:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  190 | };
      | ^
gio/tests/gdbus-example-subtree.c:228:1: error: missing initializer for field ‘get_property’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  228 | };
      | ^
gio/tests/gdbus-example-subtree.c:325:1: error: missing initializer for field ‘padding’ of ‘GDBusSubtreeVTable’ {aka ‘const struct _GDBusSubtreeVTable’}
  325 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
cb0b4b00df Fix missing initializer warning in gio/tests/gnotification-server.c
gio/tests/gnotification-server.c: In function ‘g_notification_server_bus_acquired’:
gio/tests/gnotification-server.c:224:3: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  224 |   };
      |   ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
d255962abb Fix missing initializer warning in gio/tests/gdbus-non-socket.c
gio/tests/gdbus-non-socket.c:116:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  116 | };
      | ^
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
2187406f70 Fix signedness warning in gio/tests/gdbus-proxy.c
gio/tests/gdbus-proxy.c: In function ‘strv_equal’:
gio/tests/gdbus-proxy.c:158:32: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  158 |     res = g_strv_length (strv) == count;
      |                                ^~
2021-04-23 10:43:05 +02:00
Emmanuel Fleury
fd926b1ea7 Fix missing initializer in gio/tests/gdbus-example-peer.c
gio/tests/gdbus-example-peer.c:120:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  120 | };
      | ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
1c084ca717 Fix missing initializer warning in gio/tests/gdbus-example-export.c
gio/tests/gdbus-example-export.c:229:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  229 | };
      | ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
4d52358fe2 Fix signedness warning in gio/tests/gsettings.c
gio/tests/gsettings.c: In function ‘strv_set_equal’:
gio/tests/gsettings.c:2268:41: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
 2268 |     res = g_strv_length ((gchar**)strv) == count;
      |                                         ^~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
83a9ba7790 Fix missing initializer warning in gio/tests/gdbus-testserver.c
gio/tests/gdbus-testserver.c:806:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  806 | };
      | ^
In file included from gio/gio.h:53,
                 from gio/tests/gdbus-testserver.c:1:
gdbusconnection.h:395:12: note: ‘padding’ declared here
  395 |   gpointer padding[8];
      |            ^~~~~~~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
5133acdaff Fix multiple signedness warnings in gio/tests/gdbus-testserver.c
gio/tests/gdbus-testserver.c: In function ‘handle_method_call’:
gio/tests/gdbus-testserver.c:334:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  334 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:343:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  343 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:352:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  352 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:361:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  361 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:370:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  370 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:379:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  379 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:388:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  388 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:397:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  397 |         for (i = 0; i < n_elts; i++)
      |                       ^
gio/tests/gdbus-testserver.c:406:23: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  406 |         for (i = 0; i < n_elts; i++)
      |                       ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
c3c1f6c4b9 Fix signedness warning in gio/tests/mimeapps.c
gio/tests/mimeapps.c: In function ‘strv_equal’:
gio/tests/mimeapps.c:31:32: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
   31 |     res = g_strv_length (strv) == count;
      |                                ^~
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
e7aec308e9 Fix signedness warning in gio/tests/proxy-test.c
gio/tests/proxy-test.c: In function ‘do_echo_test’:
gio/tests/proxy-test.c:855:25: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
  855 |   for (total = 0; total < nwrote; total += nread)
      |                         ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
8608eccf9a Fix signedness warning in gio/tests/file.c
gio/tests/file.c: In function ‘written_cb’:
gio/tests/file.c:358:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
  358 |   if (data->pos < strlen (data->data))
      |                 ^
2021-04-15 10:19:29 +02:00
Emmanuel Fleury
4d1f76ec50 Fix signedness warning in gio/tests/gdbus-test-codegen.c
gio/tests/gdbus-test-codegen.c: In function ‘check_object_manager’:
gio/tests/gdbus-test-codegen.c:2344:20: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
 2344 |   if (om_signal_id != -1)
      |                    ^~
2021-04-15 00:00:22 +02:00
Emmanuel Fleury
34cd8a98c7 Fix signedness warning in gio/tests/testfilemonitor.c
gio/tests/testfilemonitor.c: In function ‘check_expected_events’:
gio/tests/testfilemonitor.c:124:39: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘gsize’ {aka ‘long unsigned int’}
  124 |   for (i = 0, li = 0, l = recorded; i < n_expected && l != NULL;)
      |                                       ^
2021-04-14 23:43:36 +02:00
Emmanuel Fleury
0a741d85a7 Fix signedness warning in gio/tests/socket.c
gio/tests/socket.c: In function ‘test_get_available’:
gio/tests/socket.c:1696:53: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘long unsigned int’
 1696 |           if (g_socket_get_available_bytes (server) > sizeof (data))
      |                                                     ^
2021-04-14 23:43:25 +02:00
Emmanuel Fleury
5595b65476 Fix multiple missing initializer warnings in gio/tests/gdbus-export.c
gio/tests/gdbus-export.c:130:1: error: missing initializer for field ‘properties’ of ‘GDBusInterfaceInfo’ {aka ‘const struct _GDBusInterfaceInfo’}
  130 | };
      | ^
In file included from gio/gio.h:57,
                 from gio/tests/gdbus-export.c:21:
gio/gdbusintrospection.h:156:25: note: ‘properties’ declared here
  156 |   GDBusPropertyInfo   **properties;
      |                         ^~~~~~~~~~
...
2021-04-14 23:26:15 +02:00
Emmanuel Fleury
60d2cfb6ae Fix missing initializer warning in gio/tests/gdbus-connection.c
gio/tests/gdbus-connection.c:90:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
   90 | };
      | ^
2021-04-14 23:26:15 +02:00
Emmanuel Fleury
00323ac0e1 Fix several signedness warnings in gio/tests/actions.c
gio/tests/actions.c: In function ‘strv_set_equal’:
gio/tests/actions.c:177:41: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  177 |     res = g_strv_length ((gchar**)strv) == count;
      |                                         ^~
gio/tests/actions.c: In function ‘test_parse_detailed’:
gio/tests/actions.c:473:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  473 |   for (i = 0; i < G_N_ELEMENTS (testcases); i++)
      |                 ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
c3d558df77 Fix multiple missing initializer warnings in gio/tests/actions.c
gio/tests/actions.c: In function ‘test_entries’:
gio/tests/actions.c:375:5: error: missing initializer for field ‘parameter_type’ of ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
  375 |     { "foo",    activate_foo                                     },
      |     ^
In file included from gio/gio.h:31,
                 from gio/tests/actions.c:1:
gio/gactionmap.h:63:16: note: ‘parameter_type’ declared here
   63 |   const gchar *parameter_type;
      |                ^~~~~~~~~~~~~~
...
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
0710429598 Fix missing initializer warning in gio/tests/gdbus-peer-object-manager.c
gio/tests/gdbus-peer-object-manager.c: In function ‘mock_interface_get_vtable’:
gio/tests/gdbus-peer-object-manager.c:111:3: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘struct _GDBusInterfaceVTable’}
  111 |   };
      |   ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
e3f6d4a08b Fix several missing initializer warnings in gio/tests/gdbus-peer.c
gio/tests/gdbus-peer.c:262:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
  262 | };
      | ^
gio/tests/gdbus-peer.c:1263:1: error: missing initializer for field ‘padding’ of ‘GDBusInterfaceVTable’ {aka ‘const struct _GDBusInterfaceVTable’}
 1263 | };
      | ^
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
7c909db13a Fix multiple missing initializer warning in gio/tests/g-file.c
gio/tests/g-file.c: In function ‘test_g_file_new_for_path’:
gio/tests/g-file.c:114:7: error: missing initializer for field ‘path3’ of ‘const struct TestPathsWithOper’
  114 |       {"/", TRUE, 0, "/./"},
      |       ^
gio/tests/g-file.c:115:7: error: missing initializer for field ‘path3’ of ‘const struct TestPathsWithOper’
  115 |       {"//", TRUE, 0, "//"},
      |       ^
...
2021-04-08 13:24:54 +02:00
Emmanuel Fleury
d936ff10e6 Fix several signedness warnings in gio/tests/network-address.c
gio/tests/network-address.c: In function ‘main’:
gio/tests/network-address.c:1194:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1194 |   for (i = 0; i < G_N_ELEMENTS (host_tests); i++)
      |                 ^
gio/tests/network-address.c:1201:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1201 |   for (i = 0; i < G_N_ELEMENTS (uri_tests); i++)
      |                 ^
gio/tests/network-address.c:1208:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1208 |   for (i = 0; i < G_N_ELEMENTS (address_tests); i++)
      |                 ^
gio/tests/network-address.c:1215:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1215 |   for (i = 0; i < G_N_ELEMENTS (address_tests); i++)
      |                 ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
c216f2299d Fix several missing initializer warnings in gio/tests/gsubprocess.c
gio/tests/gsubprocess.c: In function ‘test_communicate_async’:
gio/tests/gsubprocess.c:774:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
  774 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_async’:
gio/tests/gsubprocess.c:1025:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1025 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_cancelled_async’:
gio/tests/gsubprocess.c:1058:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1058 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
gio/tests/gsubprocess.c: In function ‘test_communicate_utf8_async_invalid’:
gio/tests/gsubprocess.c:1202:3: error: missing initializer for field ‘running’ of ‘TestAsyncCommunicateData’
 1202 |   TestAsyncCommunicateData data = { flags, 0, };
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
b07fdb6e4a Fix signedness warning in gio/tests/converter-stream.c:g_expander_converter_convert()
gio/tests/converter-stream.c: In function ‘g_expander_converter_convert’:
gio/tests/converter-stream.c:128:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  128 |       for (i = 0; i < block_size; i++)
      |                     ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
56e25d81f6 Fix several signedness warnings in gio/tests/converter-stream.c:g_compressor_converter_convert()
gio/tests/converter-stream.c: In function ‘g_compressor_converter_convert’:
gio/tests/converter-stream.c:234:23: error: comparison of integer expressions of different signedness: ‘long int’ and ‘gsize’ {aka ‘long unsigned int’}
  234 |       if (in_end - in < block_size)
      |                       ^
gio/tests/converter-stream.c:244:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  244 |       for (i = 0; i < block_size; i++)
      |                     ^
gio/tests/converter-stream.c:257:33: error: comparison of integer expressions of different signedness: ‘long int’ and ‘gsize’ {aka ‘long unsigned int’}
  257 |       if (v == 0 && in_end - in == block_size && (flags & G_CONVERTER_INPUT_AT_END) == 0)
      |                                 ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
cc1e7302f3 Fix signedness warning in gio/tests/converter-stream.c:test_expander()
gio/tests/converter-stream.c: In function ‘test_expander’:
gio/tests/converter-stream.c:356:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  356 |   for (i = 0; i < sizeof(unexpanded_data); i++)
      |                 ^
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
d2c0fd468c Fix several signedness warnings in gio/tests/converter-stream.c:test_compressor()
gio/tests/converter-stream.c: In function ‘test_compressor’:
gio/tests/converter-stream.c:445:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  445 |   for (i = 0; i < expanded_size; i++)
      |                 ^
gio/tests/converter-stream.c:454:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
  454 |    g_assert (i == expanded_size -1);
      |                ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
29cd18b044 Fix several signedness warnings in gio/tests/converter-stream.c:test_converter_pollable()
gio/tests/converter-stream.c: In function ‘test_converter_pollable’:
gio/tests/converter-stream.c:1077:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
 1077 |   for (i = 0; i < expanded_size; i++)
      |                 ^
gio/tests/converter-stream.c:1086:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘gsize’ {aka ‘long unsigned int’}
 1086 |    g_assert (i == expanded_size -1);
      |                ^~
2021-04-07 10:33:16 +02:00
Emmanuel Fleury
eafc764bb2 Fix several signedness warnings in gio/tests/converter-stream.c:main()
gio/tests/converter-stream.c: In function ‘main’:
gio/tests/converter-stream.c:1220:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1220 |   for (i = 0; i < G_N_ELEMENTS (compressor_tests); i++)
      |                 ^
gio/tests/converter-stream.c:1223:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1223 |   for (i = 0; i < G_N_ELEMENTS (truncation_tests); i++)
      |                 ^
gio/tests/converter-stream.c:1226:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1226 |   for (i = 0; i < G_N_ELEMENTS (charset_tests); i++)
      |                 ^
2021-04-05 12:03:51 +02:00
Emmanuel Fleury
88253f171c Fix signedness warning in gio/tests/contenttype.c
gio/tests/contenttype.c: In function ‘test_tree’:
gio/tests/contenttype.c:337:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  337 |   for (i = 0; i < G_N_ELEMENTS (tests); i++)
      |                 ^
2021-04-05 12:03:51 +02:00
Emmanuel Fleury
8bcb2b9e76 Fix several signedness warnings in gio/tests/contexts.c
gio/tests/contexts.c: In function ‘test_context_specific_emit’:
gio/tests/contexts.c:379:21: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint32’ {aka ‘int’}
  379 |       for (i = 0; i < g_test_rand_int_range (1, 5); i++)
      |                     ^
gio/tests/contexts.c:383:55: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
  383 |         while (g_atomic_int_get (&observed_values[i]) != n)
      |                                                       ^~
gio/tests/contexts.c:387:41: error: comparison of integer expressions of different signedness: ‘gint64’ {aka ‘long int’} and ‘guint64’ {aka ‘long unsigned int’}
  387 |             if (g_get_monotonic_time () > expiry)
      |                                         ^
2021-04-05 12:03:51 +02:00
Abanoub Ghadban
1bdfc1a36b gfileinfo: Add tests for get and set {access,creation}_date_time APIs 2021-03-28 23:07:39 +02:00
Frederic Martinsons
7f2fef5c26 tests: Deactivate tls-bindings test suite for windows
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>

Helps: #2297
2021-03-23 11:11:45 +00:00
Frederic Martinsons
59e999fd0a Add two test cases which covers disconnection scenario in another thread
1) Check that schedule_call_in_idle code branch of gdbusnamewatching.c
   is working to call vanished handler in the thread which had watched the name
2) Check cancellation of vanished handler if the name is unwatched before
   vanished callback is dispatched.

Closes #2011

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Frederic Martinsons
2f5f69e969 Use OwnNameData structure when owning a name instead of WatchNameData.
The two structures share some common variable name but it's confusing.

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Frederic Martinsons
98abfc9da7 Correct memleak introduced by !1885
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-17 08:36:47 +01:00
Sebastian Dröge
db0ec9528e Merge branch '2328-file-new-empty-path' into 'master'
glocalvfs: Create a dummy file for g_file_new_for_path("")

Closes #2328

See merge request GNOME/glib!1983
2021-03-11 09:42:19 +00:00
Philip Withnall
519bdf665b Merge branch 'work-out-libutil-soname-at-build-time' into 'master'
gio/tests/{meson.build,pollable.c}: Determine libutil SONAME at build time

See merge request GNOME/glib!1977
2021-03-10 19:35:18 +00:00
Philip Withnall
d52728f994 glocalvfs: Create a dummy file for g_file_new_for_path("")
`""` is not a valid path (`stat()` on it returns `ENOENT`). Previously,
a full `GLocalFile` was being created, which ended up resolving to
`$CWD`, through path canonicalisation. That isn’t right.

Fix it by creating a `GDummyFile` instead, and adding a unit test.

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

Fixes: #2328
2021-03-10 19:10:38 +00:00
Iain Lane
373e46c2b2
gio/tests/{meson.build,pollable.c}: Determine libutil SONAME at build time
Calling `dlopen()` with `libutil.so` makes the installed tests depend on
having glibc's development files installed. To avoid this, we can work
out the runtime library name at build time and `dlopen` that instead.

This approach is [taken from libfprint][1], thanks to Marco Trevisan.

[1]: f401f399a8
2021-03-10 18:04:17 +00:00
Philip Withnall
57a53ec964 gioerror: Add conversion from ENXIO to G_IO_ERROR_NOT_REGULAR_FILE
`ENXIO` can be returned from `open(2)` for special files (FIFOs, device
files and domain sockets) which are not backed by anything.

This fixes the error returned by `g_file_replace()` when trying to
replace such a file, so that it now matches the documentation.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 17:55:51 +00:00
Philip Withnall
730015a8ed tests: Add comprehensive tests for static behaviour of g_file_replace()
These test all the functionality and combinations of flags I can think
of. They do not cover dynamic behaviour (for example, what would happen
if the source file is deleted by another process part-way through a call
to `g_file_replace()`).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 17:55:51 +00:00
Philip Withnall
87e19535fe glocalfileoutputstream: Fix CREATE_REPLACE_DESTINATION with symlinks
The `G_FILE_CREATE_REPLACE_DESTINATION` flag is equivalent to unlinking
the destination file and re-creating it from scratch. That did
previously work, but in the process the code would call `open(O_CREAT)`
on the file. If the file was a dangling symlink, this would create the
destination file (empty). That’s not an intended side-effect, and has
security implications if the symlink is controlled by a lower-privileged
process.

Fix that by not opening the destination file if it’s a symlink, and
adjusting the rest of the code to cope with
 - the fact that `fd == -1` is not an error iff `is_symlink` is true,
 - and that `original_stat` will contain the `lstat()` results for the
   symlink now, rather than the `stat()` results for its target (again,
   iff `is_symlink` is true).

This means that the target of the dangling symlink is no longer created,
which was the bug. The symlink itself continues to be replaced (as
before) with the new file — this is the intended behaviour of
`g_file_replace()`.

The behaviour for non-symlink cases, or cases where the symlink was not
dangling, should be unchanged.

Includes a unit test.

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

Fixes: #2325
2021-03-10 17:55:51 +00:00
Philip Withnall
5f2eae1156 tests: Stop using g_test_bug_base() in file tests
Since a following commit is going to add a new test which references
Gitlab, so it’s best to move the URI bases inside the test cases.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-10 16:02:35 +00:00
Chun-wei Fan
cf02c280ff gio/tests/pollable.c: Fix build on non-Linux UNIX
For non-Linux UNIX systems, the label 'close_libutil:' in
'test_pollable_unix_pty()' will have no statement that goes with that
label.  Just do a 'return' on non-Linux UNIX systems.
2021-02-27 10:53:53 +08:00
Simon McVittie
f443144091 Merge branch 'pollable-test-dlopen-leak' into 'master'
tests: Fix leak of dlopened module in pollable test

See merge request GNOME/glib!1936
2021-02-25 18:26:57 +00:00
Philip Withnall
50cf90dc56 tests: Test g_subprocess_launcher_close() doesn’t close too many FDs
Expand an existing unit test to check that the target FD of a
`g_subprocess_launcher_take_fd()` call doesn’t get closed when
`g_subprocess_launcher_close()` is called. Only the source FD should be
closed by the parent process.

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

Helps: #2332
2021-02-19 18:27:00 +00:00
Simon McVittie
ee53840fa6 tests: Use a more realistic language code than sv_SV
Swedish as spoken in El Salvador is not listed in
/usr/share/i18n/SUPPORTED, and in any case is probably not what we meant.
A more plausible language code would be Swedish as spoken in Sweden.

Prompted by improving the Debian packaging of GLib to generate most of
the language codes mentioned in the tests, so that we can have better
test coverage.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 14:43:12 +00:00
Philip Withnall
2f91caf77e tests: Add a basic test for require-same-user D-Bus auth flag
It’s not feasible to test that the require-same-user flag can cause
authentication to fail, as that would require the build environment to
have two users available. We can, however, test that it passes when
authenticating a client and server running under the same user account.

I have manually tested that the new flag works, by running the following
as user A:
```
`$prefix/gdbus-daemon --print-env &`
gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames
```

And then running the `gdbus call` command again as user B (with the same
value for `DBUS_SESSION_BUS_ADDRESS` in the environment), which
produces:
```
Error connecting: Unexpected lack of content trying to read a line
```
(an authentication rejection)

Commenting out the use of
`G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` from
`gdbusdaemon.c`, the `gdbus call` command succeeds for both users.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-11 16:12:40 +00:00
Philip Withnall
a1db705bc2 Merge branch 'wip/gdbus-flags-from-the-future' into 'master'
gdbus: Reject attempts to set future connection or server flags

See merge request GNOME/glib!1934
2021-02-11 11:53:13 +00:00
Philip Withnall
68ce7a28e1 tests: Add tests for key name handling in the keyfile backend
This tests the two recent commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-10 22:10:00 +00:00
Philip Withnall
57a5ed3d08 tests: Fix leak of dlopened module in pollable test
Coverity CID: #1446243

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-09 11:06:53 +00:00
Simon McVittie
ba25c8a770 gdbus: Reject attempts to set future connection or server flags
The GDBusConnectionFlags and GDBusServerFlags can affect how we carry
out authentication and authorization, either making it more or less
restrictive, so it's desirable to "fail closed" if a program is compiled
against a new version of GLib but run against an old version.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 13:35:16 +00:00
Simon McVittie
df4501316c tls-interaction: Add test coverage for various ways to set the password
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:22:48 +00:00
Philip Withnall
73b293fd30 gio: Use g_memdup2() instead of g_memdup() in obvious places
Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 14:13:21 +00:00
Sebastian Dröge
e6f506a92c Merge branch 'fix/unix-stream-pollable-detection' into 'master'
gunix: Fix {Input,Output}Stream pollable detection

Closes #1180

See merge request GNOME/glib!1846
2021-02-02 10:46:52 +00:00
Ole André Vadla Ravnås
d7ee70c013 gunix: Fix {Input,Output}Stream pollable detection
For devices such as PTYs, where not being able to cancel a pending read
operation is problematic for many applications.

Fixes: #1180
2021-02-02 11:11:53 +01:00
Simon McVittie
f378352051 tests: Mark tests with AddressSanitizer-detected leaks
Various tests have leaks where it isn't clear whether the data is
intentionally not freed, or leaked due to a bug. If we mark these
tests as TODO, we can skip them under AddressSanitizer and get the
rest to pass, giving us a baseline from which to avoid regressions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 11:19:59 +00:00
Simon McVittie
5685546ab1 gio: Don't run gsocketclient-slow test under sanitizers
AddressSanitizer, UndefinedBehaviourSanitizer and probably others
involve adding instrumentation into the code under test, which doesn't
go well with LD_PRELOAD modules that absolutely need to be
self-contained.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
5b476d0d9c socket-service test: Don't leak writev vectors
Detected by AddressSanitizer.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-29 20:26:02 +00:00
Simon McVittie
de87bcf7ff gdbus-serialization: Don't leak string containing first serialization
We format the message into a string twice, once for each byte-order,
but only return the one corresponding to the last byte-order to the
caller. This means we need to free the first one.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-28 21:39:23 +00:00
Sebastian Dröge
fdc192f460 Merge branch 'fix/darwin-nosigpipe-regression' into 'master'
gsocket: Fix SO_NOSIGPIPE regression on Darwin

See merge request GNOME/glib!1894
2021-01-27 07:35:04 +00:00
Frederic Martinsons
d890b1ce5f Extend dbus watching name tests:
- use watcher auto start flag.
  - use watch_name_on_connection_with_closures.
  - use an existing service name for auto start.

Closes #2011

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-01-25 15:00:12 +01:00
Francesco Tamagni
f6ce5739f8 gsocket: Fix SO_NOSIGPIPE regression on Darwin
Where the early call to g_socket_set_option() fails because of
check_socket() failing due to `inited` still being FALSE.

This brings 634b692 back into working order, by fixing the regression
introduced in 39f047e.

Co-authored-by: Ole André Vadla Ravnås <oleavr@gmail.com>
2021-01-21 21:17:24 +01:00
Philip Withnall
8bdd7438e5 Merge branch '968-add-gdbus-obj-path-escape' into 'master'
Add g_dbus_utils_object_path_escape and g_dbus_utils_object_path_unescape

Closes #968

See merge request GNOME/glib!1871
2021-01-20 13:23:25 +00:00
MARTINSONS Frederic
47355c358d Add g_dbus_utils_object_path_escape and g_dbus_utils_object_path_unescape
These two APIs are useful to publish an object which path content is not
controlled (e.g. dynamically built or coming from external source).

Closes #968

(Rebased and tweaked by Frederic Martinsons)

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-01-20 13:23:24 +00:00
Philip Withnall
b6a1fa47fe Merge branch 'settings-test-cleanups' into 'master'
Various memory leak cleanups to GSettings tests

See merge request GNOME/glib!610
2021-01-20 13:15:26 +00:00
Philip Withnall
5cafd748e3 tests: Remove incorrect unref from tls-bindings tests
`g_tls_backend_get_default()` does not return a reference to the
backend, so don’t drop one.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-20 12:51:41 +00:00
Philip Withnall
98274e09de tests: Free GSettingsBackend singleton at end of gsettings tests
This makes the tests a whole lot closer to being valgrind-clean, and
revealed a few legitimate memory leaks in amongst the noise caused by
keeping the singleton GSettingsBackend around for the lifetime of the
process.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2021-01-20 12:51:41 +00:00
Krzesimir Nowak
a2525129a7 tests: Update the expected count in file test
We added another desktop file, so update the file count.
2021-01-09 16:00:50 +01:00
Krzesimir Nowak
cdf0a50c69 gdesktopappinfo: Fix validation of XDG_CURRENT_DESKTOP
Split out XDG_CURRENT_DESKTOP handling to a separate function and make
sure that it drops all the invalid entries properly. Earlier a bad
entry could slip through the checks by sitting just after another bad
entry, like in env being set to `invalid1!:invalid2!`, where
`invalid2!` could slip the checks.
2021-01-09 15:39:09 +01:00
Philip Withnall
d90d914fc5 tests: Add more debug information to gdbus-connection-slow
It occasionally fails in CI with output like:
```
196/274 glib:gio / gdbus-connection-slow        FAIL     0.54 s (killed by signal 6 SIGABRT)

--- command ---
G_TEST_BUILDDIR='/builds/pwithnall/glib/_build/gio/tests' G_TEST_SRCDIR='/builds/pwithnall/glib/gio/tests' GIO_MODULE_DIR='' /builds/pwithnall/glib/_build/gio/tests/gdbus-connection-slow
--- stdout ---
\# random seed: R02S4eb186e89e2472eedd11538b37192543
1..2
\# Start of gdbus tests
\# Start of connection tests
Bail out! GLib-GIO:ERROR:../gio/tests/gdbus-connection-slow.c:98:test_connection_flush: assertion failed (error == NULL): Child process killed by signal 11 (g-exec-error-quark, 19)
--- stderr ---
**
GLib-GIO:ERROR:../gio/tests/gdbus-connection-slow.c:98:test_connection_flush: assertion failed (error == NULL): Child process killed by signal 11 (g-exec-error-quark, 19)
cleaning up pid 12991
```

which is not very helpful. Add some more debug output to print the
stdout and stderr of the child process, to hopefully give an insight
into why it’s dying with signal 11 (sigsegv).

I can’t reproduce the sigsegv locally.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-07 17:55:21 +00:00
Ole André Vadla Ravnås
9ac3a27f03 gsocket: Fix credentials error-handling on Apple OSes
- When querying a TCP socket, getsockopt() may succeed but the resulting
  `optlen` will be zero. This means we'd previously be reading
  uninitialized stack memory in such cases.
- After a file-descriptor has gone through FD-passing, getsockopt() may
  fail with EINVAL. At least this is the case with TCP sockets.
- While at it also use SOL_LOCAL instead of hard-coding its value.
2021-01-04 12:29:47 +00:00
Emmanuel Fleury
76426c0158 Rewriting the G_GNUC_NORETURN into G_NORETURN macros everywhere 2020-11-25 11:34:05 +00:00
Sebastian Dröge
fa8a39c6c6 Merge branch 'py-fixes' into 'master'
Python formatting improvements

See merge request GNOME/glib!1757
2020-11-20 18:10:40 +00:00
Philip Withnall
f4607def16 tests: Drop unnecessary volatile qualifiers from tests
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
7f905ff1fa tests: Fix non-atomic access to some shared variables
And drop the `volatile` qualifier from the variables, as that doesn’t
help with thread safety.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
fab561f8d0 gobject: Drop use of volatile from get_type() macros
http://isvolatileusefulwiththreads.in/c/

It’s possible that the variables here are only marked as volatile
because they’re arguments to `g_once_*()`. Those arguments will be
modified in a subsequent commit.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
f936bba0d1 tests: Improve validity of binary GDBusMessage parsing tests
These tests were originally written using the output directly from a
fuzzer which had triggered the bugs we’re testing for. However, that
means they’re liable to no longer test what they’re intended to test if
the `GDBusMessage` parsing code is changed to (for example) check for
certain errors earlier in future.

It’s better to only have one invalidity in each binary blob, so change
the test messages to all be valid apart from the specific thing they’re
testing for.

The changes were based on reading the D-Bus specification directly:
https://dbus.freedesktop.org/doc/dbus-specification.html

During these changes I found one problem in
`test_message_parse_deep_header_nesting()` where it wasn’t actually
nesting variants in the header deeply enough to trigger the bug it was
supposed to be testing for. Fixed that.

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

Fixes: #1963
2020-11-18 13:19:13 +00:00
Philip Withnall
d270b6c3db py: Various flake8 cleanups
None of these are particularly significant, but they do get the CI
output clean.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Philip Withnall
905b22a17e py: Reformat all Python files consistently
This commit is the unmodified results of running
```
black $(git ls-files '*.py')
```
with black version 19.10b0. See #2046.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Frederic Martinsons
e817a049f0 Correct shellcheck errors (and ignore world splitting when we want it)
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2020-11-15 17:34:27 +01:00
Sebastian Dröge
728c591d76 Merge branch '1560-converter-zero-size' into 'master'
gresource: Fix handling of zero-sized compressed resource entries

Closes #1560

See merge request GNOME/glib!1752
2020-11-14 21:35:18 +00:00
Philip Withnall
353020928c gresource: Fix handling of zero-sized compressed resource entries
The zlib `GConverter` can’t handle an output buffer of size 0.

Add tests.

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

Fixes: #1560
2020-11-14 19:03:18 +00:00
Niels De Graef
6fa5c13c30 gio, glib: Use g_assert_cmpstrv where it makes sense 2020-11-14 18:17:32 +00:00
Simon McVittie
f53aaeac9f gio/tests/gsettings: Assert that temporary directory ends up empty
If there are stray files left over, g_rmdir() will fail with ENOTEMPTY.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:26:01 +00:00
Simon McVittie
782c1b424e gio/tests/gsettings: Assert that g_chmod succeeds
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:59 +00:00
Simon McVittie
3f9f7da0f1 gio/tests/gsettings: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:22 +00:00
Simon McVittie
3468369625 gio/tests/appmonitor: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:24:05 +00:00
Simon McVittie
b3b4ad4f94 gio/tests/live-g-file: Use g_assert_no_errno()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-31 12:20:53 +00:00
Simon McVittie
e5cee9ce5a gio/tests/gdbus-peer: Exercise fds attached to a large message
This incidentally also exercises the intended pattern for sending fds in
a D-Bus message: the fd list is meant to contain exactly those fds that
are referenced by a handle (type 'h') in the body of the message, with
numeric handle value n corresponding to g_unix_fd_list_peek_fds(...)[n].

Being able to send and receive file descriptors that are not referenced by
a handle (as in OpenFile here) is a quirk of the GDBus API, and while it's
entirely possible in the wire protocol, other D-Bus implementations like
libdbus and sd-bus typically don't provide APIs that make this possible.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/2074
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 12:03:59 +00:00
Michael Catanzaro
1d28fd530c Fix race in socketclient-slow test
This test ensures that g_socket_client_connect_to_host_async() fails if
it is cancelled, but it's not cancelled until after 1 millisecond. Our
CI testers are hitting that race window, and Milan is able to reproduce
the crash locally as well. Switching it from 1ms to 0ms is enough for
Milan to avoid the crash, but not enough for our CI, so let's move the
cancellation to a GSocketClientEvent callback where the timing is
completely deterministic.

Hopefully fixes #2221
2020-10-26 14:18:06 +00:00
Sergio Costas
c12762a091 GSubprocessLauncher: allow to close passed FDs
By default, when using g_subprocess_launcher_take_fd() to pass an
FD to a child, the GSubprocessLauncher object also takes ownership
of the FD in the parent, and closes it during finalize(). This is
a reasonable assumption in the majority of the cases, but sometimes
it isn't a good idea.

An example is when creating a GSubprocessLauncher in JavaScript:
here, the destruction process is managed by the Garbage Collector,
which means that those sockets will remain opened for some time
after all the references to the object has been droped. This means
that it could be not possible to detect when the child has closed
that same FD, because in order to make that work, both FDs
instances (the one in the parent and the one in the children) must
be closed. This can be a problem in, as an example, a process that
launches a child that communicates with Wayland using an specific
socket (like when using the new API MetaWaylandClient).

Of course, it isn't a valid solution to manually call close() in
the parent process just after the call to spawn(), because the FD
number could be reused in the time between it is manually closed,
and when the object is destroyed and closes again that FD. If that
happens, it will close an incorrect FD.

One solution could be to call run_dispose() from Javascript on the
GSubprocessLauncher object, to force freeing the resources.
Unfortunately, the current code frees them in the finalize()
method, not in dispose() (this is fixed in !1670 (merged) ) but it
isn't a very elegant solution.

This proposal adds a new method, g_subprocess_launcher_close(),
that allows to close the FDs passed to the child. To avoid problems,
after closing an FD with this method, no more spawns are allowed.

Fix: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1677
2020-10-12 20:29:48 +02:00
Maxim Mikityanskiy
094eca7076 gio: Expose g_file_build_attribute_list_for_copy
Expose a function that prepares an attribute query string to be passed
to g_file_query_info() to get a list of attributes normally copied with
the file. This function is used by the implementation of
g_file_copy_attributes, and it's useful if one needs to split
g_file_copy_attributes into two stages, for example, when nautilus does
a recursive move of a directory. When files are moved from the source
directory, its modification time changes. To preserve the mtime on the
destination directory, it has to be queried before moving files and set
after doing it, hence these two stages.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
2020-10-06 10:16:49 +01:00
Patrick Griffis
f9fc29f0b7 gtlscertificate: Add support for PKCS #11 backed certificates
This reverts commit d58e5de9e9.
2020-10-01 17:09:04 +01:00
Simon McVittie
38a2aed5f0 GDBus: Use G_DBUS_METHOD_INVOCATION_HANDLED in method implementations
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-01 16:32:50 +01:00
Simon McVittie
500d065f3d GDBus tests: Use G_SOURCE_REMOVE, G_SOURCE_CONTINUE
The meaning of the boolean result of a GSource function is clearer if
we use these aliases.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-01 16:32:50 +01:00
Philip Withnall
b43fb9cbfb guri: Fix URI scope parsing
The previous parsing code could read off the end of a URI if it had an
incorrect %-escaped character in.

Fix that, and more closely implement parsing for the syntax defined in
RFC 6874, which is the amendment to RFC 3986 which specifies zone ID
syntax.

This requires reworking some network-address tests, which were
previously treating zone IDs incorrectly.

oss-fuzz#23816

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-09-30 19:39:30 +01:00
Carlos Garnacho
cf85241aba tests: Add splice cancellation test
This doesn't trigger the cancellation assertion issue when run locally
(the task didn't return yet, so the error is simply overwritten), but
perhaps it ever does in CI. Anyhow, it's good to have a cancellation
test.
2020-08-28 11:38:51 +02:00
Andre Miranda
60eefd4de9 glocalfileinfo: Add statx() support
This currently just implements the same functionality as the existing
`stat()`/`fstat()`/`fstatat()`/`lstat()` calls, although where a reduced
field set is requested it may return faster.

Helps: #1970
2020-08-17 12:33:05 +01:00
Philip Withnall
b80b864fe3 tests: Add a test for getting/setting xattrs on a local file
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #422
2020-07-24 23:43:01 +01:00
Philip Withnall
582ffcd6ea Merge branch 'cancellable-test-debugging' into 'master'
tests: Fix intermittent failure in GCancellableSource test

Closes #1764

See merge request GNOME/glib!1539
2020-06-25 13:02:18 +00:00
Ruslan Marchenko
44524b9daa Add g_(d)tls_connection_get_channel_binding_data calls and enums
* Add g_tls_connection_get_channel_binding_data API call
 * Add g_dtls_connection_get_channel_binding_data API call
 * Add get_binding_data method to GTlsConnection class
 * Add get_binding_data method to GDtlsConnection interface
 * Add GTlsChannelBindingType enum with tls-unique and
   tls-server-end-point types
 * Add GTlsChannelBindingError enum and G_TLS_CHANNEL_BINDING_ERROR
   quark
 * Add new API calls to documentation reference gio-sections-common
2020-06-25 12:40:34 +00:00
Philip Withnall
ee3216b31b tests: Iterate the GMainContext directly rather than using a GMainLoop
This speeds up the `cancellable` test a little by stopping waiting for
the threads to start up as soon as they have started, rather than after
an arbitrary timeout.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1764
2020-06-25 13:12:51 +01:00
Philip Withnall
5e49d53cd5 tests: Use G_SOURCE_CONTINUE/G_SOURCE_REMOVE instead of booleans
This makes no functional difference, but clarifies the code a little.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-25 13:12:51 +01:00
Philip Withnall
a956b096af tests: Use atomics to access counter shared between threads
This should fix some sporadic test failures in this test, although I
can’t be sure as I was unable to reproduce the original failure.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1764
2020-06-25 13:12:51 +01:00
Philip Withnall
5571aaa1c5 tests: Use g_test_message() rather than g_printerr() in cancellable test
This makes sure the message gets formatted correctly and sent to the
right log file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-25 13:12:51 +01:00
Philip Withnall
5b12608157 tests: Fix intermittent failure in GCancellableSource test
It seems that allowing the GCancellable to be finalised in either the
main thread or the worker thread sometimes leads to crashes when running
on CI.

I cannot reproduce these crashes locally, and various analyses with
memcheck, drd and helgrind have failed to give any clues.

Fix this for this particular test case by deferring destruction of the
`GCancellable` instances until after the worker thread has joined.
That’s OK because this test is specifically checking a race between
`g_cancellable_cancel()` and disposal of a `GCancellableSource`.

The underlying bug remains unfixed, though, and I can only hope that we
eventually find a reliable way of reproducing it so it can be analysed
and fixed.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-25 13:12:51 +01:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Simon McVittie
44c004c84e Normalize C source files to end with exactly one newline
Some editors automatically remove trailing blank lines, or
automatically add a trailing newline to avoid having a trailing
non-blank line that is not terminated by a newline. To avoid unrelated
whitespace changes when users of such editors contribute to GLib,
let's pre-emptively normalize all files.

Unlike more intrusive whitespace normalization like removing trailing
whitespace from each line, this seems unlikely to cause significant
issues with cherry-picking changes to stable branches.

Implemented by:

    find . -name '*.[ch]' -print0 | \
    xargs -0 perl -0777 -p -i -e 's/\n+\z//g; s/\z/\n/g'

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-06-10 09:48:02 +01:00
Chun-wei Fan
a94f32f140 gdbus-object-manager-example: Fix build on Visual Studio
This ensures that we do really export the symbols for Visual
Studio-style builds, by using _GLIB_EXTERN to decorate the generated
prototypes and including config.h so that we are sure the symbols are
actually exported.
2020-05-28 17:20:22 +08:00
Sebastian Dröge
2730e5dcc3 Merge branch 'fix-file-test' into 'master'
tests: Speed up the file test and make it more reliable

See merge request GNOME/glib!1508
2020-05-22 10:54:58 +00:00
Philip Withnall
26c433d26c tests: Speed up the file test and make it more reliable
Sometimes this test was timing out due to the file monitor notifications
taking longer than the arbitrary 2s delay before ending the test and
checking its results at the end of `iclosed_cb()`.

Avoid that timing-dependence by ending the test when the expected file
monitor notifications are seen, or after a 10s timeout (if so, the test
is failed).

This makes the test run 4× faster in the normal case, as it’s no longer
waiting for a timeout to elapse if the file monitor notifications come
in sooner.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-22 11:05:27 +01:00
Philip Withnall
43969bf41a tests: Port file test to use g_assert_*() rather than g_assert()
g_assert() can be compiled out with G_DISABLE_ASSERT, which renders the
test rather useless.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-22 11:04:34 +01:00
Philip Withnall
9f27f49e34 tests: Speed up the cancellable test
The test added for #1841 spawned 100000 threads. That was fine on a
desktop machine, but on a heavily loaded CI machine, it could result in
large (and unpredictable) slowdowns, resulting in the test taking over
120s in about 1 in 5 runs, and hence failing that CI pipeline due to a
timeout. When passing normally on CI, the test would take around 90s.

Here’s a histogram of time per iteration on a failing (timed out) test
run. Each iteration is one thread spawn:

  Iteration duration (µs) | Frequency
  ------------------------+----------
                     ≤100 |     0
                  100–200 | 30257
                  200–400 | 13696
                  400–800 |  1046
                 800–1000 |   123
                1000–2000 |   583
                2000–4000 |  3779
                4000–8000 |  4972
               8000–10000 |  1027
              10000–20000 |  2610
              20000–40000 |   650
              40000–80000 |    86
             80000–100000 |    10
            100000–200000 |     2
                  >200000 |     0

There’s no actual need for the test to spawn 100000 threads, so rewrite
it to reuse a single thread, and pass new data to that thread.

Reverting the original commit (e4a690f5dd) reproduces the failure on
100 out of 100 test runs with this commit applied, so the test still
works.

The test now takes 3s, rather than 11s, to run on my computer, and has
passed when run with `meson test --repeat 1000 cancellable`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-20 17:21:14 +01:00
Dr. Michael Lauer
ec2f60a008 gio: add gcredential support for macOS
[smcv: Apply my review feedback from
<https://bugzilla.gnome.org/show_bug.cgi?id=668866>]

Co-authored-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.gnome.org/GNOME/glib/issues/507
2020-05-07 14:19:16 +01:00
Simon McVittie
05cb229082 GCredentials: Add the concept of credentials that lack the process ID
struct xucred on macOS doesn't have the process ID, only the user ID
and groups.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-05-07 14:19:16 +01:00
Philip Withnall
6bf221c441 tests: Isolate directory access for gdbus-server-auth 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.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1954
2020-05-05 16:07:32 +01:00
Philip Withnall
6978a4f87a tests: Fix a memory leak in gdbus-server-auth
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 16:07:32 +01:00
Philip Withnall
2f171d0ed4 tests: Fix remaining race in gdbus-connection filter test
Commit 721e385 left one remaining race in the filter test, with a
comment associated with it. Unfortunately, the (seemingly unrelated)
changes in #1841 to `GCancellable` seem to have made this remaining race
a lot more likely to fail on FreeBSD than before.

What’s likely to have happened (although I was unable to reproduce the
failure, due to not having a FreeBSD system; I was only able to
reproduce the problem as a 3/1000 failure on Linux, which is still worth
fixing) is that the atomic write of the `FilterData.serial` to be
expected by the filter function sometimes happened after the filter
function had executed, so the expected message was dropped and didn’t
result in an update to the `FilterData` state.

Rework the test so that instead of setting some expectations (on
`FilterData`) in one thread and then checking them in another thread,
the worker thread just unconditionally returns messages from the filter
function to the main thread, and then the main thread checks whether the
expected one has been filtered.

With this change applied, the `gdbus-connection` test passes 5000 times
in a row for me, on Linux; and doesn’t seem to fail any more on the
FreeBSD CI machines over a few runs. (Previously it failed on 4/5 runs.)

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #2092
Fixes: #1957
2020-05-05 13:29:29 +01:00
Ross Burton
2709d5e1bb gio/tests/memory-monitor-*.py.in: skip if 3rd party modules not available
The GIO tests memory-monitor-dbus and memory-monitor-portal use a number
of third party Python modules that may not be present when running the
test case.

Instead of failing due to missing imports, catch the ImportError and
mock a test case that skips.  This can't use the usual unittest.skip
logic because the test case class itself uses a 3rd party module.

Closes #2083.
2020-04-23 15:01:25 +01:00
Philip Withnall
fa76bde252 Merge branch 'tap' into 'master'
gio: use TAPTestRunner in the memory monitor tests

See merge request GNOME/glib!1443
2020-04-09 14:33:09 +00:00
Ross Burton
1fcd32a159 gio: use TAPTestRunner in the memory monitor tests
There are two memory monitor tests that use Python's unittest module directly,
but GLib tests should be outputting TAP.  Use the embedded TAPTestRunner to
ensure that TAP is output for these tests too.
2020-04-09 14:55:39 +01:00
Philip Withnall
82a557502d Merge branch '1841-cancellable-race-fix' into 'master'
Resolve "Signal handler disconnection race when finalising GCancellableSource"

Closes #1841

See merge request GNOME/glib!1400
2020-04-09 12:00:52 +00:00
Nirbheek Chauhan
b462e2c80c meson: Use the b_vscrt option for selecting the CRT
This option has been available since 0.48, and we should use it
instead of only guessing based on buildtype.
2020-04-03 16:39:22 +05:30
Philip Withnall
721e385593 tests: Use atomics for shared data in gdbus-connection test
D-Bus filter functions run in a worker thread. The `gdbus-connection`
test was sharing a `FilterData` struct between the main thread and the
filter function, which was occasionally (on the order of 0.01% of test
runs) causing spurious test failures due to racing on reads/writes of
`num_handled`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #480
2020-03-17 15:22:04 +00:00
Philip Withnall
0d567c784d tests: Port gdbus-connection to use g_assert_*() rather than g_assert()
g_assert() can be compiled out with G_DISABLE_ASSERT, which renders the
test rather useless.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #480
2020-03-17 15:21:51 +00:00
Philip Withnall
42c7e89228 Merge branch 'w32-fileinfo-mtime-usec' into 'master'
Support nanoseconds in stat timestamps on Windows

See merge request GNOME/glib!1329
2020-03-06 12:58:00 +00:00
Philip Withnall
b3b814f9c2 Merge branch 'wip/smcv/skip-low-mem' into 'master'
tests: Skip MemoryMonitor test if GObject-Introspection is too old

See merge request GNOME/glib!1397
2020-03-02 10:26:50 +00:00
Philip Withnall
e4a690f5dd gcancellable: Fix minor race between GCancellable and GCancellableSource
There’s a minor race condition between cancellation of a `GCancellable`,
and disposal/finalisation of a `GCancellableSource` in another thread.

Thread A                               Thread B
 g_cancellable_cancel(C)
 →cancellable_source_cancelled(C, S)
                                       g_source_unref(S)
                                       cancellable_source_dispose(S)
 →→g_source_ref(S)
 →→# S is invalid at this point; crash

Thankfully, the `GCancellable` sets `cancelled_running` while it’s
emitting the `cancelled` signal, so if `cancellable_source_dispose()` is
called while that’s high, we know that the thread which is doing the
cancellation has already started (or is committed to starting) calling
`cancellable_source_cancelled()`.

Fix the race by resurrecting the `GCancellableSource` in
`cancellable_source_dispose()`, and signalling this using
`GCancellableSource.resurrected_during_cancellation`. Check for that
flag in `cancellable_source_cancelled()` and ignore cancellation if it’s
set.

The modifications to `resurrected_during_cancellation` and the
cancellable source’s refcount have to be done with `cancellable_mutex`
held so that they are seen atomically by each thread. This should not
affect performance too much, as it only happens during cancellation or
disposal of a `GCancellableSource`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1841
2020-02-29 20:15:39 +00:00
Philip Withnall
4093321c9a tests: Use g_assert_*() in cancellable test rather than g_assert()
`g_assert()` is compiled out if `G_DISABLE_ASSERT` is defined, and
`g_assert_*()` gives more detailed failure messages.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-02-28 16:06:46 +00:00
Jan Alexander Steffens (heftig)
7bdcfcf73a
tests: Move memory_monitor_tests under installed_tests_enabled
So they're not installed when the latter is disabled.
2020-02-28 14:10:25 +01:00
Simon McVittie
fdbd9ed7f7 tests: Skip MemoryMonitor test if GObject-Introspection is too old
Distributions will likely want to update GLib before
GObject-Introspection, to avoid circular dependencies.

Signed-off-by: Simon McVittie <smcv@debian.org>
2020-02-28 12:42:36 +00:00
Philip Withnall
99a325356d tests: Fix a compiler warning about string+int arithmetic
Clang warns about string+int not appending to the string (to try and
catch newbie mistakes). While this test didn’t expect that to happen, it
was substituting the same constant string in multiple places for no good
reason. Switch to a single static const string, which should also fix
the compiler warning.

We have to define the string length since it’s used in various
stack-allocated array lengths. This is the easiest fix without more
major refactoring of the test to be less 90s.

Also make things a bit more static.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-02-24 16:18:58 +00:00
Sebastian Dröge
2b06b6498b Merge branch 'speed-up-actions-test' into 'master'
tests: Speed up the GIO actions test

See merge request GNOME/glib!1298
2020-02-24 13:16:09 +00:00
Philip Withnall
238c774970 tests: Reduce iteration counts on gdbus-threading test
When running under CI, each iteration takes so long that the total test
time is around 200s. If the CI runner is highly loaded, this can tip it
over the timeout of 360s.

Reduce the iteration counts unless running the test thoroughly.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 12:24:02 +00:00
Philip Withnall
cfe8d423d4 tests: Bump the refcount timeout in gdbus-threading
Currently the test waits for 1s before deciding that a refcount has been
leaked. But slow test machines might take longer than that between
scheduling different threads to sort out the refcount, so increase the
timeout.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 11:37:36 +00:00
Philip Withnall
55eb360c65 tests: Skip g-file-info-filesystem-readonly test if bindfs fails
bindfs is part of the setup process, so if it fails (as can happen if
the `fuse` kernel module has not been loaded — not much we can do about
that) then skip the test.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-02-24 09:08:20 +00:00
Philip Withnall
0f0af5ae3a tests: Mark gdbus-threading as non-flaky any more
See previous commits and #1515.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1515
2020-02-24 09:03:02 +00:00
Philip Withnall
f74a987d21 tests: Use TestSignal rather than NameOwnerChanged to test signals
When testing that signals are delivered to the correct thread, and are
delivered the correct number of times, call `EmitSignal()` on the
`gdbus-testserver` to trigger a signal emission, and listen for that.

Previously, the code listened for `NameOwnerChanged` and connected to
the bus again to trigger emission of that. The problem with that is that
other things happening on the bus (for example, an old
`gdbus-testserver` instance disconnecting) can cause `NameOwnerChanged`
signal emissions. Sometimes, the `gdbus-threading` test was failing the
`signal_count == 1` assertion due to receiving more than one
`NameOwnerChanged` emission.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 09:03:02 +00:00
Philip Withnall
cd0ab355cd tests: Use GMainContext instead of GMainLoop in gdbus-threading
This is equivalent, but makes the loop exit conditions a little clearer,
since they’re actually in a `while` statement, rather than being a
`g_main_loop_quit()` call in a callback somewhere else in the file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 09:03:02 +00:00
Philip Withnall
79ef610f03 tests: Wait until unsubscribing from a signal has completed
As with the previous commit, don’t stop iterating the `context` in
`test_delivery_in_thread_func()` until the unsubscription from a signal
is complete, and hence there’s a guarantee that no callbacks are pending
in the `thread_context`.

This commit uses the `GDestroyNotify` for
`g_dbus_connection_signal_subscribe()` as a synchronisation message from
the D-Bus worker thread to the `test_delivery_in_thread_func()` thread
to notify of signal unsubscription.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1515
2020-02-24 09:01:03 +00:00
Philip Withnall
af6dbece87 tests: Wait until unwatching the gdbus-testserver name has completed
Previously, the code in `ensure_gdbus_testserver_up()` created a proxy
object and watched its `name-owner` to see when the
`com.example.TestService` name appeared.

This ended up subscribing to three signals (one of them for name
ownership, and two unused for properties of the proxy), and was racy. In
particular, the `name-owner` property could be set before all D-Bus
messages had been processed — it could have been derived from getting
the owner of the name, for example.

This left unprocessed messages hanging around in the `context`, but that
context was never iterated again, which essentially leaked the
references held by those messages. That included a reference to the
`GDBusConnection`.

The first part of the fix is to simplify the code to use
`g_bus_watch_name_on_connection()`, so there’s only one signal
subscription to worry about.

The second part of the fix is to use the `GDestroyNotify` callback for
the watch data to be notified of when all D-Bus traffic has been
processed and the signal unsubscription is complete. At this point, it’s
guaranteed that there are no idle callbacks pending in the
`GMainContext`, since the `GDestroyNotify` callback is the last one
invoked on the `GMainContext`.

Essentially, this commit uses the `GDestroyNotify` callback as a
synchronisation message between the D-Bus worker thread and the thread
calling `ensure_gdbus_testserver_up()`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1515
2020-02-24 09:01:03 +00:00
Philip Withnall
ac274b4005 tests: Add timeout to assert_connection_has_one_ref()
Iterate the given `context` while waiting, rather than sleeping. This
ensures that if the errant `GDBusConnection` ref is held by some pending
callback in the given `context`, it will actually be released.

Typically `context` is going to be the global default main context.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 09:00:59 +00:00
Philip Withnall
b2e543f6a4 tests: Take explicit connection and context when ensuring testserver up
This introduces no functional changes, but makes the code a little more
explicit about which connection and main context it’s operating on.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
2020-02-24 07:46:22 +00:00
Philip Withnall
b302ee956e tests: Move refcount checks to the end of each test in gdbus-threading
These checks used to be a precondition on test_threaded_singleton(); but
the earlier tests could leave the refcount of the shared connection in a
bad state, and this wouldn’t be caught until later.

Factor out the check, increase the iteration count to 1000 (so the check
blocks for up to 1s rather than 100ms), and call it in more places.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1515
2020-02-24 07:46:22 +00:00