mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virLogHandlerPreExecRestart: Refactor memory cleanup
Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c357518776
commit
eef2bcc7d7
@ -608,56 +608,48 @@ virLogHandlerDomainAppendLogFile(virLogHandlerPtr handler,
|
|||||||
virJSONValuePtr
|
virJSONValuePtr
|
||||||
virLogHandlerPreExecRestart(virLogHandlerPtr handler)
|
virLogHandlerPreExecRestart(virLogHandlerPtr handler)
|
||||||
{
|
{
|
||||||
virJSONValuePtr ret = virJSONValueNewObject();
|
g_autoptr(virJSONValue) ret = virJSONValueNewObject();
|
||||||
virJSONValuePtr files;
|
g_autoptr(virJSONValue) files = virJSONValueNewArray();
|
||||||
size_t i;
|
size_t i;
|
||||||
char domuuid[VIR_UUID_STRING_BUFLEN];
|
char domuuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
files = virJSONValueNewArray();
|
|
||||||
|
|
||||||
if (virJSONValueObjectAppend(ret, "files", files) < 0) {
|
|
||||||
virJSONValueFree(files);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < handler->nfiles; i++) {
|
for (i = 0; i < handler->nfiles; i++) {
|
||||||
virJSONValuePtr file = virJSONValueNewObject();
|
g_autoptr(virJSONValue) file = virJSONValueNewObject();
|
||||||
|
|
||||||
if (virJSONValueArrayAppend(files, file) < 0) {
|
|
||||||
virJSONValueFree(file);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virJSONValueObjectAppendNumberInt(file, "pipefd",
|
if (virJSONValueObjectAppendNumberInt(file, "pipefd",
|
||||||
handler->files[i]->pipefd) < 0)
|
handler->files[i]->pipefd) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendString(file, "path",
|
if (virJSONValueObjectAppendString(file, "path",
|
||||||
virRotatingFileWriterGetPath(handler->files[i]->file)) < 0)
|
virRotatingFileWriterGetPath(handler->files[i]->file)) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendString(file, "driver",
|
if (virJSONValueObjectAppendString(file, "driver",
|
||||||
handler->files[i]->driver) < 0)
|
handler->files[i]->driver) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendString(file, "domname",
|
if (virJSONValueObjectAppendString(file, "domname",
|
||||||
handler->files[i]->domname) < 0)
|
handler->files[i]->domname) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
virUUIDFormat(handler->files[i]->domuuid, domuuid);
|
virUUIDFormat(handler->files[i]->domuuid, domuuid);
|
||||||
if (virJSONValueObjectAppendString(file, "domuuid", domuuid) < 0)
|
if (virJSONValueObjectAppendString(file, "domuuid", domuuid) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virSetInherit(handler->files[i]->pipefd, true) < 0) {
|
if (virSetInherit(handler->files[i]->pipefd, true) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot disable close-on-exec flag"));
|
_("Cannot disable close-on-exec flag"));
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virJSONValueFree(ret);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virJSONValueArrayAppend(files, file) < 0)
|
||||||
|
return NULL;
|
||||||
|
file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virJSONValueObjectAppend(ret, "files", files) < 0)
|
||||||
|
return NULL;
|
||||||
|
files = NULL;
|
||||||
|
|
||||||
|
return g_steal_pointer(&ret);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user