]> xenbits.xensource.com Git - libvirt.git/commitdiff
Exit on errors from virDaemonSetupLogging
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 15 Dec 2021 15:35:41 +0000 (16:35 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 5 Jan 2022 13:08:39 +0000 (14:08 +0100)
This prevents starting any daemons with improper logging settings.  This is
desirable on its own, but will be even more beneficial when more functions start
reporting errors and failing on them, coming up in following patches

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/locking/lock_daemon.c
src/logging/log_daemon.c
src/remote/remote_daemon.c
src/util/virdaemon.c
src/util/virdaemon.h

index 107fb22bc2c93e462179c4349024eab6428cef3f..ea81940a43251341459f2f568103b4ad8c61f37c 100644 (file)
@@ -913,13 +913,14 @@ int main(int argc, char **argv) {
     }
     VIR_FREE(remote_config_file);
 
-    virDaemonSetupLogging("virtlockd",
-                          config->log_level,
-                          config->log_filters,
-                          config->log_outputs,
-                          privileged,
-                          verbose,
-                          godaemon);
+    if (virDaemonSetupLogging("virtlockd",
+                              config->log_level,
+                              config->log_filters,
+                              config->log_outputs,
+                              privileged,
+                              verbose,
+                              godaemon) < 0)
+        exit(EXIT_FAILURE);
 
     if (!pid_file &&
         virPidFileConstructPath(privileged,
index de6bf082e89b9461d272d79dd4aeec7fb5371f3b..fe7fa8534aeca41f2ce79dfe33705cebde242c80 100644 (file)
@@ -719,13 +719,14 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }
 
-    virDaemonSetupLogging("virtlogd",
-                          config->log_level,
-                          config->log_filters,
-                          config->log_outputs,
-                          privileged,
-                          verbose,
-                          godaemon);
+    if (virDaemonSetupLogging("virtlogd",
+                              config->log_level,
+                              config->log_filters,
+                              config->log_outputs,
+                              privileged,
+                              verbose,
+                              godaemon) < 0)
+        exit(EXIT_FAILURE);
 
     if (!pid_file &&
         virPidFileConstructPath(privileged,
index 4e10f3ad230779cf2282629a83f0fd8875f72c9e..8a4610da83c8aae143ecfe88e3ee5b2fa8d5f0a7 100644 (file)
@@ -936,13 +936,14 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }
 
-    virDaemonSetupLogging(DAEMON_NAME,
-                          config->log_level,
-                          config->log_filters,
-                          config->log_outputs,
-                          privileged,
-                          verbose,
-                          godaemon);
+    if (virDaemonSetupLogging(DAEMON_NAME,
+                              config->log_level,
+                              config->log_filters,
+                              config->log_outputs,
+                              privileged,
+                              verbose,
+                              godaemon) < 0)
+        exit(EXIT_FAILURE);
 
     /* Let's try to initialize global variable that holds the host's boot time. */
     if (virHostBootTimeInit() < 0) {
index bb2df2eb2cab12f3f61d29e5dca1ea9d5ffed4a4..795206301227791ccce78b1bae9ddb7ce685313f 100644 (file)
@@ -151,7 +151,7 @@ virDaemonForkIntoBackground(const char *argv0)
  * but if verbose or error debugging is asked for then also output
  * informational and debug messages. Default size if 64 kB.
  */
-void
+int
 virDaemonSetupLogging(const char *daemon_name,
                       unsigned int log_level,
                       char *log_filters,
@@ -160,7 +160,8 @@ virDaemonSetupLogging(const char *daemon_name,
                       bool verbose,
                       bool godaemon)
 {
-    virLogReset();
+    if (virLogReset() < 0)
+        return -1;
 
     /*
      * Libvirtd's order of precedence is:
@@ -169,15 +170,17 @@ virDaemonSetupLogging(const char *daemon_name,
      * Given the precedence, we must process the variables in the opposite
      * order, each one overriding the previous.
      */
-    if (log_level != 0)
-        virLogSetDefaultPriority(log_level);
+    if (log_level != 0 &&
+        virLogSetDefaultPriority(log_level) < 0)
+        return -1;
 
     /* 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(log_filters));
-    ignore_value(virLogSetOutputs(log_outputs));
+    if (virLogSetFilters(log_filters) < 0 ||
+        virLogSetOutputs(log_outputs) < 0)
+        return -1;
 
     /* If there are some environment variables defined, use those instead */
     virLogSetFromEnv();
@@ -185,16 +188,22 @@ virDaemonSetupLogging(const char *daemon_name,
     /*
      * Command line override for --verbose
      */
-    if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO))
-        virLogSetDefaultPriority(VIR_LOG_INFO);
+    if (verbose &&
+        virLogGetDefaultPriority() > VIR_LOG_INFO &&
+        virLogSetDefaultPriority(VIR_LOG_INFO) < 0)
+        return -1;
 
     /* 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 (virLogSetDefaultOutput(daemon_name, godaemon, privileged) < 0)
+        return -1;
+
+    if (virLogGetNbOutputs() == 0 &&
+        virLogSetOutputs(virLogGetDefaultOutput()) < 0)
+        return -1;
 
-    if (virLogGetNbOutputs() == 0)
-        virLogSetOutputs(virLogGetDefaultOutput());
+    return 0;
 }
 
 
index d032b8ddb3b962f924cbf2ef88d1a45bc4c61cb3..9ed0942d6d0ef66648e5f9105fcb63eac46067e2 100644 (file)
@@ -58,13 +58,13 @@ VIR_ENUM_IMPL(virDaemonErr,
 
 int virDaemonForkIntoBackground(const char *argv0);
 
-void virDaemonSetupLogging(const char *daemon_name,
-                           unsigned int log_level,
-                           char *log_filters,
-                           char *log_outputs,
-                           bool privileged,
-                           bool verbose,
-                           bool godaemon);
+int virDaemonSetupLogging(const char *daemon_name,
+                          unsigned int log_level,
+                          char *log_filters,
+                          char *log_outputs,
+                          bool privileged,
+                          bool verbose,
+                          bool godaemon);
 
 int virDaemonUnixSocketPaths(const char *sock_prefix,
                              bool privileged,