[gvfs] Adds infrastructure for the backends to exit cleanly



commit 517ae68514f5489c5494d0a3c667a727d1bf2681
Author: Timothy Arceri <t_arceri yahoo com au>
Date:   Fri Apr 12 19:38:51 2013 +1000

    Adds infrastructure for the backends to exit cleanly
    
    https://bugzilla.gnome.org/show_bug.cgi?id=511802

 daemon/gvfsdaemon.c | 22 +++++++++++++++++++---
 daemon/gvfsdaemon.h |  3 +++
 daemon/main.c       | 10 ++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
index c0ac8ca..6cb3341 100644
--- a/daemon/gvfsdaemon.c
+++ b/daemon/gvfsdaemon.c
@@ -46,6 +46,11 @@ enum {
   PROP_0
 };
 
+enum {
+  SHUTDOWN,
+  LAST_SIGNAL
+};
+
 typedef struct {
   char *obj_path;
   GVfsRegisterPathCallback callback;
@@ -86,6 +91,8 @@ typedef struct {
   GDBusConnection *conn;
 } NewConnectionData;
 
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static void              g_vfs_daemon_get_property (GObject        *object,
                                                    guint           prop_id,
                                                    GValue         *value,
@@ -173,6 +180,15 @@ g_vfs_daemon_class_init (GVfsDaemonClass *klass)
   gobject_class->finalize = g_vfs_daemon_finalize;
   gobject_class->set_property = g_vfs_daemon_set_property;
   gobject_class->get_property = g_vfs_daemon_get_property;
+
+  signals[SHUTDOWN] =
+    g_signal_new ("shutdown",
+                 G_TYPE_FROM_CLASS (gobject_class),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (GVfsDaemonClass, shutdown),
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 }
 
 static void
@@ -344,9 +360,9 @@ g_vfs_daemon_set_max_threads (GVfsDaemon                    *daemon,
 }
 
 static gboolean
-exit_at_idle (gpointer data)
+exit_at_idle (GVfsDaemon *daemon)
 {
-  exit (0);
+  g_signal_emit (daemon, signals[SHUTDOWN], 0);
   return FALSE;
 }
 
@@ -364,7 +380,7 @@ static void
 daemon_schedule_exit (GVfsDaemon *daemon)
 {
   if (daemon->exit_tag == 0)
-    daemon->exit_tag = g_timeout_add_seconds (1, exit_at_idle, daemon);
+    daemon->exit_tag = g_timeout_add_seconds (1, (GSourceFunc)exit_at_idle, daemon);
 }
 
 static void
diff --git a/daemon/gvfsdaemon.h b/daemon/gvfsdaemon.h
index d28fb8f..371dbd4 100644
--- a/daemon/gvfsdaemon.h
+++ b/daemon/gvfsdaemon.h
@@ -45,6 +45,9 @@ struct _GVfsDaemonClass
 {
   GObjectClass parent_class;
 
+  /* signals */
+  void (*shutdown) (GVfsDaemon *daemon);
+
   /* vtable */
   
 };
diff --git a/daemon/main.c b/daemon/main.c
index 1661442..f394a32 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -118,6 +118,13 @@ on_name_acquired (GDBusConnection *connection,
 #endif
 }
 
+static void
+daemon_shutdown (GVfsDaemon *daemon,
+                 GMainLoop  *loop)
+{
+  if (g_main_loop_is_running (loop))
+    g_main_loop_quit (loop);
+}
 
 int
 main (int argc, char *argv[])
@@ -181,6 +188,9 @@ main (int argc, char *argv[])
   if (daemon == NULL)
     return 1;
 
+  g_signal_connect (daemon, "shutdown",
+                   G_CALLBACK (daemon_shutdown), loop);
+
   flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
   if (replace)
     flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;


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