On Fri, Mar 27, 2026 at 06:40:42PM +0100, Klaas van Aarsen wrote:
> We have a bug in the Angband code related to getch of ncurses (
> https://github.com/angband/angband/pull/6559).
> It turns out that getch returns ERR when the terminal connection is broken
> (SIGHUP). The code currently interprets it as a timeout (set by halfdelay)
> and spins on input, leaving a zombie process with 100% CPU.
> The man page on getch only mentions that errno might be EINTR if the getch
> call is interrupted, but nothing on a broken terminal connection.
> How might we detect that the terminal connection is broken?

From the comments in the above, I'd suppose that someone should modify
main-gcu.c to add a delay after errors (to throttle it down).

halfdelay doesn't do what you expected, because it's assuming that reads
are blocked - but they return immediately because the input file is closed.
To see what errno might be, see read(2) -- perhaps EBADF or EINVAL.

   halfdelay
       halfdelay configures half-delay mode, which is similar to cbreak mode in
       that  characters typed by the user are immediately available to the pro‐
       gram.  However, after blocking for tenths tenth-seconds, an input  char‐
       acter reading function returns ERR if no input is pending.  The value of
       tenths  must  be  between  1  and 255.  Use nocbreak to leave half-delay
       mode.

Try napms (it doesn't care about stdin).

   napms
       napms  sleeps  for  ms  milliseconds.  If ms exceeds 30,000 (thirty sec‐
       onds), it is capped at that value.

...mixing getch with fgets doesn't appear to be a good idea, since
ncurses doesn't use the input stream -- only the file descriptor.
Expect some difference in behavior.

-- 
Thomas E. Dickey <[email protected]>
https://invisible-island.net

Attachment: signature.asc
Description: PGP signature

Reply via email to