From 03e58b3b43c67cd74c2c8aae471366a224883509 Mon Sep 17 00:00:00 2001 From: Scott James Remnant Date: Tue, 2 Mar 2010 19:52:25 +0000 Subject: [PATCH] [main] Write the pid of plymouthd to a file 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 | 18 +++++++++++++++++- src/libply/ply-utils.h | 2 +- src/main.c | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index b26773c5..cbc64732 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -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); diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index 5e41f841..712b8690 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -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); diff --git a/src/main.c b/src/main.c index af956eed..a714079c 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { -- 2.47.3