[libvirt] [PATCH] daemon: Fix LIBVIRT_DEBUG=1 default output

This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd: $ git show 7022b09111d4322d21396a70d58320a9ad773962 commit 7022b09111d4322d21396a70d58320a9ad773962 Author: Daniel P. Berrange <berrange@redhat.com> Date: Thu Sep 27 13:13:09 2012 +0100 Automatically enable systemd journal logging Probe to see if the systemd journal is accessible, and if so enable logging to the journal by default, rather than stderr (current default under systemd). Previously 'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug output to stderr, now it send debug output to the journal. Only use the journal by default if running in daemon mode, or if stdin is _not_ a tty. This should make libvirtd launched from systemd use the journal, but preserve the old behavior in most situations. --- daemon/libvirtd.c | 9 ++++++--- src/util/logging.c | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index d2e0a04..279a9d1 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -636,10 +636,13 @@ daemonSetupLogging(struct daemonConfig *config, virLogParseOutputs(config->log_outputs); /* - * If no defined outputs, then first try to direct it - * to the systemd journal (if it exists).... + * If no defined outputs, and either running + * as daemon or not on a tty, then first try + * to direct it to the systemd journal + * (if it exists).... */ - if (virLogGetNbOutputs() == 0) { + if (virLogGetNbOutputs() == 0 && + (godaemon || isatty(STDIN_FILENO) != 1)) { char *tmp; if (access("/run/systemd/journal/socket", W_OK) >= 0) { if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0) diff --git a/src/util/logging.c b/src/util/logging.c index 9a8bba1..dd43842 100644 --- a/src/util/logging.c +++ b/src/util/logging.c @@ -1247,6 +1247,8 @@ virLogParseOutputs(const char *outputs) if (cur == NULL) return -1; + VIR_DEBUG("outputs=%s", outputs); + virSkipSpaces(&cur); while (*cur != 0) { prio= virParseNumber(&cur); -- 1.7.11.7

On 10/24/2012 03:01 PM, Cole Robinson wrote:
This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:
$ git show 7022b09111d4322d21396a70d58320a9ad773962 commit 7022b09111d4322d21396a70d58320a9ad773962 Author: Daniel P. Berrange <berrange@redhat.com> Date: Thu Sep 27 13:13:09 2012 +0100
Automatically enable systemd journal logging
Probe to see if the systemd journal is accessible, and if so enable logging to the journal by default, rather than stderr (current default under systemd).
Previously 'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug output to stderr, now it send debug output to the journal.
Only use the journal by default if running in daemon mode, or if stdin is _not_ a tty. This should make libvirtd launched from systemd use the journal, but preserve the old behavior in most situations.
Makes sense.
- if (virLogGetNbOutputs() == 0) { + if (virLogGetNbOutputs() == 0 && + (godaemon || isatty(STDIN_FILENO) != 1)) {
isatty() is only required to return non-zero for ttys; there is no guarantee that it will return 1. You need to write this as: (godaemon || !isatty(STDIN_FILENO)) ACK with that change. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 10/24/2012 03:47 PM, Eric Blake wrote:
On 10/24/2012 03:01 PM, Cole Robinson wrote:
This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:
$ git show 7022b09111d4322d21396a70d58320a9ad773962 commit 7022b09111d4322d21396a70d58320a9ad773962 Author: Daniel P. Berrange <berrange@redhat.com> Date: Thu Sep 27 13:13:09 2012 +0100
Automatically enable systemd journal logging
Probe to see if the systemd journal is accessible, and if so enable logging to the journal by default, rather than stderr (current default under systemd).
Previously 'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug output to stderr, now it send debug output to the journal.
Only use the journal by default if running in daemon mode, or if stdin is _not_ a tty. This should make libvirtd launched from systemd use the journal, but preserve the old behavior in most situations.
Makes sense.
Thinking about it a bit more, should we be checking if stderr, rather than stdin, is a ttty? That is, if you run 'libvirtd </dev/null' from a terminal, don't you still want output to the stderr tty? -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 10/24/2012 06:11 PM, Eric Blake wrote:
On 10/24/2012 03:47 PM, Eric Blake wrote:
On 10/24/2012 03:01 PM, Cole Robinson wrote:
This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:
$ git show 7022b09111d4322d21396a70d58320a9ad773962 commit 7022b09111d4322d21396a70d58320a9ad773962 Author: Daniel P. Berrange <berrange@redhat.com> Date: Thu Sep 27 13:13:09 2012 +0100
Automatically enable systemd journal logging
Probe to see if the systemd journal is accessible, and if so enable logging to the journal by default, rather than stderr (current default under systemd).
Previously 'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug output to stderr, now it send debug output to the journal.
Only use the journal by default if running in daemon mode, or if stdin is _not_ a tty. This should make libvirtd launched from systemd use the journal, but preserve the old behavior in most situations.
Makes sense.
Thinking about it a bit more, should we be checking if stderr, rather than stdin, is a ttty? That is, if you run 'libvirtd </dev/null' from a terminal, don't you still want output to the stderr tty?
But the libvirtd > out 2>&1 is going to stop working which is a lot more useful then anything stdin related. - Cole

On 10/25/2012 02:35 PM, Cole Robinson wrote:
Thinking about it a bit more, should we be checking if stderr, rather than stdin, is a ttty? That is, if you run 'libvirtd </dev/null' from a terminal, don't you still want output to the stderr tty?
But the libvirtd > out 2>&1 is going to stop working which is a lot more useful then anything stdin related.
Fair enough - I'm happy to leave the isatty() check on stdin alone. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 10/25/2012 04:43 PM, Eric Blake wrote:
On 10/25/2012 02:35 PM, Cole Robinson wrote:
Thinking about it a bit more, should we be checking if stderr, rather than stdin, is a ttty? That is, if you run 'libvirtd </dev/null' from a terminal, don't you still want output to the stderr tty?
But the libvirtd > out 2>&1 is going to stop working which is a lot more useful then anything stdin related.
Fair enough - I'm happy to leave the isatty() check on stdin alone.
Thanks Eric, pushed now. - Cole

On Wed, Oct 24, 2012 at 05:01:54PM -0400, Cole Robinson wrote:
This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:
$ git show 7022b09111d4322d21396a70d58320a9ad773962 commit 7022b09111d4322d21396a70d58320a9ad773962 Author: Daniel P. Berrange <berrange@redhat.com> Date: Thu Sep 27 13:13:09 2012 +0100
Automatically enable systemd journal logging
Probe to see if the systemd journal is accessible, and if so enable logging to the journal by default, rather than stderr (current default under systemd).
Previously 'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug output to stderr, now it send debug output to the journal.
Only use the journal by default if running in daemon mode, or if stdin is _not_ a tty. This should make libvirtd launched from systemd use the journal, but preserve the old behavior in most situations.
Yep, makes total sense. I should have noticed that when writing this originally. Daniel -- |: 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 :|
participants (3)
-
Cole Robinson
-
Daniel P. Berrange
-
Eric Blake