]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* static.local/ is now created
[citadel.git] / webcit / webserver.c
index 1652a4ff5de15add8d71c2afc60114dbd41df1b3..a263c9c9254a7cae6a1ad34466483382a420d8ec 100644 (file)
@@ -44,6 +44,7 @@ int ndirs=2; //sizeof(static_content_dirs);//sizeof(char *);
  */
 char *static_content_dirs[] = {
        "static",                     /** static templates */
+       "static.local",               /** site local static templates */
        "tiny_mce"                    /** the JS editor */
 };
 
@@ -465,7 +466,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,33 +481,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) {
-               if (pid_file) {
-                       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");
@@ -514,10 +506,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);
                }
 
@@ -706,12 +707,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"
        );