From patchwork Sat Oct 27 13:15:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 194618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EBA682C0098 for ; Sun, 28 Oct 2012 00:15:29 +1100 (EST) Received: from localhost ([::1]:36701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TS6EZ-0006ZQ-WC for incoming@patchwork.ozlabs.org; Sat, 27 Oct 2012 09:15:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TS6ET-0006Z7-8Z for qemu-devel@nongnu.org; Sat, 27 Oct 2012 09:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TS6ES-0005Bf-0r for qemu-devel@nongnu.org; Sat, 27 Oct 2012 09:15:21 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:51660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TS6ER-0005BY-KG for qemu-devel@nongnu.org; Sat, 27 Oct 2012 09:15:19 -0400 Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 0493BA1F32; Sat, 27 Oct 2012 17:15:19 +0400 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id CAB712AB; Sat, 27 Oct 2012 17:15:17 +0400 (MSK) From: Michael Tokarev To: Anthony Liguori Date: Sat, 27 Oct 2012 17:15:15 +0400 Message-Id: <1351343715-7446-1-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 86.62.121.231 Cc: Peter Maydell , Stefan Hajnoczi , Michael Tokarev , qemu-devel@nongnu.org, Blue Swirl , Hitoshi Mitake Subject: [Qemu-devel] [PATCH] disallow -daemonize usage of stdio (curses display, -nographic, -serial stdio etc) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Curses display requires stdin/out to stay on the terminal, so -daemonize makes no sense in this case. Instead of leaving display uninitialized like is done since 995ee2bf469de6bb, explicitly detect this case earlier and error out. -nographic can actually be used with -daemonize, by redirecting everything to a null device, but the problem is that according to documentation and historical behavour, -nographic redirects guest ports to stdin/out, which, again, makes no sense in case of -daemonize. Since -nographic is a legacy option, don't bother fixing this case (to allow -nographic and -daemonize by redirecting guest ports to null instead of stdin/out in this case), but disallow it completely instead, to stop garbling host terminal. If no display display needed and user wants to use -nographic, the right way to go is to use -serial null -parallel null -monitor none -display none -vga none instead of -nographic. Also prevent the same issue -- it was possible to get garbled host tty after -nographic -daemonize and it is still possible to have it by using -serial stdio -daemonize Fix this by disallowing opening stdio chardev when -daemonize is specified. Signed-off-by: Michael Tokarev --- qemu-char.c | 4 ++++ vl.c | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index afe2bfb..21c6a0d 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -772,6 +772,10 @@ static CharDriverState *qemu_chr_open_stdio(QemuOpts *opts) if (stdio_nb_clients >= STDIO_MAX_CLIENTS) { return NULL; } + if (is_daemonized()) { + error_report("cannot use stdio with -daemonize"); + return NULL; + } if (stdio_nb_clients == 0) { old_fd0_flags = fcntl(0, F_GETFL); tcgetattr (0, &oldtty); diff --git a/vl.c b/vl.c index 9f99ef4..db48d62 100644 --- a/vl.c +++ b/vl.c @@ -3413,6 +3413,26 @@ int main(int argc, char **argv, char **envp) default_sdcard = 0; } + if (is_daemonized()) { + /* According to documentation and historically, -nographic redirects + * serial port, parallel port and monitor to stdio, which does not work + * with -daemonize. We can redirect these to null instead, but since + * -nographic is legacy, let's just error out. + */ + if (display_type == DT_NOGRAPHIC + /* && (default_parallel || default_serial + || default_monitor || default_virtcon) */) { + fprintf(stderr, "-nographic can not be used with -daemonize\n"); + exit(1); + } +#ifdef CONFIG_CURSES + if (display_type == DT_CURSES) { + fprintf(stderr, "curses display can not be used with -daemonize\n"); + exit(1); + } +#endif + } + if (display_type == DT_NOGRAPHIC) { if (default_parallel) add_device_config(DEV_PARALLEL, "null"); @@ -3687,9 +3707,7 @@ int main(int argc, char **argv, char **envp) break; #if defined(CONFIG_CURSES) case DT_CURSES: - if (!is_daemonized()) { - curses_display_init(ds, full_screen); - } + curses_display_init(ds, full_screen); break; #endif #if defined(CONFIG_SDL)