]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* corrected use of our absolute directories
[citadel.git] / webcit / webserver.c
index 038ab57ae2c19cc6d18ae89facc2967943222502..78ee06f3153c58a9c6c385b2f95630e36e8fb28c 100644 (file)
@@ -33,20 +33,25 @@ extern pthread_key_t MyConKey;
 char socket_dir[PATH_MAX];      /**< where to talk to our citadel server */
 static const char editor_absolut_dir[PATH_MAX]=EDITORDIR; /**< nailed to what configure gives us. */
 static char static_dir[PATH_MAX]; /**< calculated on startup */
+static char static_local_dir[PATH_MAX]; /**< calculated on startup */
 char  *static_dirs[]={ /**< needs same sort order as the web mapping */
        (char*)static_dir,                  /** our templates on disk */
+       (char*)static_local_dir,            /** user provided templates disk */
        (char*)editor_absolut_dir           /** the editor on disk */
 };
-int ndirs=2; //sizeof(static_content_dirs);//sizeof(char *);
 
 /**
  * Subdirectories from which the client may request static content
+ *
+ * (If you add more, remember to increment 'ndirs' below)
  */
 char *static_content_dirs[] = {
        "static",                     /** static templates */
+       "static.local",               /** site local static templates */
        "tiny_mce"                    /** the JS editor */
 };
 
+int ndirs=3;
 
 
 char *server_cookie = NULL; /**< our Cookie connection to the client */
@@ -86,14 +91,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 +106,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 +136,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 +147,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);
@@ -465,7 +470,7 @@ void graceful_shutdown(int signum) {
 /*
  * Start running as a daemon.
  */
-void start_daemon(int do_close_stdio, char *pid_file) 
+void start_daemon(char *pid_file) 
 {
        int status = 0;
        pid_t child = 0;
@@ -480,31 +485,24 @@ void start_daemon(int do_close_stdio, char *pid_file)
         */
        chdir("/");
 
+       signal(SIGHUP, SIG_IGN);
+       signal(SIGINT, SIG_IGN);
+       signal(SIGQUIT, SIG_IGN);
+
        child = fork();
        if (child != 0) {
-               fp = fopen(pid_file, "w");
-               if (fp != NULL) {
-                       fprintf(fp, "%d\n", child);
-                       fclose(fp);
-               }
                exit(0);
        }
-       
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
 
        setsid();
        umask(0);
-       if (do_close_stdio) {
-               freopen("/dev/null", "r", stdin);
-               freopen("/dev/null", "w", stdout);
-               freopen("/dev/null", "w", stderr);
-       }
+       freopen("/dev/null", "r", stdin);
+       freopen("/dev/null", "w", stdout);
+       freopen("/dev/null", "w", stderr);
+
        do {
                current_child = fork();
 
-               signal(SIGTERM, graceful_shutdown);
        
                if (current_child < 0) {
                        perror("fork");
@@ -512,10 +510,19 @@ void start_daemon(int do_close_stdio, char *pid_file)
                }
        
                else if (current_child == 0) {
+                       signal(SIGTERM, graceful_shutdown);
                        return; /* continue starting citadel. */
                }
        
                else {
+                       signal(SIGTERM, SIG_IGN);
+                       if (pid_file) {
+                               fp = fopen(pid_file, "w");
+                               if (fp != NULL) {
+                                       fprintf(fp, "%d\n", current_child);
+                                       fclose(fp);
+                               }
+                       }
                        waitpid(current_child, &status, 0);
                }
 
@@ -547,7 +554,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 +615,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 +628,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 +646,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':
@@ -700,12 +711,12 @@ int main(int argc, char **argv)
 
        /* daemonize, if we were asked to */
        if (running_as_daemon) {
-               start_daemon(0, pidfile);
+               start_daemon(pidfile);
        }
 
        /** Tell 'em who's in da house */
        lprintf(1, SERVER "\n");
-       lprintf(1, "Copyright (C) 1996-2006 by the Citadel development team.\n"
+       lprintf(1, "Copyright (C) 1996-2007 by the Citadel development team.\n"
                "This software is distributed under the terms of the "
                "GNU General Public License.\n\n"
        );
@@ -716,7 +727,7 @@ int main(int argc, char **argv)
        initialize_locales();
        locale = setlocale(LC_ALL, "");
        mo = malloc(strlen(webcitdir) + 20);
-       lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR));
+       lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale"));
        free(mo);
        lprintf(9, "Text domain: %s\n", textdomain("webcit"));
        lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
@@ -737,8 +748,10 @@ int main(int argc, char **argv)
                         (dirbuffer[0]!='\0')?"/":"");
        basedir=RUNDIR;
        COMPUTE_DIRECTORY(socket_dir);
-       basedir=DATADIR;
+       basedir=DATADIR "/static";
        COMPUTE_DIRECTORY(static_dir);
+       basedir=DATADIR "/static.local";
+       COMPUTE_DIRECTORY(static_local_dir);
        /** we should go somewhere we can leave our coredump, if enabled... */
        lprintf(9, "Changing directory to %s\n", socket_dir);
        if (chdir(webcitdir) != 0) {