Skip to content

Commit b134b17

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 d407266 commit b134b17

File tree

7 files changed

+21
-57
lines changed

7 files changed

+21
-57
lines changed

ext/pcntl/config.m4

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ int main(void) {
2828
AC_MSG_RESULT([no, cross-compiling])
2929
])
3030

31-
AC_CHECK_TYPE([siginfo_t],[PCNTL_CFLAGS="-DHAVE_STRUCT_SIGINFO_T"],,[#include <signal.h>])
32-
3331
PHP_NEW_EXTENSION(pcntl, pcntl.c php_signal.c, $ext_shared, cli, $PCNTL_CFLAGS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
3432
fi

ext/pcntl/pcntl.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,8 @@ ZEND_GET_MODULE(pcntl)
104104

105105
static void (*orig_interrupt_function)(zend_execute_data *execute_data);
106106

107-
#ifdef HAVE_STRUCT_SIGINFO_T
108107
static void pcntl_signal_handler(int, siginfo_t*, void*);
109108
static void pcntl_siginfo_to_zval(int, siginfo_t*, zval*);
110-
#else
111-
static void pcntl_signal_handler(int);
112-
#endif
113109
static void pcntl_signal_dispatch(void);
114110
static void pcntl_signal_dispatch_tick_function(int dummy_int, void *dummy_pointer);
115111
static void pcntl_interrupt_function(zend_execute_data *execute_data);
@@ -166,7 +162,7 @@ PHP_RSHUTDOWN_FUNCTION(pcntl)
166162
/* Reset all signals to their default disposition */
167163
ZEND_HASH_FOREACH_NUM_KEY_VAL(&PCNTL_G(php_signal_table), signo, handle) {
168164
if (Z_TYPE_P(handle) != IS_LONG || Z_LVAL_P(handle) != (zend_long)SIG_DFL) {
169-
php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, 0);
165+
php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, false);
170166
}
171167
} ZEND_HASH_FOREACH_END();
172168

@@ -662,7 +658,7 @@ PHP_FUNCTION(pcntl_signal)
662658
zend_argument_value_error(2, "must be either SIG_DFL or SIG_IGN when an integer value is given");
663659
RETURN_THROWS();
664660
}
665-
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == (void *)SIG_ERR) {
661+
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), restart_syscalls) == (void *)SIG_ERR) {
666662
PCNTL_G(last_error) = errno;
667663
php_error_docref(NULL, E_WARNING, "Error assigning signal");
668664
RETURN_FALSE;
@@ -682,7 +678,7 @@ PHP_FUNCTION(pcntl_signal)
682678
handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
683679
Z_TRY_ADDREF_P(handle);
684680

685-
if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) {
681+
if (php_signal4(signo, pcntl_signal_handler, restart_syscalls, true) == (void *)SIG_ERR) {
686682
PCNTL_G(last_error) = errno;
687683
php_error_docref(NULL, E_WARNING, "Error assigning signal");
688684
RETURN_FALSE;
@@ -841,8 +837,7 @@ PHP_FUNCTION(pcntl_sigprocmask)
841837
/* }}} */
842838
#endif
843839

844-
#ifdef HAVE_STRUCT_SIGINFO_T
845-
# ifdef HAVE_SIGWAITINFO
840+
#ifdef HAVE_SIGWAITINFO
846841

847842
/* {{{ Synchronously wait for queued signals */
848843
PHP_FUNCTION(pcntl_sigwaitinfo)
@@ -884,8 +879,9 @@ PHP_FUNCTION(pcntl_sigwaitinfo)
884879
RETURN_LONG(signal_no);
885880
}
886881
/* }}} */
887-
# endif
888-
# ifdef HAVE_SIGTIMEDWAIT
882+
#endif
883+
884+
#ifdef HAVE_SIGTIMEDWAIT
889885
/* {{{ Wait for queued signals */
890886
PHP_FUNCTION(pcntl_sigtimedwait)
891887
{
@@ -947,7 +943,7 @@ PHP_FUNCTION(pcntl_sigtimedwait)
947943
RETURN_LONG(signal_no);
948944
}
949945
/* }}} */
950-
# endif
946+
#endif
951947

952948
static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_siginfo) /* {{{ */
953949
{
@@ -1003,7 +999,6 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi
1003999
}
10041000
}
10051001
/* }}} */
1006-
#endif
10071002

