summaryrefslogtreecommitdiffstats
path: root/adb
diff options
context:
space:
mode:
authorAlistair Buxton <a.j.buxton@gmail.com>2013-03-01 22:16:41 +0100
committerElliott Hughes <enh@google.com>2015-04-05 10:02:34 -0700
commitdfa09fd635e341d5e47d67123a0e938710be5949 (patch)
treecb2ea2204dd98fbc16fa852219641118514e138f /adb
parent6d951c2c3fd4af4459d86ce81068e01873aa2ea8 (diff)
downloadsystem_core-dfa09fd635e341d5e47d67123a0e938710be5949.zip
system_core-dfa09fd635e341d5e47d67123a0e938710be5949.tar.gz
system_core-dfa09fd635e341d5e47d67123a0e938710be5949.tar.bz2
Disable CR/LF translation for adb interactive shell.
adb shell uses termios to disable canonical input processing in order to get raw control codes but it does not disable CR/LF translation. The default for Linux terminals is to convert CR to LF unless the running program specifically asks for this to be disabled. Since adb does not, there is no way to send a CR to any program run on adb shell. Many programs do in fact differentiate and so are broken by this behaviour, notably nano. This patch sets the termios flags to disable all line ending translation. Change-Id: I8b950220f7cc52fefaed2ee37d97e0789b40a078 Signed-off-by: Alistair Buxton <a.j.buxton@gmail.com>
Diffstat (limited to 'adb')
-rw-r--r--adb/commandline.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index f9ca5ed..34efefe 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -256,29 +256,25 @@ void stdin_raw_restore(int fd);
}
#else
-static struct termios tio_save;
+static termios g_saved_terminal_state;
-static void stdin_raw_init(int fd)
-{
- struct termios tio;
+static void stdin_raw_init(int fd) {
+ if (tcgetattr(fd, &g_saved_terminal_state)) return;
- if(tcgetattr(fd, &tio)) return;
- if(tcgetattr(fd, &tio_save)) return;
+ termios tio;
+ if (tcgetattr(fd, &tio)) return;
- tio.c_lflag = 0; /* disable CANON, ECHO*, etc */
+ cfmakeraw(&tio);
- /* no timeout but request at least one character per read */
+ // No timeout but request at least one character per read.
tio.c_cc[VTIME] = 0;
tio.c_cc[VMIN] = 1;
- tcsetattr(fd, TCSANOW, &tio);
- tcflush(fd, TCIFLUSH);
+ tcsetattr(fd, TCSAFLUSH, &tio);
}
-static void stdin_raw_restore(int fd)
-{
- tcsetattr(fd, TCSANOW, &tio_save);
- tcflush(fd, TCIFLUSH);
+static void stdin_raw_restore(int fd) {
+ tcsetattr(fd, TCSAFLUSH, &g_saved_terminal_state);
}
#endif