A number of cleanups. Now compiles with libc5, glibc, and uClibc. Fix a few
[oweals/busybox.git] / klogd.c
diff --git a/klogd.c b/klogd.c
index 7f7d6a142c3236407bfd1ef9f0c1ab3f6af09bb0..241a99175fa8f4e1c4c6f81711e1c3f1207f17f3 100644 (file)
--- a/klogd.c
+++ b/klogd.c
 #include <ctype.h>
 #include <sys/syslog.h>
 
-#if ! defined __GLIBC__ && ! defined __UCLIBC__
-#include <sys/syscall.h>
-#include <linux/unistd.h>
-typedef unsigned int socklen_t;
-
-#ifndef __alpha__
-# define __NR_klogctl __NR_syslog
-static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
-#else                                                  /* __alpha__ */
-#define klogctl syslog
-#endif
-
+#if __GNU_LIBRARY__ < 5
+# ifdef __alpha__
+#   define klogctl syslog
+# endif
 #else
 # include <sys/klog.h>
 #endif
+
 #include "busybox.h"
 
 static void klogd_signal(int sig)
@@ -125,18 +118,10 @@ static void doKlogd (void)
        }
 }
 
-static void daemon_init (char **argv, char *dz, void fn (void))
-{
-       setsid(); /* start a new session? */
-       strncpy(argv[0], dz, strlen(argv[0]));
-       fn();
-       exit(0);
-}
-
 extern int klogd_main(int argc, char **argv)
 {
        /* no options, no getopt */
-       int opt, pid;
+       int opt;
        int doFork = TRUE;
 
        /* do normal option parsing */
@@ -151,15 +136,10 @@ extern int klogd_main(int argc, char **argv)
        }
 
        if (doFork == TRUE) {
-               pid = fork();
-               if (pid < 0)
-                       exit(pid);
-               else if (pid == 0) {
-                       daemon_init (argv, "klogd", doKlogd);
-               }
-       } else {
-               doKlogd();
+               if (daemon(0, 1) < 0)
+                       perror_msg_and_die("daemon");
        }
+       doKlogd();
        
        return EXIT_SUCCESS;
 }