Skip to contentSkip to conversation

os-posix: Log to logfile in case of daemonize

PATCH In review Alex Pyrgiotis 5 participants 17 messages Dec 16, 2015 – Mar 1, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 os-posix: Log to logfile in case of daemonize

From: Dimitris Aragiorgis <[email protected]>

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.

include/qemu/log.h +1 -0
index 362cbc4..b5de1df 100644
@@ -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
os-posix.c +11 -1
index e4da406..18052fb 100644
@@ -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();
qemu-log.c +5 -0
index 7cb01a8..44447bc 100644
@@ -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" },
Signature · 1 line
2.6.2
#1 lore raw

os-posix.c void os_daemonize(void) · line 269

Quoted 4 lines · Alex Pyrgiotis
os-posix.c +4 -0
+
+        log = qemu_get_log_filename();
+        if (log != NULL) {
+            TFR(fd = qemu_open(log, O_RDWR | O_APPEND | O_CREAT, 0640));

Here you are opening the same file twice, but the FILE* that is opened in do_qemu_set_log does not necessarily have O_APPEND.

I like the idea of moving stderr to the logfile, but I'm not sure how to do it. For now, can you prepare a simple patch that only does the "dup" if "isatty" returns true for the file descriptor? This lets you use redirection at the shell level to save the stdout and stderr.

Paolo

Quoted 9 lines
os-posix.c +5 -0
+        } 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);
     }
#2 lore raw

Hi,

Quoted 11 lines · Paolo Bonzini

os-posix.c void os_daemonize(void) · line 269

Quoted 4 lines · Alex Pyrgiotis
os-posix.c +4 -0
+
+        log = qemu_get_log_filename();
+        if (log != NULL) {
+            TFR(fd = qemu_open(log, O_RDWR | O_APPEND | O_CREAT, 0640));

Here you are opening the same file twice, but the FILE* that is opened in do_qemu_set_log does not necessarily have O_APPEND.

This is partially true :) I am opening this file twice only if the -d option is passed along with -D. Still, point taken.

Quoted 5 lines

I like the idea of moving stderr to the logfile, but I'm not sure how to do it. For now, can you prepare a simple patch that only does the "dup" if "isatty" returns true for the file descriptor? This lets you use redirection at the shell level to save the stdout and stderr.

This could be a workaround. Still, I think it is a bit unorthodox to change the core behavior of logging depending on the type of output (tty or not). I understand that checking the type of output is sometimes used to enable/disable colors automatically, for example.

Besides that, when one executes a daemon, shell redirection is hardly, if ever, used. More so if the daemon already has a logfile option.

So, we decided to give it a go and find the least painful way to log the stderr of a QEMU process to a logfile.

To our understanding, the logfile (-D option) is used only for messages generated by qemu_log()/qemu_log_mask(). The current situation however is that fprintf(stderr, ...) is used in various places throughout the codebase for logging/debug purposes. A simple solution would be to redirect the stderr to the logfile when -D is used, but this may confuse people who expect the current behavior for their logfiles.

Therefore, our suggestion is to introduce another option, "-log-stderr". If this is given then we can 'dup2' stderr to the already opened logfile inside do_qemu_set_log(). And we should not close it even if -d is not given.

Afterwards, os_setup_post() in case of daemonize, would always dup2 0, 1 to /dev/null and only if qemu_logfile is not NULL would dup2 2 to /dev/null as well.

To sum up if one wants to log stderr to the logfile, one should pass -D along with -log-stderr. Eventually qemu_log(), qemu_log_mask(), and fprintf(stderr, ...) will end up writing to our logfile. The -daemonize option should respect the other options.

What do you think?

dimara

Quoted 12 lines

Paolo

Quoted 9 lines
os-posix.c +5 -0
+        } 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);
     }
#3 lore raw
Quoted 11 lines · Dimitris Aragiorgis

Besides that, when one executes a daemon, shell redirection is hardly, if ever, used. More so if the daemon already has a logfile option.

