[PATCHv2 0/3] Share duplicated daemon code in *SetupLogging functions

This patch is part of the bite sized task, Share duplicated daemon code. A new function is introduced for shared code in *SetupLogging functions. Commit 1: Share Dup Daemon Function *SetupLogging Introduce src/util/virdaemon.c/h files. Introduce new function virDaemonSetupLogging for shared code in *SetupLogging. Convert all callers of *SetupLogging functions to virDaemonSetupLogging. Introduce new struct virDaemonLogConfig for log configs (log_*) in *DeamonConfig structs. *DeamonConfig is an input to virDaemonSetupLogging. Commit 2: Alloc and Free virDaemonLogConfig Introduce functions to alloc and free the new struct virDaemonLogConfig. Commit 3: Passing virDaemonLogConfig to DaemonSetupLogging Convert all the callers that now pass virDaemonLogConfig to the new function virDaemonSetupLogging. Lan (3): Share Dup Daemon Function *SetupLogging Alloc and Free virDaemonLogConfig Passing virDaemonLogConfig to DaemonSetupLogging src/libvirt_private.syms | 4 ++ src/locking/lock_daemon.c | 66 +++++------------------- src/logging/log_daemon.c | 58 +++++---------------- src/remote/remote_daemon.c | 65 +++++------------------- src/util/Makefile.inc.am | 2 + src/util/virdaemon.c | 101 +++++++++++++++++++++++++++++++++++++ src/util/virdaemon.h | 43 ++++++++++++++++ 7 files changed, 186 insertions(+), 153 deletions(-) create mode 100644 src/util/virdaemon.c create mode 100644 src/util/virdaemon.h -- 2.17.1

