summaryrefslogtreecommitdiff
path: root/src/lighttpd-angel.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2022-09-26 18:58:43 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2022-10-01 12:40:58 -0400
commitd7e28afdf5a8d723d94f067e505f71d701b57b0e (patch)
tree8e48fbd4c07415d841d559895f848c4a8fb2b674 /src/lighttpd-angel.c
parentfb14470308fb8302081c91dc49b2cbaadb7619ba (diff)
downloadlighttpd-git-d7e28afdf5a8d723d94f067e505f71d701b57b0e.tar.gz
[lighttpd-angel] waitpid after HUP before restart
When lighttpd-angel gets SIGHUP, lighttpd-angel sends SIGINT to the lighttpd process, which triggers lighttpd graceful shutdown. Wait for lighttpd process to exit before starting a new process. Avoid theoretical race condition between kill() and waitpid() by removing call to wait() in SIGCHLD signal handler.
Diffstat (limited to 'src/lighttpd-angel.c')
-rw-r--r--src/lighttpd-angel.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/lighttpd-angel.c b/src/lighttpd-angel.c
index 189c1b92..8e029b0b 100644
--- a/src/lighttpd-angel.c
+++ b/src/lighttpd-angel.c
@@ -32,8 +32,6 @@ static volatile pid_t pid = -1;
#define UNUSED(x) ( (void)(x) )
static void sigaction_handler(int sig, siginfo_t *si, void *context) {
- int exitcode;
-
UNUSED(context);
switch (sig) {
case SIGINT:
@@ -51,14 +49,10 @@ static void sigaction_handler(int sig, siginfo_t *si, void *context) {
/** do a graceful shutdown on the main process and start a new child */
kill(pid, SIGINT);
-
- usleep(5 * 1000); /** wait 5 microsec */
-
- start_process = 1;
+ start_process = -1;/*(flag to waitpid(), then restart process)*/
break;
case SIGCHLD:
- /** a child died, de-combie it */
- wait(&exitcode);
+ /* defer handling to waitpid() in main() */
break;
}
}
@@ -101,7 +95,7 @@ int main(int argc, char **argv) {
while (!is_shutdown) {
int exitcode = 0;
- if (start_process) {
+ if (start_process == 1) {
pid = fork();
if (0 == pid) {