[glick2] Add libdbus version of --exit-with-session



commit ddf2f25a42502cb4ee2df6172408c5337ae962fd
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Nov 30 11:30:58 2011 +0100

    Add libdbus version of --exit-with-session

 Makefile.am  |   11 ++++++++---
 configure.ac |   11 +++++++++++
 fs.c         |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 04ae94b..b94e35b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,7 @@ AM_CPPFLAGS =					\
 	-I$(top_builddir)			\
 	$(GLIB_CFLAGS)				\
 	$(GIO_CFLAGS)				\
+	$(DBUS_CFLAGS)				\
 	$(FUSE_CFLAGS)				\
 	-DLIBEXECDIR=\"$(libexecdir)\"		\
 	-DBINDIR=\"$(bindir)\"			\
@@ -31,8 +32,12 @@ glick_session_SOURCES = session.c
 glick_runner_SOURCES = runner.c format.h glick.h
 glick_runner_LDADD = $(GLIB_LIBS) $(FUSE_LIBS)
 
-glick_fs_SOURCES = fs.c format.h glick.h
-glick_fs_LDADD = $(GIO_LIBS) $(FUSE_LIBS)
+if !HAVE_GDBUS
+dbus_utils_sources = dbus-utils.h dbus-utils.c
+endif
+
+glick_fs_SOURCES = fs.c format.h glick.h $(dbus_utils_sources)
+glick_fs_LDADD = $(GIO_LIBS) $(FUSE_LIBS) $(DBUS_LIBS)
 
 glick_mkbundle_SOURCES = mkbundle.c format.h
 glick_mkbundle_LDADD = $(GIO_LIBS)
@@ -113,7 +118,7 @@ glick.desktop: Makefile glick.desktop.in
 	  $(edit) $${srcdir}$  in >$  tmp
 	mv $  tmp $@
 
-EXTRA_DIST=glick2.conf.in glick.desktop.in glick2.xml glick2.spec glick2.init
+EXTRA_DIST=glick2.conf.in glick.desktop.in glick2.xml glick2.spec glick2.init dbus-utils.h dbus-utils.c
 
 DISTCHECK_CONFIGURE_FLAGS=--disable-setuid-install
 
diff --git a/configure.ac b/configure.ac
index 16309ed..892cfdc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,6 +19,17 @@ PKG_CHECK_MODULES(GLIB, [$glib_modules])
 gio_modules="glib-2.0 gthread-2.0 gio-2.0"
 PKG_CHECK_MODULES(GIO, [$gio_modules])
 
+
+PKG_CHECK_MODULES(GDBUS, [gio-2.0 >= 2.26], have_gdbus=yes, have_gdbus=no)
+if test "x$have_gdbus" = "xyes"; then
+   AC_DEFINE(HAVE_GDBUS,1, [Set if gdbus is available])
+else
+   PKG_CHECK_MODULES(DBUS, ["dbus-1"])
+fi
+
+AM_CONDITIONAL([HAVE_GDBUS], [test "x$have_gdbus" = "xyes"])
+AC_SUBST(HAVE_GDBUS)
+
 fuse_modules="fuse"
 PKG_CHECK_MODULES(FUSE, [$fuse_modules])
 
diff --git a/fs.c b/fs.c
index 664f1e2..e99ba85 100644
--- a/fs.c
+++ b/fs.c
@@ -22,6 +22,10 @@
 #include "glick.h"
 #include "format.h"
 
+#ifndef HAVE_GDBUS
+#include "dbus-utils.h"
+#endif
+
 typedef enum {
   GLICK_INODE_FLAGS_NONE = 0,
   GLICK_INODE_FLAGS_OWNED = 1 << 0,
@@ -3220,7 +3224,7 @@ sha1_digest_hash (gconstpointer  key)
   return *p;
 }
 
-#if GLIB_CHECK_VERSION(2, 26, 0)
+#ifdef HAVE_GDBUS
 static void
 session_bus_died (GDBusConnection *connection,
 		  gboolean         remote_peer_vanished,
@@ -3228,6 +3232,29 @@ session_bus_died (GDBusConnection *connection,
 {
   g_main_loop_quit (mainloop);
 }
+#else
+static DBusHandlerResult
+fs_dbus_filter (DBusConnection *connection,
+		DBusMessage *message,
+		void *user_data)
+{
+  gboolean handled = TRUE;
+  DBusError error;
+
+  g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+  g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
+  dbus_error_init (&error);
+  if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected"))
+    g_main_loop_quit (mainloop);
+  else
+    handled = FALSE;
+
+  if (dbus_error_is_set (&error))
+    dbus_error_free (&error);
+
+  return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+}
 #endif
 
 int
@@ -3274,19 +3301,33 @@ main (int argc, char *argv[])
 
   if (die_with_session)
     {
-#if GLIB_CHECK_VERSION(2, 26, 0)
+#ifdef HAVE_GDBUS
       GDBusConnection *connection;
       connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
       if (connection == NULL)
 	{
-	  g_printerr ("Unable to connect to session bus, but --die-with-session specified\n");
+	  g_printerr ("Unable to connect to session bus, but --exit-with-session specified\n");
 	  return 1;
 	}
       g_dbus_connection_set_exit_on_close (connection, FALSE);
       g_signal_connect (connection, "closed",
 			G_CALLBACK (session_bus_died), NULL);
 #else
-      g_printerr ("No GDBus support in glib, but --die-with-session specified, will leak session process\n");
+      DBusConnection *connection;
+
+      connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+      if (connection == NULL)
+	{
+	  g_printerr ("Unable to connect to session bus, but --exit-with-session specified\n");
+	  return 1;
+	}
+      dbus_connection_set_exit_on_disconnect (connection, FALSE);
+      _g_dbus_connection_integrate_with_main  (connection);
+      if (!dbus_connection_add_filter (connection, fs_dbus_filter, NULL, NULL))
+	{
+	  g_printerr ("Unable to add dbus filter\n");
+	  return 1;
+	}
 #endif
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]