[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: signals interrupting wgetch

From: Thomas Dickey
Subject: Re: signals interrupting wgetch
Date: Thu, 21 Jul 2005 19:33:10 -0400 (EDT)

On Wed, 20 Jul 2005, John Gruenenfelder wrote:

I seem to be having a problem with signals interrupting my call to wgetnstr
(which uses wgetch).  According to the man page for wgetch:

"Under the ncurses implementation, handled signals never interrupt getch."

But the handled signals don't include SIGALRM.  (I see that the manpage
does not list them).  Checking the code, the apparent intent of that
comment was to reflect the behavior for these signals:


There's some treatment of SIGALRM when handling SIGTSTP, but I don't
think that's what you are encountering.  Long ago there was also code
(ifdef'd out since shortly after ncurses 4.2) to loop inside wgetch()
when an EINTR was detected:

        > patch by Alexander V Lukyanov:
        + removed the cycle on EINTR, as it seems to be useless.

ncurses also installs handlers for SIGINT and SIGTERM to (attempt to)
cleanup on an interrupt that stops the program.

Until today, this was the case.  Today I updated the kernel from 2.6.11 to
2.6.12.  This is on a Debian Sid (current) machine.

The signal in question is SIGALRM which is generated every two seconds.
When the signal occurs, wgetnstr returns -1.  Checking errno (via perror), the
error is:
 "Interrupted system call"

I assume your program has a handler for SIGALRM, and that the EINTR is
just reporting that the read was interrupted.

By changing part of my code, I could do with out the timer which generates
SIGALRM and just poll the clock, but I'd like to know why the behavior changed
or if perhaps I am doing something wrong.

Well, as you said - the kernel changed.  Perhaps that was a bug(fix).

For reference, the extent of my ncurses configuration is:

 keypad(stdscr, TRUE);
 main_win = newwin(LINES - 1, COLS, 0, 0);
 scrollok(main_win, TRUE);

And then I proceed to start reading/writing main_win.

I assume it's more complicated than that - I checked by sending SIGALRM
to a program executing in wgetnstr() just now, and it stopped the program.

Thomas E. Dickey

reply via email to

[Prev in Thread] Current Thread [Next in Thread]