Commit Graph

48 Commits

Author SHA1 Message Date
Ting-Wei Lan
9147403893 gtestdbus: Fix watcher crash on FreeBSD
In file gio/gtestdbus.c, function watch_parent, there is a loop which
waits for commands sent from the parent process and kills all processes
recorded in 'pids_to_kill' array on parent process exit. The detection
of parent process exit is done by calling g_poll and checking whether
the returned event is G_IO_HUP. However, 'revents' is a bit mask, and
we should use a bitwise-AND check instead of the equality check here.

It seems to work fine on Linux, but it fails on FreeBSD because the
g_poll returns both G_IO_IN and G_IO_HUP on pipe close. This means the
watcher process continues waiting for commands after the parent process
exit, and g_io_channel_read_line returns G_IO_STATUS_EOF with 'command'
set to NULL. Then the watcher process crashes with segfault when calling
sscanf because 'command' is NULL. Since the test result is already
reported by the parent process as 'OK', this kind of crash is likely to
be unnoticed unless someone checks dmesg messages after the test:

pid 57611 (defaultvalue), uid 1001: exited on signal 11
pid 57935 (actions), uid 1001: exited on signal 11
pid 57945 (gdbus-bz627724), uid 1001: exited on signal 11
pid 57952 (gdbus-connection), uid 1001: exited on signal 11
pid 57970 (gdbus-connection-lo), uid 1001: exited on signal 11
pid 57976 (gdbus-connection-sl), uid 1001: exited on signal 11
pid 58039 (gdbus-exit-on-close), uid 1001: exited on signal 11
pid 58043 (gdbus-exit-on-close), uid 1001: exited on signal 11
pid 58047 (gdbus-exit-on-close), uid 1001: exited on signal 11
pid 58051 (gdbus-exit-on-close), uid 1001: exited on signal 11
pid 58055 (gdbus-export), uid 1001: exited on signal 11
pid 58059 (gdbus-introspection), uid 1001: exited on signal 11
pid 58065 (gdbus-names), uid 1001: exited on signal 11
pid 58071 (gdbus-proxy), uid 1001: exited on signal 11
pid 58079 (gdbus-proxy-threads), uid 1001: exited on signal 11
pid 58083 (gdbus-proxy-well-kn), uid 1001: exited on signal 11
pid 58091 (gdbus-test-codegen), uid 1001: exited on signal 11
pid 58095 (gdbus-threading), uid 1001: exited on signal 11
pid 58104 (gmenumodel), uid 1001: exited on signal 11
pid 58108 (gnotification), uid 1001: exited on signal 11
pid 58112 (gdbus-test-codegen-), uid 1001: exited on signal 11
pid 58116 (gapplication), uid 1001: exited on signal 11
pid 58132 (dbus-appinfo), uid 1001: exited on signal 11

If the watcher process crashes before killing the dbus-daemon process
spawned by the parent process, the dbus-daemon process will keep running
after all tests complete. Due to the implementation of 'communicate'
function in Python subprocess, it causes meson to crash. 'communicate'
assumes the stdout and stderr pipes are closed when the child process
exits, but it is not true if processes forked by the child process
doesn't exit. It causes Python subprocess 'communicate' function to
block on the call to poll until the timeout expires even if the test
finishes in a few seconds. Meson assumes the timeout exception always
means the test is still running. It calls 'communicate' again and
crashes because pipes no longer exist.

https://gitlab.gnome.org/Infrastructure/GitLab/issues/286
https://github.com/mesonbuild/meson/issues/3967
https://bugs.python.org/issue30154
2018-08-20 11:13:19 +01:00
Philip Withnall
9b4c50f63d all: Remove trailing newlines from g_message()/g_warning()/g_error()s
All those logging functions already add a newline to any message they
print, so there’s no need to add a trailing newline in the message
passed to them.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-04-27 16:46:19 +01:00
Simon McVittie
3d50691a30 g_test_dbus_down: Ensure next test does not use old connection
There's a race condition somewhere in GTestDBus that can result in
the next test being started at a time when g_bus_get() would still
return the connection that is in the process of closing. This can
be reproduced reasonably reliably by running the gapplication test
10K times in a loop.

