mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
locking: use g_strdup instead of VIR_STRDUP
Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
b11457158e
commit
9e96101d40
@ -447,9 +447,8 @@ virLockDaemonUnixSocketPaths(bool privileged,
|
||||
char **adminSockfile)
|
||||
{
|
||||
if (privileged) {
|
||||
if (VIR_STRDUP(*sockfile, RUNSTATEDIR "/libvirt/virtlockd-sock") < 0 ||
|
||||
VIR_STRDUP(*adminSockfile, RUNSTATEDIR "/libvirt/virtlockd-admin-sock") < 0)
|
||||
goto error;
|
||||
*sockfile = g_strdup(RUNSTATEDIR "/libvirt/virtlockd-sock");
|
||||
*adminSockfile = g_strdup(RUNSTATEDIR "/libvirt/virtlockd-admin-sock");
|
||||
} else {
|
||||
char *rundir = NULL;
|
||||
mode_t old_umask;
|
||||
@ -760,8 +759,7 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client,
|
||||
_("Missing ownerName data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
if (VIR_STRDUP(priv->ownerName, ownerName) < 0)
|
||||
goto error;
|
||||
priv->ownerName = g_strdup(ownerName);
|
||||
if (!(ownerUUID = virJSONValueObjectGetString(object, "ownerUUID"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing ownerUUID data in JSON document"));
|
||||
@ -831,8 +829,7 @@ virLockDaemonExecRestartStatePath(bool privileged,
|
||||
char **state_file)
|
||||
{
|
||||
if (privileged) {
|
||||
if (VIR_STRDUP(*state_file, RUNSTATEDIR "/virtlockd-restart-exec.json") < 0)
|
||||
goto error;
|
||||
*state_file = g_strdup(RUNSTATEDIR "/virtlockd-restart-exec.json");
|
||||
} else {
|
||||
char *rundir = NULL;
|
||||
mode_t old_umask;
|
||||
@ -1162,14 +1159,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
case 'p':
|
||||
VIR_FREE(pid_file);
|
||||
if (VIR_STRDUP_QUIET(pid_file, optarg) < 0)
|
||||
goto no_memory;
|
||||
pid_file = g_strdup(optarg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
VIR_FREE(remote_config_file);
|
||||
if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0)
|
||||
goto no_memory;
|
||||
remote_config_file = g_strdup(optarg);
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
@ -1247,8 +1242,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Ensure the rundir exists (on tmpfs on some systems) */
|
||||
if (privileged) {
|
||||
if (VIR_STRDUP_QUIET(run_dir, RUNSTATEDIR "/libvirt") < 0)
|
||||
goto no_memory;
|
||||
run_dir = g_strdup(RUNSTATEDIR "/libvirt");
|
||||
} else {
|
||||
if (!(run_dir = virGetUserRuntimeDirectory())) {
|
||||
VIR_ERROR(_("Can't determine user directory"));
|
||||
@ -1448,8 +1442,4 @@ int main(int argc, char **argv) {
|
||||
VIR_FREE(run_dir);
|
||||
virLockDaemonConfigFree(config);
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
VIR_ERROR(_("Can't allocate memory"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ int
|
||||
virLockDaemonConfigFilePath(bool privileged, char **configfile)
|
||||
{
|
||||
if (privileged) {
|
||||
if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlockd.conf") < 0)
|
||||
goto error;
|
||||
*configfile = g_strdup(SYSCONFDIR "/libvirt/virtlockd.conf");
|
||||
} else {
|
||||
char *configdir = NULL;
|
||||
|
||||
|
@ -277,8 +277,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server G_GNUC_UNUSED,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(priv->ownerName, args->owner.name) < 0)
|
||||
goto cleanup;
|
||||
priv->ownerName = g_strdup(args->owner.name);
|
||||
memcpy(priv->ownerUUID, args->owner.uuid, VIR_UUID_BUFLEN);
|
||||
priv->ownerId = args->owner.id;
|
||||
priv->ownerPid = args->owner.pid;
|
||||
|
@ -120,8 +120,7 @@ static char *virLockManagerLockDaemonPath(bool privileged)
|
||||
{
|
||||
char *path;
|
||||
if (privileged) {
|
||||
if (VIR_STRDUP(path, RUNSTATEDIR "/libvirt/virtlockd-sock") < 0)
|
||||
return NULL;
|
||||
path = g_strdup(RUNSTATEDIR "/libvirt/virtlockd-sock");
|
||||
} else {
|
||||
char *rundir = NULL;
|
||||
|
||||
@ -422,8 +421,7 @@ 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 (VIR_STRDUP(priv->name, params[i].value.str) < 0)
|
||||
goto cleanup;
|
||||
priv->name = g_strdup(params[i].value.str);
|
||||
} else if (STREQ(params[i].key, "id")) {
|
||||
priv->id = params[i].value.iv;
|
||||
} else if (STREQ(params[i].key, "pid")) {
|
||||
@ -515,8 +513,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
|
||||
if (newName) {
|
||||
VIR_DEBUG("Got an LVM UUID %s for %s", newName, name);
|
||||
if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0)
|
||||
goto cleanup;
|
||||
newLockspace = g_strdup(driver->lvmLockSpaceDir);
|
||||
autoCreate = true;
|
||||
break;
|
||||
}
|
||||
@ -532,8 +529,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
|
||||
if (newName) {
|
||||
VIR_DEBUG("Got an SCSI ID %s for %s", newName, name);
|
||||
if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0)
|
||||
goto cleanup;
|
||||
newLockspace = g_strdup(driver->scsiLockSpaceDir);
|
||||
autoCreate = true;
|
||||
break;
|
||||
}
|
||||
@ -542,17 +538,14 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
}
|
||||
|
||||
if (driver->fileLockSpaceDir) {
|
||||
if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
|
||||
goto cleanup;
|
||||
newLockspace = g_strdup(driver->fileLockSpaceDir);
|
||||
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &newName) < 0)
|
||||
goto cleanup;
|
||||
autoCreate = true;
|
||||
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
|
||||
} else {
|
||||
if (VIR_STRDUP(newLockspace, "") < 0)
|
||||
goto cleanup;
|
||||
if (VIR_STRDUP(newName, name) < 0)
|
||||
goto cleanup;
|
||||
newLockspace = g_strdup("");
|
||||
newName = g_strdup(name);
|
||||
VIR_DEBUG("Using direct lease for %s", name);
|
||||
}
|
||||
|
||||
@ -587,8 +580,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
if (virAsprintf(&newLockspace, "%s/%s",
|
||||
path, lockspace) < 0)
|
||||
goto cleanup;
|
||||
if (VIR_STRDUP(newName, name) < 0)
|
||||
goto cleanup;
|
||||
newName = g_strdup(name);
|
||||
|
||||
} break;
|
||||
default:
|
||||
|
@ -440,10 +440,7 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
driver->io_timeout = 0;
|
||||
driver->user = (uid_t) -1;
|
||||
driver->group = (gid_t) -1;
|
||||
if (VIR_STRDUP(driver->autoDiskLeasePath, LOCALSTATEDIR "/lib/libvirt/sanlock") < 0) {
|
||||
VIR_FREE(driver);
|
||||
goto error;
|
||||
}
|
||||
driver->autoDiskLeasePath = g_strdup(LOCALSTATEDIR "/lib/libvirt/sanlock");
|
||||
|
||||
if (virLockManagerSanlockLoadConfig(driver, configFile) < 0)
|
||||
goto error;
|
||||
@ -514,8 +511,7 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
||||
if (STREQ(param->key, "uuid")) {
|
||||
memcpy(priv->vm_uuid, param->value.uuid, 16);
|
||||
} else if (STREQ(param->key, "name")) {
|
||||
if (VIR_STRDUP(priv->vm_name, param->value.str) < 0)
|
||||
goto error;
|
||||
priv->vm_name = g_strdup(param->value.str);
|
||||
} else if (STREQ(param->key, "pid")) {
|
||||
priv->vm_pid = param->value.iv;
|
||||
} else if (STREQ(param->key, "id")) {
|
||||
@ -540,10 +536,6 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
||||
|
||||
lock->privateData = priv;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
VIR_FREE(priv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void virLockManagerSanlockFree(virLockManagerPtr lock)
|
||||
|
@ -179,8 +179,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
|
||||
plugin->driver = driver;
|
||||
plugin->handle = handle;
|
||||
plugin->refs = 1;
|
||||
if (VIR_STRDUP(plugin->name, name) < 0)
|
||||
goto cleanup;
|
||||
plugin->name = g_strdup(name);
|
||||
|
||||
VIR_FREE(configFile);
|
||||
VIR_FREE(modfile);
|
||||
|
Loading…
Reference in New Issue
Block a user