]> Pileus Git - ~andy/fetchmail/blobdiff - daemon.c
Working version of Debian changelog code.
[~andy/fetchmail] / daemon.c
index 5c66ed5ad9ee9b7bf0daaad86bf3ead9377f4267..5937524b201bedd945ff8e8a29f14dc996daa6ff 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -85,7 +85,7 @@ daemonize (const char *logfile, void (*termhook)(int))
 {
   int fd;
   pid_t childpid;
-  RETSIGTYPE sigchld_handler();
+  RETSIGTYPE sigchld_handler(int);
 
   /* if we are started by init (process 1) via /etc/inittab we needn't 
      bother to detach from our process group context */
@@ -109,7 +109,7 @@ daemonize (const char *logfile, void (*termhook)(int))
      group leader */
 
   if ((childpid = fork()) < 0) {
-    error(0, errno, "fork");
+    report(stderr, "fork (%s)\n", strerror(errno));
     return(PS_IOERR);
   }
   else if (childpid > 0) 
@@ -122,13 +122,14 @@ daemonize (const char *logfile, void (*termhook)(int))
 #if    defined(HAVE_SETSID)            /* POSIX */
   /* POSIX makes this soooo easy to do */
   if (setsid() < 0) {
-    error(0, errno, "setsid");
+    report(stderr, "setsid (%s)\n", strerror(errno));
     return(PS_IOERR);
   }
 #elif  defined(SIGTSTP)                /* BSD */
   /* change process group */
+#ifndef __EMX__
   setpgrp(0, getpid());
-
+#endif
   /* lose controlling tty */
   if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
     ioctl(fd, TIOCNOTTY, (char *) 0);
@@ -136,12 +137,14 @@ daemonize (const char *logfile, void (*termhook)(int))
   }
 #else                                  /* SVR3 and older */
   /* change process group */
+#ifndef __EMX__
   setpgrp();
+#endif
   
   /* lose controlling tty */
   signal(SIGHUP, SIG_IGN);
   if ((childpid = fork()) < 0) {
-    error(0, errno, "fork");
+    report(stderr, "fork (%)\n", strerror(errno));
     return(PS_IOERR);
   }
   else if (childpid > 0) {
@@ -165,7 +168,7 @@ nottyDetach:
 
   /* Reopen stdin descriptor on /dev/null */
   if ((fd = open("/dev/null", O_RDWR)) < 0) {   /* stdin */
-    error(0, errno, "open: /dev/null");
+    report(stderr, "open: /dev/null (%s)\n", strerror(errno));
     return(PS_IOERR);
   }
 
@@ -173,11 +176,11 @@ nottyDetach:
     fd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0666);       /* stdout */
   else
     if (dup(fd) < 0) {                         /* stdout */
-      error(0, errno, "dup");
+      report(stderr, "dup (%s)\n", strerror(errno));
       return(PS_IOERR);
     }
   if (dup(fd) < 0) {                           /* stderr */
-    error(0, errno, "dup");
+    report(stderr, "dup (%s)\n", strerror(errno));
     return(PS_IOERR);
   }