diff options
author | anton <anton@cvs.openbsd.org> | 2019-08-14 07:34:50 +0000 |
---|---|---|
committer | anton <anton@cvs.openbsd.org> | 2019-08-14 07:34:50 +0000 |
commit | fd1e2c3940032086025dddcc3a88bd68b60a78e5 (patch) | |
tree | cc7f2ea47b483bcbdde5fbf7ccc3eddd9c5bd448 | |
parent | edb34c21723f51d28c4e97cd8762173f7372abed (diff) |
Improve the error message when supplying an invalid template to vmctl
start. Favoring 'invalid template' over 'permission denied' should give
the user a better hint on what went wrong.
ok kn@ mlarkin@
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 6 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.c | 9 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.h | 3 |
3 files changed, 14 insertions, 4 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index 60b028b7809..b5a2fc420a0 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.69 2019/05/22 16:19:21 jasper Exp $ */ +/* $OpenBSD: vmctl.c,v 1.70 2019/08/14 07:34:49 anton Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -249,6 +249,10 @@ vm_start_complete(struct imsg *imsg, int *ret, int autoconnect) "file"); *ret = ENOENT; break; + case VMD_PARENT_INVALID: + warnx("invalid template"); + *ret = EINVAL; + break; default: errno = res; warn("start vm command failed"); diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 23c34dd6dd1..654af5974d3 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.114 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: vmd.c,v 1.115 2019/08/14 07:34:49 anton Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -1373,9 +1373,14 @@ vm_instance(struct privsep *ps, struct vmd_vm **vm_parent, /* return without error if the parent is NULL (nothing to inherit) */ if ((vmc->vmc_flags & VMOP_CREATE_INSTANCE) == 0 || - (*vm_parent = vm_getbyname(vmc->vmc_instance)) == NULL) + vmc->vmc_instance[0] == '\0') return (0); + if ((*vm_parent = vm_getbyname(vmc->vmc_instance)) == NULL) { + errno = VMD_PARENT_INVALID; + return (-1); + } + errno = 0; vmcp = &(*vm_parent)->vm_params; vcpp = &vmcp->vmc_params; diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index 2d848e5d37e..30922d1d36e 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.95 2019/07/17 05:51:07 pd Exp $ */ +/* $OpenBSD: vmd.h,v 1.96 2019/08/14 07:34:49 anton Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -72,6 +72,7 @@ #define VMD_VM_STOP_INVALID 1004 #define VMD_CDROM_MISSING 1005 #define VMD_CDROM_INVALID 1006 +#define VMD_PARENT_INVALID 1007 /* Image file signatures */ #define VM_MAGIC_QCOW "QFI\xfb" |