31 $this->signalHandlers = array();
32 if (extension_loaded(
'pcntl')) {
33 if (function_exists(
'pcntl_async_signals')) {
34 $this->asyncSignalHandling = pcntl_async_signals();
36 if (function_exists(
'pcntl_sigprocmask')) {
37 pcntl_sigprocmask(SIG_BLOCK, array(), $this->blockedSignals);
44 if ($this->asyncSignalHandling !== null) {
45 pcntl_async_signals($this->asyncSignalHandling);
47 if ($this->blockedSignals !== null) {
48 pcntl_sigprocmask(SIG_SETMASK, $this->blockedSignals);
50 if ($this->signalHandlers) {
51 pcntl_signal_dispatch();
52 foreach ($this->signalHandlers as $signo =>
$handler) {
59 if (function_exists(
'pcntl_signal_get_handler')) {
60 $this->signalHandlers[$signo] = pcntl_signal_get_handler($signo);
62 $this->signalHandlers[$signo] = SIG_DFL;
64 $this->assertTrue(pcntl_signal($signo,
$handler));
72 $siginfo = array(
'signo' => $signo,
'errno' => 0,
'code' => 0);
73 $errHandler->handleSignal($signo, $siginfo);
74 $this->assertCount(1,
$handler->getRecords());
75 $this->assertTrue(
$handler->hasCriticalRecords());
77 $this->assertSame($siginfo, $records[0][
'context']);
92 if (!defined(
'SIGCONT') || !defined(
'SIGURG')) {
93 $this->markTestSkipped(
'This test requires the SIGCONT and SIGURG pcntl constants.');
96 $this->setSignalHandler(SIGCONT, SIG_IGN);
97 $this->setSignalHandler(SIGURG, SIG_IGN);
101 $pid = posix_getpid();
103 $this->assertTrue(posix_kill($pid, SIGURG));
104 $this->assertTrue(pcntl_signal_dispatch());
105 $this->assertCount(0,
$handler->getRecords());
107 $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO,
false,
false,
false);
109 $this->assertTrue(posix_kill($pid, SIGCONT));
110 $this->assertTrue(pcntl_signal_dispatch());
111 $this->assertCount(0,
$handler->getRecords());
113 $this->assertTrue(posix_kill($pid, SIGURG));
114 $this->assertTrue(pcntl_signal_dispatch());
115 $this->assertCount(1,
$handler->getRecords());
116 $this->assertTrue(
$handler->hasInfoThatContains(
'SIGURG'));
128 $this->setSignalHandler($signo, SIG_DFL);
130 $path = tempnam(sys_get_temp_dir(),
'monolog-');
131 $this->assertNotFalse(
$path);
136 $streamHandler->setFormatter($this->getIdentityFormatter());
137 $logger =
new Logger(
'test', array($streamHandler));
139 $errHandler->registerSignalHandler($signo, LogLevel::INFO, $callPrevious,
false,
false);
140 pcntl_sigprocmask(SIG_SETMASK, array(SIGCONT));
141 posix_kill(posix_getpid(), $signo);
142 pcntl_signal_dispatch();
144 pcntl_sigprocmask(SIG_BLOCK, array(), $oldset);
145 file_put_contents(
$path, implode(
' ', $oldset), FILE_APPEND);
146 posix_kill(posix_getpid(), $signo);
147 pcntl_signal_dispatch();
151 $this->assertNotSame(-1, $pid);
152 $this->assertNotSame(-1, pcntl_waitpid($pid, $status));
153 $this->assertNotSame(-1, $status);
154 $this->assertSame($expected, file_get_contents(
$path));
159 if (!defined(
'SIGCONT') || !defined(
'SIGINT') || !defined(
'SIGURG')) {
164 array(SIGINT,
false,
'Program received signal SIGINT'.SIGCONT.
'Program received signal SIGINT'),
165 array(SIGINT,
true,
'Program received signal SIGINT'),
166 array(SIGURG,
false,
'Program received signal SIGURG'.SIGCONT.
'Program received signal SIGURG'),
167 array(SIGURG,
true,
'Program received signal SIGURG'.SIGCONT.
'Program received signal SIGURG'),
178 $this->setSignalHandler(SIGURG, SIG_IGN);
183 pcntl_signal(SIGURG,
function ($signo, array $siginfo = null) use (&$previousCalled) {
186 $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO, $callPrevious,
false,
false);
187 $this->assertTrue(posix_kill(posix_getpid(), SIGURG));
188 $this->assertTrue(pcntl_signal_dispatch());
189 $this->assertCount(1,
$handler->getRecords());
190 $this->assertTrue(
$handler->hasInfoThatContains(
'SIGURG'));
191 $this->assertSame($callPrevious ? 1 : 0, $previousCalled);
210 $this->setSignalHandler(SIGURG, SIG_IGN);
212 $parentPid = posix_getpid();
213 $microtime = microtime(
true);
218 posix_kill($parentPid, SIGURG);
223 $this->assertNotSame(-1, $pid);
226 $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO,
false, $restartSyscalls,
false);
227 if ($restartSyscalls) {
229 $this->assertNotSame(-1, pcntl_waitpid($pid, $status));
232 $this->assertSame(-1, pcntl_waitpid($pid, $status));
234 $this->assertSame($restartSyscalls, microtime(
true) - $microtime > 0.15);
235 $this->assertTrue(pcntl_signal_dispatch());
236 $this->assertCount(1,
$handler->getRecords());
237 if ($restartSyscalls) {
239 $this->assertSame(-1, pcntl_waitpid($pid, $status));
242 $this->assertNotSame(-1, pcntl_waitpid($pid, $status));
263 $this->setSignalHandler(SIGURG, SIG_IGN);
264 pcntl_async_signals($initialAsync);
268 $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO,
false,
false, $desiredAsync);
269 $this->assertTrue(posix_kill(posix_getpid(), SIGURG));
270 $this->assertCount($expectedBefore,
$handler->getRecords());
271 $this->assertTrue(pcntl_signal_dispatch());
272 $this->assertCount($expectedAfter,
$handler->getRecords());
278 array(
false,
false, 0, 1),
279 array(
false, null, 0, 1),
280 array(
false,
true, 1, 1),
281 array(
true,
false, 0, 1),
282 array(
true, null, 1, 1),
283 array(
true,
true, 1, 1),
callablePreviousProvider()
restartSyscallsProvider()
defaultPreviousProvider()
testRegisterCallablePreviousSignalHandler($callPrevious)
callablePreviousProvider testRegisterSignalHandler function pcntl_signal_get_handler ...
testRegisterAsyncSignalHandler($initialAsync, $desiredAsync, $expectedBefore, $expectedAfter)
asyncProvider testRegisterDefaultPreviousSignalHandler function pcntl_async_signals ...
testRegisterSignalHandler()
testHandleSignal extension pcntl extension posix function pcntl_signal function pcntl_signal_disp...
setSignalHandler($signo, $handler=SIG_DFL)
testRegisterDefaultPreviousSignalHandler($signo, $callPrevious, $expected)
defaultPreviousProvider testRegisterSignalHandler function pcntl_fork function pcntl_sigprocmask ...
testRegisterSyscallRestartingSignalHandler($restartSyscalls)
restartSyscallsProvider testRegisterDefaultPreviousSignalHandler function pcntl_fork function pcnt...
Stores to any stream resource.
Used for testing purposes.
Monolog POSIX signal handler.