mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
Adapt to VIR_STRDUP and VIR_STRNDUP in src/remote/*
This commit is contained in:
parent
a88fb3009f
commit
d2846c25bd
@ -368,8 +368,8 @@ remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
|
|||||||
#define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \
|
#define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \
|
||||||
if (STRCASEEQ(var->name, ARG_NAME)) { \
|
if (STRCASEEQ(var->name, ARG_NAME)) { \
|
||||||
VIR_FREE(ARG_VAR); \
|
VIR_FREE(ARG_VAR); \
|
||||||
if (!(ARG_VAR = strdup(var->value))) \
|
if (VIR_STRDUP(ARG_VAR, var->value) < 0) \
|
||||||
goto no_memory; \
|
goto failed; \
|
||||||
var->ignore = 1; \
|
var->ignore = 1; \
|
||||||
continue; \
|
continue; \
|
||||||
}
|
}
|
||||||
@ -497,24 +497,20 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
if (virAsprintf(&port, "%d", conn->uri->port) < 0)
|
if (virAsprintf(&port, "%d", conn->uri->port) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
} else if (transport == trans_tls) {
|
} else if (transport == trans_tls) {
|
||||||
if (!(port = strdup(LIBVIRTD_TLS_PORT)))
|
if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
} else if (transport == trans_tcp) {
|
} else if (transport == trans_tcp) {
|
||||||
if (!(port = strdup(LIBVIRTD_TCP_PORT)))
|
if (VIR_STRDUP(port, LIBVIRTD_TCP_PORT) < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
} /* Port not used for unix, ext., default for ssh */
|
} /* Port not used for unix, ext., default for ssh */
|
||||||
|
|
||||||
if (conn->uri && conn->uri->server)
|
if (VIR_STRDUP(priv->hostname,
|
||||||
priv->hostname = strdup(conn->uri->server);
|
conn->uri && conn->uri->server ?
|
||||||
else
|
conn->uri->server : "localhost") < 0)
|
||||||
priv->hostname = strdup("localhost");
|
goto failed;
|
||||||
|
|
||||||
if (!priv->hostname)
|
if (conn->uri && VIR_STRDUP(username, conn->uri->user) < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
|
|
||||||
if (conn->uri && conn->uri->user &&
|
|
||||||
!(username = strdup(conn->uri->user)))
|
|
||||||
goto no_memory;
|
|
||||||
|
|
||||||
/* Get the variables from the query string.
|
/* Get the variables from the query string.
|
||||||
* Then we need to reconstruct the query string (because
|
* Then we need to reconstruct the query string (because
|
||||||
@ -557,8 +553,8 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
(STREQ(conn->uri->scheme, "remote") ||
|
(STREQ(conn->uri->scheme, "remote") ||
|
||||||
STRPREFIX(conn->uri->scheme, "remote+"))) {
|
STRPREFIX(conn->uri->scheme, "remote+"))) {
|
||||||
/* Allow remote serve to probe */
|
/* Allow remote serve to probe */
|
||||||
if (!(name = strdup("")))
|
if (VIR_STRDUP(name, "") < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
} else {
|
} else {
|
||||||
virURI tmpuri = {
|
virURI tmpuri = {
|
||||||
.scheme = conn->uri->scheme,
|
.scheme = conn->uri->scheme,
|
||||||
@ -587,8 +583,8 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Probe URI server side */
|
/* Probe URI server side */
|
||||||
if (!(name = strdup("")))
|
if (VIR_STRDUP(name, "") < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("proceeding with name = %s", name);
|
VIR_DEBUG("proceeding with name = %s", name);
|
||||||
@ -635,15 +631,11 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case trans_libssh2:
|
case trans_libssh2:
|
||||||
if (!sockname) {
|
if (!sockname &&
|
||||||
if (flags & VIR_DRV_OPEN_REMOTE_RO)
|
VIR_STRDUP(sockname,
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
|
flags & VIR_DRV_OPEN_REMOTE_RO ?
|
||||||
else
|
LIBVIRTD_PRIV_UNIX_SOCKET_RO : LIBVIRTD_PRIV_UNIX_SOCKET) < 0)
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);
|
goto failed;
|
||||||
|
|
||||||
if (sockname == NULL)
|
|
||||||
goto no_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("Starting LibSSH2 session");
|
VIR_DEBUG("Starting LibSSH2 session");
|
||||||
|
|
||||||
@ -678,12 +670,10 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
VIR_FREE(userdir);
|
VIR_FREE(userdir);
|
||||||
} else {
|
} else {
|
||||||
if (flags & VIR_DRV_OPEN_REMOTE_RO)
|
if (VIR_STRDUP(sockname,
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
|
flags & VIR_DRV_OPEN_REMOTE_RO ?
|
||||||
else
|
LIBVIRTD_PRIV_UNIX_SOCKET_RO : LIBVIRTD_PRIV_UNIX_SOCKET) < 0)
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);
|
goto failed;
|
||||||
if (sockname == NULL)
|
|
||||||
goto no_memory;
|
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Proceeding with sockname %s", sockname);
|
VIR_DEBUG("Proceeding with sockname %s", sockname);
|
||||||
}
|
}
|
||||||
@ -705,17 +695,14 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case trans_ssh:
|
case trans_ssh:
|
||||||
if (!command && !(command = strdup("ssh")))
|
if (!command && VIR_STRDUP(command, "ssh") < 0)
|
||||||
goto no_memory;
|
goto failed;
|
||||||
|
|
||||||
if (!sockname) {
|
if (!sockname &&
|
||||||
if (flags & VIR_DRV_OPEN_REMOTE_RO)
|
VIR_STRDUP(sockname,
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
|
flags & VIR_DRV_OPEN_REMOTE_RO ?
|
||||||
else
|
LIBVIRTD_PRIV_UNIX_SOCKET_RO : LIBVIRTD_PRIV_UNIX_SOCKET) < 0)
|
||||||
sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);
|
goto failed;
|
||||||
if (!sockname)
|
|
||||||
goto no_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(priv->client = virNetClientNewSSH(priv->hostname,
|
if (!(priv->client = virNetClientNewSSH(priv->hostname,
|
||||||
port,
|
port,
|
||||||
@ -1493,11 +1480,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
|
|||||||
|
|
||||||
for (i = 0; i < nparams; ++i) {
|
for (i = 0; i < nparams; ++i) {
|
||||||
/* call() will free this: */
|
/* call() will free this: */
|
||||||
val[i].field = strdup(params[i].field);
|
if (VIR_STRDUP(val[i].field, params[i].field) < 0)
|
||||||
if (val[i].field == NULL) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
val[i].value.type = params[i].type;
|
val[i].value.type = params[i].type;
|
||||||
switch (params[i].type) {
|
switch (params[i].type) {
|
||||||
case VIR_TYPED_PARAM_INT:
|
case VIR_TYPED_PARAM_INT:
|
||||||
@ -1519,11 +1503,9 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
|
|||||||
val[i].value.remote_typed_param_value_u.b = params[i].value.b;
|
val[i].value.remote_typed_param_value_u.b = params[i].value.b;
|
||||||
break;
|
break;
|
||||||
case VIR_TYPED_PARAM_STRING:
|
case VIR_TYPED_PARAM_STRING:
|
||||||
val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s);
|
if (VIR_STRDUP(val[i].value.remote_typed_param_value_u.s,
|
||||||
if (val[i].value.remote_typed_param_value_u.s == NULL) {
|
params[i].value.s) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
|
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
|
||||||
@ -1608,12 +1590,9 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
|
|||||||
ret_param->value.remote_typed_param_value_u.b;
|
ret_param->value.remote_typed_param_value_u.b;
|
||||||
break;
|
break;
|
||||||
case VIR_TYPED_PARAM_STRING:
|
case VIR_TYPED_PARAM_STRING:
|
||||||
param->value.s =
|
if (VIR_STRDUP(param->value.s,
|
||||||
strdup(ret_param->value.remote_typed_param_value_u.s);
|
ret_param->value.remote_typed_param_value_u.s) < 0)
|
||||||
if (!param->value.s) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
|
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
|
||||||
@ -1653,10 +1632,8 @@ remoteDeserializeDomainDiskErrors(remote_domain_disk_error *ret_errors_val,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ret_errors_len; i++) {
|
for (i = 0; i < ret_errors_len; i++) {
|
||||||
if (!(errors[i].disk = strdup(ret_errors_val[i].disk))) {
|
if (VIR_STRDUP(errors[i].disk, ret_errors_val[i].disk) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
errors[i].error = ret_errors_val[i].error;
|
errors[i].error = ret_errors_val[i].error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4470,28 +4447,28 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (VIR_ALLOC(localAddr) < 0)
|
if (VIR_ALLOC(localAddr) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
localAddr->family = msg->local.family;
|
localAddr->family = msg->local.family;
|
||||||
if (!(localAddr->service = strdup(msg->local.service)) ||
|
if (VIR_STRDUP(localAddr->service, msg->local.service) < 0 ||
|
||||||
!(localAddr->node = strdup(msg->local.node)))
|
VIR_STRDUP(localAddr->node, msg->local.node) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC(remoteAddr) < 0)
|
if (VIR_ALLOC(remoteAddr) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
remoteAddr->family = msg->remote.family;
|
remoteAddr->family = msg->remote.family;
|
||||||
if (!(remoteAddr->service = strdup(msg->remote.service)) ||
|
if (VIR_STRDUP(remoteAddr->service, msg->remote.service) < 0 ||
|
||||||
!(remoteAddr->node = strdup(msg->remote.node)))
|
VIR_STRDUP(remoteAddr->node, msg->remote.node) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC(subject) < 0)
|
if (VIR_ALLOC(subject) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
if (VIR_ALLOC_N(subject->identities, msg->subject.subject_len) < 0)
|
if (VIR_ALLOC_N(subject->identities, msg->subject.subject_len) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
subject->nidentity = msg->subject.subject_len;
|
subject->nidentity = msg->subject.subject_len;
|
||||||
for (i = 0; i < subject->nidentity; i++) {
|
for (i = 0; i < subject->nidentity; i++) {
|
||||||
if (!(subject->identities[i].type = strdup(msg->subject.subject_val[i].type)) ||
|
if (VIR_STRDUP(subject->identities[i].type, msg->subject.subject_val[i].type) < 0 ||
|
||||||
!(subject->identities[i].name = strdup(msg->subject.subject_val[i].name)))
|
VIR_STRDUP(subject->identities[i].name, msg->subject.subject_val[i].name) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
event = virDomainEventGraphicsNewFromDom(dom,
|
event = virDomainEventGraphicsNewFromDom(dom,
|
||||||
@ -4506,7 +4483,7 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
|
|||||||
remoteDomainEventQueue(priv, event);
|
remoteDomainEventQueue(priv, event);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
no_memory:
|
error:
|
||||||
if (localAddr) {
|
if (localAddr) {
|
||||||
VIR_FREE(localAddr->service);
|
VIR_FREE(localAddr->service);
|
||||||
VIR_FREE(localAddr->node);
|
VIR_FREE(localAddr->node);
|
||||||
@ -5100,11 +5077,8 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
|
|||||||
(xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &ret) == -1)
|
(xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &ret) == -1)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
*result = strdup(ret.result);
|
if (VIR_STRDUP(*result, ret.result) < 0)
|
||||||
if (*result == NULL) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
rv = 0;
|
rv = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user