[Xfce4-commits] <xfce4-settings:master> Use daemon() for xfsettingsd if available.

Nick Schermer noreply at xfce.org
Mon Jun 13 18:18:02 CEST 2011


Updating branch refs/heads/master
         to ea01020acf4ac0047d1e3e19aa306be74602668f (commit)
       from 6d8de7184f4452ad503c270459f9192f9400bb41 (commit)

commit ea01020acf4ac0047d1e3e19aa306be74602668f
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Jun 13 18:16:17 2011 +0200

    Use daemon() for xfsettingsd if available.

 configure.ac.in    |    1 +
 xfsettingsd/main.c |   39 ++++++++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 311578d..3d33a53 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -64,6 +64,7 @@ dnl **********************************
 dnl *** Check for standard headers ***
 dnl **********************************
 AC_CHECK_HEADERS([errno.h memory.h math.h stdlib.h string.h unistd.h signal.h time.h sys/types.h])
+AC_CHECK_FUNCS([daemon setsid])
 
 dnl ******************************
 dnl *** Check for i18n support ***
diff --git a/xfsettingsd/main.c b/xfsettingsd/main.c
index 91758e1..3bcc920 100644
--- a/xfsettingsd/main.c
+++ b/xfsettingsd/main.c
@@ -108,6 +108,32 @@ dbus_connection_filter_func (DBusConnection     *connection,
 
 
 
+static gint
+daemonize (void)
+{
+#ifdef HAVE_DAEMON
+    return daemon (1, 1);
+#else
+    pid_t pid;
+
+    pid = fork ();
+    if (pid < 0)
+        return -1;
+
+    if (pid > 0)
+        _exit (EXIT_SUCCESS);
+
+#ifdef HAVE_SETSID
+    if (setsid () < 0)
+        return -1;
+#endif
+
+    return 0;
+#endif
+}
+
+
+
 gint
 main (gint argc, gchar **argv)
 {
@@ -124,7 +150,6 @@ main (gint argc, gchar **argv)
     GObject              *displays_helper;
 #endif
     GObject              *workspaces_helper;
-    pid_t                 pid;
     guint                 i;
     const gint            signums[] = { SIGQUIT, SIGTERM };
     DBusConnection       *dbus_connection;
@@ -216,19 +241,11 @@ main (gint argc, gchar **argv)
     /* daemonize the process */
     if (!opt_no_daemon)
     {
-        /* try to fork the process */
-        pid = fork ();
-
-        if (G_UNLIKELY (pid == -1))
+        if (daemonize () == -1)
         {
             /* show message and continue in normal mode */
             g_warning ("Failed to fork the process: %s. Continuing in non-daemon mode.", g_strerror (errno));
         }
-        else if (pid > 0)
-        {
-            /* succesfully created a fork */
-            _exit (EXIT_SUCCESS);
-        }
     }
 
     /* launch settings manager */
@@ -254,7 +271,7 @@ main (gint argc, gchar **argv)
         {
             g_object_unref (G_OBJECT (clipboard_daemon));
             clipboard_daemon = NULL;
-            
+
             g_printerr (G_LOG_DOMAIN ": %s\n", "Another clipboard manager is already running.");
         }
     }



More information about the Xfce4-commits mailing list