Skip to content

Commit f28b84a

Browse files
committed
Fix test hanging
1 parent 7ec329d commit f28b84a

File tree

3 files changed

+57
-35
lines changed

3 files changed

+57
-35
lines changed

ext/pcntl/pcntl.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,10 @@ PHP_FUNCTION(pcntl_signal_dispatch)
715715
static bool php_pcntl_set_user_signal_infos(
716716
/* const */ HashTable *const user_signals,
717717
sigset_t *const set,
718-
size_t arg_num
718+
size_t arg_num,
719+
bool allow_empty_signal_array
719720
) {
720-
if (zend_hash_num_elements(user_signals) == 0) {
721+
if (!allow_empty_signal_array && zend_hash_num_elements(user_signals) == 0) {
721722
zend_argument_value_error(arg_num, "cannot be empty");
722723
return false;
723724
}
@@ -787,21 +788,11 @@ PHP_FUNCTION(pcntl_sigprocmask)
787788
}
788789

789790
sigset_t set;
790-
/* Can set an empty array of signals for SIG_SETMASK */
791-
if (how == SIG_SETMASK && zend_hash_num_elements(user_set) == 0) {
792-
if (sigemptyset(&set) != 0) {
793-
PCNTL_G(last_error) = errno;
794-
php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
795-
RETURN_FALSE;
796-
}
797-
goto skip_setting_user_signals;
798-
}
799-
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 2);
791+
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 2, /* allow_empty_signal_array */ how == SIG_SETMASK);
800792
/* Some error occurred */
801793
if (!status) {
802794
RETURN_FALSE;
803795
}
804-
skip_setting_user_signals:
805796

806797
if (sigprocmask(how, &set, &old_set) != 0) {
807798
PCNTL_G(last_error) = errno;
@@ -845,7 +836,7 @@ PHP_FUNCTION(pcntl_sigwaitinfo)
845836
ZEND_PARSE_PARAMETERS_END();
846837

847838
sigset_t set;
848-
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 1);
839+
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 1, /* allow_empty_signal_array */ false);
849840
/* Some error occurred */
850841
if (!status) {
851842
RETURN_FALSE;
@@ -891,7 +882,7 @@ PHP_FUNCTION(pcntl_sigtimedwait)
891882
ZEND_PARSE_PARAMETERS_END();
892883

893884
sigset_t set;
894-
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 1);
885+
bool status = php_pcntl_set_user_signal_infos(user_set, &set, 1, /* allow_empty_signal_array */ false);
895886
/* Some error occurred */
896887
if (!status) {
897888
RETURN_FALSE;

ext/pcntl/tests/002.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if (
1111
or !function_exists('pcntl_sigtimedwait')
1212
) { die('skip required functionality is not available'); }
1313
elseif (!defined('CLD_EXITED')) die('skip CLD_EXITED not defined');
14-
elseif (getenv('SKIP_ASAN')) die('skip Fails intermittently under asan/msan');
1514
elseif (getenv("SKIP_REPEAT")) die("skip cannot be repeated");
1615
elseif (str_contains(PHP_OS, 'FreeBSD')) die('skip Results in parallel test runner hang on FreeBSD');
1716
?>
@@ -24,7 +23,7 @@ if ($pid == -1) {
2423
} else if ($pid) {
2524
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,(string)SIGTERM));
2625
$oldset = array();
27-
pcntl_sigprocmask(SIG_BLOCK, array(), $oldset);
26+
pcntl_sigprocmask(SIG_UNBLOCK, array(SIGINT), $oldset);
2827
var_dump(in_array(SIGCHLD, $oldset));
2928
var_dump(in_array(SIGTERM, $oldset));
3029

ext/pcntl/tests/003.phpt

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,61 @@ if (!function_exists("pcntl_sigprocmask")) die("skip pcntl_sigprocmask() not ava
1010
--FILE--
1111
<?php
1212

13+
const SIGNO_NAMES = [
14+
SIGINT => "SIGINT",
15+
SIGTERM => "SIGTERM",
16+
SIGCHLD => "SIGCHLD",
17+
];
18+
19+
function map_signo_to_name(int $no): string {
20+
return SIGNO_NAMES[$no];
21+
}
22+
1323
// Clear mask
14-
pcntl_sigprocmask(SIG_SETMASK, array(), $prev);
24+
pcntl_sigprocmask(SIG_SETMASK, [], $prev);
1525

16-
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,SIGTERM), $old);
17-
var_dump(count($old));
18-
pcntl_sigprocmask(SIG_BLOCK, array(SIGINT), $old);
19-
var_dump(count($old));
20-
pcntl_sigprocmask(SIG_UNBLOCK, array(SIGINT), $old);
21-
var_dump(count($old));
22-
pcntl_sigprocmask(SIG_SETMASK, array(SIGINT), $old);
23-
var_dump(count($old));
24-
pcntl_sigprocmask(SIG_SETMASK, array(), $old);
25-
var_dump(count($old));
26+
pcntl_sigprocmask(SIG_BLOCK, [SIGCHLD, SIGTERM], $old);
27+
var_dump(array_map(map_signo_to_name(...), $old));
28+
pcntl_sigprocmask(SIG_BLOCK, [SIGINT], $old);
29+
var_dump(array_map(map_signo_to_name(...), $old));
30+
pcntl_sigprocmask(SIG_UNBLOCK, [SIGINT], $old);
31+
var_dump(array_map(map_signo_to_name(...), $old));
32+
pcntl_sigprocmask(SIG_SETMASK, [SIGINT], $old);
33+
var_dump(array_map(map_signo_to_name(...), $old));
34+
pcntl_sigprocmask(SIG_SETMASK, [], $old);
35+
var_dump(array_map(map_signo_to_name(...), $old));
2636

2737
// Restore previous mask
2838
pcntl_sigprocmask(SIG_SETMASK, $prev, $old);
29-
var_dump(count($old));
39+
var_dump(array_map(map_signo_to_name(...), $old));
3040

3141
?>
3242
--EXPECT--
33-
int(0)
34-
int(2)
35-
int(3)
36-
int(2)
37-
int(1)
38-
int(0)
43+
array(0) {
44+
}
45+
array(2) {
46+
[0]=>
47+
string(7) "SIGTERM"
48+
[1]=>
49+
string(7) "SIGCHLD"
50+
}
51+
array(3) {
52+
[0]=>
53+
string(6) "SIGINT"
54+
[1]=>
55+
string(7) "SIGTERM"
56+
[2]=>
57+
string(7) "SIGCHLD"
58+
}
59+
array(2) {
60+
[0]=>
61+
string(7) "SIGTERM"
62+
[1]=>
63+
string(7) "SIGCHLD"
64+
}
65+
array(1) {
66+
[0]=>
67+
string(6) "SIGINT"
68+
}
69+
array(0) {
70+
}

0 commit comments

Comments
 (0)