From nobody Sat Aug 15 12:50:29 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hMf8P3l2zz6nkhN for ; Sat, 15 Aug 2026 12:50:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hMf8P2y7nz3pKH for ; Sat, 15 Aug 2026 12:50:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786798229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CcHeJDxJfl5ERd87VTS0iv4JWQPHzDo3piqV5DsTnDM=; b=FdwyR1MBGVdnMe8aGPrSF7YEqZeHVhlHY0UvYNz7lBnpMfr8iQfi/ZMmN3fUbIH7WoHMuU lLMws+fZaagmAOMTRS+wL2IHrMtbmRCFc94QCXkrvm7PygSKK7+QYcSJvkd3GkwzOOAN4N tJXW2EDnLPrt7by4y//BfmWHcPg91rRORonnhoKHYx/tghZpb+X7F132Fhi4s5me7H2FQ5 mAcWXzP5+uouIHs94eDZOgwETtFzGEgqpWL9LRh2Vr95U8Ukaio534qFScTRiS+coaDdYT 7flygUq5x3E4pwIsOgZe3+Df0VHYFX0pV8qQl2WvK16IA+6HLnftl1BOmocQeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786798229; a=rsa-sha256; cv=none; b=PS0i60vSBaZxJxFTaVPE/V5ejc+UyWrtoR5wLY75AVsf4jp1C/MDJbZ2jdEPm1GVWhmVXA V6NcJDaTyICg77SzWc3mjFvYfKOoVAeH0S5fZyclKV5fy6Sxs5YR36OCjUN2KvNFBlx4MY t3+ZSd5fcs+eSzqZNmKNFldzNnJRlfkwI7wUHvoZsRb62R/vYk9Ff/lgJf5MJB7D2HDN4t +aUq52CvhnZzMAkLBVioug1LcOX4lMgZX6X3JFt8UTcJpxKsv9XAUUyqlVvWNPsbWAW3q6 Z9uSoFjwI7vpZndgEYQi0F3h87LpkrA9EpXagLb4PAMX0AJzvCxGqbVSa31O1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786798229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CcHeJDxJfl5ERd87VTS0iv4JWQPHzDo3piqV5DsTnDM=; b=uHuPaCYQsozPVUGBgWjJC/DivxSB59LnmQsqfaQWKdBTgEtXs0hdP1JTPXcetwwjLZJN7i PgggVcBRMqYT6AI7tnorY/7ZO/c7+6CDNgw7wc7ZGO8eLaiS21XSS1ghYjZgbzBsJNhmtC 0j7QGPhGhcxQN6QcFhEzN80wxlvJVxG+52gbVNXq9ofaruKnNAvaMr+BL+Z2+JHT4TF049 6iZf9JRiF2ZQukPLBQOAkyiwD5dIlqvQbIQi9y+NyHF48FYxZAUu7WBc4JKF0qly4mQxG6 keayj554+iRn09YuS3zI9txguBHpPKfsCe9+6bSrgutLfQymTcpmZmvO7pIg8g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hMf8P1hMczkMr for ; Sat, 15 Aug 2026 12:50:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 32d50 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 15 Aug 2026 12:50:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roman Bogorodskiy Subject: git: 1f3aeb3ea5a5 - main - bhyve: monitor: detect monitor exit List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: novel X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f3aeb3ea5a52e16e87439160dc19c53526600c3 Auto-Submitted: auto-generated Date: Sat, 15 Aug 2026 12:50:29 +0000 Message-Id: <6a806095.32d50.53c35a21@gitrepo.freebsd.org> The branch main has been updated by novel: URL: https://cgit.FreeBSD.org/src/commit/?id=1f3aeb3ea5a52e16e87439160dc19c53526600c3 commit 1f3aeb3ea5a52e16e87439160dc19c53526600c3 Author: Roman Bogorodskiy AuthorDate: 2026-08-11 16:20:31 +0000 Commit: Roman Bogorodskiy CommitDate: 2026-08-15 08:58:02 +0000 bhyve: monitor: detect monitor exit Currently, sending SIGTERM to the bhyve process triggers ACPI poweroff for a VM. However, when running bhyve in monitor mode (-M), there are two processes: the monitor process and the actual VM process. Sending SIGTERM to the VM process works as before -- it powers off the VM. But sending SIGTERM to the monitor process just kills the monitor process, leaving the stale VM process running. Fix that by creating a pipe between these two processes. The child process uses the pipe to detect when the monitor goes away, and exits automatically. MFC after: 2 weeks Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58788 --- usr.sbin/bhyve/bhyverun.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index c089d1fbc8fa..339cf5071906 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -54,9 +54,7 @@ #include #include #include -#ifdef BHYVE_SNAPSHOT #include -#endif #include #include #include @@ -127,6 +125,29 @@ static struct vcpu_info { static cpuset_t **vcpumap; +static void +monitor_pipe_handler(int fd __unused, enum ev_type type __unused, + void *param __unused) +{ + + exit(BHYVE_EXIT_ERROR); +} + +static void +monitor_pipe_init(int fd) +{ +#ifndef WITHOUT_CAPSICUM + cap_rights_t rights; + + cap_rights_init(&rights, CAP_EVENT); + if (caph_rights_limit(fd, &rights) == -1) + err(BHYVE_EXIT_ERROR, "Unable to apply rights to monitor pipe"); +#endif + + if (mevent_add(fd, EVF_READ, monitor_pipe_handler, NULL) == NULL) + errx(BHYVE_EXIT_ERROR, "Unable to register parent exit event"); +} + /* * XXX This parser is known to have the following issues: * 1. It accepts null key=value tokens ",," as setting "cpus" to an @@ -922,17 +943,29 @@ main(int argc, char *argv[]) init_bootrom(ctx); if (get_config_bool_default("monitor", false)) { + int monitor_pipe[2]; + pid_t child; + while (1) { - pid_t child = fork(); + if (pipe2(monitor_pipe, O_CLOEXEC) == -1) + err(BHYVE_EXIT_ERROR, "pipe2"); + + child = fork(); if (child == -1) { EPRINTLN("Monitor mode fork failed: %s", strerror(errno)); exit(BHYVE_EXIT_ERROR); } - if (child == 0) + if (child == 0) { + close(monitor_pipe[1]); + monitor_pipe_init(monitor_pipe[0]); break; + } + + close(monitor_pipe[0]); while ((error = waitpid(child, &status, 0)) == -1 && errno == EINTR) ; + close(monitor_pipe[1]); if (error == -1) { EPRINTLN("Monitor mode wait failed: %s", strerror(errno));