From:             
Operating system: (Arch) Linux
PHP version:      5.3.8
Package:          PCNTL related
Bug Type:         Bug
Bug description:pcntl_signal() + fgetc() is not allowing me to break with CTRL+C

Description:
------------
Running the following code at the commandline as demonstrated simply does
not 
work for me. It gobbles up all presses of ^C and will not quit (^\ ie
CTRL+\ 
produces SIGQUIT and is useful in this situation):

  php -r "declare(ticks = 1); function quit() { print \"X\\n\"; die; } 
pcntl_signal(SIGINT, \"quit\"); fgetc(STDIN);"


Running the following, on the other hand, works for me just fine.

  php -r "declare(ticks = 1); function quit() { print \"X\\n\"; die; } 
pcntl_signal(SIGINT, \"quit\"); while(1) { sleep(1); };"

Pressing ^C shuts the script down nicely.

I see no problems with the first code example. It should work, right?
Here's 
what 
strace is saying:

My console | strace console
           | (....)
           | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
           | rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
           | read(0, 0x943e5f4, 8192)      = ? ERESTARTSYS (To be
restarted)
           | --- SIGINT (Interrupt) @ 0 (0) ---
           | sigreturn()                   = ? (mask now [])
           | read(0, 0x943e5f4, 8192)      = ? ERESTARTSYS (To be
restarted)
  ^C ---------------^
           | --- SIGINT (Interrupt) @ 0 (0) ---
           | sigreturn()                   = ? (mask now [])
           | read(0, 0x943e5f4, 8192)      = ? ERESTARTSYS (To be
restarted)
  ^C ---------------^
           | --- SIGINT (Interrupt) @ 0 (0) ---
           | sigreturn()                   = ? (mask now [])
           | read(0, 
 (waiting) ---------^


It gets even more interesting. Setting parameter 3 to pcntl_signal, 
restart_signals, to false makes PHP gobble up one ^C *then* quit:

php -r "declare(ticks = 1); function quit() { print \"X\\n\"; die; } 
pcntl_signal(SIGINT, \"quit\", 0); fgetc(STDIN);"

Like so:
My console | strace console
           | (...)
           | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
           | rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
           | rt_sigaction(SIGINT, {0x82d8690, ~[RTMIN RT_1], SA_INTERRUPT},

{SIG_DFL, [], 0}, 8) = 0
           | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
           | rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
           | read(0, 0x9e985f8, 8192)      = ? ERESTARTSYS (To be
restarted)
   ^C --------------^
           | --- SIGINT (Interrupt) @ 0 (0) ---
           | sigreturn()                   = ? (mask now [])
           | read(0, 0x9e985f8, 8192)      = ? ERESTARTSYS (To be
restarted)
   ^C --------------^
           | --- SIGINT (Interrupt) @ 0 (0) ---
           | sigreturn()                   = ? (mask now [])
           | rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
   ! -->   | 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
           | close(2)                      = 0
           | close(1)                      = 0
           | (...)

As you can see from my exclamation, *the custom quit function is WORKING*
in the 
second example, just not straight away. PHP seems to be having indigestion
with 
the restart_syscalls bit...?

I wasn't sure what to put in what boxes since there were multiple scripts
and 
backtraces (if you could call them such) so I put them all here. Hope
that's 
okay.

i336


-- 
Edit bug report at https://bugs.php.net/bug.php?id=55614&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55614&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55614&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55614&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55614&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55614&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55614&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55614&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55614&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55614&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55614&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55614&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55614&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55614&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55614&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55614&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55614&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55614&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55614&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55614&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55614&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55614&r=mysqlcfg

Reply via email to