diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-12-07 14:43:25 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-12-07 14:43:25 +0000 |
commit | 5c2ba242ac38e8a83aa1b8ac94ffbe8bfc986c3b (patch) | |
tree | fbe51e5184e262d000bb6e3abef2ba41d05298bb /usr.sbin/vmd/config.c | |
parent | b2f164b6764c84086133b178ee3365bf5bc118ff (diff) |
Fix error handling in a few cases: some function return (-1) on error,
while others return (errno) on error. We probably have to agree on
something.
Diffstat (limited to 'usr.sbin/vmd/config.c')
-rw-r--r-- | usr.sbin/vmd/config.c | 16 |
1 files changed, 12 insertions, 4 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; |