From: PHO Date: Sat, 27 Dec 2008 13:45:35 +0000 (+0900) Subject: Removed unportable dependency on . X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=daemon.git;a=commitdiff_plain;h=9c6b9ad6e19924196d66bba74bd87bc91ebf1fef Removed unportable dependency on . --- diff --git a/configure.ac b/configure.ac index a48bcd1..bb8b380 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ([2.63]) +AC_PREREQ([2.6]) AC_INIT([daemon], [1.8], [pho@cielonegro.org]) AM_INIT_AUTOMAKE @@ -26,6 +26,7 @@ AC_TYPE_SSIZE_T # Checks for library functions. AC_CHECK_FUNCS([ftruncate]) AC_CHECK_FUNCS([strtol]) +AC_CHECK_FUNCS([strerror]) AC_FUNC_MALLOC AC_CONFIG_FILES([ diff --git a/daemon.c b/daemon.c index 82b19a1..5b769dd 100644 --- a/daemon.c +++ b/daemon.c @@ -33,10 +33,10 @@ #include -#include #include #include #include +#include #include #include @@ -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); } diff --git a/pidfile.c b/pidfile.c index 8fc42c9..b699efb 100644 --- a/pidfile.c +++ b/pidfile.c @@ -36,7 +36,6 @@ #include #include #include -#include #include static int _pidfile_remove(struct pidfh *pfh, int freeit);