[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] daemon: Add early libvirtd start verbose errors.



Early errors during start of libvirtd didn't have
an error reporting mechanism and caused libvirtd
to exit silently (only the return value indicated
an error). This patch adds error messages printed
to stderr if verbose parameter is specified to the
daemon.

fixes: https://bugzilla.redhat.com/show_bug.cgi?id=728654
---
 daemon/libvirtd.c |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 53f1002..c3867af 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1328,14 +1328,20 @@ int main(int argc, char **argv) {

         case 'p':
             VIR_FREE(pid_file);
-            if (!(pid_file = strdup(optarg)))
+            if (!(pid_file = strdup(optarg))) {
+                if (verbose)
+                    fprintf(stderr, _("ERROR: Can't allocate memory\n"));
                 exit(EXIT_FAILURE);
+            }
             break;

         case 'f':
             VIR_FREE(remote_config_file);
-            if (!(remote_config_file = strdup(optarg)))
+            if (!(remote_config_file = strdup(optarg))) {
+                if (verbose)
+                    fprintf(stderr, _("ERROR: Can't allocate memory\n"));
                 exit(EXIT_FAILURE);
+            }
             break;

         case OPT_VERSION:
@@ -1353,21 +1359,30 @@ int main(int argc, char **argv) {
         }
     }

-    if (!(config = daemonConfigNew(privileged)))
+    if (!(config = daemonConfigNew(privileged))) {
+        if (verbose)
+            fprintf(stderr, _("ERROR: Can't create configuration\n"));
         exit(EXIT_FAILURE);
+    }

     /* No explicit config, so try and find a default one */
     if (remote_config_file == NULL) {
         implicit_conf = true;
         if (daemonConfigFilePath(privileged,
-                                 &remote_config_file) < 0)
+                                 &remote_config_file) < 0) {
+            if (verbose)
+                fprintf(stderr, _("ERROR: Can't determine config path\n"));
             exit(EXIT_FAILURE);
+        }
     }

     /* Read the config file if it exists*/
     if (remote_config_file &&
-        daemonConfigLoad(config, remote_config_file, implicit_conf) < 0)
+        daemonConfigLoad(config, remote_config_file, implicit_conf) < 0) {
+        if (verbose)
+            fprintf(stderr, _("ERROR: Can't load config file '%s'\n"), remote_config_file);
         exit(EXIT_FAILURE);
+    }

     if (config->host_uuid &&
         virSetHostUUIDStr(config->host_uuid) < 0) {
@@ -1375,19 +1390,28 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }

-    if (daemonSetupLogging(config, privileged, verbose, godaemon) < 0)
+    if (daemonSetupLogging(config, privileged, verbose, godaemon) < 0) {
+        if (verbose)
+            fprintf(stderr, _("ERROR: Can't initialise logging\n"));
         exit(EXIT_FAILURE);
+    }
+
+    /* error logging is up, use libvirt's error logging from now */

     if (!pid_file && privileged &&
         daemonPidFilePath(privileged,
-                          &pid_file) < 0)
+                          &pid_file) < 0) {
+        VIR_ERROR(_("Can't determine pid file path."));
         exit(EXIT_FAILURE);
+    }

     if (daemonUnixSocketPaths(config,
                               privileged,
                               &sock_file,
-                              &sock_file_ro) < 0)
+                              &sock_file_ro) < 0) {
+        VIR_ERROR(_("Can't determine socket paths"));
         exit(EXIT_FAILURE);
+    }

     if (godaemon) {
         char ebuf[1024];
-- 
1.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]