qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] os-posix: Log to logfile in case of daemonize
@ 2015-12-16 16:56 Alex Pyrgiotis
  2016-02-08  9:29 ` Paolo Bonzini
  0 siblings, 1 reply; 17+ messages in thread
From: Alex Pyrgiotis @ 2015-12-16 16:56 UTC (permalink / raw)
  To: qemu-devel

From: Dimitris Aragiorgis <dimara@arrikto.com>

In case of daemonize, use the logfile passed with the -D option in
order to redirect stdout/stderr to a file instead of /dev/null.

Signed-off-by: Dimitris Aragiorgis <dimara@arrikto.com>
Signed-off-by: Alex Pyrgiotis <apyrgio@arrikto.com>

diff --git a/include/qemu/log.h b/include/qemu/log.h
index 362cbc4..b5de1df 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -175,6 +175,7 @@ static inline void qemu_set_log(int log_flags)
 }
 
 void qemu_set_log_filename(const char *filename);
+char *qemu_get_log_filename(void);
 int qemu_str_to_log_mask(const char *str);
 
 /* Print a usage message listing all the valid logging categories
diff --git a/os-posix.c b/os-posix.c
index e4da406..18052fb 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -40,6 +40,7 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 #include "qemu/rcu.h"
+#include "qemu/log.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -255,16 +256,25 @@ void os_daemonize(void)
 void os_setup_post(void)
 {
     int fd = 0;
+    char *log = NULL;
 
     if (daemonize) {
         if (chdir("/")) {
             perror("not able to chdir to /");
             exit(1);
         }
-        TFR(fd = qemu_open("/dev/null", O_RDWR));
+
+        log = qemu_get_log_filename();
+        if (log != NULL) {
+            TFR(fd = qemu_open(log, O_RDWR | O_APPEND | O_CREAT, 0640));
+        } else {
+            TFR(fd = qemu_open("/dev/null", O_RDWR));
+        }
         if (fd == -1) {
+            fprintf(stderr, "Cannot open \"%s\" for logging\n", log);
             exit(1);
         }
+        g_free(log);
     }
 
     change_root();
diff --git a/qemu-log.c b/qemu-log.c
index 7cb01a8..44447bc 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -90,6 +90,11 @@ void qemu_set_log_filename(const char *filename)
     qemu_set_log(qemu_loglevel);
 }
 
+char *qemu_get_log_filename(void)
+{
+    return g_strdup(logfilename);
+}
+
 const QEMULogItem qemu_log_items[] = {
     { CPU_LOG_TB_OUT_ASM, "out_asm",
       "show generated host assembly code for each compiled TB" },
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-03-01 13:54 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-16 16:56 [Qemu-devel] [PATCH] os-posix: Log to logfile in case of daemonize Alex Pyrgiotis
2016-02-08  9:29 ` Paolo Bonzini
2016-02-11 12:12   ` Dimitris Aragiorgis
2016-02-11 12:31     ` Paolo Bonzini
2016-02-11 16:49       ` Dimitris Aragiorgis
2016-02-11 17:56         ` Paolo Bonzini
2016-02-18 11:38           ` [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized Dimitris Aragiorgis
2016-02-18 15:22             ` Paolo Bonzini
2016-02-18 17:12               ` Dimitris Aragiorgis
2016-02-19 17:25                 ` Paolo Bonzini
2016-03-01 11:15             ` Gerd Hoffmann
2016-03-01 11:47               ` Daniel P. Berrange
2016-03-01 11:51                 ` Paolo Bonzini
2016-03-01 11:58                   ` Daniel P. Berrange
2016-03-01 12:03                     ` Paolo Bonzini
2016-03-01 13:54                       ` Daniel P. Berrange
2016-03-01 11:50               ` Paolo Bonzini

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).