mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virLockDaemonClientPreExecRestart: Modernize JSON object construction
Use virJSONValueObjectAdd instead of step-by-step construction of the object. This also removes a handful impossible to reach errors with translatable messages. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
19c7be9ad6
commit
f24bc212ab
@ -549,41 +549,21 @@ virLockDaemonClientPreExecRestart(virNetServerClient *client G_GNUC_UNUSED,
|
||||
void *opaque)
|
||||
{
|
||||
virLockDaemonClient *priv = opaque;
|
||||
virJSONValue *object = virJSONValueNewObject();
|
||||
virJSONValue *object = NULL;
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
if (virJSONValueObjectAppendBoolean(object, "restricted", priv->restricted) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot set restricted data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
if (virJSONValueObjectAppendNumberUint(object, "ownerPid", priv->ownerPid) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot set ownerPid data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
if (virJSONValueObjectAppendNumberUint(object, "ownerId", priv->ownerId) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot set ownerId data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
if (virJSONValueObjectAppendString(object, "ownerName", priv->ownerName) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot set ownerName data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
virUUIDFormat(priv->ownerUUID, uuidstr);
|
||||
if (virJSONValueObjectAppendString(object, "ownerUUID", uuidstr) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot set ownerUUID data in JSON document"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectAdd(&object,
|
||||
"b:restricted", priv->restricted,
|
||||
"u:ownerPid", priv->ownerPid,
|
||||
"u:ownerId", priv->ownerId,
|
||||
"s:ownerName", priv->ownerName,
|
||||
"s:ownerUUID", uuidstr,
|
||||
NULL) < 0)
|
||||
return NULL;
|
||||
|
||||
return object;
|
||||
|
||||
error:
|
||||
virJSONValueFree(object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user