Skip to content

Commit bcffcc8

Browse files
committed
ext/pcntl simplification.
assuming pcntl is an unix-only extension and they all support the siginfo_t type, we re using exclusively this more advanced api.
1 parent cbe0144 commit bcffcc8

File tree

7 files changed

+22
-55
lines changed

7 files changed

+22
-55
lines changed

ext/pcntl/pcntl.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,8 @@ ZEND_GET_MODULE(pcntl)
185185

186186
static void (*orig_interrupt_function)(zend_execute_data *execute_data);
187187

188-
#ifdef HAVE_STRUCT_SIGINFO_T
189188
static void pcntl_signal_handler(int, siginfo_t*, void*);
190189
static void pcntl_siginfo_to_zval(int, siginfo_t*, zval*);
191-
#else
192-
static void pcntl_signal_handler(int);
193-
#endif
194190
static void pcntl_signal_dispatch(void);
195191
static void pcntl_signal_dispatch_tick_function(int dummy_int, void *dummy_pointer);
196192
static void pcntl_interrupt_function(zend_execute_data *execute_data);
@@ -240,7 +236,7 @@ PHP_RSHUTDOWN_FUNCTION(pcntl)
240236
/* Reset all signals to their default disposition */
241237
ZEND_HASH_FOREACH_NUM_KEY_VAL(&PCNTL_G(php_signal_table), signo, handle) {
242238
if (Z_TYPE_P(handle) != IS_LONG || Z_LVAL_P(handle) != (zend_long)SIG_DFL) {
243-
php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, 0);
239+
php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, false);
244240
}
245241
} ZEND_HASH_FOREACH_END();
246242

@@ -835,7 +831,7 @@ PHP_FUNCTION(pcntl_signal)
835831
zend_argument_value_error(2, "must be either SIG_DFL or SIG_IGN when an integer value is given");
836832
RETURN_THROWS();
837833
}
838-
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == (void *)SIG_ERR) {
834+
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), restart_syscalls) == (void *)SIG_ERR) {
839835
PCNTL_G(last_error) = errno;
840836
php_error_docref(NULL, E_WARNING, "Error assigning signal");
841837
RETURN_FALSE;
@@ -1007,8 +1003,7 @@ PHP_FUNCTION(pcntl_sigprocmask)
10071003
/* }}} */
10081004
#endif
10091005

1010-
#ifdef HAVE_STRUCT_SIGINFO_T
1011-
# ifdef HAVE_SIGWAITINFO
1006+
#ifdef HAVE_SIGWAITINFO
10121007

10131008
/* {{{ Synchronously wait for queued signals */
10141009
PHP_FUNCTION(pcntl_sigwaitinfo)
@@ -1050,8 +1045,9 @@ PHP_FUNCTION(pcntl_sigwaitinfo)
10501045
RETURN_LONG(signal_no);
10511046
}
10521047
/* }}} */
1053-
# endif
1054-
# ifdef HAVE_SIGTIMEDWAIT
1048+
#endif
1049+
1050+
#ifdef HAVE_SIGTIMEDWAIT
10551051
/* {{{ Wait for queued signals */
10561052
PHP_FUNCTION(pcntl_sigtimedwait)
10571053
{
@@ -1113,7 +1109,7 @@ PHP_FUNCTION(pcntl_sigtimedwait)
11131109
RETURN_LONG(signal_no);
11141110
}
11151111
/* }}} */
1116-
# endif
1112+
#endif
11171113

11181114
static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_siginfo) /* {{{ */
11191115
{
@@ -1183,7 +1179,6 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi
11831179
}
11841180
}
11851181
/* }}} */
1186-
#endif
11871182

11881183
#ifdef HAVE_GETPRIORITY
11891184
/* {{{ Get the priority of any process */
@@ -1325,11 +1320,7 @@ PHP_FUNCTION(pcntl_strerror)
13251320
/* }}} */
13261321

