posix change for undoing redirections after failed exec; change readline to set lines and columns after SIGTSTP/SIGCONT

This commit is contained in:
Chet Ramey
2025-01-28 10:15:16 -05:00
parent 25e213a551
commit 0390b4354a
15 changed files with 307 additions and 71 deletions
+1
View File
@@ -640,6 +640,7 @@ extern int _rl_history_search_pos;
/* signals.c */
extern int volatile _rl_caught_signal;
extern int volatile _rl_handling_signal;
extern _rl_sigcleanup_func_t *_rl_sigcleanup;
extern void *_rl_sigcleanarg;
+15 -5
View File
@@ -80,15 +80,25 @@ static int ksrflow;
#endif
/* Dummy call to force a backgrounded readline to stop before it tries
to get the tty settings. */
to get the tty settings. But we use the information to set our idea
of the screen size if we're in a signal handling context, since it
doesn't make sense to waste it. */
static void
set_winsize (int tty)
{
#if defined (TIOCGWINSZ)
#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE)
struct winsize w;
if (ioctl (tty, TIOCGWINSZ, &w) == 0)
(void) ioctl (tty, TIOCSWINSZ, &w);
if (_rl_tcgetwinsize (tty, &w) == 0)
{
(void) _rl_tcsetwinsize (tty, &w);
/* We restrict this to the case where we're running a signal handler
and executing after a SIGTSTP. We can relax it later. */
#if defined (SIGTSTP)
if (RL_ISSTATE (RL_STATE_SIGHANDLER) && _rl_handling_signal == SIGTSTP && rl_prefer_env_winsize == 0)
_rl_set_screen_size (w.ws_row, w.ws_col); /* don't waste the info */
#endif
}
#endif /* TIOCGWINSZ */
}
+3
View File
@@ -55,4 +55,7 @@
# define tcflow(fd, action) ioctl(fd, TCXONC, action)
#endif
extern int _rl_tcgetwinsize (int, struct winsize *);
extern void _rl_tcsetwinsize (int, struct winsize *);
#endif /* _RL_WINSIZE_H */
+5
View File
@@ -88,6 +88,7 @@ int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
/* Private variables. */
int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */
int volatile _rl_handling_signal = 0;
/* If non-zero, print characters corresponding to received signals as long as
the user has indicated his desire to do so (_rl_echo_control_chars). */
@@ -133,6 +134,7 @@ _rl_signal_handler (int sig)
if (sig == SIGWINCH)
{
RL_SETSTATE(RL_STATE_SIGHANDLER);
_rl_handling_signal = SIGWINCH;
rl_resize_terminal ();
/* XXX - experimental for now */
@@ -142,6 +144,7 @@ _rl_signal_handler (int sig)
if (rl_signal_event_hook)
(*rl_signal_event_hook) ();
_rl_handling_signal = 0;
RL_UNSETSTATE(RL_STATE_SIGHANDLER);
}
else
@@ -177,6 +180,7 @@ _rl_handle_signal (int sig)
#endif /* !HAVE_POSIX_SIGNALS */
RL_SETSTATE(RL_STATE_SIGHANDLER);
_rl_handling_signal = sig;
#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
/* Since the signal will not be blocked while we are in the signal
@@ -301,6 +305,7 @@ _rl_handle_signal (int sig)
rl_reset_after_signal ();
}
_rl_handling_signal = 0;
RL_UNSETSTATE(RL_STATE_SIGHANDLER);
SIGHANDLER_RETURN;
}
+29 -5
View File
@@ -258,6 +258,30 @@ _win_get_screensize (int *swp, int *shp)
}
#endif
int
_rl_tcgetwinsize (int tty, struct winsize *wp)
{
#if defined (HAVE_TCGETWINSIZE)
return (tcgetwinsize (tty, wp));
#elif defined (TIOCGWINSZ)
return (ioctl (tty, TIOCGWINSZ, wp));
#else
return -1;
#endif
}
void
_rl_tcsetwinsize (int tty, struct winsize *wp)
{
#if defined (HAVE_TCGETWINSIZE)
tcsetwinsize (tty, wp);
#elif defined (TIOCGWINSZ)
ioctl (tty, TIOCSWINSZ, wp);
#else
;
#endif
}
/* Get readline's idea of the screen size. TTY is a file descriptor open
to the terminal. If IGNORE_ENV is true, we do not pay attention to the
values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being
@@ -266,19 +290,19 @@ void
_rl_get_screen_size (int tty, int ignore_env)
{
char *ss;
#if defined (TIOCGWINSZ)
#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE)
struct winsize window_size;
#endif /* TIOCGWINSZ */
#endif /* TIOCGWINSZ || HAVE_TCGETWINSIZE */
int wr, wc;
wr = wc = -1;
#if defined (TIOCGWINSZ)
if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE)
if (_rl_tcgetwinsize (tty, &window_size) == 0)
{
wc = (int) window_size.ws_col;
wr = (int) window_size.ws_row;
}
#endif /* TIOCGWINSZ */
#endif /* TIOCGWINSZ || HAVE_TCGETWINSIZE */
#if defined (__EMX__)
_emx_get_screensize (&wc, &wr);