summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell.c
diff options
context:
space:
mode:
authorThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2008-07-10 06:04:19 +0000
committerThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2008-07-10 06:04:19 +0000
commit8084ce80fb10fe7a7865258eeae217d58569772e (patch)
tree40792a47e023711e2a4d313c44a8a87e5a9ff40b /cpukit/libmisc/shell/shell.c
parentAdded S_IRWXU, S_IRWXG and S_IRWXO to file mode. (diff)
downloadrtems-8084ce80fb10fe7a7865258eeae217d58569772e.tar.bz2
Restore terminal settings on exit.
Diffstat (limited to 'cpukit/libmisc/shell/shell.c')
-rw-r--r--cpukit/libmisc/shell/shell.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 6c1aff0a4b..035f626134 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -664,6 +664,7 @@ rtems_boolean rtems_shell_main_loop(
rtems_shell_cmd_t *shell_cmd;
rtems_status_code sc;
struct termios term;
+ struct termios previous_term;
char *prompt = NULL;
int cmd;
int cmd_count = 1; /* assume a script and so only 1 command line */
@@ -740,7 +741,8 @@ rtems_boolean rtems_shell_main_loop(
}
else {
/* make a raw terminal,Linux Manuals */
- if (tcgetattr(fileno(stdin), &term) >= 0) {
+ if (tcgetattr(fileno(stdin), &previous_term) >= 0) {
+ term = previous_term;
term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
term.c_oflag &= ~OPOST;
term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
@@ -913,8 +915,17 @@ rtems_boolean rtems_shell_main_loop(
if (cmd_argv)
free (cmd_argv);
- if ( stdinToClose )
+ if (stdinToClose) {
fclose( stdinToClose );
+ } else {
+ if (tcsetattr( fileno( stdin), TCSADRAIN, &previous_term) < 0) {
+ fprintf(
+ stderr,
+ "shell: cannot reset terminal attributes (%s)\n",
+ shell_env->devname
+ );
+ }
+ }
if ( stdoutToClose )
fclose( stdoutToClose );
return result;