Skip to content

Commit 7034263

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 2fa8473 + bda28eb commit 7034263

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

sapi/fpm/fpm/fpm_children.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,27 @@ static void fpm_child_free(struct fpm_child_s *child) /* {{{ */
6363
}
6464
/* }}} */
6565

66+
static void fpm_postponed_child_free(struct fpm_event_s *ev, short which, void *arg)
67+
{
68+
struct fpm_child_s *child = (struct fpm_child_s *) arg;
69+
70+
if (child->fd_stdout != -1) {
71+
fpm_event_del(&child->ev_stdout);
72+
close(child->fd_stdout);
73+
}
74+
if (child->fd_stderr != -1) {
75+
fpm_event_del(&child->ev_stderr);
76+
close(child->fd_stderr);
77+
}
78+
79+
fpm_child_free((struct fpm_child_s *) child);
80+
}
81+
6682
static void fpm_child_close(struct fpm_child_s *child, int in_event_loop) /* {{{ */
6783
{
6884
if (child->fd_stdout != -1) {
6985
if (in_event_loop) {
86+
child->postponed_free = true;
7087
fpm_event_fire(&child->ev_stdout);
7188
}
7289
if (child->fd_stdout != -1) {
@@ -76,14 +93,20 @@ static void fpm_child_close(struct fpm_child_s *child, int in_event_loop) /* {{{
7693

7794
if (child->fd_stderr != -1) {
7895
if (in_event_loop) {
96+
child->postponed_free = true;
7997
fpm_event_fire(&child->ev_stderr);
8098
}
8199
if (child->fd_stderr != -1) {
82100
close(child->fd_stderr);
83101
}
84102
}
85103

86-
fpm_child_free(child);
104+
if (in_event_loop && child->postponed_free) {
105+
fpm_event_set_timer(&child->ev_free, 0, &fpm_postponed_child_free, child);
106+
fpm_event_add(&child->ev_free, 1000);
107+
} else {
108+
fpm_child_free(child);
109+
}
87110
}
88111
/* }}} */
89112

sapi/fpm/fpm/fpm_children.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ struct fpm_child_s {
2323
struct fpm_child_s *prev, *next;
2424
struct timeval started;
2525
struct fpm_worker_pool_s *wp;
26-
struct fpm_event_s ev_stdout, ev_stderr;
26+
struct fpm_event_s ev_stdout, ev_stderr, ev_free;
2727
int shm_slot_i;
2828
int fd_stdout, fd_stderr;
2929
void (*tracer)(struct fpm_child_s *);
3030
struct timeval slow_logged;
31-
int idle_kill;
31+
bool idle_kill;
32+
bool postponed_free;
3233
pid_t pid;
3334
int scoreboard_i;
3435
struct zlog_stream *log_stream;

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static void fpm_pctl_kill_idle_child(struct fpm_child_s *child) /* {{{ */
318318
if (child->idle_kill) {
319319
fpm_pctl_kill(child->pid, FPM_PCTL_KILL);
320320
} else {
321-
child->idle_kill = 1;
321+
child->idle_kill = true;
322322
fpm_pctl_kill(child->pid, FPM_PCTL_QUIT);
323323
}
324324
}

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
180180
if (!arg) {
181181
return;
182182
}
183-
child = fpm_child_find((intptr_t) arg);
184-
if (!child) {
185-
return;
186-
}
183+
child = (struct fpm_child_s *) arg;
187184

188185
is_stdout = (fd == child->fd_stdout);
189186
if (is_stdout) {
@@ -276,6 +273,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
276273

277274
fpm_event_del(event);
278275

276+
child->postponed_free = true;
279277
if (is_stdout) {
280278
close(child->fd_stdout);
281279
child->fd_stdout = -1;
@@ -329,10 +327,10 @@ int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */
329327
child->fd_stdout = fd_stdout[0];
330328
child->fd_stderr = fd_stderr[0];
331329

332-
fpm_event_set(&child->ev_stdout, child->fd_stdout, FPM_EV_READ, fpm_stdio_child_said, (void *) (intptr_t) child->pid);
330+
fpm_event_set(&child->ev_stdout, child->fd_stdout, FPM_EV_READ, fpm_stdio_child_said, child);
333331
fpm_event_add(&child->ev_stdout, 0);
334332

335-
fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, (void *) (intptr_t) child->pid);
333+
fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, child);
336334
fpm_event_add(&child->ev_stderr, 0);
337335
return 0;
338336
}

0 commit comments

Comments
 (0)