Skip to content

Commit 485a42f

Browse files
committed
Work around incorrect NSIG on FreeBSD
1 parent d3e8ae1 commit 485a42f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

ext/pcntl/pcntl.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747
#endif
4848

4949
#ifndef NSIG
50-
# ifdef SIGRTMAX
51-
# define NSIG (SIGRTMAX + 1)
52-
# else
53-
# define NSIG 32
54-
# endif
50+
# define NSIG 32
5551
#endif
5652

5753
ZEND_DECLARE_MODULE_GLOBALS(pcntl)
@@ -430,6 +426,14 @@ PHP_RINIT_FUNCTION(pcntl)
430426
PCNTL_G(head) = PCNTL_G(tail) = PCNTL_G(spares) = NULL;
431427
PCNTL_G(async_signals) = 0;
432428
PCNTL_G(last_error) = 0;
429+
PCNTL_G(num_signals) = NSIG;
430+
#ifdef SIGRTMAX
431+
/* At least FreeBSD reports an incorrecrt NSIG that does not include realtime signals.
432+
* As SIGRTMAX may be a dynamic value, adjust the value in INIT. */
433+
if (NSIG < SIGRTMAX + 1) {
434+
PCNTL_G(num_signals) = SIGRTMAX + 1;
435+
}
436+
#endif
433437
return SUCCESS;
434438
}
435439

@@ -900,16 +904,16 @@ PHP_FUNCTION(pcntl_signal)
900904
RETURN_THROWS();
901905
}
902906

903-
if (signo >= NSIG) {
904-
zend_argument_value_error(1, "must be less than %d", NSIG);
907+
if (signo >= PCNTL_G(num_signals)) {
908+
zend_argument_value_error(1, "must be less than %d", PCNTL_G(num_signals));
905909
RETURN_THROWS();
906910
}
907911

908912
if (!PCNTL_G(spares)) {
909913
/* since calling malloc() from within a signal handler is not portable,
910914
* pre-allocate a few records for recording signals */
911915
int i;
912-
for (i = 0; i < NSIG; i++) {
916+
for (i = 0; i < PCNTL_G(num_signals); i++) {
913917
struct php_pcntl_pending_signal *psig;
914918

915919
psig = emalloc(sizeof(*psig));
@@ -1037,7 +1041,7 @@ PHP_FUNCTION(pcntl_sigprocmask)
10371041
RETURN_THROWS();
10381042
}
10391043

1040-
for (signo = 1; signo < NSIG; ++signo) {
1044+
for (signo = 1; signo < PCNTL_G(num_signals); ++signo) {
10411045
if (sigismember(&oldset, signo) != 1) {
10421046
continue;
10431047
}

ext/pcntl/php_pcntl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ZEND_BEGIN_MODULE_GLOBALS(pcntl)
4848
int last_error;
4949
volatile char pending_signals;
5050
bool async_signals;
51+
unsigned num_signals;
5152
ZEND_END_MODULE_GLOBALS(pcntl)
5253

5354
#if defined(ZTS) && defined(COMPILE_DL_PCNTL)

0 commit comments

Comments
 (0)