Skip to content

Commit d0c8aba

Browse files
DennisBirkholznikic
authored andcommitted
Pcntl: Make realtime signals available
Expose constants SIGRTMIN and SIGRTMAX and adjust range checks to support realtime signals.
1 parent 85243ee commit d0c8aba

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ext/pcntl/pcntl.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646

4747
#include <errno.h>
4848

49+
#ifndef NSIG
50+
# ifdef SIGRTMAX
51+
# define NSIG (SIGRTMAX + 1)
52+
# else
53+
# define NSIG 32
54+
# endif
55+
#endif
56+
4957
ZEND_DECLARE_MODULE_GLOBALS(pcntl)
5058
static PHP_GINIT_FUNCTION(pcntl);
5159

@@ -301,6 +309,12 @@ void php_register_signal_constants(INIT_FUNC_ARGS)
301309
REGISTER_LONG_CONSTANT("SIGSYS", (zend_long) SIGSYS, CONST_CS | CONST_PERSISTENT);
302310
REGISTER_LONG_CONSTANT("SIGBABY", (zend_long) SIGSYS, CONST_CS | CONST_PERSISTENT);
303311
#endif
312+
#ifdef SIGRTMIN
313+
REGISTER_LONG_CONSTANT("SIGRTMIN", (zend_long) SIGRTMIN, CONST_CS | CONST_PERSISTENT);
314+
#endif
315+
#ifdef SIGRTMAX
316+
REGISTER_LONG_CONSTANT("SIGRTMAX", (zend_long) SIGRTMAX, CONST_CS | CONST_PERSISTENT);
317+
#endif
304318

305319
#if HAVE_GETPRIORITY || HAVE_SETPRIORITY
306320
REGISTER_LONG_CONSTANT("PRIO_PGRP", PRIO_PGRP, CONST_CS | CONST_PERSISTENT);
@@ -984,7 +998,7 @@ PHP_FUNCTION(pcntl_signal)
984998
return;
985999
}
9861000

987-
if (signo < 1 || signo > 32) {
1001+
if (signo < 1 || signo >= NSIG) {
9881002
php_error_docref(NULL, E_WARNING, "Invalid signal");
9891003
RETURN_FALSE;
9901004
}
@@ -993,7 +1007,7 @@ PHP_FUNCTION(pcntl_signal)
9931007
/* since calling malloc() from within a signal handler is not portable,
9941008
* pre-allocate a few records for recording signals */
9951009
int i;
996-
for (i = 0; i < 32; i++) {
1010+
for (i = 0; i < NSIG; i++) {
9971011
struct php_pcntl_pending_signal *psig;
9981012

9991013
psig = emalloc(sizeof(*psig));
@@ -1112,7 +1126,7 @@ PHP_FUNCTION(pcntl_sigprocmask)
11121126
} else {
11131127
zend_hash_clean(Z_ARRVAL_P(user_oldset));
11141128
}
1115-
for (signo = 1; signo < MAX(NSIG-1, SIGRTMAX); ++signo) {
1129+
for (signo = 1; signo < NSIG; ++signo) {
11161130
if (sigismember(&oldset, signo) != 1) {
11171131
continue;
11181132
}

ext/pcntl/php_signal.h

-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
#ifndef PHP_SIGNAL_H
2323
#define PHP_SIGNAL_H
2424

25-
#ifndef NSIG
26-
# define NSIG 32
27-
#endif
28-
#ifndef SIGRTMAX
29-
# define SIGRTMAX 64
30-
#endif
31-
3225
#ifdef HAVE_STRUCT_SIGINFO_T
3326
typedef void Sigfunc(int, siginfo_t*, void*);
3427
#else

0 commit comments

Comments
 (0)