mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
ch: use g_auto in virCHMonitorNew
Also introduces a G_DEFINE_AUTOPTR_CLEANUP_FUNC for virCHMonitor. Signed-off-by: William Douglas <william.douglas@intel.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
9e99f84328
commit
13fc1432c6
@ -444,9 +444,8 @@ chMonitorCreateSocket(const char *socket_path)
|
|||||||
virCHMonitor *
|
virCHMonitor *
|
||||||
virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
||||||
{
|
{
|
||||||
virCHMonitor *ret = NULL;
|
g_autoptr(virCHMonitor) mon = NULL;
|
||||||
virCHMonitor *mon = NULL;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
virCommand *cmd = NULL;
|
|
||||||
int socket_fd = 0;
|
int socket_fd = 0;
|
||||||
|
|
||||||
if (virCHMonitorInitialize() < 0)
|
if (virCHMonitorInitialize() < 0)
|
||||||
@ -458,7 +457,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
|||||||
if (!vm->def) {
|
if (!vm->def) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("VM is not defined"));
|
_("VM is not defined"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prepare to launch Cloud-Hypervisor socket */
|
/* prepare to launch Cloud-Hypervisor socket */
|
||||||
@ -467,7 +466,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Cannot create socket directory '%s'"),
|
_("Cannot create socket directory '%s'"),
|
||||||
socketdir);
|
socketdir);
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNew(vm->def->emulator);
|
cmd = virCommandNew(vm->def->emulator);
|
||||||
@ -477,7 +476,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Cannot create socket '%s'"),
|
_("Cannot create socket '%s'"),
|
||||||
mon->socketpath);
|
mon->socketpath);
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virCommandAddArg(cmd, "--api-socket");
|
virCommandAddArg(cmd, "--api-socket");
|
||||||
@ -486,7 +485,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
|||||||
|
|
||||||
/* launch Cloud-Hypervisor socket */
|
/* launch Cloud-Hypervisor socket */
|
||||||
if (virCommandRunAsync(cmd, &mon->pid) < 0)
|
if (virCommandRunAsync(cmd, &mon->pid) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
/* get a curl handle */
|
/* get a curl handle */
|
||||||
mon->handle = curl_easy_init();
|
mon->handle = curl_easy_init();
|
||||||
@ -494,13 +493,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
|
|||||||
/* now has its own reference */
|
/* now has its own reference */
|
||||||
mon->vm = virObjectRef(vm);
|
mon->vm = virObjectRef(vm);
|
||||||
|
|
||||||
ret = mon;
|
return g_steal_pointer(&mon);
|
||||||
mon = NULL;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCHMonitorClose(mon);
|
|
||||||
virCommandFree(cmd);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virCHMonitorDispose(void *opaque)
|
static void virCHMonitorDispose(void *opaque)
|
||||||
|
@ -53,6 +53,7 @@ struct _virCHMonitor {
|
|||||||
|
|
||||||
virCHMonitor *virCHMonitorNew(virDomainObj *vm, const char *socketdir);
|
virCHMonitor *virCHMonitorNew(virDomainObj *vm, const char *socketdir);
|
||||||
void virCHMonitorClose(virCHMonitor *mon);
|
void virCHMonitorClose(virCHMonitor *mon);
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose);
|
||||||
|
|
||||||
int virCHMonitorCreateVM(virCHMonitor *mon);
|
int virCHMonitorCreateVM(virCHMonitor *mon);
|
||||||
int virCHMonitorBootVM(virCHMonitor *mon);
|
int virCHMonitorBootVM(virCHMonitor *mon);
|
||||||
|
Loading…
Reference in New Issue
Block a user