Skip to content

Commit 1ed0ebd

Browse files
committed
ensure only one signal handler is set
1 parent f8495e5 commit 1ed0ebd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Zend/zend_max_execution_timer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
# define sigev_notify_thread_id _sigev_un._tid
3434
# endif
3535

36+
int is_handler_set = 0; // global flag
37+
3638
ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
3739
{
3840
struct sigevent sev;
@@ -41,6 +43,13 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
4143
sev.sigev_signo = SIGRTMIN;
4244
sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid);
4345

46+
// Now check to see if a we've already set a signal handler
47+
if(is_handler_set) {
48+
// emit a warning and return
49+
zend_error(E_WARNING, "A max execution timer was already configured and will not be configured again.");
50+
return;
51+
}
52+
4453
// 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
4554
if (timer_create(CLOCK_BOOTTIME, &sev, &EG(max_execution_timer_timer)) != 0) {
4655
zend_strerror_noreturn(E_ERROR, errno, "Could not create timer");
@@ -53,6 +62,7 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
5362
# endif
5463

5564
sigaction(sev.sigev_signo, NULL, &EG(oldact));
65+
is_handler_set = 1;
5666
}
5767
/* }}} */
5868

@@ -107,6 +117,7 @@ void zend_max_execution_timer_shutdown(void) /* {{{ */
107117
if(sigaction(SIGRTMIN, &ign_sigrtmin, &prev) < 0) {
108118
zend_strerror_noreturn(E_ERROR, errno, "Could not clear pending timer signal");
109119
}
120+
is_handler_set = 0;
110121
}
111122
/* }}}} */
112123

0 commit comments

Comments
 (0)