So, we decided to give it a go and find the least painful way to log the stderr of a QEMU process to a logfile.

To our understanding, the logfile (-D option) is used only for messages generated by qemu_log()/qemu_log_mask(). The current situation however is that fprintf(stderr, ...) is used in various places throughout the codebase for logging/debug purposes.

Right, mostly through error_report.

Actually I like your approach (log to -D if daemonize is used). I just was not sure of the best way to implement it.

Perhaps when the logfile is opened you can replace the straight fopen with

    qemu_logfile = fopen(...);
    if (daemonized) {
        dup2(fileno(qemu_logfile), STDERR_FILENO);
        fclose(qemu_logfile);
        qemu_logfile = stderr;
    }

Then the logfile will never be closed by qemu_log_close, and stderr will always be sent to it. Does this look sane?

Paolo

#4 lore raw

Hi,

Quoted 15 lines · Paolo Bonzini
Quoted 11 lines · Dimitris Aragiorgis

Besides that, when one executes a daemon, shell redirection is hardly, if ever, used. More so if the daemon already has a logfile option.

So, we decided to give it a go and find the least painful way to log the stderr of a QEMU process to a logfile.

To our understanding, the logfile (-D option) is used only for messages generated by qemu_log()/qemu_log_mask(). The current situation however is that fprintf(stderr, ...) is used in various places throughout the codebase for logging/debug purposes.

Quoted 5 lines

Right, mostly through error_report.

Actually I like your approach (log to -D if daemonize is used). I just was not sure of the best way to implement it.

Well my apprach was based on the extra option so that the current behavior does not change and logfiles become too noisy out of the blue.

I have a patch already that:

- modifies do_qemu_set_log() so that if -log-stderr is given to:
+ open the logfile
+ dup stderr to it
+ skip qemu_log_close()
- modifies os_setup_post() to dup stderr to /dev/null only if qemu_logfile is NULL.

If we do not want this extra option, I guess we are talking about logging stderr to -D *only* if daemonize is used, right?

Quoted 9 lines

Perhaps when the logfile is opened you can replace the straight fopen with

    qemu_logfile = fopen(...);
    if (daemonized) {
        dup2(fileno(qemu_logfile), STDERR_FILENO);
        fclose(qemu_logfile);
        qemu_logfile = stderr;
    }
Quoted 3 lines

Then the logfile will never be closed by qemu_log_close, and stderr will always be sent to it. Does this look sane?

I guess the above snippet will go in do_qemu_set_log(), right?

If true, we have to open the logfile even if the -d option is not given. Besides that, log.c should become aware of daemonize.

Depending on your answers I'll prepare the corresponding patch.

Thanks,
dimara

Quoted 1 line

Paolo

#5 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Quoted 7 lines · Dimitris Aragiorgis
Quoted 7 lines

Perhaps when the logfile is opened you can replace the straight fopen with

qemu_logfile = fopen(...); if (daemonized) { dup2(fileno(qemu_logfile), STDERR_FILENO); fclose(qemu_logfile); qemu_logfile = stderr; }

Quoted 8 lines
Quoted 3 lines

Then the logfile will never be closed by qemu_log_close, and stderr will always be sent to it. Does this look sane?

I guess the above snippet will go in do_qemu_set_log(), right?

If true, we have to open the logfile even if the -d option is not given.

Right, but only if daemonize.

Quoted 1 line

Besides that, log.c should become aware of daemonize.

Yes.

Paolo

#6 lore raw

PATCH 1/1 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.

---
 include/qemu/log.h |    6 ------
 os-posix.c         |    6 +++++-
 util/log.c         |   11 +++++++++--
 3 files changed, 14 insertions(+), 9 deletions(-)
include/qemu/log.h +0 -6
index 30817f7..dda65fd 100644
@@ -94,12 +94,6 @@ static inline void qemu_log_close(void)
     }
 }
 
