summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Larkin <mlarkin@cvs.openbsd.org>2016-05-10 11:00:55 +0000
committerMike Larkin <mlarkin@cvs.openbsd.org>2016-05-10 11:00:55 +0000
commit8496c967314a96d73856d532a5b3aa8419dab477 (patch)
tree050a22013c3d2729c605649c414e9f406b6b2191
parentf05106156dc3f5c935c6f9efc6fd1a0832d98480 (diff)
move some argument checking from vmmaction() to start_vm()
from a diff posted to tech@ by Fabien Siron, thanks.
-rw-r--r--usr.sbin/vmctl/main.c16
-rw-r--r--usr.sbin/vmctl/vmctl.c15
2 files changed, 15 insertions, 16 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c
index 5dc4b25522b..83b6fab3b8f 100644
--- a/usr.sbin/vmctl/main.c
+++ b/usr.sbin/vmctl/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.16 2016/04/25 15:14:34 mlarkin Exp $ */
+/* $OpenBSD: main.c,v 1.17 2016/05/10 11:00:54 mlarkin Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -188,20 +188,6 @@ vmmaction(struct parse_result *res)
switch (res->action) {
case CMD_START:
- /* XXX validation should be done in start_vm() */
- if (res->size < 1)
- errx(1, "specified memory size too small");
- if (res->path == NULL)
- errx(1, "no kernel specified");
- if (res->ndisks > VMM_MAX_DISKS_PER_VM)
- errx(1, "too many disks");
- else if (res->ndisks == 0)
- warnx("starting without disks");
- if (res->nifs == -1)
- res->nifs = 0;
- if (res->nifs == 0)
- warnx("starting without network interfaces");
-
ret = start_vm(res->name, res->size, res->nifs,
res->ndisks, res->disks, res->path);
if (ret) {
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c
index d21151b78c0..462a82a1a13 100644
--- a/usr.sbin/vmctl/vmctl.c
+++ b/usr.sbin/vmctl/vmctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.c,v 1.14 2016/05/10 10:49:22 mlarkin Exp $ */
+/* $OpenBSD: vmctl.c,v 1.15 2016/05/10 11:00:54 mlarkin Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
@@ -67,6 +67,19 @@ start_vm(const char *name, int memsize, int nnics, int ndisks, char **disks,
struct vm_create_params *vcp;
int i;
+ if (memsize < 1)
+ errx(1, "specified memory size too small");
+ if (kernel == NULL)
+ errx(1, "no kernel specified");
+ if (ndisks > VMM_MAX_DISKS_PER_VM)
+ errx(1, "too many disks");
+ else if (ndisks == 0)
+ warnx("starting without disks");
+ if (nnics == -1)
+ nnics = 0;
+ if (nnics == 0)
+ warnx("starting without network interfaces");
+
vcp = malloc(sizeof(struct vm_create_params));
if (vcp == NULL)
return (ENOMEM);