[glick2] Add --exit-with-session argument to glick-fs



commit 961990621d6355b37420b08f4f269a5906f15d40
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Oct 13 15:47:24 2011 +0200

    Add --exit-with-session argument to glick-fs

 fs.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/fs.c b/fs.c
index 50a2c35..c201373 100644
--- a/fs.c
+++ b/fs.c
@@ -186,6 +186,8 @@ struct _GlickThreadOp {
 #define ENTRY_CACHE_TIMEOUT_SEC 10000
 #define ATTR_CACHE_TIMEOUT_SEC 10000
 
+static gboolean die_with_session = FALSE;
+
 static GlickInodeDir *glick_root;
 static GlickInodeDir *glick_bundles_dir;
 static GHashTable *glick_inodes; /* inode -> GlickInode */
@@ -3199,10 +3201,18 @@ sha1_digest_hash (gconstpointer  key)
   return *p;
 }
 
+static void
+session_bus_died (GDBusConnection *connection,
+		  gboolean         remote_peer_vanished,
+		  GError          *error)
+{
+  g_main_loop_quit (mainloop);
+}
+
 int
 main (int argc, char *argv[])
 {
-  struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
+  struct fuse_args args = FUSE_ARGS_INIT(1, argv);
   struct fuse_chan *ch;
   int err = -1;
   const char *homedir;
@@ -3210,6 +3220,17 @@ main (int argc, char *argv[])
   g_thread_init (NULL);
   g_type_init ();
 
+  if (argc > 1)
+    {
+      if (strcmp (argv[1], "--exit-with-session") == 0)
+	die_with_session = TRUE;
+      else
+	{
+	  g_printerr ("Unknown argument %s\n", argv[1]);
+	  return 1;
+	}
+    }
+
   glick_thread_pool = g_thread_pool_new (thread_pool_func, NULL, 20,
 					 FALSE, NULL);
 
@@ -3230,6 +3251,20 @@ main (int argc, char *argv[])
   glick_mountpoint = g_build_filename (homedir, ".glick", NULL);
   mkdir (glick_mountpoint, 0700);
 
+  if (die_with_session)
+    {
+      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");
+	  return 1;
+	}
+      g_dbus_connection_set_exit_on_close (connection, FALSE);
+      g_signal_connect (connection, "closed",
+			G_CALLBACK (session_bus_died), NULL);
+    }
+
   if ((ch = fuse_mount (glick_mountpoint, NULL)) != NULL)
     {
       struct fuse_session *se;



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