summary refs log tree commit diff stats
path: root/util/log.c
diff options
context:
space:
mode:
authorDimitris Aragiorgis <dimara@arrikto.com>2016-02-18 13:38:38 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2016-02-22 18:40:29 +0100
commit96c33a4523ee1abe382ce4ff3e82b90ba78aa186 (patch)
tree607b65f8018eb543241c4cffd2825bc395f3e463 /util/log.c
parentd42a0d1484f03d05184ed9bb867fee42476a588f (diff)
downloadfocaccia-qemu-96c33a4523ee1abe382ce4ff3e82b90ba78aa186.tar.gz
focaccia-qemu-96c33a4523ee1abe382ce4ff3e82b90ba78aa186.zip
log: Redirect stderr to logfile if deamonized
In case of daemonize, use the logfile passed with the -D option in
order to redirect stderr to it instead of /dev/null.

Also remove some unused code in log.h.

Signed-off-by: Dimitris Aragiorgis <dimara@arrikto.com>
Message-Id: <1455795518-19205-1-git-send-email-dimara@arrikto.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/log.c')
-rw-r--r--util/log.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/util/log.c b/util/log.c
index 2709e98f98..a7ddc7ecd1 100644
--- a/util/log.c
+++ b/util/log.c
@@ -56,13 +56,20 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
 #ifdef CONFIG_TRACE_LOG
     qemu_loglevel |= LOG_TRACE;
 #endif
-    if (qemu_loglevel && !qemu_logfile) {
+    if ((qemu_loglevel || is_daemonized()) && !qemu_logfile) {
         if (logfilename) {
             qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
             if (!qemu_logfile) {
                 perror(logfilename);
                 _exit(1);
             }
+            /* In case we are a daemon redirect stderr to logfile */
+            if (is_daemonized()) {
+                dup2(fileno(qemu_logfile), STDERR_FILENO);
+                fclose(qemu_logfile);
+                /* This will skip closing logfile in qemu_log_close() */
+                qemu_logfile = stderr;
+            }
         } else {
             /* Default to stderr if no log file specified */
             qemu_logfile = stderr;
@@ -82,7 +89,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
             log_append = 1;
         }
     }
-    if (!qemu_loglevel && qemu_logfile) {
+    if (!qemu_loglevel && !is_daemonized() && qemu_logfile) {
         qemu_log_close();
     }
 }