}
ply_daemon_handle_t *
-ply_create_daemon (void)
+ply_create_daemon (const char *pid_file)
{
pid_t pid;
int sender_fd, receiver_fd;
_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);
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);
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);
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)
{
pause ();
}
+ if (pid_file != NULL)
+ {
+ unlink (pid_file);
+ free (pid_file);
+ pid_file = NULL;
+ }
+
signal (signum, SIG_DFL);
raise(signum);
}
"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))
"no-daemon", &no_daemon,
"debug", &debug,
"debug-file", &debug_buffer_path,
+ "pid-file", &pid_file,
NULL);
if (should_help)
if (! no_daemon)
{
- daemon_handle = ply_create_daemon ();
+ daemon_handle = ply_create_daemon (pid_file);
if (daemon_handle == NULL)
{