From c4ba6192dda8b5e5165754fc1f46d982cfdf57d0 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sun, 7 Jul 2013 19:42:28 -0700 Subject: [PATCH] Switch to GNU daemon() call --- src/a2pid.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/a2pid.c b/src/a2pid.c index 9fe77ce..3590332 100755 --- a/src/a2pid.c +++ b/src/a2pid.c @@ -540,33 +540,9 @@ void main(int argc, char **argv) */ if (strcmp(argv[1], "--daemon") == 0) { - pid_t pid, sid; /* our process ID and Session ID */ - - pid = fork(); /* fork off the parent process */ - if (pid < 0) - die("a2pid: fork() failure"); - /* - * If we got a good PID, then - * we can exit the parent process - */ - if (pid > 0) - exit(EXIT_SUCCESS); - umask(0); /* change the file mode mask */ - /* - * Open any logs here - */ - sid = setsid(); /* create a new SID for the child process */ - if (sid < 0) - die("a2pid: setsid() failure"); - if ((chdir("/")) < 0) /* change the current working directory */ - die("a2pid: chdir() failure"); - /* - * Close out the standard file descriptors - */ - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - isdaemon = TRUE; + if (daemon(0, 0) != 0) + die("a2pid: daemon() failure"); + isdaemon = TRUE; /* * Another argument must be tty device */