Passing virDaemonLogConfig to the shared function DaemonSetupLogging instead of passing *DaemonConfig to *SetupLogging functions Signed-off-by: Lan Bai <lbai@xxxxxxxx> --- src/libvirt_private.syms | 2 ++ src/locking/lock_daemon.c | 12 ++++++++++-- src/logging/log_daemon.c | 14 ++++++++++++-- src/remote/remote_daemon.c | 12 ++++++++++-- src/util/virdaemon.c | 6 +++--- src/util/virdaemon.h | 3 --- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 50cbd6d7af..8aed0457bf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1907,6 +1907,8 @@ virCryptoHashString; virCryptoHaveCipher; # util/virdaemon.h +virDaemonLogConfigFree; +virDaemonLogConfigNew; virDaemonSetupLogging; # util/virdbus.h diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 5ba851cb55..efbffca4fb 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -1031,6 +1031,7 @@ int main(int argc, char **argv) { mode_t old_umask; bool privileged = false; virLockDaemonConfigPtr config = NULL; + virDaemonLogConfigPtr log_config = NULL; int rv; struct option opts[] = { @@ -1134,8 +1135,14 @@ int main(int argc, char **argv) { } VIR_FREE(remote_config_file); - if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), - "virtlockd", privileged, + if (!(log_config = virDaemonLogConfigNew(config->log_level, + config->log_filters, + config->log_outputs))) { + VIR_ERROR(_("Can't create log configuration")); + exit(EXIT_FAILURE); + } + + if (virDaemonSetupLogging(log_config, "virtlockd", privileged, verbose, godaemon)< 0) { VIR_ERROR(_("Can't initialize logging")); exit(EXIT_FAILURE); @@ -1366,5 +1373,6 @@ int main(int argc, char **argv) { VIR_FREE(state_file); VIR_FREE(run_dir); virLockDaemonConfigFree(config); + virDaemonLogConfigFree(log_config); return ret; } diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 9f962300ed..9bb4d64f7f 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -811,6 +811,7 @@ int main(int argc, char **argv) { mode_t old_umask; bool privileged = false; virLogDaemonConfigPtr config = NULL; + virDaemonLogConfigPtr log_config = NULL; int rv; struct option opts[] = { @@ -913,8 +914,15 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), - "virtlogd", privileged, verbose, godaemon); + if (!(log_config = virDaemonLogConfigNew(config->log_level, + config->log_filters, + config->log_outputs))) { + VIR_ERROR(_("Can't create log configuration")); + exit(EXIT_FAILURE); + } + + virDaemonSetupLogging(log_config, "virtlogd", + privileged, verbose, godaemon); if (!pid_file && virPidFileConstructPath(privileged, RUNSTATEDIR, @@ -1141,5 +1149,7 @@ int main(int argc, char **argv) { VIR_FREE(run_dir); VIR_FREE(remote_config_file); virLogDaemonConfigFree(config); + virDaemonLogConfigFree(log_config); + return ret; } diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 4bbdc255d0..7b4779a041 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -966,6 +966,7 @@ int main(int argc, char **argv) { # endif /* ! LIBVIRTD */ #endif /* ! WITH_IP */ struct daemonConfig *config; + virDaemonLogConfigPtr log_config = NULL; bool privileged = geteuid() == 0 ? true : false; bool implicit_conf = false; char *run_dir = NULL; @@ -1096,8 +1097,14 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), - DAEMON_NAME, privileged, + if (!(log_config = virDaemonLogConfigNew(config->log_level, + config->log_filters, + config->log_outputs))) { + VIR_ERROR(_("Can't create log configuration")); + exit(EXIT_FAILURE); + } + + if (virDaemonSetupLogging(log_config, DAEMON_NAME, privileged, verbose, godaemon) < 0) { VIR_ERROR(_("Can't initialize logging")); exit(EXIT_FAILURE); @@ -1431,6 +1438,7 @@ int main(int argc, char **argv) { VIR_FREE(remote_config_file); daemonConfigFree(config); + virDaemonLogConfigFree(log_config); return ret; } diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c index 44bdfb9132..e4baa26c79 100644 --- a/src/util/virdaemon.c +++ b/src/util/virdaemon.c @@ -81,14 +81,14 @@ virDaemonLogConfigNew(unsigned int log_level, char *log_outputs) { virDaemonLogConfigPtr ret; - + if (VIR_ALLOC(ret) < 0) return NULL; ret->log_level = log_level; ret->log_filters = g_strdup(log_filters); ret->log_outputs = g_strdup(log_outputs); - + return ret; } @@ -97,5 +97,5 @@ virDaemonLogConfigFree(virDaemonLogConfigPtr data) { VIR_FREE(data->log_filters); VIR_FREE(data->log_outputs); - VIR_FREE(data); + VIR_FREE(data); } diff --git a/src/util/virdaemon.h b/src/util/virdaemon.h index 46cd80e6a8..7785670842 100644 --- a/src/util/virdaemon.h +++ b/src/util/virdaemon.h @@ -41,6 +41,3 @@ virDaemonLogConfigNew(unsigned int log_level, void virDaemonLogConfigFree(virDaemonLogConfigPtr data); - - - -- 2.17.1