strange D-Bus interactions with gtk_dialog_run
Gnaural
gnaural at users.sourceforge.net
Mon Nov 19 20:03:01 PST 2007
Hi again, in context:
--- Havoc Pennington <hp at redhat.com> wrote:
> The big picture is that if you call
> dbus_connection_setup_with_g_main()
> (this will get called if you're using dbus-glib),
> then there will be
> handlers in the GLib main loop that do the read,
> write, and dispatch.
Oops... if that's what "main loop integration" means,
I think I'm wrong in my last answer; I'm using GLib in
my application, but the D-Bus code is solely low-level
C API. Maybe the proof would be that I'm not linking
with dbus-glib, only dbus. Originally, I did write a
dbus-glib server, but dropped it when I realized I
couldn't cross-compile it for windows.
Fact is, once I found Matthew Johnson's example code,
I was actually happier with it that my dbus-glib
solution, because I didn't need all the GObject
encapsulation code of dbus-glib. I really just need to
share a few simple variables. So for my needs,
Johnson's code did everything I needed in about 10
lines. The only problem was that his code was
non-blocking, so I tried to make it blocking, but
read_write didn't act right. So I used
read_write_dispatch, then launched the thing in it's
own thread, and it worked like a charm... EXCEPT when
I realized that the Linux version exhibited a bizarre
interaction with gtk_dialog_run calls from the
gtk_main thread.
And I spent part of the weekend trying to make a
simple example to post here (using a GTK+ GUI updated
via g_timeouts running in parallel with another thread
running a blocking dbus_connection_read_write_dispatch
loop). But I couldn't get it to fail! By the end, I
was adding in more threads and timeouts that the real
program has. (Note: I could simulate the failure by
calling a gtk_dialog_run from a g_timeout in the main
thread, but that was pretty removed from the actual
circumstances).
Backtraces from my real app do show something strange
happens to main thread after I've called
gtk_dialog_run; it gets poluted with calls to
libdbus-1.so.3 that were previously only in the thread
I was running from D-Bus. I'll post the two before and
after backtraces of the two threads at the end.
In the mean time, how can I simply modify Johnson's
code to be blocking? Here's his:
/////////
// loop, testing for new messages
while (true) {
// non blocking read of the next available
message
dbus_connection_read_write(conn, 0);
msg = dbus_connection_pop_message(conn);
// loop again if we haven't got a message
if (NULL == msg) {
sleep(1);
continue;
}
// check this is a method call for the right
interface and method
if (dbus_message_is_method_call(msg,
"test.method.Type", "Method"))
reply_to_method_call(msg, conn);
// free the message
dbus_message_unref(msg);
}
/////////
Here's mine:
/////////
while (dbus_connection_read_write_dispatch
(gds_remote_connection, -1))
{
msg = dbus_connection_pop_message
(gds_remote_connection);
//return if we haven't got a message
if (NULL != msg) {
//check if it is a method call for the right
interface & method:
if (dbus_message_is_method_call (msg, //DBusMessage
* msg
GNAURAL_DBUS_INTERFACE, //char * interface
"GetBeatfreq")) //char * method
{
fprintf (stderr, "Running GetBeatfreq\n");
GetBeatfreq (msg, gds_remote_connection);
}
//free the message
dbus_message_unref (msg);
}
}
/////////
Thanks!
PS - Here's some backtrace info:
==============================
Backtrace main thread (1) when working properly:
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb75f9637 in poll () from
/lib/i686/cmov/libc.so.6
#2 0xb771c585 in ?? () from /usr/lib/libglib-2.0.so.0
#3 0x0829c058 in ?? ()
#4 0x00000002 in ?? ()
#5 0x00000080 in ?? ()
#6 0x0829c058 in ?? ()
#7 0x00000002 in ?? ()
#8 0xb7789aa0 in ?? () from /usr/lib/libglib-2.0.so.0
#9 0xb7789ae0 in ?? () from /usr/lib/libglib-2.0.so.0
#10 0xbff725a4 in ?? ()
#11 0x00000001 in ?? ()
#12 0x00000001 in ?? ()
#13 0x08096388 in ?? ()
#14 0x0829c058 in ?? ()
#15 0xb75f95c0 in ?? () from /lib/i686/cmov/libc.so.6
#16 0xb7680c80 in ?? () from
/lib/i686/cmov/libpthread.so.0
#17 0xb767f530 in ?? () from
/lib/i686/cmov/libpthread.so.0
#18 0xb773bf72 in g_thread_self () from
/usr/lib/libglib-2.0.so.0
#19 0xb771c937 in g_main_loop_run () from
/usr/lib/libglib-2.0.so.0
#20 0xb7d7b354 in gtk_main () from
/usr/lib/libgtk-x11-2.0.so.0
#21 0x0805a084 in main (argc=1, argv=0xbff72714) at
main.c:326
##########
Backtrace D-Bus thread (2) when working properly:
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb75f9637 in poll () from
/lib/i686/cmov/libc.so.6
#2 0xb77f101b in ?? () from /usr/lib/libdbus-1.so.3
#3 0xb6fa42c0 in ?? ()
#4 0x00000001 in ?? ()
#5 0xffffffff in ?? ()
#6 0xb77ef757 in ?? () from /usr/lib/libdbus-1.so.3
#7 0xb77ef749 in ?? () from /usr/lib/libdbus-1.so.3
#8 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#9 0xb6fa42d8 in ?? ()
#10 0xb77e97b9 in ?? () from /usr/lib/libdbus-1.so.3
#11 0xb6fa42c0 in ?? ()
#12 0x00000001 in ?? ()
#13 0xffffffff in ?? ()
#14 0xb77d36fb in ?? () from /usr/lib/libdbus-1.so.3
#15 0x00000000 in ?? ()
##########
Backtrace main thread (1) when frozen after call to
gtk_dialog_run:
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb7681676 in pthread_cond_wait@@GLIBC_2.3.2 ()
from /lib/i686/cmov/libpthread.so.0
#2 0xb77f0296 in ?? () from /usr/lib/libdbus-1.so.3
#3 0x082d6ff0 in ?? ()
#4 0x082d6f68 in ?? ()
#5 0xbff70688 in ?? ()
#6 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#7 0x082b2d90 in ?? ()
#8 0xffffffff in ?? ()
#9 0xbff70698 in ?? ()
#10 0xb77e7373 in ?? () from /usr/lib/libdbus-1.so.3
#11 0x082d6ff0 in ?? ()
#12 0x082d6f68 in ?? ()
#13 0xbff70698 in ?? ()
#14 0xb77e7268 in ?? () from /usr/lib/libdbus-1.so.3
#15 0x082d6f68 in ?? ()
#16 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#17 0xbff706b8 in ?? ()
#18 0xb77d300a in ?? () from /usr/lib/libdbus-1.so.3
#19 0x082d6ff0 in ?? ()
#20 0x082d6f68 in ?? ()
#21 0xb77d2f6f in ?? () from /usr/lib/libdbus-1.so.3
#22 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#23 0x00000007 in ?? ()
#24 0x082b2d90 in ?? ()
#25 0xbff706e8 in ?? ()
#26 0xb77d3476 in ?? () from /usr/lib/libdbus-1.so.3
#27 0x082d6f40 in ?? ()
#28 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#29 0xbff706e8 in ?? ()
#30 0xb77d02c5 in ?? () from /usr/lib/libdbus-1.so.3
#31 0x082d6f40 in ?? ()
#32 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#33 0xffffffff in ?? ()
#34 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#35 0x082b2d90 in ?? ()
#36 0x082b2d90 in ?? ()
#37 0xbff70708 in ?? ()
#38 0xb77d4478 in ?? () from /usr/lib/libdbus-1.so.3
#39 0x082b2d90 in ?? ()
#40 0x00000007 in ?? ()
#41 0xffffffff in ?? ()
#42 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#43 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#44 0xffffffff in ?? ()
#45 0xbff70798 in ?? ()
#46 0xb77d535d in ?? () from /usr/lib/libdbus-1.so.3
#47 0x082b44b8 in ?? ()
#48 0xb76808ac in __pthread_mutex_unlock_usercnt ()
from /lib/i686/cmov/libpthread.so.0
##########
Backtrace D-Bus thread (2) after thread 1 locks:
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb75f9637 in poll () from
/lib/i686/cmov/libc.so.6
#2 0xb77f101b in ?? () from /usr/lib/libdbus-1.so.3
#3 0xb6fa42c0 in ?? ()
#4 0x00000001 in ?? ()
#5 0xffffffff in ?? ()
#6 0xb77ef757 in ?? () from /usr/lib/libdbus-1.so.3
#7 0xb77ef749 in ?? () from /usr/lib/libdbus-1.so.3
#8 0xb77fa610 in ?? () from /usr/lib/libdbus-1.so.3
#9 0xb6fa42d8 in ?? ()
#10 0xb77e97b9 in ?? () from /usr/lib/libdbus-1.so.3
#11 0xb6fa42c0 in ?? ()
#12 0x00000001 in ?? ()
#13 0xffffffff in ?? ()
#14 0xb77d36fb in ?? () from /usr/lib/libdbus-1.so.3
#15 0x00000000 in ?? ()
More information about the dbus
mailing list