]> xenbits.xensource.com Git - libvirt.git/commitdiff
locking: Use g_strdup_printf() instead of virAsprintf()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 22 Oct 2019 13:26:14 +0000 (15:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Nov 2019 15:15:58 +0000 (16:15 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/locking/lock_daemon.c
src/locking/lock_daemon_config.c
src/locking/lock_driver_lockd.c
src/locking/lock_driver_sanlock.c
src/locking/lock_manager.c

index 7d8c11a2a352e0666feb5f56e13487d0aa41e8a1..2fa32387944e3d5731b5052c868d07775706d4ae 100644 (file)
@@ -464,11 +464,8 @@ virLockDaemonUnixSocketPaths(bool privileged,
         }
         umask(old_umask);
 
-        if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0 ||
-            virAsprintf(adminSockfile, "%s/virtlockd-admin-sock", rundir) < 0) {
-            VIR_FREE(rundir);
-            goto error;
-        }
+        *sockfile = g_strdup_printf("%s/virtlockd-sock", rundir);
+        *adminSockfile = g_strdup_printf("%s/virtlockd-admin-sock", rundir);
 
         VIR_FREE(rundir);
     }
@@ -531,8 +528,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
     /* Define the default output. This is only applied if there was no setting
      * from either the config or the environment.
      */
-    if (virLogSetDefaultOutput("virtlockd", godaemon, privileged) < 0)
-        return -1;
+    virLogSetDefaultOutput("virtlockd", godaemon, privileged);
 
     if (virLogGetNbOutputs() == 0)
         virLogSetOutputs(virLogGetDefaultOutput());
@@ -845,10 +841,7 @@ virLockDaemonExecRestartStatePath(bool privileged,
         }
         umask(old_umask);
 
-        if (virAsprintf(state_file, "%s/virtlockd-restart-exec.json", rundir) < 0) {
-            VIR_FREE(rundir);
-            goto error;
-        }
+        *state_file = g_strdup_printf("%s/virtlockd-restart-exec.json", rundir);
 
         VIR_FREE(rundir);
     }
@@ -865,7 +858,7 @@ virLockDaemonGetExecRestartMagic(void)
 {
     char *ret;
 
-    ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid()));
+    ret = g_strdup_printf("%lld", (long long int)getpid());
     return ret;
 }
 
index 6e635f1e0b7893468fc1070c343b8ee94d09fba3..d7e13013d7c460c3f92fbb27da3b354d7014c616 100644 (file)
@@ -46,10 +46,7 @@ virLockDaemonConfigFilePath(bool privileged, char **configfile)
         if (!(configdir = virGetUserConfigDirectory()))
             goto error;
 
-        if (virAsprintf(configfile, "%s/virtlockd.conf", configdir) < 0) {
-            VIR_FREE(configdir);
-            goto error;
-        }
+        *configfile = g_strdup_printf("%s/virtlockd.conf", configdir);
         VIR_FREE(configdir);
     }
 
index 9452f2957c1fc0755004d50f27128b0f88095d46..e8f0329b05cb2e906fe8c9d54af3cc91b3331b43 100644 (file)
@@ -127,10 +127,7 @@ static char *virLockManagerLockDaemonPath(bool privileged)
         if (!(rundir = virGetUserRuntimeDirectory()))
             return NULL;
 
-        if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) {
-            VIR_FREE(rundir);
-            return NULL;
-        }
+        path = g_strdup_printf("%s/virtlockd-sock", rundir);
 
         VIR_FREE(rundir);
     }
@@ -577,9 +574,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
                            _("Missing path or lockspace for lease resource"));
             goto cleanup;
         }
-        if (virAsprintf(&newLockspace, "%s/%s",
-                        path, lockspace) < 0)
-            goto cleanup;
+        newLockspace = g_strdup_printf("%s/%s", path, lockspace);
         newName = g_strdup(name);
 
     }   break;
index 018f07aba74ddf6457eeaf8f8b44ed8ff7de0763..87ba0fbfbbb558599e74dee99f695c230720b46e 100644 (file)
@@ -103,7 +103,7 @@ virLockManagerSanlockError(int err,
 #if HAVE_SANLOCK_STRERROR
         *message = g_strdup(sanlock_strerror(err));
 #else
-        ignore_value(virAsprintfQuiet(message, _("sanlock error %d"), err));
+        message = g_strdup_printf(_("sanlock error %d"), err);
 #endif
         return true;
     } else {
@@ -211,10 +211,8 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
     char *dir = NULL;
     int retries = LOCKSPACE_RETRIES;
 
-    if (virAsprintf(&path, "%s/%s",
-                    driver->autoDiskLeasePath,
-                    VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0)
-        goto error;
+    path = g_strdup_printf("%s/%s", driver->autoDiskLeasePath,
+                           VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE);
 
     if (virStrcpyStatic(ls.name,
                         VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) {
@@ -645,9 +643,7 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDriverPtr driver,
         goto cleanup;
     }
 
-    if (virAsprintf(&path, "%s/%s",
-                    driver->autoDiskLeasePath, res->name) < 0)
-        goto cleanup;
+    path = g_strdup_printf("%s/%s", driver->autoDiskLeasePath, res->name);
     if (virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Lease path '%s' exceeds %d characters"),
index 6898bfc556574d5b5cfdd0fac99fc1376d88f9e9..07318fb53f0b4f7da0212193a8eda4c2fcfb7344 100644 (file)
@@ -131,9 +131,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
     VIR_DEBUG("name=%s driverName=%s configDir=%s flags=0x%x",
               name, driverName, configDir, flags);
 
-    if (virAsprintf(&configFile, "%s/%s-%s.conf",
-                    configDir, driverName, name) < 0)
-        return NULL;
+    configFile = g_strdup_printf("%s/%s-%s.conf", configDir, driverName, name);
 
     if (STREQ(name, "nop")) {
         driver = &virLockDriverNop;