@@ -82,6 +82,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_sigprocmask, 0, 0, 2)
82
82
ZEND_ARG_INFO (1 , oldset )
83
83
ZEND_END_ARG_INFO ()
84
84
85
+ #ifdef HAVE_STRUCT_SIGINFO_T
86
+ # if HAVE_SIGWAITINFO && HAVE_SIGTIMEDWAIT
85
87
ZEND_BEGIN_ARG_INFO_EX (arginfo_pcntl_sigwaitinfo , 0 , 0 , 1 )
86
88
ZEND_ARG_INFO (0 , set )
87
89
ZEND_ARG_INFO (1 , info )
@@ -93,6 +95,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_sigtimedwait, 0, 0, 1)
93
95
ZEND_ARG_INFO (0 , seconds )
94
96
ZEND_ARG_INFO (0 , nanoseconds )
95
97
ZEND_END_ARG_INFO ()
98
+ # endif
99
+ #endif
96
100
97
101
ZEND_BEGIN_ARG_INFO_EX (arginfo_pcntl_wifexited , 0 , 0 , 1 )
98
102
ZEND_ARG_INFO (0 , status )
@@ -185,9 +189,11 @@ const zend_function_entry pcntl_functions[] = {
185
189
#ifdef HAVE_SIGPROCMASK
186
190
PHP_FE (pcntl_sigprocmask , arginfo_pcntl_sigprocmask )
187
191
#endif
188
- #if HAVE_SIGWAITINFO && HAVE_SIGTIMEDWAIT
192
+ #ifdef HAVE_STRUCT_SIGINFO_T
193
+ # if HAVE_SIGWAITINFO && HAVE_SIGTIMEDWAIT
189
194
PHP_FE (pcntl_sigwaitinfo , arginfo_pcntl_sigwaitinfo )
190
195
PHP_FE (pcntl_sigtimedwait , arginfo_pcntl_sigtimedwait )
196
+ # endif
191
197
#endif
192
198
#ifdef HAVE_WCONTINUED
193
199
PHP_FE (pcntl_wifcontinued , arginfo_pcntl_wifcontinued )
@@ -219,7 +225,12 @@ ZEND_GET_MODULE(pcntl)
219
225
220
226
static void (* orig_interrupt_function )(zend_execute_data * execute_data );
221
227
228
+ #ifdef HAVE_STRUCT_SIGINFO_T
229
+ static void pcntl_signal_handler (int , siginfo_t * , void * );
230
+ static void pcntl_siginfo_to_zval (int , siginfo_t * , zval * );
231
+ #else
222
232
static void pcntl_signal_handler (int );
233
+ #endif
223
234
static void pcntl_signal_dispatch ();
224
235
static void pcntl_interrupt_function (zend_execute_data * execute_data );
225
236
@@ -997,7 +1008,7 @@ PHP_FUNCTION(pcntl_signal)
997
1008
php_error_docref (NULL , E_WARNING , "Invalid value for handle argument specified" );
998
1009
RETURN_FALSE ;
999
1010
}
1000
- if (php_signal (signo , (Sigfunc * ) Z_LVAL_P (handle ), (int ) restart_syscalls ) == SIG_ERR ) {
1011
+ if (php_signal (signo , (Sigfunc * ) Z_LVAL_P (handle ), (int ) restart_syscalls ) == ( Sigfunc * ) SIG_ERR ) {
1001
1012
PCNTL_G (last_error ) = errno ;
1002
1013
php_error_docref (NULL , E_WARNING , "Error assigning signal" );
1003
1014
RETURN_FALSE ;
@@ -1019,7 +1030,7 @@ PHP_FUNCTION(pcntl_signal)
1019
1030
if (Z_REFCOUNTED_P (handle )) Z_ADDREF_P (handle );
1020
1031
}
1021
1032
1022
- if (php_signal4 (signo , pcntl_signal_handler , (int ) restart_syscalls , 1 ) == SIG_ERR ) {
1033
+ if (php_signal4 (signo , pcntl_signal_handler , (int ) restart_syscalls , 1 ) == ( Sigfunc * ) SIG_ERR ) {
1023
1034
PCNTL_G (last_error ) = errno ;
1024
1035
php_error_docref (NULL , E_WARNING , "Error assigning signal" );
1025
1036
RETURN_FALSE ;
@@ -1114,7 +1125,8 @@ PHP_FUNCTION(pcntl_sigprocmask)
1114
1125
/* }}} */
1115
1126
#endif
1116
1127
1117
- #if HAVE_SIGWAITINFO && HAVE_SIGTIMEDWAIT
1128
+ #ifdef HAVE_STRUCT_SIGINFO_T
1129
+ # if HAVE_SIGWAITINFO && HAVE_SIGTIMEDWAIT
1118
1130
static void pcntl_sigwaitinfo (INTERNAL_FUNCTION_PARAMETERS , int timedwait ) /* {{{ */
1119
1131
{
1120
1132
zval * user_set , * user_signo , * user_siginfo = NULL ;
@@ -1168,65 +1180,75 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{
1168
1180
if (!signo && siginfo .si_signo ) {
1169
1181
signo = siginfo .si_signo ;
1170
1182
}
1183
+ pcntl_siginfo_to_zval (signo , & siginfo , user_siginfo );
1184
+ RETURN_LONG (signo );
1185
+ }
1186
+ /* }}} */
1187
+
1188
+ /* {{{ proto int pcnlt_sigwaitinfo(array set[, array &siginfo])
1189
+ Synchronously wait for queued signals */
1190
+ PHP_FUNCTION (pcntl_sigwaitinfo )
1191
+ {
1192
+ pcntl_sigwaitinfo (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
1193
+ }
1194
+ /* }}} */
1195
+
1196
+ /* {{{ proto int pcntl_sigtimedwait(array set[, array &siginfo[, int seconds[, int nanoseconds]]])
1197
+ Wait for queued signals */
1198
+ PHP_FUNCTION (pcntl_sigtimedwait )
1199
+ {
1200
+ pcntl_sigwaitinfo (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
1201
+ }
1202
+ /* }}} */
1203
+ # endif
1171
1204
1205
+ static void pcntl_siginfo_to_zval (int signo , siginfo_t * siginfo , zval * user_siginfo ) /* {{{ */
1206
+ {
1172
1207
if (signo > 0 && user_siginfo ) {
1173
1208
if (Z_TYPE_P (user_siginfo ) != IS_ARRAY ) {
1174
1209
zval_dtor (user_siginfo );
1175
1210
array_init (user_siginfo );
1176
1211
} else {
1177
1212
zend_hash_clean (Z_ARRVAL_P (user_siginfo ));
1178
1213
}
1179
- add_assoc_long_ex (user_siginfo , "signo" , sizeof ("signo" )- 1 , siginfo . si_signo );
1180
- add_assoc_long_ex (user_siginfo , "errno" , sizeof ("errno" )- 1 , siginfo . si_errno );
1181
- add_assoc_long_ex (user_siginfo , "code" , sizeof ("code" )- 1 , siginfo . si_code );
1214
+ add_assoc_long_ex (user_siginfo , "signo" , sizeof ("signo" )- 1 , siginfo -> si_signo );
1215
+ add_assoc_long_ex (user_siginfo , "errno" , sizeof ("errno" )- 1 , siginfo -> si_errno );
1216
+ add_assoc_long_ex (user_siginfo , "code" , sizeof ("code" )- 1 , siginfo -> si_code );
1182
1217
switch (signo ) {
1183
1218
#ifdef SIGCHLD
1184
1219
case SIGCHLD :
1185
- add_assoc_long_ex (user_siginfo , "status" , sizeof ("status" )- 1 , siginfo . si_status );
1220
+ add_assoc_long_ex (user_siginfo , "status" , sizeof ("status" )- 1 , siginfo -> si_status );
1186
1221
# ifdef si_utime
1187
- add_assoc_double_ex (user_siginfo , "utime" , sizeof ("utime" )- 1 , siginfo . si_utime );
1222
+ add_assoc_double_ex (user_siginfo , "utime" , sizeof ("utime" )- 1 , siginfo -> si_utime );
1188
1223
# endif
1189
1224
# ifdef si_stime
1190
- add_assoc_double_ex (user_siginfo , "stime" , sizeof ("stime" )- 1 , siginfo . si_stime );
1225
+ add_assoc_double_ex (user_siginfo , "stime" , sizeof ("stime" )- 1 , siginfo -> si_stime );
1191
1226
# endif
1192
- add_assoc_long_ex (user_siginfo , "pid" , sizeof ("pid" )- 1 , siginfo .si_pid );
1193
- add_assoc_long_ex (user_siginfo , "uid" , sizeof ("uid" )- 1 , siginfo .si_uid );
1227
+ add_assoc_long_ex (user_siginfo , "pid" , sizeof ("pid" )- 1 , siginfo -> si_pid );
1228
+ add_assoc_long_ex (user_siginfo , "uid" , sizeof ("uid" )- 1 , siginfo -> si_uid );
1229
+ break ;
1230
+ case SIGUSR1 :
1231
+ case SIGUSR2 :
1232
+ add_assoc_long_ex (user_siginfo , "pid" , sizeof ("pid" )- 1 , siginfo -> si_pid );
1233
+ add_assoc_long_ex (user_siginfo , "uid" , sizeof ("uid" )- 1 , siginfo -> si_uid );
1194
1234
break ;
1195
1235
#endif
1196
1236
case SIGILL :
1197
1237
case SIGFPE :
1198
1238
case SIGSEGV :
1199
1239
case SIGBUS :
1200
- add_assoc_double_ex (user_siginfo , "addr" , sizeof ("addr" )- 1 , (zend_long )siginfo . si_addr );
1240
+ add_assoc_double_ex (user_siginfo , "addr" , sizeof ("addr" )- 1 , (zend_long )siginfo -> si_addr );
1201
1241
break ;
1202
1242
#ifdef SIGPOLL
1203
1243
case SIGPOLL :
1204
- add_assoc_long_ex (user_siginfo , "band" , sizeof ("band" )- 1 , siginfo . si_band );
1244
+ add_assoc_long_ex (user_siginfo , "band" , sizeof ("band" )- 1 , siginfo -> si_band );
1205
1245
# ifdef si_fd
1206
- add_assoc_long_ex (user_siginfo , "fd" , sizeof ("fd" )- 1 , siginfo . si_fd );
1246
+ add_assoc_long_ex (user_siginfo , "fd" , sizeof ("fd" )- 1 , siginfo -> si_fd );
1207
1247
# endif
1208
1248
break ;
1209
1249
#endif
1210
1250
}
1211
1251
}
1212
-
1213
- RETURN_LONG (signo );
1214
- }
1215
- /* }}} */
1216
-
1217
- /* {{{ proto int pcnlt_sigwaitinfo(array set[, array &siginfo])
1218
- Synchronously wait for queued signals */
1219
- PHP_FUNCTION (pcntl_sigwaitinfo )
1220
- {
1221
- pcntl_sigwaitinfo (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
1222
- }
1223
- /* }}} */
1224
-
1225
- /* {{{ proto int pcntl_sigtimedwait(array set[, array &siginfo[, int seconds[, int nanoseconds]]])
1226
- Wait for queued signals */
1227
- PHP_FUNCTION (pcntl_sigtimedwait )
1228
- {
1229
- pcntl_sigwaitinfo (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
1230
1252
}
1231
1253
/* }}} */
1232
1254
#endif
@@ -1333,7 +1355,11 @@ PHP_FUNCTION(pcntl_strerror)
1333
1355
/* }}} */
1334
1356
1335
1357
/* Our custom signal handler that calls the appropriate php_function */
1358
+ #ifdef HAVE_STRUCT_SIGINFO_T
1359
+ static void pcntl_signal_handler (int signo , siginfo_t * siginfo , void * context )
1360
+ #else
1336
1361
static void pcntl_signal_handler (int signo )
1362
+ #endif
1337
1363
{
1338
1364
struct php_pcntl_pending_signal * psig ;
1339
1365
@@ -1347,6 +1373,14 @@ static void pcntl_signal_handler(int signo)
1347
1373
psig -> signo = signo ;
1348
1374
psig -> next = NULL ;
1349
1375
1376
+ #ifdef HAVE_STRUCT_SIGINFO_T
1377
+ zval user_siginfo ;
1378
+ ZVAL_NEW_ARR (& user_siginfo );
1379
+ array_init (& user_siginfo );
1380
+ pcntl_siginfo_to_zval (signo , siginfo , & user_siginfo );
1381
+ psig -> siginfo = Z_ARRVAL (user_siginfo );
1382
+ #endif
1383
+
1350
1384
/* the head check is important, as the tick handler cannot atomically clear both
1351
1385
* the head and tail */
1352
1386
if (PCNTL_G (head ) && PCNTL_G (tail )) {
@@ -1363,7 +1397,7 @@ static void pcntl_signal_handler(int signo)
1363
1397
1364
1398
void pcntl_signal_dispatch ()
1365
1399
{
1366
- zval param , * handle , retval ;
1400
+ zval params [ 2 ] , * handle , retval ;
1367
1401
struct php_pcntl_pending_signal * queue , * next ;
1368
1402
sigset_t mask ;
1369
1403
sigset_t old_mask ;
@@ -1376,8 +1410,8 @@ void pcntl_signal_dispatch()
1376
1410
sigfillset (& mask );
1377
1411
sigprocmask (SIG_BLOCK , & mask , & old_mask );
1378
1412
1379
- /* Bail if the queue is empty or if we are already playing the queue*/
1380
- if (! PCNTL_G (head ) || PCNTL_G (processing_signal_queue )) {
1413
+ /* Bail if the queue is empty or if we are already playing the queue */
1414
+ if (!PCNTL_G (head ) || PCNTL_G (processing_signal_queue )) {
1381
1415
sigprocmask (SIG_SETMASK , & old_mask , NULL );
1382
1416
return ;
1383
1417
}
@@ -1394,13 +1428,19 @@ void pcntl_signal_dispatch()
1394
1428
if ((handle = zend_hash_index_find (& PCNTL_G (php_signal_table ), queue -> signo )) != NULL ) {
1395
1429
if (Z_TYPE_P (handle ) != IS_LONG ) {
1396
1430
ZVAL_NULL (& retval );
1397
- ZVAL_LONG (& param , queue -> signo );
1431
+ ZVAL_LONG (& params [0 ], queue -> signo );
1432
+ #ifdef HAVE_STRUCT_SIGINFO_T
1433
+ ZVAL_ARR (& params [1 ], queue -> siginfo );
1434
+ #else
1435
+ ZVAL_NULL (& params [1 ]);
1436
+ #endif
1398
1437
1399
1438
/* Call php signal handler - Note that we do not report errors, and we ignore the return value */
1400
1439
/* FIXME: this is probably broken when multiple signals are handled in this while loop (retval) */
1401
- call_user_function (EG (function_table ), NULL , handle , & retval , 1 , & param );
1402
- zval_ptr_dtor (& param );
1440
+ call_user_function (EG (function_table ), NULL , handle , & retval , 2 , params );
1403
1441
zval_ptr_dtor (& retval );
1442
+ zval_ptr_dtor (& params [0 ]);
1443
+ zval_ptr_dtor (& params [1 ]);
1404
1444
}
1405
1445
}
1406
1446
0 commit comments