if (port_number == 0) {
lprintf(1, "Cannot start: no port number specified.\n");
- exit(1);
+ exit(WC_EXIT_BIND);
}
sin.sin_port = htons((u_short) port_number);
s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
if (s < 0) {
lprintf(1, "Can't create a socket: %s\n", strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
/** Set some socket options that make sense. */
i = 1;
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
lprintf(1, "Can't bind: %s\n", strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
if (listen(s, queue_len) < 0) {
lprintf(1, "Can't listen: %s\n", strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
return (s);
}
if (i != 0) if (errno != ENOENT) {
lprintf(1, "citserver: can't unlink %s: %s\n",
sockpath, strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
memset(&addr, 0, sizeof(addr));
if (s < 0) {
lprintf(1, "citserver: Can't create a socket: %s\n",
strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
lprintf(1, "citserver: Can't bind: %s\n",
strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
if (listen(s, actual_queue_len) < 0) {
lprintf(1, "citserver: Can't listen: %s\n",
strerror(errno));
- exit(errno);
+ exit(WC_EXIT_BIND);
}
chmod(sockpath, 0777);
child = fork();
if (child != 0) {
- fp = fopen(pid_file, "w");
- if (fp != NULL) {
- fprintf(fp, "%d\n", child);
- fclose(fp);
+ if (pid_file) {
+ fp = fopen(pid_file, "w");
+ if (fp != NULL) {
+ fprintf(fp, "%d\n", child);
+ fclose(fp);
+ }
}
exit(0);
}
} while (do_restart);
- unlink(pid_file);
+ if (pid_file) {
+ unlink(pid_file);
+ }
exit(WEXITSTATUS(status));
}
int home_specified=0;
char relhome[PATH_MAX]="";
char webcitdir[PATH_MAX] = DATADIR;
- char pidfile[PATH_MAX] = "";
+ char *pidfile = NULL;
char *hdir;
const char *basedir;
#ifdef ENABLE_NLS
/** Parse command line */
#ifdef HAVE_OPENSSL
- while ((a = getopt(argc, argv, "h:i:p:t:x:d:cfs")) != EOF)
+ while ((a = getopt(argc, argv, "h:i:p:t:x:dD:cfs")) != EOF)
#else
- while ((a = getopt(argc, argv, "h:i:p:t:x:d:cf")) != EOF)
+ while ((a = getopt(argc, argv, "h:i:p:t:x:dD:cf")) != EOF)
#endif
switch (a) {
case 'h':
home=1;
break;
case 'd':
- hdir = strdup(optarg);
- safestrncpy(pidfile, hdir,sizeof pidfile);
+ running_as_daemon = 1;
+ break;
+ case 'D':
+ pidfile = strdup(optarg);
running_as_daemon = 1;
break;
case 'i':