allow async ignored signals to be reset to SIG_DFL; give rl_input_available_hook precedence in readline:rl_gather_tyi

This commit is contained in:
Chet Ramey
2023-01-24 11:14:22 -05:00
parent a37b2af985
commit d0bc56a325
9 changed files with 116 additions and 48 deletions
+2
View File
@@ -476,6 +476,8 @@ The default hook checks @code{rl_instream}; if an application is using a
different input source, it should set the hook appropriately.
Readline queries for available input when implementing intra-key-sequence
timeouts during input and incremental searches.
This function must return zero if there is no input available, and non-zero
if input is available.
This may use an application-specific timeout before returning a value;
Readline uses the value passed to @code{rl_set_keyboard_input_timeout()}
or the value of the user-settable @var{keyseq-timeout} variable.
+2 -2
View File
@@ -5,7 +5,7 @@ Copyright (C) 1988-2023 Free Software Foundation, Inc.
@set EDITION 8.2
@set VERSION 8.2
@set UPDATED 19 January 2023
@set UPDATED 21 January 2023
@set UPDATED-MONTH January 2023
@set LASTCHANGE Thu Jan 19 17:22:06 EST 2023
@set LASTCHANGE Sat Jan 21 17:10:44 EST 2023
+40 -36
View File
@@ -138,13 +138,7 @@ win32_isatty (int fd)
/* Readline timeouts */
/* I don't know how to set a timeout for _getch() in MinGW32, so we use
SIGALRM. */
#if (defined (HAVE_PSELECT) || defined (HAVE_SELECT)) && !defined (__MINGW32__)
# define RL_TIMEOUT_USE_SELECT
#else
# define RL_TIMEOUT_USE_SIGALRM
#endif
/* We now define RL_TIMEOUT_USE_SELECT or RL_TIMEOUT_USE_SIGALRM in rlprivate.h */
int rl_set_timeout (unsigned int, unsigned int);
int rl_timeout_remaining (unsigned int *, unsigned int *);
@@ -259,38 +253,45 @@ rl_gather_tyi (void)
input = 0;
tty = fileno (rl_instream);
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
FD_ZERO (&readfds);
FD_ZERO (&exceptfds);
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
USEC_TO_TIMEVAL (_keyboard_input_timeout, timeout);
#if defined (RL_TIMEOUT_USE_SELECT)
result = _rl_timeout_select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout, NULL);
#else
result = select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout);
#endif
if (result <= 0)
return 0; /* Nothing to read. */
#endif
result = -1;
errno = 0;
#if defined (FIONREAD)
result = ioctl (tty, FIONREAD, &chars_avail);
if (result == -1 && errno == EIO)
return -1;
if (result == -1)
chars_avail = 0;
#endif
if (result == -1 && rl_input_available_hook)
/* Move this up here to give it first shot, but it can't set chars_avail */
/* XXX - need rl_chars_available_hook? */
if (rl_input_available_hook)
{
result = (*rl_input_available_hook) ();
if (result == 0)
result = -1;
}
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
if (result == -1)
{
FD_ZERO (&readfds);
FD_ZERO (&exceptfds);
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
USEC_TO_TIMEVAL (_keyboard_input_timeout, timeout);
#if defined (RL_TIMEOUT_USE_SELECT)
result = _rl_timeout_select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout, NULL);
#else
result = select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout);
#endif
if (result <= 0)
return 0; /* Nothing to read. */
}
#endif
#if defined (FIONREAD)
if (result == -1)
{
errno = 0;
result = ioctl (tty, FIONREAD, &chars_avail);
if (result == -1 && errno == EIO)
return -1;
if (result == -1)
chars_avail = 0;
}
#endif
#if defined (O_NDELAY)
if (result == -1)
{
@@ -315,8 +316,11 @@ rl_gather_tyi (void)
#if defined (__MINGW32__)
/* Use getch/_kbhit to check for available console input, in the same way
that we read it normally. */
chars_avail = isatty (tty) ? _kbhit () : 0;
result = 0;
if (result == -1)
{
chars_avail = isatty (tty) ? _kbhit () : 0;
result = 0;
}
#endif
/* If there's nothing available, don't waste time trying to read
@@ -658,7 +662,7 @@ rl_timeout_remaining (unsigned int *secs, unsigned int *usecs)
/* This should only be called if RL_TIMEOUT_USE_SELECT is defined. */
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
#if defined (RL_TIMEOUT_USE_SELECT)
int
_rl_timeout_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout, const sigset_t *sigmask)
{
+15 -1
View File
@@ -303,8 +303,22 @@ extern int _rl_pushed_input_available (void);
extern int _rl_timeout_init (void);
extern int _rl_timeout_handle_sigalrm (void);
#if defined (_POSIXSELECT_H_) && !defined (__MINGW32__) && (defined (HAVE_SELECT) || defined (HAVE_PSELECT))
#if defined (_POSIXSELECT_H_)
/* use as a sentinel for fd_set, struct timeval, and sigset_t definitions */
#if defined (__MINGW32__)
# define RL_TIMEOUT_USE_SIGALRM
#elif defined (HAVE_SELECT) || defined (HAVE_PSELECT)
# define RL_TIMEOUT_USE_SELECT
#elif defined (_MSC_VER)
/* can't use select/pselect or SIGALRM, so no timeouts */
#else
# define RL_TIMEOUT_USE_SIGALRM
#endif
#endif
#if defined (RL_TIMEOUT_USE_SELECT)
extern int _rl_timeout_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *, const sigset_t *);
#endif