GNOME Bugzilla – Bug 734501
SIGTRAP when using Gtk in dbus service
Last modified: 2014-08-15 00:39:19 UTC
Hi, I'm debugging a strange issue in blueman that occurs if a GTK+ 3 library with wayland support is used. It also involves Python and dbus, so I'm not 100 % sure where exactly the issue comes from. I was able to extract a minimal example to replicate it: % cat /usr/share/dbus-1/system-services/cschramm.test.service [D-BUS Service] Name=cschramm.test Exec=/home/schramm/test User=root % cat /home/schramm/test #!/usr/bin/python import gi.repository.Gtk % python >>> import dbus >>> dbus.SystemBus().get_object('cschramm.test', '/') This triggers a SIGTRAP that can be observed in both the python shell and syslog. If wayland support is disabled in GTK, the issue does not occur. Also, if the service has another user than root it seems to work fine. We've seen the problem at least in Debian, Gentoo, and Manjaro now, see https://github.com/blueman-project/blueman/issues/83. I appreciate any help with tracing this down!
Thanks for taking the time to report this bug. Without a stack trace from the crash it's very hard to determine what caused it. Can you get us a stack trace? Please see http://live.gnome.org/GettingTraces for more information on how to do so. Thanks in advance!
Wasn't easy to convince dbus to generate core dumps... :D I could trace it down to glib. (Can you please reassign the bug? But read the last paragraph first.). GTK+ uses g_logv as a log handler for wayland and that's where the program crashes. It can be replicated without dbus, python, GTK+, and root using the following minimal program: #include <glib.h> int main(void) { va_list argp; g_logv("Domain", G_LOG_LEVEL_ERROR, "Message", argp); } This triggers the SIGTRAP at: g_logv (log_domain=0x40071c "Domain", log_level=G_LOG_LEVEL_ERROR, format=<optimized out>, args=<optimized out>) at /tmp/buildd/glib2.0-2.40.0/./glib/gmessages.c:1038 Looking at [1] it seems like a problem with the g_log_depth private variable. [1] https://git.gnome.org/browse/glib/tree/glib/gmessages.c?h=glib-2-40#n1038 Maybe glib needs some initialization before g_logv may be used? (Which would make it a GTK+ bug again, since it makes invalid use of glib then.)
Glib does not need initialization. This does not sound like a gtk issue. Points to investigate: why does a non-ui dbus service need to import gtk bindings ? Why does it not avoid opening a display connection?
If glib does not need any initialization, then it's in deed not a GTK issue. Also my g_logv example above should work then, shouldn't it? So please reassign this to glib. What happens in case of our application is that the dbus service includes a file shared with multiple components of the application. And this file in turn includes gi.repository.Gtk. Gtk is in fact not needed for the dbus service, but for other components. Yes, this common file is ugly and could be avoided, no doubt about that... ;) Anyway, as soon as the Gtk binding gets imported the library starts initializing including a call to wl_display_connect if wayland support is built in. In case of the dbus service, wayland will try to log the message "error: XDG_RUNTIME_DIR not set in the environment.". This is where g_logv gets called and the application crashes just as my code above does.
Importing the gtk python bindings has the side effect of opening a display connection. There's ways around that, but I don't speak enough python to explain them...