From bbaa56f7378240fca3db9165dfd02a4504d95ff1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Jul 2025 21:55:42 +0200 Subject: [PATCH] use pollfd[1] array for poll() argument Signed-off-by: Denys Vlasenko --- libbb/read_key.c | 11 ++++++----- shell/shell_common.c | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libbb/read_key.c b/libbb/read_key.c index cf8ed411e..1bea75fcf 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -11,7 +11,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) { - struct pollfd pfd; + struct pollfd pfd[1]; const char *seq; int n; @@ -112,8 +112,8 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) 0 }; - pfd.fd = fd; - pfd.events = POLLIN; + pfd->fd = fd; + pfd->events = POLLIN; buffer++; /* saved chars counter is in buffer[-1] now */ @@ -135,6 +135,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) return -1; } } + /* It is tempting to read more than one byte here, * but it breaks pasting. Example: at shell prompt, * user presses "c","a","t" and then pastes "\nline\n". @@ -173,7 +174,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) * so if we block for long it's not really an escape sequence. * Timeout is needed to reconnect escape sequences * split up by transmission over a serial console. */ - if (safe_poll(&pfd, 1, 50) == 0) { + if (safe_poll(pfd, 1, 50) == 0) { /* No more data! * Array is sorted from shortest to longest, * we can't match anything later in array - @@ -222,7 +223,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) * n = bytes read. Try to read more until we time out. */ while (n < KEYCODE_BUFFER_SIZE-1) { /* 1 for count byte at buffer[-1] */ - if (safe_poll(&pfd, 1, 50) == 0) { + if (safe_poll(pfd, 1, 50) == 0) { /* No more data! */ break; } diff --git a/shell/shell_common.c b/shell/shell_common.c index 9a03f7265..2baa9d3a8 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -55,7 +55,7 @@ const char* FAST_FUNC shell_builtin_read(struct builtin_read_params *params) { struct pollfd pfd[1]; -#define fd (pfd[0].fd) /* -u FD */ +#define fd (pfd->fd) /* -u FD */ unsigned err; unsigned end_ms; /* -t TIMEOUT */ int nchars; /* -n NUM */ @@ -142,7 +142,7 @@ shell_builtin_read(struct builtin_read_params *params) * bash seems to ignore -p PROMPT for this use case. */ int r; - pfd[0].events = POLLIN; + pfd->events = POLLIN; r = poll(pfd, 1, /*timeout:*/ 0); /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */ return (const char *)(uintptr_t)(r <= 0);