← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~bratsche/xsplash/daemon into lp:xsplash

 

Cody Russell has proposed merging lp:~bratsche/xsplash/daemon into lp:xsplash.

Requested reviews:
    Scott James Remnant (scott)
-- 
https://code.launchpad.net/~bratsche/xsplash/daemon/+merge/11731
Your team ayatana-commits is subscribed to branch lp:xsplash.
=== modified file 'src/xsplash.c'
--- src/xsplash.c	2009-09-08 16:11:32 +0000
+++ src/xsplash.c	2009-09-14 19:58:07 +0000
@@ -125,6 +125,7 @@
 static guint     throbber_frames  = 50;
 static gboolean  ping_pong        = FALSE;
 static gboolean  have_xcomposite  = FALSE;
+static gboolean  daemon_mode      = FALSE;
 static gboolean  is_composited    = FALSE;
 static gboolean  redirected       = FALSE;
 static GSList   *signal_list      = NULL;
@@ -141,6 +142,11 @@
     "Filename for background image", NULL
   },
   {
+    "daemon", 'd', 0,
+    G_OPTION_ARG_NONE, &daemon_mode,
+    "Run in daemon mode", NULL
+  },
+  {
     "logo", 'l', 0,
     G_OPTION_ARG_FILENAME, &logo_image,
     "Filename for logo image", NULL
@@ -828,6 +834,7 @@
   guint            nameret = 0;
   struct passwd *pwd;
   uid_t uid;
+  pid_t pid, sid;
 
   pwd = getpwnam (XSPLASH_USER);
   if (pwd == NULL)
@@ -850,6 +857,33 @@
       exit (1);
     }
 
+  if (daemon_mode)
+    {
+      /* fork from our parent process */
+      pid = fork ();
+
+      if (pid < 0)
+        exit (EXIT_FAILURE);
+
+      if (pid > 0)
+        exit (EXIT_SUCCESS);
+
+      sid = setsid ();
+      if (sid < 0)
+        exit (EXIT_FAILURE);
+
+      pwd = getpwnam (XSPLASH_USER);
+      if (pwd == NULL)
+        {
+          g_error ("Unknown user: %s", XSPLASH_USER);
+          return 1;
+        }
+
+      uid = pwd->pw_uid;
+
+      setuid (uid);
+    }
+
   gtk_init (&argc, &argv);
 
   log_init (XSPLASH_LOG); g_message ("xsplash started");


Follow ups