/*
- * install_init_scripts() -- Make sure "webserver" is in /etc/inittab
+ * install_init_scripts() -- Create and deploy SysV init scripts.
*
*/
void install_init_scripts(void)
"\n"
"start) echo -n \"Starting WebCit... \"\n"
" if $WEBCIT_DIR/webserver "
- "-d/var/run/webcit.pid "
+ "-D/var/run/webcit.pid "
"-t/dev/null "
"-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
" then\n"
#ifdef HAVE_OPENSSL
fprintf(fp, " echo -n \"Starting WebCit SSL... \"\n"
" if $WEBCIT_DIR/webserver "
- "-d/var/run/webcit-ssl.pid "
+ "-D/var/run/webcit-ssl.pid "
"-t/dev/null "
"-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
" then\n"
#define SLEEPING 180 /* TCP connection timeout */
#define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
#define PORT_NUM 2000 /* port number to listen on */
-#define SERVER "WebCit v7.00" /* who's in da house */
+#define SERVER "WebCit v7.02" /* who's in da house */
#define DEVELOPER_ID 0
#define CLIENT_ID 4
-#define CLIENT_VERSION 700 /* This version of WebCit */
+#define CLIENT_VERSION 702 /* This version of WebCit */
#define MINIMUM_CIT_VERSION 690 /* min required Citadel ver. */
#define DEFAULT_HOST "localhost" /* Default Citadel server */
#define DEFAULT_PORT "504"
#define DEFAULT_HTTPAUTH_USER ""
#define DEFAULT_HTTPAUTH_PASS ""
+
+/* Exit codes 101 through 109 are initialization failures so we don't want to
+ * just keep respawning indefinitely.
+ */
+#define WC_EXIT_BIND 101 /* Can't bind to the port */
+#define WC_EXIT_SSL 102 /* Can't initialize SSL */
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':