Instead of relying on waiting for the weak reference to be released,
we can force the issue by clearing it.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=768996
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894677
2018-04-10 11:22:41 +01:00
Philip Withnall
5cddde1fb2 Consistently save errno immediately after the operation setting it
Prevent the situation where errno is set by function A, then function B
is called (which is typically _(), but could be anything else) and it
overwrites errno, then errno is checked by the caller.

errno is a horrific API, and we need to be careful to save its value as
soon as a function call (which might set it) returns. i.e. Follow the
pattern:
  int errsv, ret;
  ret = some_call_which_might_set_errno ();
  errsv = errno;

  if (ret < 0)
    puts (strerror (errsv));

This patch implements that pattern throughout GLib. There might be a few
places in the test code which still use errno directly. They should be
ported as necessary. It doesn’t modify all the call sites like this:
  if (some_call_which_might_set_errno () && errno == ESOMETHING)
since the refactoring involved is probably more harmful than beneficial
there. It does, however, refactor other call sites regardless of whether
they were originally buggy.

https://bugzilla.gnome.org/show_bug.cgi?id=785577
2017-08-03 10:21:13 +01:00
Philip Withnall
18f8b77c04 gio: Use g_strerror() instead of strerror()
This marginally improves thread safety, and marginally improves
consistency.

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

https://bugzilla.gnome.org/show_bug.cgi?id=733821
2017-06-21 11:20:29 +01:00
Sébastien Wilmet
3bf4a720c3 gio/: LGPLv2+ -> LGPLv2.1+
Sub-directories inside gio/ already processed in a previous commit:
- fam/
- gdbus-2.0/ (which contains only codegen/)
- gvdb/
- inotify/
- tests/
- win32/
- xdgmime/

Other sub-directories inside gio/:
- completion/: no license headers
- kqueue/: not LGPL, BSD-style license

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00
Christian Hergert
18a33f72db introspection: use (nullable) or (optional) instead of (allow-none)
If we have an input parameter (or return value) we need to use (nullable).
However, if it is an (inout) or (out) parameter, (optional) is sufficient.

It looks like (nullable) could be used for everything according to the
Annotation documentation, but (optional) is more specific.
2016-11-22 14:14:37 -08:00
Tobias Nygren
0d0db60959 gio/gtestdbus.c: don't use non-standard %m printf modifier
https://bugzilla.gnome.org/show_bug.cgi?id=756706
2016-02-19 11:29:32 +00:00
Simon McVittie
32492c6ab0 GDBus: try XDG_RUNTIME_DIR/bus before resorting to dbus-launch
This is the right thing to do for the "a session is a user-session"
model implemented in dbus 1.9.14, which is described in
<http://lists.freedesktop.org/archives/dbus/2015-January/016522.html>.

It also resembles sd-bus' behaviour, although sd-bus will only try
kdbus and XDG_RUNTIME_DIR/bus, and never runs dbus-launch.

On systems following the more traditional "a session is a login-session"
model, X_R_D/bus won't exist, so it is harmless to check for it before
falling back to X11 autolaunching. Again, this matches the behaviour
of current libdbus and sd-bus versions.

Now that we do this, g_test_dbus_unset() needs to clear XDG_RUNTIME_DIR
as well as everything else.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=747941
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-06-09 18:17:16 +01:00
Simon McVittie
4865538ce3 GTestDBus: use g_printerr() for status message
This avoids any possibility of interfering with test syntax (such as
TAP) on stdout. TAP specifically does not parse stderr.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 20:24:30 +01:00
Philip Withnall
d80adeaa96 gtestdbus: Don’t close stdout for dbus-daemon
The stdout FD passed to dbus-daemon is propagated to all its child
processes, such as service activated processes. If we close the FD after
reading the bus address from the daemon, any child process which
subsequently writes to stdout (e.g. for logging) will get a SIGPIPE and
explode.

Instead of closing the stdout FD immediately after dbus-daemon has
spawned, keep it open until the daemon is killed.

https://bugzilla.gnome.org/show_bug.cgi?id=732019
2014-06-22 13:02:18 +01:00
Chun-wei Fan
c2a828772b gio/gtestdbus.c: Fix write_config_file() for Windows
Windows does not like g_unlink() to be called on files whose file
descriptor is still open, so doing that would cause a permission
denied error.  Since the fd is not used in that function after
acquiring the temp file, close it earlier before
g_file_set_contents(), so that it can complete successfully.