10081003
#ifdef HAVE_GETPRIORITY
10091004
/* {{{ Get the priority of any process */
@@ -1145,11 +1140,7 @@ PHP_FUNCTION(pcntl_strerror)
11451140
/* }}} */
11461141

11471142
/* Our custom signal handler that calls the appropriate php_function */
1148-
#ifdef HAVE_STRUCT_SIGINFO_T
11491143
static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
1150-
#else
1151-
static void pcntl_signal_handler(int signo)
1152-
#endif
11531144
{
11541145
struct php_pcntl_pending_signal *psig = PCNTL_G(spares);
11551146
if (!psig) {
@@ -1161,9 +1152,7 @@ static void pcntl_signal_handler(int signo)
11611152
psig->signo = signo;
11621153
psig->next = NULL;
11631154

1164-
#ifdef HAVE_STRUCT_SIGINFO_T
11651155
psig->siginfo = *siginfo;
1166-
#endif
11671156

11681157
/* the head check is important, as the tick handler cannot atomically clear both
11691158
* the head and tail */
@@ -1215,20 +1204,14 @@ void pcntl_signal_dispatch(void)
12151204
if (Z_TYPE_P(handle) != IS_LONG) {
12161205
ZVAL_NULL(&retval);
12171206
ZVAL_LONG(&params[0], queue->signo);
1218-
#ifdef HAVE_STRUCT_SIGINFO_T
12191207
array_init(&params[1]);
12201208
pcntl_siginfo_to_zval(queue->signo, &queue->siginfo, &params[1]);
1221-
#else
1222-
ZVAL_NULL(&params[1]);
1223-
#endif
12241209

12251210
/* Call php signal handler - Note that we do not report errors, and we ignore the return value */
12261211
/* FIXME: this is probably broken when multiple signals are handled in this while loop (retval) */
12271212
call_user_function(NULL, NULL, handle, &retval, 2, params);
12281213
zval_ptr_dtor(&retval);
1229-
#ifdef HAVE_STRUCT_SIGINFO_T
12301214
zval_ptr_dtor(&params[1]);
1231-
#endif
12321215
}
12331216
}
12341217

ext/pcntl/pcntl.stub.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,15 +932,13 @@ function pcntl_signal_dispatch(): bool {}
932932
function pcntl_sigprocmask(int $mode, array $signals, &$old_signals = null): bool {}
933933
#endif
934934

935-
#ifdef HAVE_STRUCT_SIGINFO_T
936935
#if (defined(HAVE_SIGWAITINFO) && defined(HAVE_SIGTIMEDWAIT))
937936
/** @param array $info */
938937
function pcntl_sigwaitinfo(array $signals, &$info = []): int|false {}
939938

940939
/** @param array $info */
941940
function pcntl_sigtimedwait(array $signals, &$info = [], int $seconds = 0, int $nanoseconds = 0): int|false {}
942941
#endif
943-
#endif
944942

945943
function pcntl_wifexited(int $status): bool {}
946944

ext/pcntl/pcntl_arginfo.h

Lines changed: 7 additions & 7 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
@@ -36,9 +36,7 @@ PHP_MINFO_FUNCTION(pcntl);
3636
struct php_pcntl_pending_signal {
3737
struct php_pcntl_pending_signal *next;
3838
zend_long signo;
39-
#ifdef HAVE_STRUCT_SIGINFO_T
4039
siginfo_t siginfo;
41-
#endif
4240
};
4341

4442
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)