From 55fed09cf18bc5534094f8854648189ca06ec16c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 28 Dec 2006 18:03:14 +0000 Subject: [PATCH] Fixed deamonization code to erase the pid file --- webcit/setup.c | 2 -- webcit/webserver.c | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/webcit/setup.c b/webcit/setup.c index 0c06de983..1baca4c20 100644 --- a/webcit/setup.c +++ b/webcit/setup.c @@ -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" diff --git a/webcit/webserver.c b/webcit/webserver.c index 1652a4ff5..fe23a8489 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -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 */ -- 2.39.2