]> Pileus Git - ~andy/fetchmail/blobdiff - daemon.c
Added URL.
[~andy/fetchmail] / daemon.c
index 985fe65b5e3e763048506c0c5debdae4091903fc..e7b9214bb218270560163f4528573404d4bf0edd 100644 (file)
--- a/daemon.c
+++ b/daemon.c
 #include <errno.h>
 #include <signal.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
+#else /* !HAVE_FCNTL_H */
 #ifdef HAVE_SYS_FCNTL_H
 #include <sys/fcntl.h>
 #endif /* HAVE_SYS_FCNTL_H */
+#endif /* !HAVE_FCNTL_H */
 #include <sys/stat.h>  /* get umask(2) prototyped */
 
 #if defined(HAVE_UNISTD_H)
 #include <unix.h>
 #endif
 
-#if defined(HAVE_SGTTY_H)
+#if !defined(HAVE_SETSID) && defined(SIGTSTP)
+#if defined(HAVE_TERMIOS_H)
+#  include <termios.h>         /* for TIOCNOTTY under Linux */
+#endif
+
+#if !defined(TIOCNOTTY) && defined(HAVE_SGTTY_H)
 #  include <sgtty.h>           /* for TIOCNOTTY under NEXTSTEP */
 #endif
+#endif /* !defined(HAVE_SETSID) && defined(SIGTSTP) */
 
 /* BSD portability hack */
 #if !defined(SIGCHLD) && defined(SIGCLD)
@@ -47,28 +56,27 @@ RETSIGTYPE
 sigchld_handler (int sig)
 /* process SIGCHLD to obtain the exit code of the terminating process */
 {
-  pid_t pid;
+    pid_t pid;
 
-#if defined(HAVE_UNION_WAIT)
-  union wait status;
-#else
-  int status;
-#endif
+#if    defined(HAVE_WAITPID)                           /* the POSIX way */
+    int status;
 
-#if    defined(HAVE_WAIT3)
-#ifdef oldhpux /* HP-UX fixed this sometime between 9.01 and 10.20 */
-  while ((pid = wait3(&status, WNOHANG, (int *) 0)) > 0)
+    while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
+       continue; /* swallow 'em up. */
+#elif  defined(HAVE_WAIT3)                             /* the BSD way */
+#if defined(HAVE_UNION_WAIT) && !defined(__FreeBSD__)
+    union wait status;
 #else
-  while ((pid = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0)
+    int status;
 #endif
-    ; /* swallow 'em up. */
-#elif  defined(HAVE_WAITPID)
-  while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
-    ; /* swallow 'em up. */
+
+    while ((pid = wait3(&status, WNOHANG, 0)) > 0)
+       continue; /* swallow 'em up. */
 #else  /* Zooks! Nothing to do but wait(), and hope we don't block... */
-  wait(&status);
-#endif
+    int status;
 
+    wait(&status);
+#endif
 }
 
 int
@@ -119,8 +127,9 @@ daemonize (const char *logfile, void (*termhook)(int))
   }
 #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);
@@ -128,7 +137,9 @@ 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);