diff options
-rw-r--r-- | usr.sbin/vmd/config.c | 16 | ||||
-rw-r--r-- | usr.sbin/vmd/vmm.c | 13 |
2 files changed, 21 insertions, 8 deletions
diff --git a/usr.sbin/vmd/config.c b/usr.sbin/vmd/config.c index 503f994c0c6..b6b01795ece 100644 --- a/usr.sbin/vmd/config.c +++ b/usr.sbin/vmd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.7 2015/12/06 21:02:51 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.8 2015/12/07 14:43:24 reyk Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -218,9 +218,12 @@ config_getdisk(struct privsep *ps, struct imsg *imsg) { struct vmd_vm *vm; unsigned int n; - - if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) + + errno = 0; + if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { + errno = ENOENT; return (-1); + } IMSG_SIZE_CHECK(imsg, &n); memcpy(&n, imsg->data, sizeof(n)); @@ -228,6 +231,7 @@ config_getdisk(struct privsep *ps, struct imsg *imsg) if (n >= vm->vm_params.vcp_ndisks || vm->vm_disks[n] != -1 || imsg->fd == -1) { log_debug("invalid disk id"); + errno = EINVAL; return (-1); } vm->vm_disks[n] = imsg->fd; @@ -241,14 +245,18 @@ config_getif(struct privsep *ps, struct imsg *imsg) struct vmd_vm *vm; unsigned int n; - if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) + errno = 0; + if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { + errno = ENOENT; return (-1); + } IMSG_SIZE_CHECK(imsg, &n); memcpy(&n, imsg->data, sizeof(n)); if (n >= vm->vm_params.vcp_nnics || vm->vm_ifs[n] != -1 || imsg->fd == -1) { log_debug("invalid interface id"); + errno = EINVAL; return (-1); } vm->vm_ifs[n] = imsg->fd; diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 76d8330c212..81b466e71f3 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.10 2015/12/06 02:26:14 reyk Exp $ */ +/* $OpenBSD: vmm.c,v 1.11 2015/12/07 14:43:24 reyk Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -191,13 +191,17 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) break; case IMSG_VMDOP_START_VM_DISK: res = config_getdisk(ps, imsg); - if (res != 0) + if (res == -1) { + res = errno; cmd = IMSG_VMDOP_START_VM_RESPONSE; + } break; case IMSG_VMDOP_START_VM_IF: res = config_getif(ps, imsg); - if (res != 0) + if (res == -1) { + res = errno; cmd = IMSG_VMDOP_START_VM_RESPONSE; + } break; case IMSG_VMDOP_START_VM_END: res = start_vm(imsg, &id); @@ -331,7 +335,8 @@ start_vm(struct imsg *imsg, uint32_t *id) if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { log_warn("%s: can't find vm", __func__); - return (-1); + ret = ENOENT; + goto err; } vcp = &vm->vm_params; |