diff options
author | Stefan Bühler <stbuehler@web.de> | 2013-08-30 15:46:13 +0000 |
---|---|---|
committer | Stefan Bühler <stbuehler@web.de> | 2013-08-30 15:46:13 +0000 |
commit | 29ff92d9ba189538954cf7b97f4a8183d87cb763 (patch) | |
tree | 6e3e9821f923b465e18701b0bd5cac2fb005fd19 | |
parent | 9cfc080ab725ce4695c21514fba336c2c2c5023d (diff) | |
download | lighttpd-git-29ff92d9ba189538954cf7b97f4a8183d87cb763.tar.gz |
[core] set signal handlers before forking child processes in modules/plugins_call_set_defaults (fixes #2502)
From: Stefan Bühler <stbuehler@web.de>
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2901 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/server.c | 90 |
2 files changed, 46 insertions, 45 deletions
@@ -33,6 +33,7 @@ NEWS * [mod_simple_vhost] fix cache; skip module if simple-vhost.server-root is empty (thx rm for reporting) * [mod_accesslog] add accesslog.syslog-level option (fixes #2480) * [core] allow files to be used as document-root (fixes #2475) + * [core] set signal handlers before forking child processes in modules/plugins_call_set_defaults (fixes #2502) - 1.4.32 - 2012-11-21 * Code cleanup with clang/sparse (fixes #2437, thx kibi) diff --git a/src/server.c b/src/server.c index 590a9d54..a7799287 100644 --- a/src/server.c +++ b/src/server.c @@ -937,6 +937,51 @@ int main (int argc, char **argv) { if (srv->srvconf.dont_daemonize == 0) daemonize(); #endif + +#ifdef HAVE_SIGACTION + memset(&act, 0, sizeof(act)); + act.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &act, NULL); + sigaction(SIGUSR1, &act, NULL); +# if defined(SA_SIGINFO) + act.sa_sigaction = sigaction_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; +# else + act.sa_handler = signal_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +# endif + sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGALRM, &act, NULL); + sigaction(SIGCHLD, &act, NULL); + +#elif defined(HAVE_SIGNAL) + /* ignore the SIGPIPE from sendfile() */ + signal(SIGPIPE, SIG_IGN); + signal(SIGUSR1, SIG_IGN); + signal(SIGALRM, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGHUP, signal_handler); + signal(SIGCHLD, signal_handler); + signal(SIGINT, signal_handler); +#endif + +#ifdef USE_ALARM + signal(SIGALRM, signal_handler); + + /* setup periodic timer (1 second) */ + if (setitimer(ITIMER_REAL, &interval, NULL)) { + log_error_write(srv, __FILE__, __LINE__, "s", "setting timer failed"); + return -1; + } + + getitimer(ITIMER_REAL, &interval); +#endif + + srv->gid = getgid(); srv->uid = getuid(); @@ -1011,51 +1056,6 @@ int main (int argc, char **argv) { } - - -#ifdef HAVE_SIGACTION - memset(&act, 0, sizeof(act)); - act.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &act, NULL); - sigaction(SIGUSR1, &act, NULL); -# if defined(SA_SIGINFO) - act.sa_sigaction = sigaction_handler; - sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; -# else - act.sa_handler = signal_handler; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; -# endif - sigaction(SIGINT, &act, NULL); - sigaction(SIGTERM, &act, NULL); - sigaction(SIGHUP, &act, NULL); - sigaction(SIGALRM, &act, NULL); - sigaction(SIGCHLD, &act, NULL); - -#elif defined(HAVE_SIGNAL) - /* ignore the SIGPIPE from sendfile() */ - signal(SIGPIPE, SIG_IGN); - signal(SIGUSR1, SIG_IGN); - signal(SIGALRM, signal_handler); - signal(SIGTERM, signal_handler); - signal(SIGHUP, signal_handler); - signal(SIGCHLD, signal_handler); - signal(SIGINT, signal_handler); -#endif - -#ifdef USE_ALARM - signal(SIGALRM, signal_handler); - - /* setup periodic timer (1 second) */ - if (setitimer(ITIMER_REAL, &interval, NULL)) { - log_error_write(srv, __FILE__, __LINE__, "s", "setting timer failed"); - return -1; - } - - getitimer(ITIMER_REAL, &interval); -#endif - #ifdef HAVE_FORK /* start watcher and workers */ num_childs = srv->srvconf.max_worker; |