Hi everyone,

The following patch moves all the validations of the start command in
start_vm() as suggested in the comment.

Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmctl/main.c,v
retrieving revision 1.16
diff -u -p -r1.16 main.c
--- main.c      25 Apr 2016 15:14:34 -0000      1.16
+++ main.c      8 May 2016 19:23:20 -0000
@@ -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) {
Index: vmctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.c,v
retrieving revision 1.13
diff -u -p -r1.13 vmctl.c
--- vmctl.c     13 Mar 2016 13:11:47 -0000      1.13
+++ vmctl.c     8 May 2016 19:23:21 -0000
@@ -67,6 +67,19 @@ start_vm(const char *name, int memsize, 
        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("stating 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);

---
Regards,
Fabien Siron

Reply via email to