-/* $OpenBSD: vmctl.c,v 1.90 2024/05/02 15:46:10 mlarkin Exp $ */
+/* $OpenBSD: vmctl.c,v 1.91 2024/07/09 15:51:11 mlarkin Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
* 0 : Message successfully processed
* EINVAL: Invalid or unexpected response from vmd
* ENOMEM: memory allocation failure
+ * ENOENT: no entries
*/
int
add_info(struct imsg *imsg, int *ret)
static size_t ct = 0;
static struct vmop_info_result *vir = NULL;
+ *ret = 0;
+
if (imsg->hdr.type == IMSG_VMDOP_GET_INFO_VM_DATA) {
vir = reallocarray(vir, ct + 1,
sizeof(struct vmop_info_result));
}
memcpy(&vir[ct], imsg->data, sizeof(struct vmop_info_result));
ct++;
- *ret = 0;
return (0);
} else if (imsg->hdr.type == IMSG_VMDOP_GET_INFO_VM_END_DATA) {
switch (info_action) {
terminate_all(vir, ct, info_flags);
break;
default:
- print_vm_info(vir, ct);
+ *ret = print_vm_info(vir, ct);
break;
}
free(vir);
- *ret = 0;
return (1);
} else {
*ret = EINVAL;
* Parameters
* list: the vm information (consolidated) returned from vmd via imsg
* ct : the size (number of elements in 'list') of the result
+ *
+ * Return values:
+ * 0: no error
+ * ENOENT: no entries printed
*/
-void
+int
print_vm_info(struct vmop_info_result *list, size_t ct)
{
struct vm_info_result *vir;
char maxmem[FMT_SCALED_STRSIZE];
char user[16], group[16];
const char *name;
- int running;
+ int running, found_running;
extern int stat_rflag;
+ found_running = 0;
+
printf("%5s %5s %5s %7s %7s %7s %12s %8s %s\n", "ID", "PID", "VCPUS",
"MAXMEM", "CURMEM", "TTY", "OWNER", "STATE", "NAME");
running = (vir->vir_creator_pid != 0 && vir->vir_id != 0);
if (!running && stat_rflag)
continue;
+
+ found_running++;
+
if (check_info_id(vir->vir_name, vir->vir_id)) {
/* get user name */
name = user_from_uid(vmi->vir_uid, 1);
}
}
}
+
+ if (found_running)
+ return (0);
+ else
+ return (ENOENT);
}
/*
-/* $OpenBSD: vmctl.h,v 1.38 2024/05/18 06:45:00 jsg Exp $ */
+/* $OpenBSD: vmctl.h,v 1.39 2024/07/09 15:51:11 mlarkin Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
int add_info(struct imsg *, int *);
const char
*vm_state(unsigned int);
-void print_vm_info(struct vmop_info_result *, size_t);
+int print_vm_info(struct vmop_info_result *, size_t);
void terminate_all(struct vmop_info_result *, size_t, unsigned int);
__dead void
vm_console(struct vmop_info_result *, size_t);