← Commit list

bbaa56f73

Denys Vlasenko
Denys Vlasenko
2025-07-02
SUCCESS Duration: 157s

Subject

use pollfd[1] array for poll() argument

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/read_key.c+6 -5
@@ -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;
}
shell/shell_common.c+2 -2
@@ -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);