Fixed deamonization code to erase the pid file
authorArt Cancro <ajc@citadel.org>
Thu, 28 Dec 2006 18:03:14 +0000 (18:03 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 28 Dec 2006 18:03:14 +0000 (18:03 +0000)
webcit/setup.c
webcit/webserver.c

index 0c06de983bed25adefb4923ae9626e8d9ef4f05d..1baca4c20a8c1a2918302f8a5189c1d29c6a78a0 100644 (file)
@@ -428,7 +428,6 @@ void install_init_scripts(void)
                        "start)         echo -n \"Starting WebCit... \"\n"
                        "               if   $WEBCIT_DIR/webserver "
                                                        "-D/var/run/webcit.pid "
-                                                       "-t/dev/null "
                                                        "-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
                        "                       echo \"ok\"\n"
@@ -439,7 +438,6 @@ void install_init_scripts(void)
        fprintf(fp,     "               echo -n \"Starting WebCit SSL... \"\n"
                        "               if  $WEBCIT_DIR/webserver "
                                                        "-D/var/run/webcit-ssl.pid "
-                                                       "-t/dev/null "
                                                        "-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
                        "                       echo \"ok\"\n"
index 1652a4ff5de15add8d71c2afc60114dbd41df1b3..fe23a84890e90bfad474c72f7c2f34f66b00a2ff 100644 (file)
@@ -465,7 +465,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;
@@ -498,15 +498,13 @@ void start_daemon(int do_close_stdio, char *pid_file)
 
        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 +512,12 @@ 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);
                        waitpid(current_child, &status, 0);
                }
 
@@ -706,7 +706,7 @@ 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 */