[PATCH] [main] Write the pid of plymouthd to a file
Scott James Remnant
scott at ubuntu.com
Tue Mar 2 08:38:55 PST 2010
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.
Author: Alberto Milone <alberto.milone at canonical.com>
Signed-off-by: Scott James Remnant <scott at ubuntu.com>
---
src/libply/ply-utils.c | 25 ++++++++++++++++++++++++-
src/libply/ply-utils.h | 4 +++-
src/main.c | 19 ++++++++++++++++++-
3 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
index b26773c..4b40e67 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", pid);
+ fclose (pidf);
+ }
+ }
+
_exit ((int) byte);
}
close (receiver_fd);
@@ -853,6 +869,13 @@ ply_detach_daemon (ply_daemon_handle_t *handle,
return true;
}
+void
+ply_remove_pid_file (const char *pid_file)
+{
+ if (ply_file_exists (pid_file))
+ unlink (pid_file);
+}
+
/* UTF-8 encoding
00000000-01111111 00-7F US-ASCII (single byte)
diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h
index 5e41f84..16f37ad 100644
--- a/src/libply/ply-utils.h
+++ b/src/libply/ply-utils.h
@@ -98,10 +98,12 @@ 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);
+void ply_remove_pid_file (const char *pid_file);
+
int ply_utf8_character_get_size (const char *string,
size_t n);
int ply_utf8_string_get_length (const char *string,
diff --git a/src/main.c b/src/main.c
index af956ee..9dbd293 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)
+ {
+ ply_remove_pid_file (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)
+ {
+ ply_remove_pid_file (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)
{
--
1.6.3.3
More information about the plymouth
mailing list