From f8c22f5c55d163a99419d87a7d61de6c97af5584 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Wed, 2 Dec 2015 23:33:44 +0000 Subject: send the tty name to vmmctl and print it as a result. --- usr.sbin/vmd/vmd.c | 20 ++++++++++++++------ usr.sbin/vmd/vmd.h | 10 ++++++++-- usr.sbin/vmmctl/vmmctl.c | 8 +++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index c19105fb81e..8dbb3eb57ff 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.10 2015/12/02 22:19:11 reyk Exp $ */ +/* $OpenBSD: vmd.c,v 1.11 2015/12/02 23:33:43 reyk Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -84,17 +85,24 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) int vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg) { - struct privsep *ps = p->p_ps; - int res = 0; - struct vmd_vm *vm; + struct vmop_start_result vmr; + struct privsep *ps = p->p_ps; + int res = 0; + struct vmd_vm *vm; switch (imsg->hdr.type) { case IMSG_VMDOP_START_VM_RESPONSE: IMSG_SIZE_CHECK(imsg, &res); + memcpy(&res, imsg->data, sizeof(res)); if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) fatalx("%s: invalid vm response", __func__); - imsg->hdr.peerid = vm->vm_peerid; - proc_forward_imsg(ps, imsg, PROC_CONTROL, -1); + vmr.vmr_result = res; + strlcpy(vmr.vmr_ttyname, vm->vm_ttyname, + sizeof(vmr.vmr_ttyname)); + if (proc_compose_imsg(ps, PROC_CONTROL, -1, + IMSG_VMDOP_START_VM_RESPONSE, + vm->vm_peerid, -1, &vmr, sizeof(vmr)) == -1) + return (-1); break; case IMSG_VMDOP_TERMINATE_VM_RESPONSE: IMSG_SIZE_CHECK(imsg, &res); diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index 87c529fc32b..1f16ba39934 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.5 2015/12/02 22:19:11 reyk Exp $ */ +/* $OpenBSD: vmd.h,v 1.6 2015/12/02 23:33:43 reyk Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -32,6 +32,7 @@ #define SOCKET_NAME "/var/run/vmd.sock" #define VMM_NODE "/dev/vmm" #define VM_NAME_MAX 64 +#define VM_TTYNAME_MAX 32 #define MAX_TAP 256 #define NR_BACKLOG 5 @@ -60,13 +61,18 @@ enum imsg_type { IMSG_VMDOP_GET_INFO_VM_END_DATA }; +struct vmop_start_result { + int vmr_result; + char vmr_ttyname[VM_TTYNAME_MAX]; +}; + struct vmd_vm { struct vm_create_params vm_params; uint32_t vm_vmid; int vm_kernel; int vm_disks[VMM_MAX_DISKS_PER_VM]; int vm_ifs[VMM_MAX_NICS_PER_VM]; - char vm_ttyname[32]; + char vm_ttyname[VM_TTYNAME_MAX]; int vm_tty; uint32_t vm_peerid; TAILQ_ENTRY(vmd_vm) vm_entry; diff --git a/usr.sbin/vmmctl/vmmctl.c b/usr.sbin/vmmctl/vmmctl.c index a8eae3cb293..4a656404aa1 100644 --- a/usr.sbin/vmmctl/vmmctl.c +++ b/usr.sbin/vmmctl/vmmctl.c @@ -115,17 +115,19 @@ start_vm(const char *name, int memsize, int nnics, int ndisks, char **disks, int start_vm_complete(struct imsg *imsg, int *ret) { + struct vmop_start_result *vmr; int res; if (imsg->hdr.type == IMSG_VMDOP_START_VM_RESPONSE) { - res = *(int *)imsg->data; + vmr = (struct vmop_start_result *)imsg->data; + res = vmr->vmr_result; if (res) { fprintf(stderr, "%s: start VM command failed (%d) - " "%s\n", __progname, res, strerror(res)); *ret = EIO; } else { - fprintf(stdout, "%s: start VM command successful\n", - __progname); + fprintf(stdout, "%s: start VM command successful, " + "tty %s\n", __progname, vmr->vmr_ttyname); *ret = 0; } } else { -- cgit v1.2.3