[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo() |
Date: |
Fri, 24 Jan 2014 18:20:58 +0100 |
From: Stefan Hajnoczi <address@hidden>
Using stdin with readline.c requires disabling echo and line buffering.
Add a portable wrapper to set the terminal attributes under Linux and
Windows.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/qemu/osdep.h | 2 ++
util/oslib-posix.c | 18 ++++++++++++++++++
util/oslib-win32.c | 19 +++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b3e2b6d..eac7172 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -240,4 +240,6 @@ static inline void qemu_init_auxval(char **envp) { }
void qemu_init_auxval(char **envp);
#endif
+void qemu_set_tty_echo(int fd, bool echo);
+
#endif
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index e00a44c..f5c4016 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -47,6 +47,9 @@ extern int daemon(int, int);
# define QEMU_VMALLOC_ALIGN getpagesize()
#endif
+#include <termios.h>
+#include <unistd.h>
+
#include <glib/gprintf.h>
#include "config-host.h"
@@ -251,3 +254,18 @@ qemu_get_local_state_pathname(const char
*relative_pathname)
return g_strdup_printf("%s/%s", CONFIG_QEMU_LOCALSTATEDIR,
relative_pathname);
}
+
+void qemu_set_tty_echo(int fd, bool echo)
+{
+ struct termios tty;
+
+ tcgetattr(fd, &tty);
+
+ if (echo) {
+ tty.c_lflag |= ECHO | ECHONL | ICANON | IEXTEN;
+ } else {
+ tty.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
+ }
+
+ tcsetattr(fd, TCSANOW, &tty);
+}
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 776ccfa..50be044 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -189,3 +189,22 @@ qemu_get_local_state_pathname(const char
*relative_pathname)
return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", base_path,
relative_pathname);
}
+
+void qemu_set_tty_echo(int fd, bool echo)
+{
+ HANDLE handle = (HANDLE)_get_osfhandle(fd);
+ DWORD dwMode = 0;
+
+ if (handle == INVALID_HANDLE_VALUE) {
+ return;
+ }
+
+ GetConsoleMode(handle, &dwMode);
+
+ if (echo) {
+ SetConsoleMode(handle, dwMode | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
+ } else {
+ SetConsoleMode(handle,
+ dwMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
+ }
+}
--
1.8.1.4
- [Qemu-devel] [PULL 04/93] qemu-iotests: Clean up all extents for vmdk, (continued)
- [Qemu-devel] [PULL 04/93] qemu-iotests: Clean up all extents for vmdk, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 08/93] gluster: Add support for creating zero-filled image, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 06/93] gluster: Convert aio routines into coroutines, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 09/93] sheepdog: fix clone operation by 'qemu-img create -b', Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 07/93] gluster: Implement .bdrv_co_write_zeroes for gluster, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 10/93] qtest: Fix the bug about disable vnc causes "make check" fail, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 11/93] docs: qcow2 compat=1.1 is now the default, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 12/93] vmdk: Fix big flat extent IO, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 13/93] readline: decouple readline from the monitor, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 14/93] readline: move readline to a generic location, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo(),
Kevin Wolf <=
- [Qemu-devel] [PULL 16/93] qemu-io: use readline.c, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 17/93] qemu-io: add command completion, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 18/93] blkdebug: Use errp for read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 19/93] blkdebug: Don't require sophisticated filename, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 20/93] qdict: Add qdict_array_split(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 21/93] qapi: extend qdict_flatten() for QLists, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 22/93] qemu-option: Add qemu_config_parse_qdict(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 23/93] blkdebug: Always call read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 24/93] blkdebug: Use command-line in read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 25/93] block: Allow reference for bdrv_file_open(), Kevin Wolf, 2014/01/24