[canopy-httpd] r1109 committed - use exit codes from sysexits.h

3 views
Skip to first unread message

codesite...@google.com

unread,
Dec 4, 2010, 3:39:02 PM12/4/10
to canopy-s...@googlegroups.com
Revision: 1109
Author: phrakt
Date: Sat Dec 4 12:37:40 2010
Log: use exit codes from sysexits.h

http://code.google.com/p/canopy-httpd/source/detail?r=1109

Modified:
/trunk/src/sbin/httpd/httpd.c

=======================================
--- /trunk/src/sbin/httpd/httpd.c Mon Nov 29 20:18:37 2010
+++ /trunk/src/sbin/httpd/httpd.c Sat Dec 4 12:37:40 2010
@@ -41,6 +41,7 @@
#include <canopy/log.h>
#include <canopy/signal.h>
#include <canopy/string.h>
+#include <canopy/sysexits.h>

#include <http/http.h>
#include <http/acl.h>
@@ -184,7 +185,7 @@

/* before anything else, give libhttp a chance to initialize itself */
if (http_init() == -1)
- errx(1, "failed to initialize HTTP library");
+ errx(EX_SOFTWARE, "failed to initialize HTTP library");

CNP_LOG_CLRMASK(mask);
CNP_LOG_MASKPRI(mask, CNP_LOG_TRACE);
@@ -192,7 +193,7 @@
CNP_LOG_MASKPRI(mask, CNP_LOG_INFO);

if ((httpd_logchan = cnp_log_open("httpd", 0, mask)) == NULL)
- errx(1, "failed to allocate log channel");
+ errx(EX_SOFTWARE, "failed to allocate log channel");

cnp_log_setmask(cnp_logchan, mask);
cnp_log_setmask(http_logchan, mask);
@@ -205,12 +206,12 @@
*/
if ((httpd_mib = cnp_mib_alloc()) == NULL) {
httpd_log_err("failed to allocate server's MIB");
- httpd_exit(1);
+ httpd_exit(EX_SOFTWARE);
}

if (httpd_mib_populate() == -1) {
httpd_log_err("failed to populate MIB");
- httpd_exit(1);
+ httpd_exit(EX_SOFTWARE);
}

cnp_mib_bind(httpd_mib, "canopy.version.major", &httpd_version_major,
@@ -236,7 +237,7 @@
/* allocate the Access Control List with a deny-by-default policy */
if ((httpd_acls = http_acl_alloc(HTTP_ACL_DENY)) == NULL) {
httpd_log_err("failed to allocate server's ACL");
- httpd_exit(1);
+ httpd_exit(EX_SOFTWARE);
}

/* parse options */
@@ -245,7 +246,7 @@
case 'c':
if (strlcpy(httpd_conf_path, optarg,
sizeof(httpd_conf_path)) >= sizeof(httpd_conf_path))
- errx(1, "configuration path too long");
+ errx(EX_USAGE, "configuration path too long");
break;
case 'd':
httpd_debug();
@@ -262,19 +263,19 @@
/* maybe it's a group ID */
httpd_gid = atoi(optarg);
if ((grp = getgrgid(httpd_gid)) == NULL)
- errx(1, "group `%s' invalid", optarg);
+ errx(EX_DATAERR, "group `%s' invalid", optarg);

break;
case 'h':
httpd_usage();
- exit(0);
+ exit(EX_OK);

break; /* NOTREACHED */
case 'P':
len = strlcpy(httpd_pidfile_path, optarg,
sizeof(httpd_pidfile_path));
if (len >= sizeof(httpd_pidfile_path))
- errx(1, "PID file path too long");
+ errx(EX_USAGE, "PID file path too long");
break;
case 'r':
httpd_flags |= HTTPD_FLAG_CHROOT;
@@ -282,7 +283,7 @@
len = strlcpy(httpd_chroot_path, optarg,
sizeof(httpd_chroot_path));
if (len >= sizeof(httpd_chroot_path))
- errx(1, "root directory path too long");
+ errx(EX_USAGE, "root directory path too long");
break;
case 'S':
httpd_flags |= HTTPD_FLAG_SYSLOG;
@@ -299,12 +300,12 @@
/* maybe it's a user ID */
httpd_uid = atoi(optarg);
if ((usr = getpwuid(httpd_uid)) == NULL)
- errx(1, "user `%s' invalid", optarg);
+ errx(EX_DATAERR, "user `%s' invalid", optarg);
break;
case 'V':
fprintf(stdout, "%s version 0.1 (built for %s/%s)\n",
httpd_server_ident, OS, MACHINE_ARCH);
- exit(0);
+ exit(EX_OK);

break; /* NOTREACHED */
case 'v':
@@ -318,36 +319,36 @@
}

if (httpd_subsys_init() == -1)
- errx(1, "failed to initialize subsystem manager");
+ errx(EX_SOFTWARE, "failed to initialize subsystem manager");

if (httpd_subsys_setlevel(HTTPD_SUBSYS_MAXLEVEL) == -1)
- httpd_exit(1);
+ httpd_exit(EX_SOFTWARE);

if (httpd_conf_load() == -1)
- httpd_exit(1);
+ httpd_exit(EX_CONFIG);

/* change our root directory if specified */
if ((httpd_flags & HTTPD_FLAG_CHROOT) && (httpd_chroot() == -1))
- httpd_exit(1);
+ httpd_exit(EX_OSERR);

if ((httpd_flags & HTTPD_FLAG_PIDFILE) &&
(httpd_pidfile_create() == -1))
- httpd_exit(1);
+ httpd_exit(EX_CANTCREAT);

/* open the local control socket */
if ((httpd_flags & HTTPD_FLAG_CTLSOCK) && (httpd_ctl_open() == -1))
- httpd_exit(1);
+ httpd_exit(EX_CANTCREAT);

/* become a daemon */
if ((httpd_flags & HTTPD_FLAG_DAEMON) && (httpd_daemonize() == -1)) {
httpd_log_err("failed to become a daemon");
- httpd_exit(1);
+ httpd_exit(EX_OSERR);
}

/* drop privileges */
if ((httpd_uid > 0) || (httpd_gid > 0)) {
if (httpd_priv_drop() == -1)
- httpd_exit(1);
+ httpd_exit(EX_OSERR);
}
else {
httpd_gid = getgid();
@@ -364,10 +365,10 @@

httpd_log_cleanup();

- httpd_exit(0);
+ httpd_exit(EX_OK);

/* NOTREACHED */
- return (0);
+ return (EX_OK);
}

/*
@@ -441,7 +442,7 @@
httpd_log_errno("failed to fork");
return (-1);
} else if (pid > 0) {
- _exit(0);
+ _exit(EX_OK);
}

if (setsid() == -1) {
@@ -453,7 +454,7 @@
httpd_log_errno("failed to fork");
return (-1);
} else if (pid > 0) {
- _exit(0);
+ _exit(EX_OK);
}

(void)chdir("/");

Reply all
Reply to author
Forward
0 new messages