summaryrefslogtreecommitdiff
path: root/src/fdevent.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2017-09-10 15:28:51 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2017-09-10 16:24:34 -0400
commit9030cfaecf07fc2426b01f6f3a1df442ccdd3ebb (patch)
tree953b0a4c4e8b7a7ac79adb67f0d5c2111d895c5d /src/fdevent.c
parent26dce93086ba46a3d9ead391b33b8a02515416ae (diff)
downloadlighttpd-git-9030cfaecf07fc2426b01f6f3a1df442ccdd3ebb.tar.gz
[core] SIGCHLD handle_waitpid hook for modules
centralize most waitpid() handling in core server, with hooks for modules to be informed of pid and status when a process exits. This enables faster discovery (and restart) of exited processes, and also allows for lighttpd to manage backend processes in the parent (master) process when server.max-worker > 0.
Diffstat (limited to 'src/fdevent.c')
-rw-r--r--src/fdevent.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/fdevent.c b/src/fdevent.c
index 36590a73..280181c1 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -581,16 +581,8 @@ static pid_t fdevent_open_logger_pipe_spawn(const char *logger, int rfd) {
}
-static void fdevent_waitpid_logger_pipe(fdevent_cmd_pipe *fcp, time_t ts) {
- pid_t pid = fcp->pid;
- if (pid > 0) {
- switch (waitpid(pid, NULL, WNOHANG)) {
- case 0: return;
- case -1: if (errno == EINTR) return; /* fall through */
- default: break;
- }
- fcp->pid = -1;
- }
+static void fdevent_restart_logger_pipe(fdevent_cmd_pipe *fcp, time_t ts) {
+ if (fcp->pid > 0) return; /* assert */
if (fcp->start + 5 < ts) { /* limit restart to once every 5 sec */
/* restart child process using existing pipe fds */
fcp->start = ts;
@@ -599,9 +591,31 @@ static void fdevent_waitpid_logger_pipe(fdevent_cmd_pipe *fcp, time_t ts) {
}
-void fdevent_waitpid_logger_pipes(time_t ts) {
+void fdevent_restart_logger_pipes(time_t ts) {
+ for (size_t i = 0; i < cmd_pipes.used; ++i) {
+ fdevent_cmd_pipe * const fcp = cmd_pipes.ptr+i;
+ if (fcp->pid > 0) continue;
+ fdevent_restart_logger_pipe(fcp, ts);
+ }
+}
+
+
+int fdevent_waitpid_logger_pipe_pid(pid_t pid, time_t ts) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
- fdevent_waitpid_logger_pipe(cmd_pipes.ptr+i, ts);
+ fdevent_cmd_pipe * const fcp = cmd_pipes.ptr+i;
+ if (pid != fcp->pid) continue;
+ fcp->pid = -1;
+ fdevent_restart_logger_pipe(fcp, ts);
+ return 1;
+ }
+ return 0;
+}
+
+
+void fdevent_clr_logger_pipe_pids(void) {
+ for (size_t i = 0; i < cmd_pipes.used; ++i) {
+ fdevent_cmd_pipe *fcp = cmd_pipes.ptr+i;
+ fcp->pid = -1;
}
}