Re: vmctl status exit 1

Simon Wollwage <[email protected]>
Newsgroups gmane.os.openbsd.misc
Message-ID <[email protected]>
Dave Voutila <[email protected]> writes:

>
> Yes, I'm in agreement that 0 semantically makes sense here.
>
> If you have a diff, happy to review if you can share in the thread.

I tried to make it so that the return codes make sense.  If there is a
test case I haven't considered, please let me know.

With nothing configured:

7655 > /usr/obj/usr.sbin/vmctl/vmctl status && echo "Ok"            
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
Ok
7656 > /usr/obj/usr.sbin/vmctl/vmctl status foo && echo "Ok"
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
7657 > 

With a VM called scratchpad configured:

7657 > /usr/obj/usr.sbin/vmctl/vmctl status && echo "Ok"     
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
    1 52231     1    1.0G    200M   ttyp4         root  running scratchpad
Ok
7660 > /usr/obj/usr.sbin/vmctl/vmctl status scratchpad && echo "Ok"
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
    1 52231     1    1.0G    452M   ttyp4         root  running scratchpad
Ok
7661 > /usr/obj/usr.sbin/vmctl/vmctl status foo && echo "Ok"        
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
7662 > 

Here the patch:

Index: vmctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmctl/vmctl.c,v
diff -u -p -r1.98 vmctl.c
--- vmctl.c     16 Apr 2026 21:34:47 -0000      1.98
+++ vmctl.c     12 Aug 2026 15:50:17 -0000
@@ -700,10 +700,11 @@ print_vm_info(struct vmop_info_result *l
        char maxmem[FMT_SCALED_STRSIZE];
        char user[16], group[16];
        const char *name;
-       int running, found_running;
+       int running, found_running, matched;
        extern int stat_rflag;
 
        found_running = 0;
+       matched = 0;
 
        printf("%5s %5s %5s %7s %7s %7s %12s %8s %s\n", "ID", "PID", "VCPUS",
            "MAXMEM", "CURMEM", "TTY", "OWNER", "STATE", "NAME");
@@ -717,6 +718,7 @@ print_vm_info(struct vmop_info_result *l
                found_running++;
 
                if (check_info_id(vir->vir_name, vir->vir_id)) {
+                       matched = 1;
                        /* get user name */
                        name = user_from_uid(vir->vir_uid, 1);
                        if (name == NULL)
@@ -764,11 +766,13 @@ print_vm_info(struct vmop_info_result *l
                                    vir->vir_ncpus, maxmem, curmem,
                                    "-", user, vm_state(vir->vir_state),
                                    vir->vir_name);
-                       }
+                       }               
                }
        }
 
-       if (found_running)
+       if (info_id == 0 && *info_name == '\0')
+               return (0);
+       else if (found_running && matched)
                return (0);
        else
                return (ENOENT);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.