Bug #79994 [Opn]: pcntl_signal_get_handler() should return SIG_IGN for externally ignored signals

From: Date: Tue, 18 Aug 2020 21:43:13 +0000
Subject: Bug #79994 [Opn]: pcntl_signal_get_handler() should return SIG_IGN for externally ignored signals
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228657@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79994&edit=1 ID: 79994 Updated by: requinix@php.net Reported by: weirdan at gmail dot com -Summary: pcntl_signal_get_handler() returns SIG_DFL for externally ignored signals +Summary: pcntl_signal_get_handler() should return SIG_IGN for externally ignored signals Status: Open Type: Bug Package: PCNTL related Operating System: Linux (Debian/sid) PHP Version: 7.4.9 Block user comment: N Private report: N New Comment: Ah, you're reporting something slightly different than I thought. That's why I like asking questions. I'm slightly rewording the summary in case I'm not the only one mistaken. Assuming that trap(1) is calling signal(7) or sigaction(7) with SIG_IGN, and given that sigaction is capable of returning the current signal handler (including whether it's ignored), then I agree that returning SIG_IGN is better than SIG_DFL. Currently, PHP is returning what PHP was told to do. No custom handler means SIG_DFL. I don't see that signal can return the current handler, though, so unless there's another function that can then this change in behavior may have to be platform-dependent. Previous Comments: ------------------------------------------------------------------------ [2020-08-18 21:21:42] weirdan at gmail dot com It should return SIG_IGN in this case. ------------------------------------------------------------------------ [2020-08-18 21:18:18] requinix@php.net Not a bug, but I'll get to that. First, a question: what should pcntl_signal_get_handler() be returning? ------------------------------------------------------------------------ [2020-08-18 21:07:57] weirdan at gmail dot com Description: ------------ Originally discovered by John Stevenson here: https://github.com/composer/xdebug-handler/issues/109#issuecomment-675462698 When signal is set to be ignored by the process that calls php binary, pcntl_signal_get_handler() run in the context of that binary reports that same signal as using default handler (SIG_DFL). However it's clearly doesn't use default handler, as can demonstrated by the script below. If it was using default handler, you'd be able to abort the script with Ctrl-C, but you can't. PS: use Ctrl-\ to stop it. Test script: --------------- <?php var_dump( "Is default handler is used for sigint?", pcntl_signal_get_handler(SIGINT) === SIG_DFL ); while (true) { echo "."; sleep(2); } // Run it as follows (in bash/zsh): // $ trap "" SIGINT; php test.php; trap - SIGINT; Expected result: ---------------- string(38) "Is default handler is used for sigint?" bool(false) .................. Actual result: -------------- string(38) "Is default handler is used for sigint?" bool(true) .................. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79994&edit=1

« previous php.bugs (#228657) next »