[gvfs/gdbus-core: 14/38] gdbus: Tweak mount finalization



commit 7bfd4a88d4314c211ea3d4641eee60c135b4b7c7
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Wed Apr 18 16:16:18 2012 +0200

    gdbus: Tweak mount finalization

 daemon/main.c  |    9 ++++++++-
 daemon/mount.c |   24 ++++++++++++++++++++----
 daemon/mount.h |    3 ++-
 3 files changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/daemon/main.c b/daemon/main.c
index 6cf186b..e88ccde 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -72,7 +72,13 @@ on_name_acquired (GDBusConnection *connection,
   g_warning ("main.c: Acquired the name %s on the session message bus\n", name);
   already_acquired = TRUE;
 
-  mount_init ();
+  if (! mount_init ())
+    {
+      /* we were not able to properly initialize ourselves, bail out */
+      g_main_loop_quit (loop);
+      return;
+    }
+
   
 #ifdef HAVE_FUSE
   if (!no_fuse)
@@ -194,6 +200,7 @@ main (int argc, char *argv[])
 
   g_main_loop_run (loop);
 
+  mount_finalize ();
 #if 0
   /* FIXME: crashing */
   if (daemon != NULL)
diff --git a/daemon/mount.c b/daemon/mount.c
index a46f7ef..0d08b46 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -73,6 +73,9 @@ static GList *mounts = NULL;
 
 static gboolean fuse_available;
 
+static GVfsDBusMountTracker *mount_tracker = NULL;
+
+
 static void lookup_mount (GVfsDBusMountTracker *object,
                           GDBusMethodInvocation *invocation,
                           GMountSpec *spec,
@@ -1020,15 +1023,17 @@ reload_pipes_cb (GIOChannel *io,
   return TRUE;
 }
 
-void
+gboolean
 mount_init (void)
 {
   GDBusConnection *conn;
   struct sigaction sa;
   GIOChannel *io;
-  GVfsDBusMountTracker *mount_tracker;
   GError *error;
+  gboolean res;
   
+  res = TRUE;
+
   read_mountable_config ();
 
   if (pipe (reload_pipes) != -1)
@@ -1050,7 +1055,7 @@ mount_init (void)
       g_warning ("Error connecting to session bus: %s (%s, %d)\n",
                   error->message, g_quark_to_string (error->domain), error->code);
       g_error_free (error);
-      return;  /* FIXME: gracefully return */
+      return FALSE;
     }
   
   mount_tracker = gvfs_dbus_mount_tracker_skeleton_new ();
@@ -1072,9 +1077,20 @@ mount_init (void)
                   error->message, g_quark_to_string (error->domain), error->code);
       g_error_free (error);
       g_object_unref (mount_tracker);
+      mount_tracker = NULL;
+      res = FALSE;
     }
   g_object_unref (conn);
   
-  /* TODO: keep reference for 'mount_tracker' */
+  return res;
 }
 
+void
+mount_finalize (void)
+{
+  if (mount_tracker != NULL)
+    {
+      g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (mount_tracker));
+      g_object_unref (mount_tracker);
+    }
+}
diff --git a/daemon/mount.h b/daemon/mount.h
index ff244b5..1a093a1 100644
--- a/daemon/mount.h
+++ b/daemon/mount.h
@@ -29,7 +29,8 @@
 
 G_BEGIN_DECLS
 
-void       mount_init             (void);
+gboolean   mount_init             (void);
+void       mount_finalize         (void);
 
 G_END_DECLS
 



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