From: cee1 Date: Thu, 21 Apr 2011 19:18:13 +0000 (-0400) Subject: main: write pid file even when not daemonizing X-Git-Tag: 0.8.4~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1e9022f119d461dddc9569d90533fb0cf726f52;p=thirdparty%2Fplymouth.git main: write pid file even when not daemonizing 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. --- diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 7973f523..b021f2f2 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -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); diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index 25500107..cae2891a 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -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); diff --git a/src/main.c b/src/main.c index 40695d74..87101c0a 100644 --- a/src/main.c +++ b/src/main.c @@ -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)) {