xref: /php-src/ext/pcntl/tests/003.phpt (revision 1bdb0fdd)
1--TEST--
2pcntl: SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK
3--EXTENSIONS--
4pcntl
5posix
6--SKIPIF--
7<?php
8if (!function_exists("pcntl_sigprocmask")) die("skip pcntl_sigprocmask() not available");
9?>
10--FILE--
11<?php
12
13const SIGNO_NAMES = [
14    SIGINT => "SIGINT",
15    SIGTERM => "SIGTERM",
16    SIGCHLD => "SIGCHLD",
17];
18
19function map_signo_to_name(int $no): string {
20    return SIGNO_NAMES[$no];
21}
22
23// Clear mask
24pcntl_sigprocmask(SIG_SETMASK, [], $prev);
25
26pcntl_sigprocmask(SIG_BLOCK, [SIGCHLD, SIGTERM], $old);
27var_dump(array_map(map_signo_to_name(...), $old));
28pcntl_sigprocmask(SIG_BLOCK, [SIGINT], $old);
29var_dump(array_map(map_signo_to_name(...), $old));
30pcntl_sigprocmask(SIG_UNBLOCK, [SIGINT], $old);
31var_dump(array_map(map_signo_to_name(...), $old));
32pcntl_sigprocmask(SIG_SETMASK, [SIGINT], $old);
33var_dump(array_map(map_signo_to_name(...), $old));
34pcntl_sigprocmask(SIG_SETMASK, [], $old);
35var_dump(array_map(map_signo_to_name(...), $old));
36
37// Restore previous mask
38pcntl_sigprocmask(SIG_SETMASK, $prev, $old);
39var_dump(array_map(map_signo_to_name(...), $old));
40
41?>
42--EXPECT--
43array(0) {
44}
45array(2) {
46  [0]=>
47  string(7) "SIGTERM"
48  [1]=>
49  string(7) "SIGCHLD"
50}
51array(3) {
52  [0]=>
53  string(6) "SIGINT"
54  [1]=>
55  string(7) "SIGTERM"
56  [2]=>
57  string(7) "SIGCHLD"
58}
59array(2) {
60  [0]=>
61  string(7) "SIGTERM"
62  [1]=>
63  string(7) "SIGCHLD"
64}
65array(1) {
66  [0]=>
67  string(6) "SIGINT"
68}
69array(0) {
70}
71