]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[main] Write the pid of plymouthd to a file
authorScott James Remnant <scott@ubuntu.com>
Tue, 2 Mar 2010 19:52:25 +0000 (19:52 +0000)
committerScott James Remnant <scott@ubuntu.com>
Tue, 2 Mar 2010 19:52:25 +0000 (19:52 +0000)
Add a --pid-file option to plymouthd that will cause the daemon's
pid to be written to the named file.  Useful to avoid grovelling
through ps output to find it again.

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

index b26773c5fd8dbe02cfd40e4c9a6e8a55038283b9..cbc64732c16bcb9bf24d499ecc4137cb4181f152 100644 (file)
@@ -794,7 +794,7 @@ ply_show_new_kernel_messages (bool should_show)
 }
 
 ply_daemon_handle_t *
-ply_create_daemon (void)
+ply_create_daemon (const char *pid_file)
 {
   pid_t pid;
   int sender_fd, receiver_fd;
@@ -820,6 +820,22 @@ ply_create_daemon (void)
           _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 5e41f841b6b36cd8cc04ea03d23680672c766053..712b8690b894a2ccc6317a168c8abe5def938d1c 100644 (file)
@@ -98,7 +98,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 (void);
+ply_daemon_handle_t *ply_create_daemon (const char *pid_file);
 bool ply_detach_daemon (ply_daemon_handle_t *handle,
                         int                  exit_code);
 
index af956eed9bdee9f7cae8a036ca23c8387de2539c..a714079c6fc1db62a1d495bc137661d779e34e04 100644 (file)
@@ -134,6 +134,7 @@ static void on_error_message (ply_buffer_t *debug_buffer,
                               size_t        number_of_bytes);
 static ply_buffer_t *debug_buffer;
 static char *debug_buffer_path = NULL;
+static char *pid_file = NULL;
 static void check_for_consoles (state_t    *state,
                                 const char *default_tty,
                                 bool        should_add_displays);
@@ -688,6 +689,13 @@ quit_program (state_t *state)
   ply_trace ("exiting event loop");
   ply_event_loop_exit (state->loop, 0);
 
+  if (pid_file != NULL)
+    {
+      unlink (pid_file);
+      free (pid_file);
+      pid_file = NULL;
+    }
+
 #ifdef PLY_ENABLE_GDM_TRANSITION
   if (state->should_retain_splash)
     {
@@ -1515,6 +1523,13 @@ on_crash (int signum)
         pause ();
       }
 
+    if (pid_file != NULL)
+      {
+       unlink (pid_file);
+       free (pid_file);
+       pid_file = NULL;
+      }
+
     signal (signum, SIG_DFL);
     raise(signum);
 }
@@ -1543,6 +1558,7 @@ main (int    argc,
                                   "debug", "Output debugging information", PLY_COMMAND_OPTION_TYPE_FLAG,
                                   "debug-file", "File to output debugging information to", PLY_COMMAND_OPTION_TYPE_STRING,
                                   "mode", "Mode is one of: boot, shutdown", PLY_COMMAND_OPTION_TYPE_STRING,
+                                 "pid-file", "Write the pid of the daemon to a file", PLY_COMMAND_OPTION_TYPE_STRING,
                                   NULL);
 
   if (!ply_command_parser_parse_arguments (state.command_parser, state.loop, argv, argc))
@@ -1564,6 +1580,7 @@ main (int    argc,
                                   "no-daemon", &no_daemon,
                                   "debug", &debug,
                                   "debug-file", &debug_buffer_path,
+                                 "pid-file", &pid_file,
                                   NULL);
 
   if (should_help)
@@ -1605,7 +1622,7 @@ main (int    argc,
 
   if (! no_daemon)
     {
-      daemon_handle = ply_create_daemon ();
+      daemon_handle = ply_create_daemon (pid_file);
 
       if (daemon_handle == NULL)
         {