This fixes a number of GTK+ tests on Windows.

https://bugzilla.gnome.org/show_bug.cgi?id=719344
2014-05-12 22:14:05 +08:00
Matthias Clasen
cb588d4532 Convert external links to markdown syntax 2014-02-05 21:23:28 -05:00
Matthias Clasen
0cc20b7e0b Don't use <filename> in docs
Switch to simpler markdown, `foo`.
2014-02-05 20:17:46 -05:00
Matthias Clasen
111803030d Don't use <envar> in docs
Switch to simpler markdown, `foo`.
2014-02-05 19:32:41 -05:00
Matthias Clasen
6566f746f6 Drop use of xinclude in GTestDBus docs 2014-02-01 20:41:47 -05:00
Matthias Clasen
4ab94a2683 gtestdbus: Use markdown for sections 2014-02-01 10:48:36 -05:00
Matthias Clasen
cade4d6f19 Fix the docs build 2014-01-31 22:14:01 -05:00
Matthias Clasen
17f51583a8 Docs: Convert examples to |[ ]| 2014-01-31 21:56:33 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Philip Withnall
c07eccd9c2 gtestdbus: Add a note about thread safety to the documentation
https://bugzilla.gnome.org/show_bug.cgi?id=712148
2013-12-06 09:41:56 +00:00
Philip Withnall
9d4cd9c5ae gtestdbus: Minor documentation fixes
https://bugzilla.gnome.org/show_bug.cgi?id=712148
2013-11-29 08:11:13 +00:00
Philip Withnall
46c1aea0e7 gtestdbus: Fix non-const use of const variables
The argv array should be declared as const.

https://bugzilla.gnome.org/show_bug.cgi?id=712148
2013-11-29 08:11:13 +00:00
Philip Withnall
598a9c5028 gtestdbus: Fix variable shadowing
Shut up, GCC.

https://bugzilla.gnome.org/show_bug.cgi?id=712148
2013-11-29 08:11:13 +00:00
Stef Walter
baf92d09d6 gtestdbus: Properly close server connections
Otherwise g_test_dbus_down() following a g_test_dbus_stop()
will hang until it times out.

https://bugzilla.gnome.org/show_bug.cgi?id=711807
2013-11-23 17:37:58 -05:00
Stef Walter
797959f05a gtestdbus: Don't destroy GSource twice
https://bugzilla.gnome.org/show_bug.cgi?id=711806
2013-11-23 13:47:29 -05:00
Dan Winship
158dde0507 Replace #ifdef HAVE_UNISTD_H checks with #ifdef G_OS_UNIX
In Windows development environments that have it, <unistd.h> is mostly
just a wrapper around several other native headers (in particular,
<io.h>, which contains read(), close(), etc, and <process.h>, which
contains getpid()). But given that some Windows dev environments don't
have <unistd.h>, everything that uses those functions on Windows
already needed to include the correct Windows header as well, and so
there is never any point to including <unistd.h> on Windows.

Also, remove some <unistd.h> includes (and a few others) that were
unnecessary even on unix.

https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-11-20 09:25:39 -05:00
Stef Walter
419b47e166 gtestdbus: Fix leak of GMainLoop
https://bugzilla.gnome.org/show_bug.cgi?id=711808
2013-11-11 06:55:09 +01:00
Xavier Claessens
06fbdb04d5 GTestDBus: Make sure only DBUS_SESSION_BUS_ADDRESS is set by default
g_test_dbus_unset() now also unset DBUS_STARTER_ADDRESS and
DBUS_STARTER_BUS_TYPE.

https://bugzilla.gnome.org/show_bug.cgi?id=697348
2013-10-29 13:42:14 -04:00
Emmanuele Bassi
54cc43630d Rename the generated private data getter function
As it turns out, we have examples of internal functions called
type_name_get_private() in the wild (especially among older libraries),
so we need to use a name for the per-instance private data getter
function that hopefully won't conflict with anything.
2013-06-24 15:43:04 +01:00
Emmanuele Bassi
32747def4b gio: Use the new private instance data declaration
Use the newly added macros, and remove the explicit calls to
g_type_class_add_private().

