From:             neuhauser at bellavista dot cz
Operating system: FreeBSD 4.9-STABLE, 5.2-CURRENT
PHP version:      4.3.4
PHP Bug Type:     Unknown/Other Function
Bug description:  ncurses_getch() interrupted by receipt of a handled signal

Description:
------------
receipt of a signal interrupts ncurses_getch(), which
should never happen

curs_getch(3X):

The behavior of getch and friends in the presence
of handled signals is unspecified in the SVr4 and
XSI Curses documentation.  Under historical curses
implementations, it  varied depending on whether
the operating system's implementation of handled
signal receipt interrupts a read(2) call in
progress or not, and also (in some implementations)
depending on whether an input timeout or
non-blocking mode hsd been set.
       
Programmers concerned about portability should be
prepared  for  either of  two  cases: (a) signal
receipt does not interrupt getch; (b) signal
receipt interrupts getch and causes it to return
ERR with errno set to EINTR.
************
Under the ncurses implementation, handled signals
never interrupt getch.
************

(emphasis added)

Reproduce code:
---------------
compare the behavior of this PHP snippet

<?php

    function sigalrm()
    {
        global $c;
        $s = sprintf("sigalrm: '%d'\n", $c);
        ncurses_addstr($s);
        ncurses_refresh();
    }

    ncurses_init();
    ncurses_cbreak();
    ncurses_nl();
    ncurses_noecho();

    pcntl_signal(SIGALRM, 'sigalrm');
    declare(ticks = 1);

    for (;;) {
        pcntl_alarm(1);
        $c = ncurses_getch();
        if ('q' == chr($c)) {
            exit(0);
        }
    }

    ncurses_end();
    exit(0);


with its C equivalent

#include <unistd.h>
#include <signal.h>
#include <curses.h>

int c;

void sigalrm()
{
    char s[40];
    sprintf(s, "sigalrm: '%d'\n", c);
    addstr(s);
    refresh();
}

int main(int argc, char** argv)
{
    initscr();
    cbreak();
    nl();
    noecho();

    signal(SIGALRM, sigalrm);

    for (;;) {
        alarm(1);
        c = getch();
        if ('q' == c) {
            return 0;
        }
    }

    endwin();
    return 0;
}


Expected result:
----------------
I was expecting to see the same output as given by the C version: single

sigalrm: '0'

line until next keypress, then the zero would be replaced with ascii code
of the pressed key

Actual result:
--------------
endless series of

sigalrm: '-1'

lines, which suggests that receipt of the alarm, although handled,
interrupts the getch() call which then returns ERR.

(as a sidenote, http://www.php.net/manual/en/ref.ncurses.php says "On
error ncurses functions return NCURSES_ERR", but said constant doesn't
exist in 4.3.3 or 4.3.4, both cli)

-- 
Edit bug report at http://bugs.php.net/?id=27132&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27132&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27132&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27132&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27132&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27132&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27132&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27132&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27132&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27132&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27132&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27132&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27132&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27132&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27132&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27132&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27132&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27132&r=float

Reply via email to