diff options
author | Guillem Jover <guillem@debian.org> | 2012-05-01 04:41:20 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2012-05-04 06:59:44 +0200 |
commit | ee81253069c1cbf38d1724faa78e75c99223b5ae (patch) | |
tree | 7ab60331ec552fc61e21f3e6348ad43ccfd07786 | |
parent | 4bcc6b8e0a587b432b145fafa642674607cddddd (diff) | |
download | dpkg-ee81253069c1cbf38d1724faa78e75c99223b5ae.tar.gz |
s-s-d: Refactor pidfile writing into a new write_pidfile() function
-rw-r--r-- | utils/start-stop-daemon.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 397967515..48f2f1b7a 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -374,6 +374,21 @@ daemonize(void) } static void +write_pidfile(const char *filename, pid_t pid) +{ + FILE *fp; + + fp = fopen(filename, "w"); + if (fp == NULL) + fatal("unable to open pidfile '%s' for writing", filename); + + fprintf(fp, "%d\n", pid); + + if (fclose(fp)) + fatal("unable to close pidfile '%s'", filename); +} + +static void pid_list_push(struct pid_list **list, pid_t pid) { struct pid_list *p; @@ -1734,17 +1749,9 @@ main(int argc, char **argv) set_io_schedule(io_sched); if (umask_value >= 0) umask(umask_value); - if (mpidfile && pidfile != NULL) { + if (mpidfile && pidfile != NULL) /* User wants _us_ to make the pidfile. */ - FILE *pidf = fopen(pidfile, "w"); - pid_t pidt = getpid(); - if (pidf == NULL) - fatal("unable to open pidfile '%s' for writing", - pidfile); - fprintf(pidf, "%d\n", pidt); - if (fclose(pidf)) - fatal("unable to close pidfile '%s'", pidfile); - } + write_pidfile(pidfile, getpid()); if (changeroot != NULL) { if (chdir(changeroot) < 0) fatal("unable to chdir() to %s", changeroot); |