One of the BiteSizedTasks Introduce src/util/virdaemon.c/h files Introduce a new function virDaemonSetupLogging (src/util/virdaemon.c) for shared code in virLockDaemonSetupLogging (src/locking/lock_daemon.c) virLogDaemonSetupLogging (src/logging/log_daemon.c) daemonSetupLogging (src/remote/remote_daemon.c) Introduce virDaemonLogConfig struct for config->log_* variables in virLockDaemonConfig/virLogDaemonConfig/daemonConfig struct Signed-off-by: Lan Bai <lbai@wisc.edu> --- src/libvirt_private.syms | 2 + src/locking/lock_daemon.c | 58 ++--------------------------- src/logging/log_daemon.c | 50 ++----------------------- src/remote/remote_daemon.c | 57 ++--------------------------- src/util/Makefile.inc.am | 4 +- src/util/virdaemon.c | 75 ++++++++++++++++++++++++++++++++++++++ src/util/virdaemon.h | 35 ++++++++++++++++++ 7 files changed, 126 insertions(+), 155 deletions(-) create mode 100644 src/util/virdaemon.c create mode 100644 src/util/virdaemon.h diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index de0c7a3133..50cbd6d7af 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1906,6 +1906,8 @@ virCryptoHashBuf; virCryptoHashString; virCryptoHaveCipher; +# util/virdaemon.h +virDaemonSetupLogging; # util/virdbus.h virDBusCallMethod; diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 5e5a0c1089..5ba851cb55 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -46,6 +46,7 @@ #include "virstring.h" #include "virgettext.h" #include "virenum.h" +#include "virdaemon.h" #include "locking/lock_daemon_dispatch.h" #include "locking/lock_protocol.h" @@ -477,59 +478,6 @@ virLockDaemonErrorHandler(void *opaque G_GNUC_UNUSED, } -/* - * Set up the logging environment - * By default if daemonized all errors go to the logfile libvirtd.log, - * but if verbose or error debugging is asked for then also output - * informational and debug messages. Default size if 64 kB. - */ -static int -virLockDaemonSetupLogging(virLockDaemonConfigPtr config, - bool privileged, - bool verbose, - bool godaemon) -{ - virLogReset(); - - /* - * Libvirtd's order of precedence is: - * cmdline > environment > config - * - * Given the precedence, we must process the variables in the opposite - * order, each one overriding the previous. - */ - if (config->log_level != 0) - virLogSetDefaultPriority(config->log_level); - - /* In case the config is empty, both filters and outputs will become empty, - * however we can't start with empty outputs, thus we'll need to define and - * setup a default one. - */ - ignore_value(virLogSetFilters(config->log_filters)); - ignore_value(virLogSetOutputs(config->log_outputs)); - - /* If there are some environment variables defined, use those instead */ - virLogSetFromEnv(); - - /* - * Command line override for --verbose - */ - if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) - virLogSetDefaultPriority(VIR_LOG_INFO); - - /* Define the default output. This is only applied if there was no setting - * from either the config or the environment. - */ - virLogSetDefaultOutput("virtlockd", godaemon, privileged); - - if (virLogGetNbOutputs() == 0) - virLogSetOutputs(virLogGetDefaultOutput()); - - return 0; -} - - - /* Display version information. */ static void virLockDaemonVersion(const char *argv0) @@ -1186,7 +1134,9 @@ int main(int argc, char **argv) { } VIR_FREE(remote_config_file); - if (virLockDaemonSetupLogging(config, privileged, verbose, godaemon) < 0) { + if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), + "virtlockd", privileged, + verbose, godaemon)< 0) { VIR_ERROR(_("Can't initialize logging")); exit(EXIT_FAILURE); } diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 772bbb805b..9f962300ed 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -45,6 +45,7 @@ #include "virstring.h" #include "virgettext.h" #include "virenum.h" +#include "virdaemon.h" #include "log_daemon_dispatch.h" #include "log_protocol.h" @@ -419,51 +420,6 @@ virLogDaemonErrorHandler(void *opaque G_GNUC_UNUSED, } -static void -virLogDaemonSetupLogging(virLogDaemonConfigPtr config, - bool privileged, - bool verbose, - bool godaemon) -{ - virLogReset(); - - /* - * Libvirtd's order of precedence is: - * cmdline > environment > config - * - * Given the precedence, we must process the variables in the opposite - * order, each one overriding the previous. - */ - if (config->log_level != 0) - virLogSetDefaultPriority(config->log_level); - - /* In case the config is empty, both filters and outputs will become empty, - * however we can't start with empty outputs, thus we'll need to define and - * setup a default one. - */ - ignore_value(virLogSetFilters(config->log_filters)); - ignore_value(virLogSetOutputs(config->log_outputs)); - - /* If there are some environment variables defined, use those instead */ - virLogSetFromEnv(); - - /* - * Command line override for --verbose - */ - if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) - virLogSetDefaultPriority(VIR_LOG_INFO); - - /* Define the default output. This is only applied if there was no setting - * from either the config or the environment. - */ - virLogSetDefaultOutput("virtlogd", godaemon, privileged); - - if (virLogGetNbOutputs() == 0) - virLogSetOutputs(virLogGetDefaultOutput()); -} - - - /* Display version information. */ static void virLogDaemonVersion(const char *argv0) @@ -957,8 +913,8 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - virLogDaemonSetupLogging(config, privileged, verbose, godaemon); - + virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), + "virtlogd", privileged, verbose, godaemon); if (!pid_file && virPidFileConstructPath(privileged, RUNSTATEDIR, diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 7082460bae..4bbdc255d0 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -57,6 +57,7 @@ #include "util/virnetdevopenvswitch.h" #include "virsystemd.h" #include "virhostuptime.h" +#include "virdaemon.h" #include "driver.h" @@ -606,58 +607,6 @@ daemonSetupNetDevOpenvswitch(struct daemonConfig *config) } -/* - * Set up the logging environment - * By default if daemonized all errors go to journald/a logfile - * but if verbose or error debugging is asked for then also output - * informational and debug messages. Default size if 64 kB. - */ -static int -daemonSetupLogging(struct daemonConfig *config, - bool privileged, - bool verbose, - bool godaemon) -{ - virLogReset(); - - /* - * Logging setup order of precedence is: - * cmdline > environment > config - * - * Given the precedence, we must process the variables in the opposite - * order, each one overriding the previous. - */ - if (config->log_level != 0) - virLogSetDefaultPriority(config->log_level); - - /* In case the config is empty, both filters and outputs will become empty, - * however we can't start with empty outputs, thus we'll need to define and - * setup a default one. - */ - ignore_value(virLogSetFilters(config->log_filters)); - ignore_value(virLogSetOutputs(config->log_outputs)); - - /* If there are some environment variables defined, use those instead */ - virLogSetFromEnv(); - - /* - * Command line override for --verbose - */ - if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) - virLogSetDefaultPriority(VIR_LOG_INFO); - - /* Define the default output. This is only applied if there was no setting - * from either the config or the environment. - */ - virLogSetDefaultOutput(DAEMON_NAME, godaemon, privileged); - - if (virLogGetNbOutputs() == 0) - virLogSetOutputs(virLogGetDefaultOutput()); - - return 0; -} - - static int daemonSetupAccessManager(struct daemonConfig *config) { @@ -1147,7 +1096,9 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if (daemonSetupLogging(config, privileged, verbose, godaemon) < 0) { + if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), + DAEMON_NAME, privileged, + verbose, godaemon) < 0) { VIR_ERROR(_("Can't initialize logging")); exit(EXIT_FAILURE); } diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index ddb3b43c5f..cf64220b63 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -42,7 +42,9 @@ UTIL_SOURCES = \ util/virconf.h \ util/vircrypto.c \ util/vircrypto.h \ - util/virdbus.c \ + util/virdaemon.c \ + util/virdaemon.h \ + util/virdbus.c \ util/virdbus.h \ util/virdbuspriv.h \ util/virdevmapper.c \ diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c new file mode 100644 index 0000000000..a2ef48b78b --- /dev/null +++ b/src/util/virdaemon.c @@ -0,0 +1,75 @@ +/* + * virdaemon.c: remote/logging/lock management daemon common code + * + * Copyright (C) 2006-2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include "virdaemon.h" +#include "virlog.h" + + +/* + * Set up the logging environment + * By default if daemonized all errors go to journald/a logfile + * but if verbose or error debugging is asked for then also output + * informational and debug messages. Default size if 64 kB. + */ +int +virDaemonSetupLogging(virDaemonLogConfigPtr config, + const char *output_fname, + bool privileged, bool verbose, bool godaemon) +{ + virLogReset(); + + /* + * Libvirtd's order of precedence is: + * cmdline > environment > config + * + * Given the precedence, we must process the variables in the opposite + * order, each one overriding the previous. + */ + if (config->log_level != 0) + virLogSetDefaultPriority(config->log_level); + + /* In case the config is empty, both filters and outputs will become empty, + * however we can't start with empty outputs, thus we'll need to define and + * setup a default one. + */ + ignore_value(virLogSetFilters(config->log_filters)); + ignore_value(virLogSetOutputs(config->log_outputs)); + + /* If there are some environment variables defined, use those instead */ + virLogSetFromEnv(); + + /* + * Command line override for --verbose + */ + if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) + virLogSetDefaultPriority(VIR_LOG_INFO); + + /* Define the default output. This is only applied if there was no setting + * from either the config or the environment. + */ + virLogSetDefaultOutput(output_fname, godaemon, privileged); + + if (virLogGetNbOutputs() == 0) + virLogSetOutputs(virLogGetDefaultOutput()); + + return 0; +} diff --git a/src/util/virdaemon.h b/src/util/virdaemon.h new file mode 100644 index 0000000000..60b4119f08 --- /dev/null +++ b/src/util/virdaemon.h @@ -0,0 +1,35 @@ +/* + * virdaemon.h: remote/logging/lock management daemon common code + * + * Copyright (C) 2006-2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include "internal.h" + +typedef struct _virDaemonLogConfig virDaemonLogConfig; +typedef virDaemonLogConfig *virDaemonLogConfigPtr; + +struct _virDaemonLogConfig { + unsigned int log_level; + char *log_filters; + char *log_outputs; +}; + +int virDaemonSetupLogging(virDaemonLogConfigPtr config, + const char *output_fname, + bool privileged, bool verbose, bool godaemon); -- 2.17.1

