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

[libvirt] [PATCH v3 08/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/locking/*



---
 src/locking/lock_daemon.c          | 30 +++++++++++-----------------
 src/locking/lock_daemon_config.c   | 12 +++++------
 src/locking/lock_daemon_dispatch.c |  6 ++----
 src/locking/lock_driver_lockd.c    | 41 ++++++++++++++++----------------------
 src/locking/lock_driver_sanlock.c  | 12 ++++-------
 src/locking/lock_manager.c         |  4 +---
 6 files changed, 41 insertions(+), 64 deletions(-)

diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 0d8ef39..bb1626e 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -370,8 +370,8 @@ virLockDaemonPidFilePath(bool privileged,
                          char **pidfile)
 {
     if (privileged) {
-        if (!(*pidfile = strdup(LOCALSTATEDIR "/run/virtlockd.pid")))
-            goto no_memory;
+        if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/virtlockd.pid") < 0)
+            goto error;
     } else {
         char *rundir = NULL;
         mode_t old_umask;
@@ -388,7 +388,8 @@ virLockDaemonPidFilePath(bool privileged,
 
         if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) {
             VIR_FREE(rundir);
-            goto no_memory;
+            virReportOOMError();
+            goto error;
         }
 
         VIR_FREE(rundir);
@@ -396,8 +397,6 @@ virLockDaemonPidFilePath(bool privileged,
 
     return 0;
 
-no_memory:
-    virReportOOMError();
 error:
     return -1;
 }
@@ -408,8 +407,8 @@ virLockDaemonUnixSocketPaths(bool privileged,
                              char **sockfile)
 {
     if (privileged) {
-        if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock")))
-            goto no_memory;
+        if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0)
+            goto error;
     } else {
         char *rundir = NULL;
         mode_t old_umask;
@@ -426,15 +425,14 @@ virLockDaemonUnixSocketPaths(bool privileged,
 
         if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) {
             VIR_FREE(rundir);
-            goto no_memory;
+            virReportOOMError();
+            goto error;
         }
 
         VIR_FREE(rundir);
     }
     return 0;
 
-no_memory:
-    virReportOOMError();
 error:
     return -1;
 }
@@ -867,10 +865,8 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client,
                        _("Missing ownerName data in JSON document"));
         goto error;
     }
-    if (!(priv->ownerName = strdup(ownerName))) {
-        virReportOOMError();
+    if (VIR_STRDUP(priv->ownerName, ownerName) < 0)
         goto error;
-    }
     if (!(ownerUUID = virJSONValueObjectGetString(object, "ownerUUID"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Missing ownerUUID data in JSON document"));
@@ -1221,13 +1217,13 @@ int main(int argc, char **argv) {
 
         case 'p':
             VIR_FREE(pid_file);
-            if (!(pid_file = strdup(optarg)))
+            if (VIR_STRDUP(pid_file, optarg) < 0)
                 exit(EXIT_FAILURE);
             break;
 
         case 'f':
             VIR_FREE(remote_config_file);
-            if (!(remote_config_file = strdup(optarg)))
+            if (VIR_STRDUP(remote_config_file, optarg) < 0)
                 exit(EXIT_FAILURE);
             break;
 
@@ -1312,10 +1308,8 @@ int main(int argc, char **argv) {
 
     /* Ensure the rundir exists (on tmpfs on some systems) */
     if (privileged) {
-        if (!(run_dir = strdup(LOCALSTATEDIR "/run/libvirt"))) {
-            virReportOOMError();
+        if (VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt") < 0)
             goto cleanup;
-        }
     } else {
         if (!(run_dir = virGetUserRuntimeDirectory())) {
             VIR_ERROR(_("Can't determine user directory"));
diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c
index c3d59bd..4d7fe7d 100644
--- a/src/locking/lock_daemon_config.c
+++ b/src/locking/lock_daemon_config.c
@@ -53,8 +53,8 @@ checkType(virConfValuePtr p, const char *filename,
 }
 
 /* If there is no config data for the key, #var_name, then do nothing.
-   If there is valid data of type VIR_CONF_STRING, and strdup succeeds,
-   store the result in var_name.  Otherwise, (i.e. invalid type, or strdup
+   If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds,
+   store the result in var_name.  Otherwise, (i.e. invalid type, or VIR_STRDUP
    failure), give a diagnostic and "goto" the cleanup-and-fail label.  */
 #define GET_CONF_STR(conf, filename, var_name)                          \
     do {                                                                \
@@ -63,10 +63,8 @@ checkType(virConfValuePtr p, const char *filename,
             if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \
                 goto error;                                             \
             VIR_FREE(data->var_name);                                   \
-            if (!(data->var_name = strdup(p->str))) {                   \
-                virReportOOMError();                                    \
+            if (VIR_STRDUP(data->var_name, p->str) < 0)                 \
                 goto error;                                             \
-            }                                                           \
         }                                                               \
     } while (0)
 
@@ -85,8 +83,8 @@ int
 virLockDaemonConfigFilePath(bool privileged, char **configfile)
 {
     if (privileged) {
-        if (!(*configfile = strdup(SYSCONFDIR "/libvirt/virtlockd.conf")))
-            goto no_memory;
+        if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlockd.conf") < 0)
+            goto error;
     } else {
         char *configdir = NULL;
 
diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c
index 8a92802..c2e1000 100644
--- a/src/locking/lock_daemon_dispatch.c
+++ b/src/locking/lock_daemon_dispatch.c
@@ -25,7 +25,7 @@
 #include "rpc/virnetserver.h"
 #include "rpc/virnetserverclient.h"
 #include "virlog.h"
-
+#include "virstring.h"
 #include "lock_daemon.h"
 #include "lock_protocol.h"
 #include "lock_daemon_dispatch_stubs.h"
@@ -275,10 +275,8 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server ATTRIBUTE_UNUSED,
         goto cleanup;
     }
 
-    if (!(priv->ownerName = strdup(args->owner.name))) {
-        virReportOOMError();
+    if (VIR_STRDUP(priv->ownerName, args->owner.name) < 0)
         goto cleanup;
-    }
     memcpy(priv->ownerUUID, args->owner.uuid, VIR_UUID_BUFLEN);
     priv->ownerId = args->owner.id;
     priv->ownerPid = args->owner.pid;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 28a4f15..70d8f1d 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -129,8 +129,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile)
     CHECK_TYPE("file_lockspace_dir", VIR_CONF_STRING);
     if (p && p->str) {
         VIR_FREE(driver->fileLockSpaceDir);
-        if (!(driver->fileLockSpaceDir = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(driver->fileLockSpaceDir, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -140,8 +139,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile)
     CHECK_TYPE("lvm_lockspace_dir", VIR_CONF_STRING);
     if (p && p->str) {
         VIR_FREE(driver->lvmLockSpaceDir);
-        if (!(driver->lvmLockSpaceDir = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(driver->lvmLockSpaceDir, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -151,8 +149,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile)
     CHECK_TYPE("scsi_lockspace_dir", VIR_CONF_STRING);
     if (p && p->str) {
         VIR_FREE(driver->scsiLockSpaceDir);
-        if (!(driver->scsiLockSpaceDir = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(driver->scsiLockSpaceDir, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -174,10 +171,8 @@ static char *virLockManagerLockDaemonPath(bool privileged)
 {
     char *path;
     if (privileged) {
-        if (!(path = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) {
-            virReportOOMError();
+        if (VIR_STRDUP(path, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0)
             return NULL;
-        }
     } else {
         char *rundir = NULL;
 
@@ -468,10 +463,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock,
             if (STREQ(params[i].key, "uuid")) {
                 memcpy(priv->uuid, params[i].value.uuid, VIR_UUID_BUFLEN);
             } else if (STREQ(params[i].key, "name")) {
-                if (!(priv->name = strdup(params[i].value.str))) {
-                    virReportOOMError();
+                if (VIR_STRDUP(priv->name, params[i].value.str) < 0)
                     return -1;
-                }
             } else if (STREQ(params[i].key, "id")) {
                 priv->id = params[i].value.i;
             } else if (STREQ(params[i].key, "pid")) {
@@ -588,8 +581,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
 
             if (newName) {
                 VIR_DEBUG("Got an LVM UUID %s for %s", newName, name);
-                if (!(newLockspace = strdup(driver->lvmLockSpaceDir)))
-                    goto no_memory;
+                if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0)
+                    goto error;
                 autoCreate = true;
                 break;
             }
@@ -605,8 +598,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
 
             if (newName) {
                 VIR_DEBUG("Got an SCSI ID %s for %s", newName, name);
-                if (!(newLockspace = strdup(driver->scsiLockSpaceDir)))
-                    goto no_memory;
+                if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0)
+                    goto error;
                 autoCreate = true;
                 break;
             }
@@ -615,17 +608,17 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
         }
 
         if (driver->fileLockSpaceDir) {
-            if (!(newLockspace = strdup(driver->fileLockSpaceDir)))
-                goto no_memory;
+            if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
+                goto error;
             if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
                 goto no_memory;
             autoCreate = true;
             VIR_DEBUG("Using indirect lease %s for %s", newName, name);
         } else {
-            if (!(newLockspace = strdup("")))
-                goto no_memory;
-            if (!(newName = strdup(name)))
-                goto no_memory;
+            if (VIR_STRDUP(newLockspace, "") < 0)
+                goto error;
+            if (VIR_STRDUP(newName, name) < 0)
+                goto error;
             VIR_DEBUG("Using direct lease for %s", name);
         }
 
@@ -662,8 +655,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
             virReportOOMError();
             return -1;
         }
-        if (!(newName = strdup(name)))
-            goto no_memory;
+        if (VIR_STRDUP(newName, name) < 0)
+            goto error;
 
     }   break;
     default:
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 4b48868..eb15e29 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -129,8 +129,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
     CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING);
     if (p && p->str) {
         VIR_FREE(driver->autoDiskLeasePath);
-        if (!(driver->autoDiskLeasePath = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(driver->autoDiskLeasePath, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -150,8 +149,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
     p = virConfGetValue(conf, "user");
     CHECK_TYPE("user", VIR_CONF_STRING);
     if (p) {
-        if (!(tmp = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(tmp, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -167,8 +165,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
     p = virConfGetValue(conf, "group");
     CHECK_TYPE("group", VIR_CONF_STRING);
     if (p) {
-        if (!(tmp = strdup(p->str))) {
-            virReportOOMError();
+        if (VIR_STRDUP(tmp, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -408,9 +405,8 @@ static int virLockManagerSanlockInit(unsigned int version,
     driver->autoDiskLease = false;
     driver->user = (uid_t) -1;
     driver->group = (gid_t) -1;
-    if (!(driver->autoDiskLeasePath = strdup(LOCALSTATEDIR "/lib/libvirt/sanlock"))) {
+    if (VIR_STRDUP(driver->autoDiskLeasePath, LOCALSTATEDIR "/lib/libvirt/sanlock") < 0) {
         VIR_FREE(driver);
-        virReportOOMError();
         goto error;
     }
 
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index 82bbe6b..4cffc3f 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -194,10 +194,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
     plugin->driver = driver;
     plugin->handle = handle;
     plugin->refs = 1;
-    if (!(plugin->name = strdup(name))) {
-        virReportOOMError();
+    if (VIR_STRDUP(plugin->name, name) < 0)
         goto cleanup;
-    }
 
     VIR_FREE(configFile);
     VIR_FREE(modfile);
-- 
1.8.1.5


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