[rygel] core: Restart application on SIGHUP



commit 256eeeeeca678ac975b40e626cbded86573c5364
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Jan 24 03:49:36 2010 +0200

    core: Restart application on SIGHUP

 src/rygel/cstuff.c        |   11 ++++++++++-
 src/rygel/cstuff.h        |    6 +++++-
 src/rygel/cstuff.vapi     |    8 +++++++-
 src/rygel/rygel-main.vala |   12 +++++++++++-
 4 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/src/rygel/cstuff.c b/src/rygel/cstuff.c
index 022f68b..93246e1 100644
--- a/src/rygel/cstuff.c
+++ b/src/rygel/cstuff.c
@@ -78,7 +78,11 @@ generate_random_udn (void)
 static void
 signal_handler (int signum)
 {
-        on_app_exit (data);
+        gboolean restart;
+
+        restart = (signum == SIGHUP);
+
+        on_app_exit (restart, data);
 }
 
 void
@@ -92,5 +96,10 @@ on_application_exit (ApplicationExitCb app_exit_cb,
         memset (&sig_action, 0, sizeof (sig_action));
         sig_action.sa_handler = signal_handler;
         sigaction (SIGINT, &sig_action, NULL);
+        sigaction (SIGHUP, &sig_action, NULL);
 }
 
+void
+restart_application (const char **args) {
+        execvp (args[0], args);
+}
diff --git a/src/rygel/cstuff.h b/src/rygel/cstuff.h
index 1ddbc63..ede0d40 100644
--- a/src/rygel/cstuff.h
+++ b/src/rygel/cstuff.h
@@ -29,7 +29,8 @@
 #include <glib.h>
 #include <uuid/uuid.h>
 
-typedef void (* ApplicationExitCb)      (gpointer user_data);
+typedef void (* ApplicationExitCb)      (gboolean restart,
+                                         gpointer user_data);
 
 G_GNUC_INTERNAL xmlNode *
 get_xml_element                         (xmlNode *node,
@@ -42,5 +43,8 @@ G_GNUC_INTERNAL void
 on_application_exit                     (ApplicationExitCb app_exit_cb,
                                          gpointer          user_data);
 
+G_GNUC_INTERNAL void
+restart_application                     (const char **args);
+
 #endif /* __CSTUFF_H__ */
 
diff --git a/src/rygel/cstuff.vapi b/src/rygel/cstuff.vapi
index 00870c5..e863be6 100644
--- a/src/rygel/cstuff.vapi
+++ b/src/rygel/cstuff.vapi
@@ -60,10 +60,16 @@ namespace CStuff {
         [CCode (cname = "generate_random_udn", cheader_filename = "cstuff.h")]
         public static string generate_random_udn ();
 
-        public delegate void ApplicationExitCb ();
+        public delegate void ApplicationExitCb (bool restart);
 
         [CCode (cname = "on_application_exit", cheader_filename = "cstuff.h")]
         public static void on_application_exit
                                         (ApplicationExitCb app_exit_cb);
+
+        [CCode (cname = "restart_application", cheader_filename = "cstuff.h")]
+        public static void restart_application (
+                                        [CCode (array_length = false,
+                                         array_null_terminated = true)]
+                                        string[] args);
     }
 }
diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala
index 855cc36..2f4d5ca 100644
--- a/src/rygel/rygel-main.vala
+++ b/src/rygel/rygel-main.vala
@@ -37,6 +37,7 @@ public class Rygel.Main : Object {
     private MainLoop main_loop;
 
     private int exit_code;
+    public bool restart;
 
     private Main () throws GLib.Error {
         Environment.set_application_name (_(BuildConfig.PACKAGE_NAME));
@@ -58,6 +59,7 @@ public class Rygel.Main : Object {
 
     public void exit (int exit_code) {
         this.exit_code = exit_code;
+
         this.main_loop.quit ();
     }
 
@@ -69,7 +71,9 @@ public class Rygel.Main : Object {
         return this.exit_code;
     }
 
-    private void application_exit_cb () {
+    private void application_exit_cb (bool restart) {
+        this.restart = restart;
+
         this.exit (0);
     }
 
@@ -188,6 +192,8 @@ public class Rygel.Main : Object {
         Main main;
         DBusService service;
 
+        var original_args = args;
+
         try {
             // Parse commandline options
             CmdlineConfig.parse_args (ref args);
@@ -210,6 +216,10 @@ public class Rygel.Main : Object {
 
         int exit_code = main.run ();
 
+        if (main.restart) {
+            Utils.restart_application (original_args);
+        }
+
         return exit_code;
     }
 }



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