* -d to daemonize, -D to daemonize with specifying
authorArt Cancro <ajc@citadel.org>
Thu, 28 Dec 2006 16:34:20 +0000 (16:34 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 28 Dec 2006 16:34:20 +0000 (16:34 +0000)
  the pid file.  Updated setup.c to use this too.
* Bumped the version number to 7.02 in preparation for release...

webcit/README.txt
webcit/configure.in
webcit/crypto.c
webcit/setup.c
webcit/webcit.h
webcit/webserver.c

index 0498744105d62197949d40e52567c2cc5a4cb6c2..20b9ef8cd24eccf336dd7e441c11e2800abb3099 100644 (file)
@@ -1,5 +1,5 @@
                         WEBCIT for the Citadel System
-                               version 7.01
+                               version 7.02
  
    Copyright (C) 1996-2006 by the authors.  Portions written by:
        Art Cancro
index dd7337afe0ee7f98131c71f7f5c493beb8642579..2cdd1c58e2181088b1f983648f450b14f4936776 100644 (file)
@@ -4,7 +4,7 @@ AC_INIT(webserver.c)
 
 
 PACKAGE=webcit
-VERSION=7.00
+VERSION=7.02
 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
 AC_SUBST(PACKAGE)
index b7d36faf9ef94c08ec0d6d82402f191bae8c7714..022b64ef05c03b0cd0df1ef18f8e04d6572fc84c 100644 (file)
@@ -63,7 +63,7 @@ void init_ssl(void)
        if (!SSLCritters) {
                lprintf(1, "citserver: can't allocate memory!!\n");
                /* Nothing's been initialized, just die */
-               exit(1);
+               exit(WC_EXIT_SSL);
        } else {
                int a;
 
@@ -73,7 +73,7 @@ void init_ssl(void)
                                lprintf(1,
                                        "citserver: can't allocate memory!!\n");
                                /** Nothing's been initialized, just die */
-                               exit(1);
+                               exit(WC_EXIT_SSL);
                        }
                        pthread_mutex_init(SSLCritters[a], NULL);
                }
index 8022ca0d271839995f307110f200d5d1b497d0f2..136892f6a10ed0d50e720113f9edc2e523abaf4d 100644 (file)
@@ -310,7 +310,7 @@ void progress(char *text, long int curr, long int cmax)
 
 
 /*
- * install_init_scripts()  -- Make sure "webserver" is in /etc/inittab
+ * install_init_scripts()  -- Create and deploy SysV init scripts.
  *
  */
 void install_init_scripts(void)
@@ -399,7 +399,7 @@ 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"
@@ -410,7 +410,7 @@ void install_init_scripts(void)
 #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"
index 804c2ba31d4c3c1ca24e72a4e6d1ce6b2e6165ac..6dc14d2f17d9b8747ecf650d17a0c215acb5c6f2 100644 (file)
@@ -122,10 +122,10 @@ extern locale_t wc_locales[];
 #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"
@@ -752,3 +752,9 @@ void http_datestring(char *buf, size_t n, time_t xtime);
 #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 */
index 038ab57ae2c19cc6d18ae89facc2967943222502..1652a4ff5de15add8d71c2afc60114dbd41df1b3 100644 (file)
@@ -86,14 +86,14 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
 
        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;
@@ -101,11 +101,11 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
 
        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);
 }
@@ -131,7 +131,7 @@ int ig_uds_server(char *sockpath, int queue_len)
        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));
@@ -142,19 +142,19 @@ int ig_uds_server(char *sockpath, int queue_len)
        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);
@@ -482,10 +482,12 @@ void start_daemon(int do_close_stdio, char *pid_file)
 
        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);
        }
@@ -547,7 +549,9 @@ void start_daemon(int do_close_stdio, char *pid_file)
 
        } while (do_restart);
 
-       unlink(pid_file);
+       if (pid_file) {
+               unlink(pid_file);
+       }
        exit(WEXITSTATUS(status));
 }
 
@@ -606,7 +610,7 @@ int main(int argc, char **argv)
        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
@@ -619,9 +623,9 @@ int main(int argc, char **argv)
 
        /** 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':
@@ -637,8 +641,10 @@ int main(int argc, char **argv)
                        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':