From ba87092078149a163ff8bf886f09b52d1afa0d6f Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 1 Jan 2015 23:16:26 -0600 Subject: [PATCH] Work around problem where hush would hang after another process was ^C'd while reading from the terminal. I think this problem is probably due to a bug in GNO's implementation of select(). The workaround is not to use poll (which calls select) when reading a key with no timeout (which is the normal case for command-line input). --- libbb/read.key.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libbb/read.key.c b/libbb/read.key.c index 4f21030ec..a371f20e0 100644 --- a/libbb/read.key.c +++ b/libbb/read.key.c @@ -28,7 +28,18 @@ int32_t FAST_FUNC read_key(int fd, char *buffer, int timeout) * If requested, wait TIMEOUT ms. TIMEOUT = -1 is useful * if fd can be in non-blocking mode. */ - if (timeout >= -1) { + /* On GNO, skip the poll if timeout == -1. + * It's pointless, since non-blocking mode isn't implemented, + * and it seems to hang in certain cases (e.g. where another + * process was interrupted while reading from the terminal). + * This may be due to bugs in the underlying select() implementation. + */ +#ifndef __GNO__ + if (timeout >= -1) +#else + if (timeout >= 0) +#endif + { if (safe_poll(&pfd, 1, timeout) == 0) { /* Timed out */ errno = EAGAIN;