qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH] vl: redirect stdio to a file in Windows GUI build
Date: Fri, 14 Aug 2015 13:43:05 +0100	[thread overview]
Message-ID: <1439556185-31724-1-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1439476631-23883-1-git-send-email-berrange@redhat.com>

If linked to the windows subsystem (-mwindows gcc arg) then there
will be no console available for stdout/err to send data to. Use
the same approach as SDL by redirecting stdout/err to text files
in the current directory.  If linked to the console subsystem
then leave stdout/err untouched.

The redirect can be disabled with QEMU_NO_STDIO_REDIRECT env
variable

The result is that qemu-system-x86_64.exe can use stdio in the
same manner as on any UNIX platform. The qemu-system-x86_64w.exe
binary will log to text files and options like -monitor stdio
will not be available.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 vl.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/vl.c b/vl.c
index bb9ed8b..c9997bf 100644
--- a/vl.c
+++ b/vl.c
@@ -2995,6 +2995,22 @@ int main(int argc, char **argv, char **envp)
     Error *main_loop_err = NULL;
     Error *err = NULL;
 
+#ifdef _WIN32
+    /*
+     * If we're linked with -nwindows GetConsoleWindow returns
+     * NULL, so we know stdout/err are not available, so lets
+     * redirect them to a file. If linked to console subsystem
+     * then we can use stdout/err as normal
+     */
+    if (GetConsoleWindow() == NULL &&
+        getenv("QEMU_NO_STDIO_REDIRECT") == NULL) {
+        freopen("stdout.txt", "w", stdout);
+        freopen("stderr.txt", "w", stderr);
+        setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffering */
+        setbuf(stderr, NULL); /* No buffering */
+    }
+#endif /* _WIN32 */
+
     qemu_init_cpu_loop();
     qemu_mutex_lock_iothread();
 
-- 
2.4.3

      reply	other threads:[~2015-08-14 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13 14:37 [Qemu-devel] [PATCH] vl: prevent SDL replacing 'main' on win32 platforms Daniel P. Berrange
2015-08-14 12:43 ` Daniel P. Berrange [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439556185-31724-1-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).