]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Fix the default log output to 'journald' when running under systemd
authorErik Skultety <eskultet@redhat.com>
Thu, 3 Jan 2019 13:32:36 +0000 (14:32 +0100)
committerErik Skultety <eskultet@redhat.com>
Tue, 8 Jan 2019 09:01:54 +0000 (10:01 +0100)
Essentially, bring back the old behaviour as of commit eba36a38 which
was later changed by commit ae06048bf5d. Even though all the stderr
messages will eventually end up in the journal, we're not making use of
the fields journald provides.

https://bugzilla.redhat.com/show_bug.cgi?id=1592644

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virlog.c

index cb6901d9bf0cf599a4e9f2fac6076efb93f8c654..3ee58c5db6705718e2c6e6229c940568653061d6 100644 (file)
@@ -223,11 +223,17 @@ virLogSetDefaultOutputToFile(const char *filename, bool privileged)
 int
 virLogSetDefaultOutput(const char *filename, bool godaemon, bool privileged)
 {
-    if (!godaemon)
-        return virLogSetDefaultOutputToStderr();
+    bool have_journald = access("/run/systemd/journal/socket", W_OK) >= 0;
+
+    if (godaemon) {
+        if (have_journald)
+            return virLogSetDefaultOutputToJournald();
+    } else {
+        if (!isatty(STDIN_FILENO) && have_journald)
+            return virLogSetDefaultOutputToJournald();
 
-    if (access("/run/systemd/journal/socket", W_OK) >= 0)
-        return virLogSetDefaultOutputToJournald();
+        return virLogSetDefaultOutputToStderr();
+    }
 
     return virLogSetDefaultOutputToFile(filename, privileged);
 }