Bug #55614 [Asn->Opn]: pcntl_signal() + fgetc() is not allowing me to break with CTRL+C

From: Date: Sun, 18 Jul 2021 10:30:28 +0000
Subject: Bug #55614 [Asn->Opn]: pcntl_signal() + fgetc() is not allowing me to break with CTRL+C
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235146@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55614&edit=1 ID: 55614 Updated by: cmb@php.net Reported by: i3367890 at gmail dot com Summary: pcntl_signal() + fgetc() is not allowing me to break with CTRL+C -Status: Assigned +Status: Open Type: Bug Package: PCNTL related Operating System: (Arch, Debian) Linux PHP Version: 5.3.8 - 8.0.7 -Assigned To: cmb +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2021-07-18 04:58:08] i3367890 at gmail dot com Testing 1 2 3... I got the error "You aren't allowed to change a bug to that state." while trying to submit the previous comment and a state change to "Re-Opened". I'd like to leave it at "Open", but I can only set it to "Assigned". That at least changes it from "Closed", which isn't what I want. ------------------------------------------------------------------------ [2021-07-18 04:55:14] i3367890 at gmail dot com Yep... adding pcntl_async_signals(true) sadly doesn't do anything. And wow, that other bug is from 2009 :) I can only concur with the comment from sjoerd@ 12 years ago, "It would certainly be desirable to be able to interrupt a blocking read by doing Ctrl-C." This is a bit of a sad language design oversight. Getting huffy about it won't do anything, but maybe empathizing with the complexity of the situation will make it feel less impossible to fix :) (...eventually™.) Thanks again for following up. I look forward to the day PHP has a sane/simple set of APIs for making CLIs that get of the user's (and developer's) way. ------------------------------------------------------------------------ [2021-07-18 04:22:08] php-bugs at lists dot php dot net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. ------------------------------------------------------------------------ [2021-07-08 10:17:27] cmb@php.net Yeah, sorry, very long time to respond. Anyhow, this can't work, because you're using ticks as signal handler, and there is no tick executed while fgets() waits for input. Did you try with pcntl_async_signals(true) That may work, but according to a comment on bug #49340, it does not. ------------------------------------------------------------------------ [2021-07-08 06:21:26] i3367890 at gmail dot com Wow, I completely forgot about posting this. Thanks for following up. Unfortunately it does still seem to be hanging around. $ php --version PHP 8.0.7 (cli) (built: Jun 4 2021 23:17:30) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.7, Copyright (c) Zend Technologies with Zend OPcache v8.0.7, Copyright (c), by Zend Technologies (This is from deb.sury.org. I'm on Debian now.) $ php -r "declare(ticks = 1); function quit() { print \"X\\n\"; die; } pcntl_signal(SIGINT, \"quit\"); fgetc(STDIN);" ^C^C^C^C^C^C^\Quit $ _ Continuous ^C^C^C still simply retries forever: PHP tty | strace tty | ... | rt_sigprocmask(SIG_UNBLOCK, [INT], NULL, 8) = 0 | read(0, 0x7fd24947f000, 8192) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) ^C ---------------^ | --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} --- | rt_sigreturn({mask=[]}) = 0 | read(0, 0x7fd24947f000, 8192) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) ^C ---------------^ | --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} --- | rt_sigreturn({mask=[]}) = 0 | read(0, 0x7fd24947f000, 8192) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) ^C ---------------^ | --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} --- | rt_sigreturn({mask=[]}) = 0 | read(0, "x\n", 8192) = 2 'x' + ------------^ <Return> | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0 Exit-> | write(1, "X\n", 2) = 2 | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0 | rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0 | rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 | close(2) = 0 | close(1) = 0 | close(0) = 0 | munmap(..., ...) = 0 | ... (NB, the note about stty cbreak at the end of the 2nd comment is somewhat orthogonal to this bug; inputting any text then pressing Return IMO suffices to demonstrate that normal input is consumed correctly.) Setting restart_signals to false still consumes one ^C before responding correctly to the second: $ strace -o /dev/pts/26 php -r "declare(ticks = 1); function quit() { print \"X\\n\"; die; } pcntl_signal(SIGINT, \"quit\", 0); fgetc(STDIN);" ^C^CX PHP tty | strace tty | rt_sigprocmask(SIG_UNBLOCK, [INT], NULL, 8) = 0 | read(0, 0x7f66fb47e000, 8192) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) ^C 1 -------------^ | --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} --- | rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call) | read(0, 0x7f66fb47e000, 8192) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) ^C 2 -------------^ | --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} --- | rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call) | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0 Exit-> | write(1, "X\n", 2) = 2 | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0 | rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0 | rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 | close(2) = 0 | close(1) = 0 | close(0) = 0 | munmap(0x7f66f7cb7000, 29808) = 0 | munmap(0x7f66f7cbf000, 16592) = 0 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=55614 -- Edit this bug report at https://bugs.php.net/bug.php?id=55614&edit=1

« previous php.bugs (#235146) next »