commit 3d69e4b7953e673d9419bc47291667a70e343891
parent 7fd6abd39870f3f4aba4d9ffea2e0d0f5006918a
Author: xplshn <anto@xplshn.com.ar>
Date: Sat, 21 Nov 2026 11:14:45 -0300
redline: stop waiting for a cursor reply after 300ms
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/shared/libredline/redline.c b/shared/libredline/redline.c
@@ -7,6 +7,7 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -372,6 +373,9 @@ disableRawMode(int fd)
}
}
+// how long a terminal gets to answer the cursor position query
+#define CURSOR_REPLY_MS 300
+
static int
getCursorPosition(int ifd, int ofd)
{
@@ -382,7 +386,13 @@ getCursorPosition(int ifd, int ofd)
if (write(ofd, "\x1b[6n", 4) != 4)
return -1;
+ // a terminal that never answers, a serial console with nothing on the
+ // other end, must not leave the shell stuck before its first prompt
while (i < sizeof(buf) - 1) {
+ struct pollfd pfd = { ifd, POLLIN, 0 };
+
+ if (poll(&pfd, 1, CURSOR_REPLY_MS) != 1)
+ break;
if (read(ifd, buf + i, 1) != 1)
break;
if (buf[i] == 'R')