13271322
/* Our custom signal handler that calls the appropriate php_function */
1328-
#ifdef HAVE_STRUCT_SIGINFO_T
13291323
static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
1330-
#else
1331-
static void pcntl_signal_handler(int signo)
1332-
#endif
13331324
{
13341325
struct php_pcntl_pending_signal *psig = PCNTL_G(spares);
13351326
if (!psig) {
@@ -1341,9 +1332,7 @@ static void pcntl_signal_handler(int signo)
13411332
psig->signo = signo;
13421333
psig->next = NULL;
13431334

1344-
#ifdef HAVE_STRUCT_SIGINFO_T
13451335
psig->siginfo = *siginfo;
1346-
#endif
13471336

13481337
/* the head check is important, as the tick handler cannot atomically clear both
13491338
* the head and tail */
@@ -1395,19 +1384,14 @@ void pcntl_signal_dispatch(void)
13951384
if ((handle = zend_hash_index_find(&PCNTL_G(php_signal_table), queue->signo)) != NULL) {
13961385
if (Z_TYPE_P(handle) != IS_LONG) {
13971386
ZVAL_LONG(&params[0], queue->signo);
1398-
#ifdef HAVE_STRUCT_SIGINFO_T
13991387
array_init(&params[1]);
14001388
pcntl_siginfo_to_zval(queue->signo, &queue->siginfo, &params[1]);
1401-
#else
1402-
ZVAL_NULL(&params[1]);
1403-
#endif
14041389

14051390
/* Call php signal handler - Note that we do not report errors, and we ignore the return value */
14061391
call_user_function(NULL, NULL, handle, &retval, 2, params);
14071392
zval_ptr_dtor(&retval);
1408-
#ifdef HAVE_STRUCT_SIGINFO_T
14091393
zval_ptr_dtor(&params[1]);
1410-
#endif
1394+
14111395
if (EG(exception)) {
14121396
break;
14131397
}

ext/pcntl/pcntl.stub.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,12 @@ function pcntl_signal_dispatch(): bool {}
10351035
function pcntl_sigprocmask(int $mode, array $signals, &$old_signals = null): bool {}
10361036
#endif
10371037

1038-
#ifdef HAVE_STRUCT_SIGINFO_T
10391038
#if (defined(HAVE_SIGWAITINFO) && defined(HAVE_SIGTIMEDWAIT))
10401039
/** @param array $info */
10411040
function pcntl_sigwaitinfo(array $signals, &$info = []): int|false {}
10421041

10431042
/** @param array $info */
10441043
function pcntl_sigtimedwait(array $signals, &$info = [], int $seconds = 0, int $nanoseconds = 0): int|false {}
1045-
#endif
10461044
#endif
10471045

10481046
function pcntl_wifexited(int $status): bool {}

ext/pcntl/pcntl_arginfo.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pcntl/pcntl_decl.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pcntl/php_pcntl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ PHP_MINFO_FUNCTION(pcntl);
3838
struct php_pcntl_pending_signal {
3939
struct php_pcntl_pending_signal *next;
4040
zend_long signo;
41-
#ifdef HAVE_STRUCT_SIGINFO_T
4241
siginfo_t siginfo;
43-
#endif
4442
};
4543

4644
ZEND_BEGIN_MODULE_GLOBALS(pcntl)

ext/pcntl/php_signal.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@
2121

2222
/* php_signal using sigaction is derived from Advanced Programming
2323
* in the Unix Environment by W. Richard Stevens p 298. */
24-
Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
24+
Sigfunc *php_signal4(int signo, Sigfunc *func, bool restart, bool mask_all)
2525
{
2626
struct sigaction act,oact;
2727

28-
#ifdef HAVE_STRUCT_SIGINFO_T
2928
act.sa_sigaction = func;
30-
#else
31-
act.sa_handler = func;
32-
#endif
3329
if (mask_all) {
3430
sigfillset(&act.sa_mask);
3531
} else {
3632
sigemptyset(&act.sa_mask);
3733
}
3834
act.sa_flags = SA_ONSTACK;
39-
#ifdef HAVE_STRUCT_SIGINFO_T
4035
act.sa_flags |= SA_SIGINFO;
41-
#endif
4236
if (!restart) {
4337
#ifdef SA_INTERRUPT
4438
act.sa_flags |= SA_INTERRUPT; /* SunOS */
@@ -50,14 +44,10 @@ Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
5044
}
5145
zend_sigaction(signo, &act, &oact);
5246

53-
#ifdef HAVE_STRUCT_SIGINFO_T
5447
return oact.sa_sigaction;
55-
#else
56-
return oact.sa_handler;
57-
#endif
5848
}
5949

60-
Sigfunc *php_signal(int signo, Sigfunc *func, int restart)
50+
Sigfunc *php_signal(int signo, Sigfunc *func, bool restart)
6151
{
62-
return php_signal4(signo, func, restart, 0);
52+
return php_signal4(signo, func, restart, false);
6353
}

ext/pcntl/php_signal.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
#ifndef PHP_SIGNAL_H
1919
#define PHP_SIGNAL_H
2020

21-
#ifdef HAVE_STRUCT_SIGINFO_T
2221
typedef void Sigfunc(int, siginfo_t*, void*);
23-
#else
24-
typedef void Sigfunc(int);
25-
#endif
26-
Sigfunc *php_signal(int signo, Sigfunc *func, int restart);
27-
Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all);
22+
23+
Sigfunc *php_signal(int signo, Sigfunc *func, bool restart);
24+
Sigfunc *php_signal4(int signo, Sigfunc *func, bool restart, bool mask_all);
2825

2926
#endif

0 commit comments

Comments
 (0)