[PATCH] Fix usage of virFileMakePath, it doesn't set errno but returns it

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

 



Also be explicity about the != 0 check in the few places that weren't.
---
 src/conf/domain_conf.c       |    6 +++---
 src/conf/network_conf.c      |    2 +-
 src/conf/nwfilter_conf.c     |    4 ++--
 src/conf/storage_conf.c      |    2 +-
 src/libxl/libxl_driver.c     |   20 ++++++++++----------
 src/lxc/lxc_container.c      |   16 ++++++++--------
 src/lxc/lxc_controller.c     |    6 +++---
 src/lxc/lxc_driver.c         |    2 +-
 src/network/bridge_driver.c  |    6 +++---
 src/qemu/qemu_driver.c       |   28 ++++++++++++++--------------
 src/qemu/qemu_process.c      |    6 +++---
 src/storage/storage_driver.c |    2 +-
 src/uml/uml_driver.c         |   13 +++++++------
 src/util/dnsmasq.c           |    2 +-
 src/util/util.c              |    2 +-
 15 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 109a947..2467fcf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9980,14 +9980,14 @@ int virDomainSaveXML(const char *configDir,
                      const char *xml)
 {
     char *configFile = NULL;
-    int fd = -1, ret = -1;
+    int fd = -1, ret = -1, err;
     size_t towrite;
 
     if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
         goto cleanup;
 
-    if (virFileMakePath(configDir)) {
-        virReportSystemError(errno,
+    if ((err = virFileMakePath(configDir)) != 0) {
+        virReportSystemError(err,
                              _("cannot create config directory '%s'"),
                              configDir);
         goto cleanup;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 45ddee2..b0dbd43 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1119,7 +1119,7 @@ int virNetworkSaveXML(const char *configDir,
     if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
         goto cleanup;
 
-    if ((err = virFileMakePath(configDir))) {
+    if ((err = virFileMakePath(configDir)) != 0) {
         virReportSystemError(err,
                              _("cannot create config directory '%s'"),
                              configDir);
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 127d4be..bd03f67 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2189,7 +2189,7 @@ int virNWFilterSaveXML(const char *configDir,
     if ((configFile = virNWFilterConfigFile(configDir, def->name)) == NULL)
         goto cleanup;
 
-    if ((err = virFileMakePath(configDir))) {
+    if ((err = virFileMakePath(configDir)) != 0) {
         virReportSystemError(err,
                              _("cannot create config directory '%s'"),
                              configDir);
@@ -2576,7 +2576,7 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
     if (!nwfilter->configFile) {
         int err;
 
-        if ((err = virFileMakePath(driver->configDir))) {
+        if ((err = virFileMakePath(driver->configDir)) != 0) {
             virReportSystemError(err,
                                  _("cannot create config directory %s"),
                                  driver->configDir);
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ca86f19..8ccfc8c 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1514,7 +1514,7 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
     if (!pool->configFile) {
         int err;
 
-        if ((err = virFileMakePath(driver->configDir))) {
+        if ((err = virFileMakePath(driver->configDir)) != 0) {
             virReportSystemError(err,
                                  _("cannot create config directory %s"),
                                  driver->configDir);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7fd257d..0a5ea07 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -854,7 +854,7 @@ libxlStartup(int privileged) {
     const libxl_version_info *ver_info;
     char *log_file = NULL;
     virCommandPtr cmd;
-    int status, ret = 0;
+    int status, ret = 0, err;
 
     /* Disable libxl driver if non-root */
     if (!privileged) {
@@ -914,28 +914,28 @@ libxlStartup(int privileged) {
                     "%s", LIBXL_SAVE_DIR) == -1)
         goto out_of_memory;
 
-    if (virFileMakePath(libxl_driver->logDir) != 0) {
+    if ((err = virFileMakePath(libxl_driver->logDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create log dir '%s': %s"),
-                  libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  libxl_driver->logDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(libxl_driver->stateDir) != 0) {
+    if ((err = virFileMakePath(libxl_driver->stateDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create state dir '%s': %s"),
-                  libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  libxl_driver->stateDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(libxl_driver->libDir) != 0) {
+    if ((err = virFileMakePath(libxl_driver->libDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create lib dir '%s': %s"),
-                  libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  libxl_driver->libDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(libxl_driver->saveDir) != 0) {
+    if ((err = virFileMakePath(libxl_driver->saveDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create save dir '%s': %s"),
-                  libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  libxl_driver->saveDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
 
@@ -3391,7 +3391,7 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
         if (autostart) {
             int err;
 
-            if ((err = virFileMakePath(driver->autostartDir))) {
+            if ((err = virFileMakePath(driver->autostartDir)) != 0) {
                 virReportSystemError(err,
                                      _("cannot create autostart directory %s"),
                                      driver->autostartDir);
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 7924858..b4138c4 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -406,7 +406,7 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
         { "none", "/selinux", "selinuxfs" },
 #endif
     };
-    int i, rc = -1;
+    int i, rc = -1, err;
     char *devpts;
 
     if (virAsprintf(&devpts, "/.oldroot%s/dev/pts", root->src) < 0) {
@@ -415,8 +415,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
     }
 
     for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
-        if (virFileMakePath(mnts[i].dst) != 0) {
-            virReportSystemError(errno,
+        if ((err = virFileMakePath(mnts[i].dst)) != 0) {
+            virReportSystemError(err,
                                  _("Failed to mkdir %s"),
                                  mnts[i].src);
             goto cleanup;
@@ -429,8 +429,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
         }
     }
 
-    if ((rc = virFileMakePath("/dev/pts") != 0)) {
-        virReportSystemError(rc, "%s",
+    if ((err = virFileMakePath("/dev/pts") != 0)) {
+        virReportSystemError(err, "%s",
                              _("Cannot create /dev/pts"));
         goto cleanup;
     }
@@ -515,7 +515,7 @@ static int lxcContainerPopulateDevices(void)
 
 static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
 {
-    int i;
+    int i, err;
 
     /* Pull in rest of container's mounts */
     for (i = 0 ; i < vmDef->nfss ; i++) {
@@ -531,8 +531,8 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
             return -1;
         }
 
-        if (virFileMakePath(vmDef->fss[i]->dst) != 0) {
-            virReportSystemError(errno,
+        if ((err = virFileMakePath(vmDef->fss[i]->dst)) != 0) {
+            virReportSystemError(err,
                                  _("Failed to create %s"),
                                  vmDef->fss[i]->dst);
             VIR_FREE(src);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 7d60090..db3ef21 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -615,7 +615,7 @@ lxcControllerRun(virDomainDefPtr def,
                  int appPty,
                  int handshakefd)
 {
-    int rc = -1;
+    int rc = -1, err;
     int control[2] = { -1, -1};
     int containerhandshake[2] = { -1, -1 };
     int containerPty = -1;
@@ -690,8 +690,8 @@ lxcControllerRun(virDomainDefPtr def,
             goto cleanup;
         }
 
-        if (virFileMakePath(devpts) != 0) {
-            virReportSystemError(errno,
+        if ((err = virFileMakePath(devpts)) != 0) {
+            virReportSystemError(err,
                                  _("Failed to make path %s"),
                                  devpts);
             goto cleanup;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7220a9b..2222365 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2541,7 +2541,7 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
     if (autostart) {
         int err;
 
-        if ((err = virFileMakePath(driver->autostartDir))) {
+        if ((err = virFileMakePath(driver->autostartDir)) != 0) {
             virReportSystemError(err,
                                  _("Cannot create autostart directory %s"),
                                  driver->autostartDir);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 660dd65..517f03d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2500,7 +2500,7 @@ static int networkSetAutostart(virNetworkPtr net,
     struct network_driver *driver = net->conn->networkPrivateData;
     virNetworkObjPtr network;
     char *configFile = NULL, *autostartLink = NULL;
-    int ret = -1;
+    int ret = -1, err;
 
     networkDriverLock(driver);
     network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2526,8 +2526,8 @@ static int networkSetAutostart(virNetworkPtr net,
             goto cleanup;
 
         if (autostart) {
-            if (virFileMakePath(driver->networkAutostartDir)) {
-                virReportSystemError(errno,
+            if ((err = virFileMakePath(driver->networkAutostartDir)) != 0) {
+                virReportSystemError(err,
                                      _("cannot create autostart directory '%s'"),
                                      driver->networkAutostartDir);
                 goto cleanup;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index aab3ab9..835e3e1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -372,7 +372,7 @@ static int
 qemudStartup(int privileged) {
     char *base = NULL;
     char *driverConf = NULL;
-    int rc;
+    int rc, err;
     virConnectPtr conn = NULL;
 
     if (VIR_ALLOC(qemu_driver) < 0)
@@ -469,40 +469,40 @@ qemudStartup(int privileged) {
             goto out_of_memory;
     }
 
-    if (virFileMakePath(qemu_driver->stateDir) != 0) {
+    if ((err = virFileMakePath(qemu_driver->stateDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create state dir '%s': %s"),
-                  qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->stateDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(qemu_driver->libDir) != 0) {
+    if ((err = virFileMakePath(qemu_driver->libDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create lib dir '%s': %s"),
-                  qemu_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->libDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(qemu_driver->cacheDir) != 0) {
+    if ((err = virFileMakePath(qemu_driver->cacheDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create cache dir '%s': %s"),
-                  qemu_driver->cacheDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->cacheDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(qemu_driver->saveDir) != 0) {
+    if ((err = virFileMakePath(qemu_driver->saveDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create save dir '%s': %s"),
-                  qemu_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->saveDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(qemu_driver->snapshotDir) != 0) {
+    if ((err = virFileMakePath(qemu_driver->snapshotDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create save dir '%s': %s"),
-                  qemu_driver->snapshotDir, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->snapshotDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
-    if (virFileMakePath(qemu_driver->autoDumpPath) != 0) {
+    if ((err = virFileMakePath(qemu_driver->autoDumpPath)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create dump dir '%s': %s"),
-                  qemu_driver->autoDumpPath, virStrerror(errno, ebuf, sizeof ebuf));
+                  qemu_driver->autoDumpPath, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
 
@@ -5019,7 +5019,7 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
         if (autostart) {
             int err;
 
-            if ((err = virFileMakePath(driver->autostartDir))) {
+            if ((err = virFileMakePath(driver->autostartDir)) != 0) {
                 virReportSystemError(err,
                                      _("cannot create autostart directory %s"),
                                      driver->autostartDir);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f2c439b..d52b0ad 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2336,7 +2336,7 @@ int qemuProcessStart(virConnectPtr conn,
                      const char *stdin_path,
                      enum virVMOperationType vmop)
 {
-    int ret;
+    int ret, err;
     off_t pos = -1;
     char ebuf[1024];
     char *pidfile = NULL;
@@ -2448,8 +2448,8 @@ int qemuProcessStart(virConnectPtr conn,
         }
     }
 
-    if (virFileMakePath(driver->logDir) != 0) {
-        virReportSystemError(errno,
+    if ((err = virFileMakePath(driver->logDir)) != 0) {
+        virReportSystemError(err,
                              _("cannot create log directory %s"),
                              driver->logDir);
         goto cleanup;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f9652f8..7b95340 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1021,7 +1021,7 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
         if (autostart) {
             int err;
 
-            if ((err = virFileMakePath(driver->autostartDir))) {
+            if ((err = virFileMakePath(driver->autostartDir)) != 0) {
                 virReportSystemError(err,
                                      _("cannot create autostart directory %s"),
                                      driver->autostartDir);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index a71ea21..fbd8bca 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -350,6 +350,7 @@ umlStartup(int privileged)
     uid_t uid = geteuid();
     char *base = NULL;
     char *userdir = NULL;
+    int err;
 
     if (VIR_ALLOC(uml_driver) < 0)
         return -1;
@@ -420,10 +421,10 @@ umlStartup(int privileged)
         goto error;
     }
 
-    if (virFileMakePath(uml_driver->monitorDir) != 0) {
+    if ((err = virFileMakePath(uml_driver->monitorDir)) != 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create monitor directory %s: %s"),
-               uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
+               uml_driver->monitorDir, virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }
 
@@ -811,7 +812,7 @@ static int umlCleanupTapDevices(virConnectPtr conn ATTRIBUTE_UNUSED,
 static int umlStartVMDaemon(virConnectPtr conn,
                             struct uml_driver *driver,
                             virDomainObjPtr vm) {
-    int ret;
+    int ret, err;
     char *logfile;
     int logfd = -1;
     umlDomainObjPrivatePtr priv = vm->privateData;
@@ -839,8 +840,8 @@ static int umlStartVMDaemon(virConnectPtr conn,
         return -1;
     }
 
-    if (virFileMakePath(driver->logDir) != 0) {
-        virReportSystemError(errno,
+    if ((err = virFileMakePath(driver->logDir)) != 0) {
+        virReportSystemError(err,
                              _("cannot create log directory %s"),
                              driver->logDir);
         return -1;
@@ -2006,7 +2007,7 @@ static int umlDomainSetAutostart(virDomainPtr dom,
         if (autostart) {
             int err;
 
-            if ((err = virFileMakePath(driver->autostartDir))) {
+            if ((err = virFileMakePath(driver->autostartDir)) != 0) {
                 virReportSystemError(err,
                                      _("cannot create autostart directory %s"),
                                      driver->autostartDir);
diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
index aadca10..27b1dcb 100644
--- a/src/util/dnsmasq.c
+++ b/src/util/dnsmasq.c
@@ -526,7 +526,7 @@ dnsmasqSave(const dnsmasqContext *ctx)
     int err;
     int ret = 0;
 
-    if ((err = virFileMakePath(ctx->config_dir))) {
+    if ((err = virFileMakePath(ctx->config_dir)) != 0) {
         virReportSystemError(err, _("cannot create config directory '%s'"),
                              ctx->config_dir);
         return -1;
diff --git a/src/util/util.c b/src/util/util.c
index 13973c3..e0c625f 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1182,7 +1182,7 @@ int virFileWritePid(const char *dir,
         goto cleanup;
     }
 
-    if ((rc = virFileMakePath(dir)))
+    if ((rc = virFileMakePath(dir)) != 0)
         goto cleanup;
 
     if (!(pidfile = virFilePid(dir, name))) {
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]