dbus daemon - creating a logfile of all messages

Ralf Habacker ralf.habacker at freenet.de
Fri May 12 10:35:54 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Havoc Pennington schrieb:
> Ralf Habacker wrote:
>>
>> void _dbus_loop_run(DBusLoop * loop)
>> {
>>    DBusMessage* msg;
>>      DBusConnection *conn = _dbus_list_pop_first (&loop->need_dispatch);
>>
>>   _dbus_verbose ("  %d connections to dispatch\n",
>> _dbus_list_get_length (&loop->need_dispatch));
>>   _dbus_loop_ref (loop);
>>
>>
>>    // loop listening for signals being emmitted
>>    while (1) {
>>
>>       // non blocking read of the next available message
>>     dbus_connection_read_write(conn, 0);
>>         while(dbus_connection_dispatch(conn) ==
>> DBUS_DISPATCH_DATA_REMAINS)
>>             ;
>>         sleep(1);
>>    }
> 
> 
> This does not make any sense. I think for what you're doing there's no
> reason to use DBusLoop; it's just confusing matters.
> 
> Looking at the old dbus-monitor.c, to fix it just remove the GMainLoop
> and replace g_main_loop_run with:
> 
>  while (dbus_connection_read_write_dispatch(connection, -1)
>     ;
> 
> I think that will work with no further effort.
> 
Thanks for this hint. I have appended a relating patch, which make
dbus-monitor glib free.

Regards
Ralf


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEZMd6oHh+5t8EXncRArqgAJ9SJftab849A40/hVYVYaY8EPwjmQCeLZFD
fxjR+EqKG7kaQJaIzLQ+Zh4=
=ZtUG
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: tools/Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/tools/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- tools/Makefile.am	6 Sep 2005 22:38:54 -0000	1.17
+++ tools/Makefile.am	12 May 2006 17:33:35 -0000
@@ -1,7 +1,6 @@
 INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_X_CFLAGS) $(DBUS_GTK_THREADS_CFLAGS) -DDBUS_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\" -DDBUS_COMPILATION
 
 if HAVE_GLIB
-GLIB_TOOLS=dbus-monitor
 
 nodist_libdbus_glib_HEADERS = dbus-glib-bindings.h
 libdbus_glibdir = $(includedir)/dbus-1.0/dbus
@@ -11,8 +10,6 @@
 
 BUILT_SOURCES = dbus-glib-bindings.h dbus-bus-introspect.xml
 
-else
-GLIB_TOOLS=
 endif
 
 if HAVE_GTK
@@ -26,7 +23,7 @@
 	DBUS_TOP_BUILDDIR=$(top_builddir) $(srcdir)/run-with-tmp-session-bus.sh ./dbus-send --print-reply=literal --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect > dbus-bus-introspect.xml.tmp && mv dbus-bus-introspect.xml.tmp dbus-bus-introspect.xml
 endif
 
-bin_PROGRAMS=dbus-send $(GLIB_TOOLS) dbus-launch dbus-cleanup-sockets $(GTK_TOOLS)
+bin_PROGRAMS=dbus-send dbus-monitor dbus-launch dbus-cleanup-sockets $(GTK_TOOLS)
 
 dbus_send_SOURCES=				\
 	dbus-print-message.c			\
@@ -52,7 +49,7 @@
 	dbus-viewer.c
 
 dbus_send_LDADD= $(top_builddir)/dbus/libdbus-1.la
-dbus_monitor_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
+dbus_monitor_LDADD= $(top_builddir)/glib/libdbus-1.la
 dbus_launch_LDADD= $(DBUS_X_LIBS)
 dbus_viewer_LDADD= $(top_builddir)/glib/libdbus-gtool.la $(DBUS_GTK_THREADS_LIBS) $(DBUS_GLIB_TOOL_LIBS)
 
Index: tools/dbus-monitor.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-monitor.c,v
retrieving revision 1.15
diff -u -r1.15 dbus-monitor.c
--- tools/dbus-monitor.c	29 Oct 2005 17:02:58 -0000	1.15
+++ tools/dbus-monitor.c	12 May 2006 17:33:36 -0000
@@ -23,8 +23,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include "dbus-print-message.h"
 
 static DBusHandlerResult
@@ -59,7 +57,7 @@
   DBusConnection *connection;
   DBusError error;
   DBusBusType type = DBUS_BUS_SESSION;
-  GMainLoop *loop;
+
   int i = 0, j = 0, numFilters = 0;
   char **filters = NULL;
   for (i = 1; i < argc; i++)
@@ -85,8 +83,6 @@
       }
     }
 
-  loop = g_main_loop_new (NULL, FALSE);
-
   dbus_error_init (&error);
   connection = dbus_bus_get (type, &error);
   if (connection == NULL)
@@ -98,8 +94,6 @@
       exit (1);
     }
 
-  dbus_connection_setup_with_g_main (connection, NULL);
-
   if (numFilters)
     {
       for (i = 0; i < j; i++)
@@ -143,9 +137,8 @@
     fprintf (stderr, "Couldn't add filter!\n");
     exit (1);
   }
-
-  g_main_loop_run (loop);
-
+  while (dbus_connection_read_write_dispatch(connection, -1))
+    ;
   exit (0);
  lose:
   fprintf (stderr, "Error: %s\n", error.message);


More information about the dbus mailing list