aboutsummaryrefslogtreecommitdiff
path: root/os.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2023-08-13 07:06:29 +0000
committerXin LI <delphij@FreeBSD.org>2023-08-13 07:06:29 +0000
commit448d114b25157a4bcc2463e584fae6bdae42fa37 (patch)
tree4824c0bc8c88657ab4001987f394a0c250a92d50 /os.c
parent159d764c16684166cab1428d7aebd0c0f3666cd3 (diff)
downloadsrc-448d114b25157a4bcc2463e584fae6bdae42fa37.tar.gz
src-448d114b25157a4bcc2463e584fae6bdae42fa37.zip
Vendor import of less v643.vendor/less/v643
Diffstat (limited to 'os.c')
-rw-r--r--os.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/os.c b/os.c
index 56e3bf32ec9e..046270e68fc4 100644
--- a/os.c
+++ b/os.c
@@ -48,6 +48,7 @@ static int use_poll = TRUE;
#endif
#if USE_POLL
#include <poll.h>
+static int any_data = FALSE;
#endif
/*
@@ -88,10 +89,10 @@ extern char *ttyin_name;
public void init_poll(void)
{
- char *delay = lgetenv("LESS_DATA_DELAY");
- int idelay = (delay == NULL) ? 0 : atoi(delay);
- if (idelay > 0)
- waiting_for_data_delay = idelay;
+ char *delay = lgetenv("LESS_DATA_DELAY");
+ int idelay = (delay == NULL) ? 0 : atoi(delay);
+ if (idelay > 0)
+ waiting_for_data_delay = idelay;
#if USE_POLL
#if defined(__APPLE__)
/* In old versions of MacOS, poll() does not work with /dev/tty. */
@@ -113,6 +114,15 @@ static int check_poll(int fd, int tty)
{
struct pollfd poller[2] = { { fd, POLLIN, 0 }, { tty, POLLIN, 0 } };
int timeout = (waiting_for_data && !(scanning_eof && follow_mode == FOLLOW_NAME)) ? -1 : waiting_for_data_delay;
+ if (!any_data)
+ {
+ /*
+ * Don't do polling if no data has yet been received,
+ * to allow a program piping data into less to have temporary
+ * access to the tty (like sudo asking for a password).
+ */
+ return (0);
+ }
poll(poller, 2, timeout);
#if LESSTEST
if (ttyin_name == NULL) /* Check for ^X only on a real tty. */
@@ -194,6 +204,11 @@ start:
#endif
#endif
#endif
+#if !MSDOS_COMPILER
+ if (fd != tty && !ABORT_SIGS())
+ /* Non-interrupt signal like SIGWINCH. */
+ return (READ_AGAIN);
+#endif
return (READ_INTR);
}
@@ -207,7 +222,7 @@ start:
* available, because that makes some background programs
* believe DOS is busy in a way that prevents those
* programs from working while "less" waits.
- * {{ This code was added 12 Jan 2007; still needed? }}
+ * {{ This code was added 12 Jan 2007; still needed? }}
*/
fd_set readfds;
@@ -234,11 +249,18 @@ start:
}
#else
#if MSDOS_COMPILER==WIN32C
- if (win32_kbhit() && WIN32getch() == intr_char)
+ if (win32_kbhit())
{
- sigs |= S_INTERRUPT;
- reading = 0;
- return (READ_INTR);
+ int c;
+
+ c = WIN32getch();
+ if (c == intr_char)
+ {
+ sigs |= S_INTERRUPT;
+ reading = 0;
+ return (READ_INTR);
+ }
+ WIN32ungetch(c);
}
#endif
#endif
@@ -282,6 +304,10 @@ start:
#endif
return (READ_ERR);
}
+#if USE_POLL
+ if (fd != tty && n > 0)
+ any_data = TRUE;
+#endif
return (n);
}