Received: from eggs.gnu.org ([2001:4830:134:3::10]:40482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VguZL-0005Y4-3g for qemu-devel@nongnu.org; Thu, 14 Nov 2013 05:54:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VguZF-00021x-4y for qemu-devel@nongnu.org; Thu, 14 Nov 2013 05:54:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VguZE-00021o-Rr for qemu-devel@nongnu.org; Thu, 14 Nov 2013 05:54:33 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAEAsWuF009761 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Nov 2013 05:54:32 -0500 From: Stefan Hajnoczi Date: Thu, 14 Nov 2013 11:54:16 +0100 Message-Id: <1384426458-24700-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1384426458-24700-1-git-send-email-stefanha@redhat.com> References: <1384426458-24700-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 3/5] osdep: add qemu_set_tty_echo() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Luiz Capitulino 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 --- 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 26136f1..eb5e145 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -215,4 +215,6 @@ bool fips_get_state(void); */ char *qemu_get_local_state_pathname(const char *relative_pathname); +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 +#include + #include #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.3.1