Skip to content

Commit c0bef12

Browse files
committed
store pid
1 parent 2dbdcf1 commit c0bef12

File tree

7 files changed

+8
-19
lines changed

7 files changed

+8
-19
lines changed

Zend/zend_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
#include <setjmp.h>
25+
#include <sys/types.h>
2526

2627
#include "zend_globals_macros.h"
2728

@@ -269,6 +270,7 @@ struct _zend_executor_globals {
269270

270271
#ifdef ZEND_TIMERS
271272
timer_t timer;
273+
pid_t pid;
272274
struct sigaction oldact;
273275
#endif
274276

Zend/zend_timer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ZEND_API void zend_timer_init(void) /* {{{ */
4747
sev.sigev_signo = SIGIO;
4848
sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid);
4949

50+
EG(pid) = getpid();
5051
// Measure wall time instead of CPU time as originally planned now that it is possible https://github.com/php/php-src/pull/6504#issuecomment-1370303727
5152
if (timer_create(CLOCK_REALTIME, &sev, &EG(timer)) != 0) {
5253
zend_strerror_noreturn(E_ERROR, errno, "Could not create timer");
@@ -80,6 +81,11 @@ void zend_timer_settime(zend_long seconds) /* {{{ }*/
8081

8182
void zend_timer_shutdown(void) /* {{{ */
8283
{
84+
/* Don't try to delete a timer created before a call to fork() */
85+
if (EG(pid) != getpid()) {
86+
return;
87+
}
88+
8389
timer_t timer = EG(timer);
8490
if (timer == (timer_t){0}) {
8591
/* Don't trigger an error here because the timer may not be initialized when PHP fail early, and on threads created by PHP but not managed by it. */

ext/opcache/ZendAccelerator.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,8 +4693,6 @@ static int accel_finish_startup(void)
46934693
zend_accel_error(ACCEL_LOG_WARNING, "Preloading failed to setuid(%d)", pw->pw_uid);
46944694
exit(1);
46954695
}
4696-
zend_timer_init();
4697-
46984696
in_child = 1;
46994697
} else { /* parent */
47004698
int status;

sapi/apache2handler/sapi_apache2.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,23 +753,13 @@ static void php_apache_signal_init(apr_pool_t *pchild, server_rec *s)
753753
}
754754
#endif
755755

756-
#ifdef ZEND_TIMERS
757-
static void php_apache_timers_init(apr_pool_t *pchild, server_rec *s)
758-
{
759-
zend_timer_init();
760-
}
761-
#endif
762-
763756
void php_ap2_register_hook(apr_pool_t *p)
764757
{
765758
ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
766759
ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
767760
ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);
768761
#ifdef ZEND_SIGNALS
769762
ap_hook_child_init(php_apache_signal_init, NULL, NULL, APR_HOOK_MIDDLE);
770-
#endif
771-
#ifdef ZEND_TIMERS
772-
ap_hook_child_init(php_apache_timers_init, NULL, NULL, APR_HOOK_MIDDLE);
773763
#endif
774764
ap_hook_child_init(php_apache_child_init, NULL, NULL, APR_HOOK_MIDDLE);
775765
}

sapi/cgi/cgi_main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,6 @@ consult the installation file that came with this distribution, or visit \n\
20532053
sigaction(SIGQUIT, &old_quit, 0);
20542054
sigaction(SIGINT, &old_int, 0);
20552055
zend_signal_init();
2056-
zend_timer_init();
20572056
break;
20582057
case -1:
20592058
perror("php (pre-forking)");

sapi/cli/php_cli_server.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#include "zend_execute.h"
6565
#include "zend_highlight.h"
6666
#include "zend_exceptions.h"
67-
#include "zend_timer.h"
6867

6968
#include "php_getopt.h"
7069

@@ -2401,8 +2400,6 @@ static void php_cli_server_startup_workers(void) {
24012400
} else if (pid == SUCCESS) {
24022401
return;
24032402
} else {
2404-
zend_timer_init();
2405-
24062403
php_cli_server_workers[php_cli_server_worker] = pid;
24072404
}
24082405
}

sapi/fpm/fpm/fpm_php.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "php_ini.h"
1212
#include "ext/standard/dl.h"
1313

14-
#include "zend_timer.h"
15-
1614
#include "fastcgi.h"
1715

1816
#include "fpm.h"
@@ -216,7 +214,6 @@ int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
216214
0 > fpm_php_set_allowed_clients(wp)) {
217215
return -1;
218216
}
219-
zend_timer_init();
220217

221218
if (wp->limit_extensions) {
222219
/* Take ownership of limit_extensions. */

0 commit comments

Comments
 (0)