-/* Set up a new log file */
-static inline void qemu_log_set_file(FILE *f)
-{
-    qemu_logfile = f;
-}
-
 /* define log items */
 typedef struct QEMULogItem {
     int mask;
os-posix.c +5 -1
index cce62ed..92fa3ba 100644
@@ -37,6 +37,7 @@
 #include "qemu-options.h"
 #include "qemu/rcu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -275,7 +276,10 @@ void os_setup_post(void)
 
         dup2(fd, 0);
         dup2(fd, 1);
-        dup2(fd, 2);
+        /* In case -D is given do not redirect stderr to /dev/null */
+        if (!qemu_logfile) {
+            dup2(fd, 2);
+        }
 
         close(fd);
 
util/log.c +9 -2
index 2709e98..a7ddc7e 100644
@@ -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();
     }
 }
Signature · 1 line
1.7.10.4
#7 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 80 lines · Dimitris Aragiorgis

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.

---
 include/qemu/log.h |    6 ------
 os-posix.c         |    6 +++++-
 util/log.c         |   11 +++++++++--
 3 files changed, 14 insertions(+), 9 deletions(-)
include/qemu/log.h +0 -6
index 30817f7..dda65fd 100644
@@ -94,12 +94,6 @@ static inline void qemu_log_close(void)
     }
 }
 
-/* Set up a new log file */
-static inline void qemu_log_set_file(FILE *f)
-{
-    qemu_logfile = f;
-}
-
 /* define log items */
 typedef struct QEMULogItem {
     int mask;
os-posix.c +5 -1
index cce62ed..92fa3ba 100644
@@ -37,6 +37,7 @@
 #include "qemu-options.h"
 #include "qemu/rcu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -275,7 +276,10 @@ void os_setup_post(void)
 
         dup2(fd, 0);
         dup2(fd, 1);
-        dup2(fd, 2);
+        /* In case -D is given do not redirect stderr to /dev/null */
+        if (!qemu_logfile) {
+            dup2(fd, 2);
+        }
 
         close(fd);
 
util/log.c +8 -1
index 2709e98..a7ddc7e 100644
@@ -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;

util/log.c void do_qemu_set_log(int log_flags, bool use_own_buffers) · line 94

Quoted 7 lines
util/log.c +1 -1
@@ -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();
     }

Why is this necessary? Perhaps qemu_log_close should dup(1,2) if QEMU is daemonized. The rest looks great.

Paolo

#8 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 85 lines · Paolo Bonzini
Quoted 82 lines · Dimitris Aragiorgis

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.

---
 include/qemu/log.h |    6 ------
 os-posix.c         |    6 +++++-
 util/log.c         |   11 +++++++++--
 3 files changed, 14 insertions(+), 9 deletions(-)
include/qemu/log.h +0 -6
index 30817f7..dda65fd 100644
@@ -94,12 +94,6 @@ static inline void qemu_log_close(void)
     }
 }
 
-/* Set up a new log file */
-static inline void qemu_log_set_file(FILE *f)
-{
-    qemu_logfile = f;
-}
-
 /* define log items */
 typedef struct QEMULogItem {
     int mask;
os-posix.c +5 -1
index cce62ed..92fa3ba 100644
@@ -37,6 +37,7 @@
 #include "qemu-options.h"
 #include "qemu/rcu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -275,7 +276,10 @@ void os_setup_post(void)
 
         dup2(fd, 0);
         dup2(fd, 1);
-        dup2(fd, 2);
+        /* In case -D is given do not redirect stderr to /dev/null */
+        if (!qemu_logfile) {
+            dup2(fd, 2);
+        }
 
         close(fd);
 
util/log.c +8 -1
index 2709e98..a7ddc7e 100644
@@ -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;
         }
Quoted 9 lines

util/log.c void do_qemu_set_log(int log_flags, bool use_own_buffers) · line 94

Quoted 5 lines
util/log.c +1 -1
     }
