[libvirt] [PATCH] util: Fix the default log output to 'journald' when running under systemd

Erik Skultety posted 1 patch 5 years, 2 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/64f3e59420a7fb546e9cc976bdb8634a09544020.1546524970.git.eskultet@redhat.com
src/util/virlog.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
[libvirt] [PATCH] util: Fix the default log output to 'journald' when running under systemd
Posted by Erik Skultety 5 years, 2 months ago
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>
---
 src/util/virlog.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index cb6901d9bf..3ee58c5db6 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -223,11 +223,17 @@ virLogSetDefaultOutputToFile(const char *filename, bool privileged)
 int
 virLogSetDefaultOutput(const char *filename, bool godaemon, bool privileged)
 {
-    if (!godaemon)
+    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();
+
         return virLogSetDefaultOutputToStderr();
-
-    if (access("/run/systemd/journal/socket", W_OK) >= 0)
-        return virLogSetDefaultOutputToJournald();
+    }
 
     return virLogSetDefaultOutputToFile(filename, privileged);
 }
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Fix the default log output to 'journald' when running under systemd
Posted by Michal Privoznik 5 years, 2 months ago
On 1/3/19 3:19 PM, Erik Skultety wrote:
> 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>
> ---
>  src/util/virlog.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list