mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virLogDaemonPreExecRestart: 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
bf666cac6b
commit
c357518776
@ -505,62 +505,54 @@ virLogDaemonPreExecRestart(const char *state_file,
|
|||||||
virNetDaemonPtr dmn,
|
virNetDaemonPtr dmn,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
virJSONValuePtr child;
|
g_autoptr(virJSONValue) object = virJSONValueNewObject();
|
||||||
char *state = NULL;
|
g_autoptr(virJSONValue) daemon = NULL;
|
||||||
virJSONValuePtr object = virJSONValueNewObject();
|
g_autoptr(virJSONValue) handler = NULL;
|
||||||
char *magic = NULL;
|
g_autofree char *state = NULL;
|
||||||
|
g_autofree char *magic = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("Running pre-restart exec");
|
VIR_DEBUG("Running pre-restart exec");
|
||||||
|
|
||||||
if (!(child = virNetDaemonPreExecRestart(dmn)))
|
if (!(daemon = virNetDaemonPreExecRestart(dmn)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueObjectAppend(object, "daemon", child) < 0) {
|
if (virJSONValueObjectAppend(object, "daemon", daemon) < 0)
|
||||||
virJSONValueFree(child);
|
return -1;
|
||||||
goto cleanup;
|
daemon = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(magic = virLogDaemonGetExecRestartMagic()))
|
if (!(magic = virLogDaemonGetExecRestartMagic()))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
|
if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!(child = virLogHandlerPreExecRestart(logDaemon->handler)))
|
if (!(handler = virLogHandlerPreExecRestart(logDaemon->handler)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueObjectAppend(object, "handler", child) < 0) {
|
|
||||||
virJSONValueFree(child);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (virJSONValueObjectAppend(object, "handler", handler) < 0)
|
||||||
|
return -1;
|
||||||
|
handler = NULL;
|
||||||
|
|
||||||
if (!(state = virJSONValueToString(object, true)))
|
if (!(state = virJSONValueToString(object, true)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Saving state %s", state);
|
VIR_DEBUG("Saving state %s", state);
|
||||||
|
|
||||||
if (virFileWriteStr(state_file,
|
if (virFileWriteStr(state_file, state, 0700) < 0) {
|
||||||
state, 0700) < 0) {
|
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Unable to save state file %s"),
|
_("Unable to save state file %s"), state_file);
|
||||||
state_file);
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (execvp(argv[0], argv) < 0) {
|
if (execvp(argv[0], argv) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to restart self"));
|
_("Unable to restart self"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
abort(); /* This should be impossible to reach */
|
abort(); /* This should be impossible to reach */
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FREE(magic);
|
|
||||||
VIR_FREE(state);
|
|
||||||
virJSONValueFree(object);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user