-    if (!qemu_loglevel && qemu_logfile) {
+    if (!qemu_loglevel && !is_daemonized() && qemu_logfile) {
         qemu_log_close();
     }

Why is this necessary? Perhaps qemu_log_close should dup(1,2) if QEMU is daemonized. The rest looks great.

Without !is_daemonized(), if we use -daemon with -D without -d, qemu_log_close() will eventually set qemu_logfile to NULL. This will make os_setup_post() redirect stderr to /dev/null, which is unwanted.

To be honest, I don't understand your suggestion. How would calling dup2(1, 2) help in our case? Isn't fd 1 the standard output?

Thanks,
dimara

Quoted 1 line

Paolo

#9 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 97 lines · Dimitris Aragiorgis
Quoted 85 lines · Paolo Bonzini
Quoted 82 lines · Dimitris Aragiorgis

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.

---
 include/qemu/log.h |    6 ------
 os-posix.c         |    6 +++++-
 util/log.c         |   11 +++++++++--
 3 files changed, 14 insertions(+), 9 deletions(-)
include/qemu/log.h +0 -6
index 30817f7..dda65fd 100644
@@ -94,12 +94,6 @@ static inline void qemu_log_close(void)
     }
 }
 
-/* Set up a new log file */
-static inline void qemu_log_set_file(FILE *f)
-{
-    qemu_logfile = f;
-}
-
 /* define log items */
 typedef struct QEMULogItem {
     int mask;
os-posix.c +5 -1
index cce62ed..92fa3ba 100644
@@ -37,6 +37,7 @@
 #include "qemu-options.h"
 #include "qemu/rcu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -275,7 +276,10 @@ void os_setup_post(void)
 
         dup2(fd, 0);
         dup2(fd, 1);
-        dup2(fd, 2);
+        /* In case -D is given do not redirect stderr to /dev/null */
+        if (!qemu_logfile) {
+            dup2(fd, 2);
+        }
 
         close(fd);
 
util/log.c +8 -1
index 2709e98..a7ddc7e 100644
@@ -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;
         }
Quoted 9 lines

util/log.c void do_qemu_set_log(int log_flags, bool use_own_buffers) · line 94

Quoted 5 lines
util/log.c +1 -1
     }
-    if (!qemu_loglevel && qemu_logfile) {
+    if (!qemu_loglevel && !is_daemonized() && qemu_logfile) {
         qemu_log_close();
     }

Why is this necessary? Perhaps qemu_log_close should dup(1,2) if QEMU is daemonized. The rest looks great.

Quoted 4 lines

Without !is_daemonized(), if we use -daemon with -D without -d, qemu_log_close() will eventually set qemu_logfile to NULL. This will make os_setup_post() redirect stderr to /dev/null, which is unwanted.

Sorry, I missed the context of this hunk. The patch is okay, thanks for putting up with me!

Paolo

#10 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

In reply to Dimitris Aragiorgis
Quoted 4 lines · Dimitris Aragiorgis

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.

Patch breaks interaction with libvirt. libvirt hangs on startup, while
probing qemu capabilities. qemu runs in probing mode (command line is
"/home/kraxel/projects/qemu/build-default/x86_64-softmmu/qemu-system-x86_64 -S -no-user-config -nodefaults -nographic -M none -qmp unix:/var/lib/libvirt/qemu/capabilities.monitor.sock,server,nowait -pidfile /var/lib/libvirt/qemu/capabilities.pidfile -daemonize" according to "systemctl status libvirtd -l"), apparently both qemu and libvirt wait for each other.

cheers,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 9 lines · Gerd Hoffmann
Quoted 4 lines · Dimitris Aragiorgis

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.

Patch breaks interaction with libvirt. libvirt hangs on startup, while
probing qemu capabilities. qemu runs in probing mode (command line is
"/home/kraxel/projects/qemu/build-default/x86_64-softmmu/qemu-system-x86_64 -S -no-user-config -nodefaults -nographic -M none -qmp unix:/var/lib/libvirt/qemu/capabilities.monitor.sock,server,nowait -pidfile /var/lib/libvirt/qemu/capabilities.pidfile -daemonize" according to "systemctl status libvirtd -l"), apparently both qemu and libvirt wait for each other.

When libvirt is probing capabilities it passes a pipe file descriptor for stderr. It reads from this pipe to detect any errors printed by QEMU before daemonizing. When QEMU daemonizes, it closes this FD and sets stderr to /dev/null. Libvirt knows qemu has successfully started up at this point.

With this patch though, this code:

@@ -275,7 +276,10 @@ void os_setup_post(void)

         dup2(fd, 0);
         dup2(fd, 1);
-        dup2(fd, 2);
+        /* In case -D is given do not redirect stderr to /dev/null */
+        if (!qemu_logfile) {

+ dup2(fd, 2);
+ }

         close(fd);

means that QEMU will never close stderr anymore, so libvirt things QEMU is still starting up....forever.

Given current libvirt behaviour / expectations, I think the only option is to revert this change.

IMHO if applications want qemu logs to go to stderr, they should explicitly ask for that to happen via a CLI arg.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#12 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 5 lines · Daniel P. Berrange

means that QEMU will never close stderr anymore, so libvirt things QEMU is still starting up....forever.

Given current libvirt behaviour / expectations, I think the only option is to revert this change.

Why not fix it instead? :)