https://bugzilla.gnome.org/show_bug.cgi?id=700035
2013-06-24 14:18:01 +01:00
Tristan Van Berkom
dd0ea5dcc2 Added examples to GTestDBus documentation 2013-03-21 16:37:21 +09:00
Dan Winship
731b469908 win32: define _WIN32_WINNT globally
Rather than defining _WIN32_WINNT only in a handful of files, define
it in config.h, like we do with _GNU_SOURCE.

(Also remove a "#define WIN32_LEAN_AND_MEAN" that isn't really all
that useful.)

https://bugzilla.gnome.org/show_bug.cgi?id=688109
2012-11-15 14:19:05 -05:00
Colin Walters
6d88a2f822 build: Add missing "static" keyword where it should be used
Otherwise we fail to build with -Werror=missing-prototypes.

https://bugzilla.gnome.org/show_bug.cgi?id=687385
2012-11-01 20:12:01 -04:00
Will Thompson
a342be7138 gtestdbus: correct documentation typos
https://bugzilla.gnome.org/show_bug.cgi?id=685787
2012-10-11 16:12:47 +01:00
Matthias Clasen
c44f8f5b9f Document g_test_dbus_get_flags 2012-09-23 20:14:27 -04:00
Chun-wei Fan
2954f70d39 Fix build on Visual C++
-glib/gmarkup.c: Use G_VA_COPY() instead of va_copy() as va_copy() may not
 be universally available.
-gio/gtestdbus.c: Include io.h on Windows for close()
2012-08-17 19:22:43 +08:00
Matthias Clasen
b55a2a2005 Don't use GIO in GTestDBus setup
Using GIO here may cause the gvfs module to be loaded, which
in turn gets onto the session bus to talk to gvfsd - not ideal
if you are trying to control the session bus life cycle. Instead,
just use old-fashioned glib file utils.
2012-08-06 12:08:21 -04:00
Colin Walters
d6aa3b3bdd GTestDBus: Don't call into gvfs
https://bugzilla.gnome.org/show_bug.cgi?id=678808
2012-06-26 12:26:05 -04:00
Chun-wei Fan
875854411a Bug 678332-GIO: Fix build on Windows/non-GCC
-gconverterinputstream.c: Avoid GCCism by not using non-standard pointer
 arithmetic on void*, but do a cast to char * as that seems to be what the
 variable was used for.
-gtestdbus.c: Don't include unistd.h unconditionally, and use g_usleep()
 instead of usleep(), as usleep() is not universally available.
2012-06-19 12:04:28 +08:00
Dan Winship
c37273dccb fix warnings 2012-04-30 09:28:42 -04:00
Alexander Larsson
74214e2997 GTestDBus: Allow to specify the dbus-daemon binary
The env var G_TEST_DBUS_DAEMON lets you change dbus-daemon to
whatever you want. This is useful to test with gdbus-daemon
2012-04-20 15:02:48 +02:00
Matthias Clasen
289e3b9143 More beautiful fix
A comma on a line by itself is too ugly to stand.
2012-04-19 17:15:14 -04:00
Alexander Larsson
bb78753a66 Fix non-win32 build error in my recent commit 2012-04-19 20:46:08 +02:00
Alexander Larsson
58e613bfc7 GTestDBus: Make work on win32
Win32 doesn't have things like fork so the existing code has no way
of working. Instead we swap it all out for a custom implementation
on win32.
2012-04-19 18:19:01 +02:00
Xavier Claessens
95bf3d1194 Add GTestDBus object
This is a helper to write unit tests using a private dbus-daemon.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
2012-04-19 10:06:26 +02:00
David Zeuthen
a6f83d73e5 Revert "Add GTestDBus object"
This reverts commit 1b5f70b5b0.
2012-04-18 13:47:51 -04:00
Xavier Claessens
1b5f70b5b0 Add GTestDBus object
This is a helper to write unit tests using a private dbus-daemon.

session_bus_up/down() are now just wrappers around a GTestDBus singleton.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
2012-04-18 11:19:13 -04:00