From 0d6cf32721359a169d5f3e27fe52231844f8d9aa Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Fri, 25 Nov 2016 11:50:51 +0100 Subject: [PATCH] admin: Allow passing NULL to virLogSetOutputs Along with an empty string, it should also be possible for users to pass NULL to the public APIs which in turn would trigger a routine(future work) responsible for defining an appropriate default logging output given the current circumstances. Signed-off-by: Erik Skultety --- daemon/libvirtd.c | 2 +- src/locking/lock_daemon.c | 2 +- src/logging/log_daemon.c | 2 +- src/util/virlog.c | 8 +++++++- src/util/virlog.h | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index cd25b508e3..3902a8bd18 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -693,7 +693,7 @@ daemonSetupLogging(struct daemonConfig *config, if (virLogGetNbFilters() == 0) virLogSetFilters(config->log_filters); - if (config->log_outputs && virLogGetNbOutputs() == 0) + if (virLogGetNbOutputs() == 0) virLogSetOutputs(config->log_outputs); /* diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 02745be652..9ee818e93e 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -478,7 +478,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, if (virLogGetNbFilters() == 0) virLogSetFilters(config->log_filters); - if (config->log_outputs && virLogGetNbOutputs() == 0) + if (virLogGetNbOutputs() == 0) virLogSetOutputs(config->log_outputs); /* diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 04bb83616d..a9aebdb6d7 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -406,7 +406,7 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config, if (virLogGetNbFilters() == 0) virLogSetFilters(config->log_filters); - if (config->log_outputs && virLogGetNbOutputs() == 0) + if (virLogGetNbOutputs() == 0) virLogSetOutputs(config->log_outputs); /* diff --git a/src/util/virlog.c b/src/util/virlog.c index a13b471a63..7b584f8e37 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1818,6 +1818,8 @@ virLogParseFilters(const char *src, virLogFilterPtr **filters) * @outputs: string defining a (set of) output(s) * * Replaces the current set of defined outputs with a new set of outputs. + * Should the set be empty or NULL, a default output is used according to the + * daemon's runtime attributes. * * Returns 0 on success or -1 in case of an error. */ @@ -1826,12 +1828,16 @@ virLogSetOutputs(const char *src) { int ret = -1; int noutputs = 0; + const char *outputstr = virLogDefaultOutput; virLogOutputPtr *outputs = NULL; if (virLogInitialize() < 0) return -1; - if ((noutputs = virLogParseOutputs(src, &outputs)) < 0) + if (src && *src) + outputstr = src; + + if ((noutputs = virLogParseOutputs(outputstr, &outputs)) < 0) goto cleanup; if (virLogDefineOutputs(outputs, noutputs) < 0) diff --git a/src/util/virlog.h b/src/util/virlog.h index b4ffecafb2..cc09f484af 100644 --- a/src/util/virlog.h +++ b/src/util/virlog.h @@ -187,7 +187,7 @@ void virLogOutputFree(virLogOutputPtr output); void virLogOutputListFree(virLogOutputPtr *list, int count); void virLogFilterFree(virLogFilterPtr filter); void virLogFilterListFree(virLogFilterPtr *list, int count); -int virLogSetOutputs(const char *outputs) ATTRIBUTE_NONNULL(1); +int virLogSetOutputs(const char *outputs); int virLogSetFilters(const char *filters); char *virLogGetDefaultOutput(void); int virLogSetDefaultOutput(const char *fname, bool godaemon, bool privileged);