Paolo

#13 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Daniel P. Berrange

means that QEMU will never close stderr anymore, so libvirt things QEMU is still starting up....forever.

Given current libvirt behaviour / expectations, I think the only option is to revert this change.

Why not fix it instead? :)

Because if the user upgrades QEMU it'll cause all existing deployed version of libvirt to hang. I think that's pretty undesirable behaviour.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#14 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 11 lines · Daniel P. Berrange
Quoted 7 lines
Quoted 5 lines

means that QEMU will never close stderr anymore, so libvirt things QEMU is still starting up....forever.

Given current libvirt behaviour / expectations, I think the only option is to revert this change.

Why not fix it instead? :)

Because if the user upgrades QEMU it'll cause all existing deployed version of libvirt to hang. I think that's pretty undesirable behaviour.

Let me rephrase, why not fix it in QEMU? Jan Tomko helped me debugging it, and I've sent a patch just before seeing your message.

Paolo

#15 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · Daniel P. Berrange
Quoted 6 lines
Quoted 5 lines

means that QEMU will never close stderr anymore, so libvirt things QEMU is still starting up....forever.

Given current libvirt behaviour / expectations, I think the only option is to revert this change.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Why not fix it instead? :)

Because if the user upgrades QEMU it'll cause all existing deployed version of libvirt to hang. I think that's pretty undesirable behaviour.

Let me rephrase, why not fix it in QEMU? Jan Tomko helped me debugging it, and I've sent a patch just before seeing your message.

Oh, we were talking with crossed wires. Yes, fixing the problem rather than fully reverting the patch is of course a reasonable solution.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#16 lore raw

Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized

In reply to Gerd Hoffmann
Quoted 9 lines · Gerd Hoffmann
Quoted 4 lines · Dimitris Aragiorgis

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.

Patch breaks interaction with libvirt. libvirt hangs on startup, while
probing qemu capabilities. qemu runs in probing mode (command line is
"/home/kraxel/projects/qemu/build-default/x86_64-softmmu/qemu-system-x86_64 -S -no-user-config -nodefaults -nographic -M none -qmp unix:/var/lib/libvirt/qemu/capabilities.monitor.sock,server,nowait -pidfile /var/lib/libvirt/qemu/capabilities.pidfile -daemonize" according to "systemctl status libvirtd -l"), apparently both qemu and libvirt wait for each other.

Patch sent, as a workaround use "./configure --enable-trace-backend=nop".

Paolo