ash,hush: fix handling of SIGINT while waiting for interactive input

function                                             old     new   delta
lineedit_read_key                                    160     237     +77
__pgetc                                              522     589     +67
fgetc_interactive                                    244     309     +65
safe_read_key                                          -      39     +39
read_key                                             588     607     +19
record_pending_signo                                  23      32      +9
signal_handler                                        75      81      +6
.rodata                                           104312  104309      -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3)            Total: 279 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2022-01-17 03:02:40 +01:00
parent a277506a64
commit 12566e7f9b
9 changed files with 122 additions and 41 deletions

View File

@@ -126,7 +126,10 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
* if fd can be in non-blocking mode.
*/
if (timeout >= -1) {
if (safe_poll(&pfd, 1, timeout) == 0) {
n = poll(&pfd, 1, timeout);
if (n < 0 && errno == EINTR)
return n;
if (n == 0) {
/* Timed out */
errno = EAGAIN;
return -1;
@@ -138,7 +141,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
* When we were reading 3 bytes here, we were eating
* "li" too, and cat was getting wrong input.
*/
n = safe_read(fd, buffer, 1);
n = read(fd, buffer, 1);
if (n <= 0)
return -1;
}
@@ -284,6 +287,15 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
goto start_over;
}
int64_t FAST_FUNC safe_read_key(int fd, char *buffer, int timeout)
{
int64_t r;
do {
r = read_key(fd, buffer, timeout);
} while (errno == EINTR);
return r;
}
void FAST_FUNC read_key_ungets(char *buffer, const char *str, unsigned len)
{
unsigned cur_len = (unsigned char)buffer[0];