diff options
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -7,6 +7,7 @@ #include <config.h> #include <stdio.h> +#include <errno.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> @@ -40,6 +41,7 @@ #endif #include "fetchmail.h" +#include "tunable.h" RETSIGTYPE sigchld_handler (int sig) @@ -95,7 +97,7 @@ daemonize (const char *logfile, void (*termhook)(int)) group leader */ if ((childpid = fork()) < 0) { - perror("fork"); + error(0, errno, "fork"); return(PS_IOERR); } else if (childpid > 0) @@ -108,7 +110,7 @@ daemonize (const char *logfile, void (*termhook)(int)) #if defined(HAVE_SETSID) /* POSIX */ /* POSIX makes this soooo easy to do */ if (setsid() < 0) { - perror("setsid"); + error(0, errno, "setsid"); return(PS_IOERR); } #elif defined(SIGTSTP) /* BSD */ @@ -127,7 +129,7 @@ daemonize (const char *logfile, void (*termhook)(int)) /* lose controlling tty */ signal(SIGHUP, SIG_IGN); if ((childpid = fork) < 0) { - perror("fork"); + error(0, errno, "fork"); return(PS_IOERR); } else if (childpid > 0) { @@ -151,7 +153,7 @@ nottyDetach: /* Reopen stdin descriptor on /dev/null */ if ((fd = open("/dev/null", O_RDWR)) < 0) { /* stdin */ - perror("open: /dev/null"); + error(0, errno, "open: /dev/null"); return(PS_IOERR); } @@ -159,11 +161,11 @@ nottyDetach: fd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0777); /* stdout */ else if (dup(fd) < 0) { /* stdout */ - perror("dup"); + error(0, errno, "dup"); return(PS_IOERR); } if (dup(fd) < 0) { /* stderr */ - perror("dup"); + error(0, errno, "dup"); return(PS_IOERR); } |