-/* $OpenBSD: vmd.c,v 1.135 2022/12/28 21:30:19 jmc Exp $ */
+/* $OpenBSD: vmd.c,v 1.136 2023/01/14 20:55:55 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
proc_priv->p_pw = &proc_privpw; /* initialized to all 0 */
proc_priv->p_chroot = ps->ps_pw->pw_dir; /* from VMD_USER */
- /* Open /dev/vmm */
- if (env->vmd_noaction == 0) {
+ /* Open /dev/vmm early. */
+ if (env->vmd_noaction == 0 && proc_id == PROC_PARENT) {
env->vmd_fd = open(VMM_NODE, O_RDWR);
if (env->vmd_fd == -1)
fatal("%s", VMM_NODE);
exit(0);
}
+ /* Send VMM device fd to vmm proc. */
+ proc_compose_imsg(&env->vmd_ps, PROC_VMM, -1,
+ IMSG_VMDOP_RECEIVE_VMM_FD, -1, env->vmd_fd, NULL, 0);
+
/* Send shared global configuration to all children */
if (config_setconfig(env) == -1)
return (-1);
-/* $OpenBSD: vmd.h,v 1.112 2022/12/23 19:25:22 dv Exp $ */
+/* $OpenBSD: vmd.h,v 1.113 2023/01/14 20:55:55 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
IMSG_VMDOP_GET_INFO_VM_DATA,
IMSG_VMDOP_GET_INFO_VM_END_DATA,
IMSG_VMDOP_LOAD,
+ IMSG_VMDOP_RECEIVE_VMM_FD,
IMSG_VMDOP_RELOAD,
IMSG_VMDOP_PRIV_IFDESCR,
IMSG_VMDOP_PRIV_IFADD,
-/* $OpenBSD: vmm.c,v 1.106 2022/11/06 11:54:08 dv Exp $ */
+/* $OpenBSD: vmm.c,v 1.107 2023/01/14 20:55:55 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
*/
if (pledge("stdio vmm sendfd recvfd proc", NULL) == -1)
fatal("pledge");
-
- /* Get and terminate all running VMs */
- get_info_vm(ps, NULL, 1);
}
int
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
imsg->fd, &var, sizeof(var));
break;
+ case IMSG_VMDOP_RECEIVE_VMM_FD:
+ if (env->vmd_fd > -1)
+ fatalx("already received vmm fd");
+ env->vmd_fd = imsg->fd;
+
+ /* Get and terminate all running VMs */
+ get_info_vm(ps, NULL, 1);
+ break;
default:
return (-1);
}