On a Sunday in 2020, Lan wrote:
One of the BiteSizedTasks
Introduce src/util/virdaemon.c/h files
Introduce a new function virDaemonSetupLogging (src/util/virdaemon.c) for shared code in virLockDaemonSetupLogging (src/locking/lock_daemon.c) virLogDaemonSetupLogging (src/logging/log_daemon.c) daemonSetupLogging (src/remote/remote_daemon.c)
Introduce virDaemonLogConfig struct for config->log_* variables in virLockDaemonConfig/virLogDaemonConfig/daemonConfig struct
Signed-off-by: Lan Bai <lbai@wisc.edu> --- src/libvirt_private.syms | 2 + src/locking/lock_daemon.c | 58 ++--------------------------- src/logging/log_daemon.c | 50 ++----------------------- src/remote/remote_daemon.c | 57 ++--------------------------- src/util/Makefile.inc.am | 4 +- src/util/virdaemon.c | 75 ++++++++++++++++++++++++++++++++++++++ src/util/virdaemon.h | 35 ++++++++++++++++++ 7 files changed, 126 insertions(+), 155 deletions(-) create mode 100644 src/util/virdaemon.c create mode 100644 src/util/virdaemon.h
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index de0c7a3133..50cbd6d7af 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1906,6 +1906,8 @@ virCryptoHashBuf; virCryptoHashString; virCryptoHaveCipher;
+# util/virdaemon.h +virDaemonSetupLogging;
# util/virdbus.h virDBusCallMethod; diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 5e5a0c1089..5ba851cb55 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -46,6 +46,7 @@ #include "virstring.h" #include "virgettext.h" #include "virenum.h" +#include "virdaemon.h"
#include "locking/lock_daemon_dispatch.h" #include "locking/lock_protocol.h" @@ -477,59 +478,6 @@ virLockDaemonErrorHandler(void *opaque G_GNUC_UNUSED, }
-/* - * Set up the logging environment - * By default if daemonized all errors go to the logfile libvirtd.log, - * but if verbose or error debugging is asked for then also output - * informational and debug messages. Default size if 64 kB. - */ -static int -virLockDaemonSetupLogging(virLockDaemonConfigPtr config, - bool privileged, - bool verbose, - bool godaemon) -{ - virLogReset(); - - /* - * Libvirtd's order of precedence is: - * cmdline > environment > config - * - * Given the precedence, we must process the variables in the opposite - * order, each one overriding the previous. - */ - if (config->log_level != 0) - virLogSetDefaultPriority(config->log_level); - - /* In case the config is empty, both filters and outputs will become empty, - * however we can't start with empty outputs, thus we'll need to define and - * setup a default one. - */ - ignore_value(virLogSetFilters(config->log_filters)); - ignore_value(virLogSetOutputs(config->log_outputs)); - - /* If there are some environment variables defined, use those instead */ - virLogSetFromEnv(); - - /* - * Command line override for --verbose - */ - if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) - virLogSetDefaultPriority(VIR_LOG_INFO); - - /* Define the default output. This is only applied if there was no setting - * from either the config or the environment. - */ - virLogSetDefaultOutput("virtlockd", godaemon, privileged); - - if (virLogGetNbOutputs() == 0) - virLogSetOutputs(virLogGetDefaultOutput()); - - return 0; -} - - - /* Display version information. */ static void virLockDaemonVersion(const char *argv0) @@ -1186,7 +1134,9 @@ int main(int argc, char **argv) { } VIR_FREE(remote_config_file);
- if (virLockDaemonSetupLogging(config, privileged, verbose, godaemon) < 0) { + if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)),
This still does not compile for me: ../../src/locking/lock_daemon.c:1131:31: error: cast from 'unsigned int *' to 'virDaemonLogConfigPtr' (aka 'struct _virDaemonLogConfig *') increases required alignment from 4 to 8 [-Werror,-Wcast-align] if (virDaemonSetupLogging((virDaemonLogConfigPtr)(&(config->log_level)), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The first step along with introducing the virDaemonLogConfig structure is moving the three log_parameters into this structure. So struct _virLockDaemonConfig { unsigned int log_level; char *log_filters; char *log_outputs; unsigned int max_clients; unsigned int admin_max_clients; }; would become something like struct _virLockDaemonConfig { virDaemonLogConfig log_config; unsigned int max_clients; unsigned int admin_max_clients; }; And a function like: virDaemonLogConfigLoadOptions(virDaemonLogConfigPtr log_config, virConfPtr conf) could be used to replace the three lines in every daemon's config loader. Jano

Introduce New functions virDaemonLogConfigNew/virDaemonLogConfigFree for alloc and free virDaemonLogConfig Signed-off-by: Lan Bai <lbai@wisc.edu> --- src/util/Makefile.inc.am | 2 +- src/util/virdaemon.c | 26 ++++++++++++++++++++++++++ src/util/virdaemon.h | 11 +++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index cf64220b63..4cac1b07fe 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -44,7 +44,7 @@ UTIL_SOURCES = \ util/vircrypto.h \ util/virdaemon.c \ util/virdaemon.h \ - util/virdbus.c \ + util/virdbus.c \ util/virdbus.h \ util/virdbuspriv.h \ util/virdevmapper.c \ diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c index a2ef48b78b..44bdfb9132 100644 --- a/src/util/virdaemon.c +++ b/src/util/virdaemon.c @@ -22,6 +22,7 @@ #include "virdaemon.h" #include "virlog.h" +#include "viralloc.h" /* @@ -73,3 +74,28 @@ virDaemonSetupLogging(virDaemonLogConfigPtr config, return 0; } + +virDaemonLogConfigPtr +virDaemonLogConfigNew(unsigned int log_level, + char *log_filters, + 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; +} + +void +virDaemonLogConfigFree(virDaemonLogConfigPtr data) +{ + VIR_FREE(data->log_filters); + VIR_FREE(data->log_outputs); + VIR_FREE(data); +} diff --git a/src/util/virdaemon.h b/src/util/virdaemon.h index 60b4119f08..46cd80e6a8 100644 --- a/src/util/virdaemon.h +++ b/src/util/virdaemon.h @@ -33,3 +33,14 @@ struct _virDaemonLogConfig { int virDaemonSetupLogging(virDaemonLogConfigPtr config, const char *output_fname, bool privileged, bool verbose, bool godaemon); + +virDaemonLogConfigPtr +virDaemonLogConfigNew(unsigned int log_level, + char *log_filter, + char *log_outputs); + +void +virDaemonLogConfigFree(virDaemonLogConfigPtr data); + + + -- 2.17.1

Passing virDaemonLogConfig to the shared function DaemonSetupLogging instead of passing *DaemonConfig to *SetupLogging functions Signed-off-by: Lan Bai <lbai@wisc.edu> --- 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
participants (2)
-
Ján Tomko
-
Lan