]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
main: write pid file even when not daemonizing
authorcee1 <fykcee1@gmail.com>
Thu, 21 Apr 2011 19:18:13 +0000 (15:18 -0400)
committerRay Strode <rstrode@redhat.com>
Thu, 21 Apr 2011 19:20:47 +0000 (15:20 -0400)
This commit moves the pid file writing code to main
from ply_create_daemon, so that it gets run even when we
plymouthd isn't daemonized.

This is more symmetrical, anyway, since unlinking of the pid
file is handled in main.

src/libply/ply-utils.c
src/libply/ply-utils.h
src/main.c

index 7973f523a1523adaebc7b2902d43a88543e367f7..b021f2f22d3a8851c042e8765005910493d7127b 100644 (file)
@@ -836,7 +836,7 @@ ply_show_new_kernel_messages (bool should_show)
 }
 
 ply_daemon_handle_t *
-ply_create_daemon (const char *pid_file)
+ply_create_daemon (void)
 {
   pid_t pid;
   int sender_fd, receiver_fd;
@@ -875,22 +875,6 @@ ply_create_daemon (const char *pid_file)
           _exit (1);
         }
 
-      if ((byte == 0) && (pid_file != NULL))
-        {
-          FILE *pidf;
-
-          pidf = fopen (pid_file, "w");
-          if (!pidf)
-            {
-              ply_error ("could not write pid file %s: %m", pid_file);
-            }
-          else
-            {
-              fprintf (pidf, "%d\n", (int)pid);
-              fclose (pidf);
-            }
-        }
-
       _exit ((int) byte);
     }
   close (receiver_fd);
index 25500107ea0254e265db1cbb86763e8e00888ed1..cae2891ac32d793b07fc71bfb66576806369408d 100644 (file)
@@ -108,7 +108,7 @@ bool ply_create_file_link (const char *source,
                            const char *destination);
 void ply_show_new_kernel_messages (bool should_show);
 
-ply_daemon_handle_t *ply_create_daemon (const char *pid_file);
+ply_daemon_handle_t *ply_create_daemon (void);
 bool ply_detach_daemon (ply_daemon_handle_t *handle,
                         int                  exit_code);
 
index 40695d7467d82af5e6dbd9f418e4f6fa89f3b2ee..87101c0a394f995e9758139ace54d95b4bcad9a8 100644 (file)
@@ -2034,6 +2034,23 @@ on_crash (int signum)
     raise(signum);
 }
 
+static void
+write_pid_file (const char *filename)
+{
+  FILE *fp;
+
+  fp = fopen (filename, "w");
+  if (fp == NULL)
+    {
+      ply_error ("could not write pid file %s: %m", filename);
+    }
+  else
+    {
+      fprintf (fp, "%d\n", (int) getpid ());
+      fclose (fp);
+    }
+}
+
 int
 main (int    argc,
       char **argv)
@@ -2140,7 +2157,7 @@ main (int    argc,
 
   if (! no_daemon)
     {
-      daemon_handle = ply_create_daemon (pid_file);
+      daemon_handle = ply_create_daemon ();
 
       if (daemon_handle == NULL)
         {
@@ -2205,6 +2222,9 @@ main (int    argc,
       return EX_UNAVAILABLE;
     }
 
+  if (pid_file != NULL)
+    write_pid_file (pid_file);
+
   if (daemon_handle != NULL
       && !ply_detach_daemon (daemon_handle, 0))
     {