diff options
author | Chet Ramey <chet.ramey@case.edu> | 2015-01-15 10:21:08 -0500 |
---|---|---|
committer | Dan Pasanen <dan.pasanen@gmail.com> | 2015-02-19 15:44:15 -0600 |
commit | bbc8b4849e0921dc4d9742359ca37f527712eccd (patch) | |
tree | a7073195c30ebb97866130352e0521fe6a4ccb7e /builtins | |
parent | c6a8bcd4a5660e7d0bc4759f08a272c97bea369d (diff) | |
download | android_external_bash-bbc8b4849e0921dc4d9742359ca37f527712eccd.tar.gz android_external_bash-bbc8b4849e0921dc4d9742359ca37f527712eccd.tar.bz2 android_external_bash-bbc8b4849e0921dc4d9742359ca37f527712eccd.zip |
Bash-4.3 patch 33stable/cm-12.1-YOG7Dstable/cm-12.1-YOG4Pstable/cm-12.1-YOG3Cstable/cm-12.0-YNG4Nstable/cm-12.0-YNG3Ccm-12.1cm-12.0
Change-Id: Id50c454f86c5df0e6cab6226ab7e5cc1a9b37883
Diffstat (limited to 'builtins')
-rw-r--r-- | builtins/common.h | 4 | ||||
-rw-r--r-- | builtins/read.c | 31 | ||||
-rw-r--r-- | builtins/read.def | 31 |
3 files changed, 60 insertions, 6 deletions
diff --git a/builtins/common.h b/builtins/common.h index cae16b1..a1298cb 100644 --- a/builtins/common.h +++ b/builtins/common.h @@ -122,6 +122,10 @@ extern void bash_logout __P((void)); /* Functions from getopts.def */ extern void getopts_reset __P((int)); +/* Functions from read.def */ +extern void read_tty_cleanup __P((void)); +extern int read_tty_modified __P((void)); + /* Functions from set.def */ extern int minus_o_option_value __P((char *)); extern void list_minus_o_opts __P((int, int)); diff --git a/builtins/read.c b/builtins/read.c index 2639042..66c8618 100644 --- a/builtins/read.c +++ b/builtins/read.c @@ -78,10 +78,12 @@ static void reset_alarm __P((void)); procenv_t alrmbuf; int sigalrm_seen; -static int reading; +static int reading, tty_modified; static SigHandler *old_alrm; static unsigned char delim; +static struct ttsave termsave; + /* In all cases, SIGALRM just sets a flag that we check periodically. This avoids problems with the semi-tricky stuff we do with the xfree of input_string at the top of the unwind-protect list (see below). */ @@ -126,7 +128,6 @@ read_builtin (list) struct stat tsb; SHELL_VAR *var; TTYSTRUCT ttattrs, ttset; - struct ttsave termsave; #if defined (ARRAY_VARS) WORD_LIST *alist; #endif @@ -159,7 +160,7 @@ read_builtin (list) USE_VAR(ps2); USE_VAR(lastsig); - sigalrm_seen = reading = 0; + sigalrm_seen = reading = tty_modified = 0; i = 0; /* Index into the string that we are reading. */ raw = edit = 0; /* Not reading raw input by default. */ @@ -376,6 +377,8 @@ read_builtin (list) retval = 128+SIGALRM; goto assign_vars; } + if (interactive_shell == 0) + initialize_terminating_signals (); old_alrm = set_signal_handler (SIGALRM, sigalrm); add_unwind_protect (reset_alarm, (char *)NULL); #if defined (READLINE) @@ -420,7 +423,10 @@ read_builtin (list) i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset); if (i < 0) sh_ttyerror (1); + tty_modified = 1; add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); } } else if (silent) /* turn off echo but leave term in canonical mode */ @@ -435,7 +441,10 @@ read_builtin (list) if (i < 0) sh_ttyerror (1); + tty_modified = 1; add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); } /* This *must* be the top unwind-protect on the stack, so the manipulation @@ -526,6 +535,8 @@ read_builtin (list) } else lastsig = 0; + if (terminating_signal && tty_modified) + ttyrestore (&termsave); /* fix terminal before exiting */ CHECK_TERMSIG; eof = 1; break; @@ -916,6 +927,20 @@ ttyrestore (ttp) struct ttsave *ttp; { ttsetattr (ttp->fd, ttp->attrs); + tty_modified = 0; +} + +void +read_tty_cleanup () +{ + if (tty_modified) + ttyrestore (&termsave); +} + +int +read_tty_modified () +{ + return (tty_modified); } #if defined (READLINE) diff --git a/builtins/read.def b/builtins/read.def index d6e5b4b..84cb218 100644 --- a/builtins/read.def +++ b/builtins/read.def @@ -140,10 +140,12 @@ static void reset_alarm __P((void)); procenv_t alrmbuf; int sigalrm_seen; -static int reading; +static int reading, tty_modified; static SigHandler *old_alrm; static unsigned char delim; +static struct ttsave termsave; + /* In all cases, SIGALRM just sets a flag that we check periodically. This avoids problems with the semi-tricky stuff we do with the xfree of input_string at the top of the unwind-protect list (see below). */ @@ -188,7 +190,6 @@ read_builtin (list) struct stat tsb; SHELL_VAR *var; TTYSTRUCT ttattrs, ttset; - struct ttsave termsave; #if defined (ARRAY_VARS) WORD_LIST *alist; #endif @@ -221,7 +222,7 @@ read_builtin (list) USE_VAR(ps2); USE_VAR(lastsig); - sigalrm_seen = reading = 0; + sigalrm_seen = reading = tty_modified = 0; i = 0; /* Index into the string that we are reading. */ raw = edit = 0; /* Not reading raw input by default. */ @@ -438,6 +439,8 @@ read_builtin (list) retval = 128+SIGALRM; goto assign_vars; } + if (interactive_shell == 0) + initialize_terminating_signals (); old_alrm = set_signal_handler (SIGALRM, sigalrm); add_unwind_protect (reset_alarm, (char *)NULL); #if defined (READLINE) @@ -482,7 +485,10 @@ read_builtin (list) i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset); if (i < 0) sh_ttyerror (1); + tty_modified = 1; add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); } } else if (silent) /* turn off echo but leave term in canonical mode */ @@ -497,7 +503,10 @@ read_builtin (list) if (i < 0) sh_ttyerror (1); + tty_modified = 1; add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); } /* This *must* be the top unwind-protect on the stack, so the manipulation @@ -588,6 +597,8 @@ read_builtin (list) } else lastsig = 0; + if (terminating_signal && tty_modified) + ttyrestore (&termsave); /* fix terminal before exiting */ CHECK_TERMSIG; eof = 1; break; @@ -978,6 +989,20 @@ ttyrestore (ttp) struct ttsave *ttp; { ttsetattr (ttp->fd, ttp->attrs); + tty_modified = 0; +} + +void +read_tty_cleanup () +{ + if (tty_modified) + ttyrestore (&termsave); +} + +int +read_tty_modified () +{ + return (tty_modified); } #if defined (READLINE) |