Skip to content

Commit 72e1633

Browse files
committed
ensure only one signal handler is set
1 parent 37e9278 commit 72e1633

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;
@@ -42,6 +44,13 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
4244
sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid);
4345

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

5463
sigaction(sev.sigev_signo, NULL, &EG(oldact));
64+
is_handler_set = 1;
5565
}
5666
/* }}} */
5767

@@ -106,6 +116,7 @@ void zend_max_execution_timer_shutdown(void) /* {{{ */
106116
if(sigaction(SIGRTMIN, &ign_sigrtmin, &prev) < 0) {
107117
zend_strerror_noreturn(E_ERROR, errno, "Could not clear pending timer signal");
108118
}
119+
is_handler_set = 0;
109120
}
110121
/* }}}} */
111122

0 commit comments

Comments
 (0)