]> gitweb @ CieloNegro.org - daemon.git/blobdiff - daemon.c
Removed unportable dependency on <err.h>.
[daemon.git] / daemon.c
index 82b19a1cb1e8ad31693de99ccfd4ca6ae2adb5bd..5b769dd49863cee1d56c120217edf75d0e870720 100644 (file)
--- a/daemon.c
+++ b/daemon.c
 
 #include <sys/param.h>
 
-#include <err.h>
 #include <errno.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
 
@@ -88,15 +88,20 @@ main(int argc, char *argv[])
                pfh = pidfile_open(pidfile, 0600, &otherpid);
                if (pfh == NULL) {
                        if (errno == EEXIST) {
-                               errx(3, "process already running, pid: %d",
-                                   otherpid);
+                fprintf(stderr, "process already running, pid: %d\n", otherpid);
+                exit(3);
                        }
-                       err(2, "pidfile ``%s''", pidfile);
+            else {
+                fprintf(stderr, "pidfile ``%s'': %s\n", pidfile, strerror(errno));
+                exit(2);
+            }
                }
        }
 
-       if (daemon(nochdir, noclose) == -1)
-               err(1, NULL);
+       if (daemon(nochdir, noclose) == -1) {
+        fprintf(stderr, "%s\n", strerror(errno));
+        exit(1);
+    }
 
        /* Now that we are the child, write out the pid */
        if (pidfile)
@@ -113,7 +118,8 @@ main(int argc, char *argv[])
                pidfile_remove(pfh);
 
        /* The child is now running, so the exit status doesn't matter. */
-       errc(1, errcode, "%s", argv[0]);
+    fprintf(stderr, "%s: %s\n", argv[0], strerror(errcode));
+    exit(1);
 }
 
 static void
@@ -122,18 +128,22 @@ restrict_process(const char *user)
        struct passwd *pw = NULL;
 
        pw = getpwnam(user);
-       if (pw == NULL)
-               errx(1, "unknown user: %s", user);
-
-    if (setuid(pw->pw_uid) != 0)
-        errx(1, "failed to setuid to %s", user);
+       if (pw == NULL) {
+        fprintf(stderr, "unknown user: %s\n", user);
+        exit(1);
+    }
+
+    if (setuid(pw->pw_uid) != 0) {
+        fprintf(stderr, "failed to setuid to %s\n", user);
+        exit(1);
+    }
 }
 
 static void
 usage(void)
 {
-       (void)fprintf(stderr,
-           "usage: daemon [-cf] [-p pidfile] [-u user] command "
-               "arguments ...\n");
+       fprintf(stderr,
+            "usage: daemon [-cf] [-p pidfile] [-u user] command "
+            "arguments ...\n");
        exit(1);
 }