mirror of https://gitee.com/openkylin/libvirt.git
Adapt to VIR_STRDUP and VIR_STRNDUP in src/locking/*
This commit is contained in:
parent
08152a6982
commit
f75ed996e7
|
@ -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;
|
||||
}
|
||||
|
@ -869,10 +867,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"));
|
||||
|
@ -1223,14 +1219,18 @@ int main(int argc, char **argv) {
|
|||
|
||||
case 'p':
|
||||
VIR_FREE(pid_file);
|
||||
if (!(pid_file = strdup(optarg)))
|
||||
if (VIR_STRDUP_QUIET(pid_file, optarg) < 0) {
|
||||
VIR_ERROR(_("Can't allocate memory"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
VIR_FREE(remote_config_file);
|
||||
if (!(remote_config_file = strdup(optarg)))
|
||||
if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0) {
|
||||
VIR_ERROR(_("Can't allocate memory"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_VERSION:
|
||||
|
@ -1314,8 +1314,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_QUIET(run_dir, LOCALSTATEDIR "/run/libvirt") < 0) {
|
||||
VIR_ERROR(_("Can't allocate memory"));
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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")) {
|
||||
|
@ -590,8 +583,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;
|
||||
}
|
||||
|
@ -607,8 +600,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;
|
||||
}
|
||||
|
@ -617,17 +610,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);
|
||||
}
|
||||
|
||||
|
@ -664,8 +657,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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue