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