mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
Prefer VIR_STRDUP over virAsprintf(&dst, "%s", str)
There's no sense in using virAsprintf() just to duplicate a string. We should use VIR_STRDUP which is designed just for that.
This commit is contained in:
parent
cdd823c073
commit
e463f4de77
@ -283,7 +283,7 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
|
|||||||
* running in disconnected operation, and report a less
|
* running in disconnected operation, and report a less
|
||||||
* useful Avahi string
|
* useful Avahi string
|
||||||
*/
|
*/
|
||||||
ret = virAsprintf(&data->mdns_name, "Virtualization Host");
|
ret = VIR_STRDUP(data->mdns_name, "Virtualization Host");
|
||||||
} else {
|
} else {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
/* Extract the host part of the potentially FQDN */
|
/* Extract the host part of the potentially FQDN */
|
||||||
|
@ -505,7 +505,7 @@ virDomainAuditRedirdev(virDomainObjPtr vm, virDomainRedirdevDefPtr redirdev,
|
|||||||
|
|
||||||
switch (redirdev->bus) {
|
switch (redirdev->bus) {
|
||||||
case VIR_DOMAIN_REDIRDEV_BUS_USB:
|
case VIR_DOMAIN_REDIRDEV_BUS_USB:
|
||||||
if (virAsprintf(&address, "USB redirdev") < 0) {
|
if (VIR_STRDUP_QUIET(address, "USB redirdev") < 0) {
|
||||||
VIR_WARN("OOM while encoding audit message");
|
VIR_WARN("OOM while encoding audit message");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -1191,29 +1191,23 @@ libxlStateInitialize(bool privileged,
|
|||||||
if (!(libxl_driver->domains = virDomainObjListNew()))
|
if (!(libxl_driver->domains = virDomainObjListNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->configDir,
|
if (VIR_STRDUP(libxl_driver->configDir, LIBXL_CONFIG_DIR) < 0)
|
||||||
"%s", LIBXL_CONFIG_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->autostartDir,
|
if (VIR_STRDUP(libxl_driver->autostartDir, LIBXL_AUTOSTART_DIR) < 0)
|
||||||
"%s", LIBXL_AUTOSTART_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->logDir,
|
if (VIR_STRDUP(libxl_driver->logDir, LIBXL_LOG_DIR) < 0)
|
||||||
"%s", LIBXL_LOG_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->stateDir,
|
if (VIR_STRDUP(libxl_driver->stateDir, LIBXL_STATE_DIR) < 0)
|
||||||
"%s", LIBXL_STATE_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->libDir,
|
if (VIR_STRDUP(libxl_driver->libDir, LIBXL_LIB_DIR) < 0)
|
||||||
"%s", LIBXL_LIB_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&libxl_driver->saveDir,
|
if (VIR_STRDUP(libxl_driver->saveDir, LIBXL_SAVE_DIR) < 0)
|
||||||
"%s", LIBXL_SAVE_DIR) == -1)
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
if (virFileMakePath(libxl_driver->logDir) < 0) {
|
if (virFileMakePath(libxl_driver->logDir) < 0) {
|
||||||
VIR_ERROR(_("Failed to create log dir '%s': %s"),
|
VIR_ERROR(_("Failed to create log dir '%s': %s"),
|
||||||
|
@ -3008,7 +3008,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
|
|||||||
ignore_value(VIR_STRDUP(protostr, ""));
|
ignore_value(VIR_STRDUP(protostr, ""));
|
||||||
break;
|
break;
|
||||||
case L2_PROTO_STP_IDX:
|
case L2_PROTO_STP_IDX:
|
||||||
ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " "));
|
ignore_value(VIR_STRDUP(protostr, "-d " NWFILTER_MAC_BGA " "));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ignore_value(virAsprintf(&protostr, "-p 0x%04x ",
|
ignore_value(virAsprintf(&protostr, "-p 0x%04x ",
|
||||||
|
@ -255,17 +255,11 @@ phypGetSystemType(virConnectPtr conn)
|
|||||||
{
|
{
|
||||||
ConnectionData *connection_data = conn->networkPrivateData;
|
ConnectionData *connection_data = conn->networkPrivateData;
|
||||||
LIBSSH2_SESSION *session = connection_data->session;
|
LIBSSH2_SESSION *session = connection_data->session;
|
||||||
char *cmd = NULL;
|
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
int exit_status = 0;
|
int exit_status = 0;
|
||||||
|
|
||||||
if (virAsprintf(&cmd, "lshmc -V") < 0) {
|
ret = phypExec(session, "lshmc -V", &exit_status, conn);
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ret = phypExec(session, cmd, &exit_status, conn);
|
|
||||||
|
|
||||||
VIR_FREE(cmd);
|
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
return exit_status;
|
return exit_status;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +498,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
|||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
uint32_t bus, target, lun;
|
uint32_t bus, target, lun;
|
||||||
char *device_path = NULL;
|
const char *device_path = "/sys/bus/scsi/devices";
|
||||||
DIR *devicedir = NULL;
|
DIR *devicedir = NULL;
|
||||||
struct dirent *lun_dirent = NULL;
|
struct dirent *lun_dirent = NULL;
|
||||||
char devicepattern[64];
|
char devicepattern[64];
|
||||||
@ -507,18 +507,12 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
virFileWaitForDevices();
|
virFileWaitForDevices();
|
||||||
|
|
||||||
if (virAsprintf(&device_path, "/sys/bus/scsi/devices") < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
devicedir = opendir(device_path);
|
devicedir = opendir(device_path);
|
||||||
|
|
||||||
if (devicedir == NULL) {
|
if (devicedir == NULL) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to opendir path '%s'"), device_path);
|
_("Failed to opendir path '%s'"), device_path);
|
||||||
retval = -1;
|
return -1;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
|
snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
|
||||||
@ -536,8 +530,6 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
closedir(devicedir);
|
closedir(devicedir);
|
||||||
|
|
||||||
out:
|
|
||||||
VIR_FREE(device_path);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user