git: 44dc35be3ca6 - main - devel/libvirt: run virt-host-validate in rc script

From: Roman Bogorodskiy <novel_at_FreeBSD.org>
Date: Tue, 08 Sep 2026 16:05:01 UTC
The branch main has been updated by novel:

URL: https://cgit.FreeBSD.org/ports/commit/?id=44dc35be3ca601ec2399120543b640e187328e37

commit 44dc35be3ca601ec2399120543b640e187328e37
Author:     Roman Bogorodskiy <novel@FreeBSD.org>
AuthorDate: 2026-09-07 16:35:03 +0000
Commit:     Roman Bogorodskiy <novel@FreeBSD.org>
CommitDate: 2026-09-08 15:57:28 +0000

    devel/libvirt: run virt-host-validate in rc script
    
    Update the libvirtd rc script to run virt-host-validate(1)
    before running libvirtd(8). This command provides information
    about possibly missing kernel modules required for certain
    features of libvirtd. Errors and warnings from this tool do not
    prevent libvirtd(8) from starting as most of the features
    are optional.
    
    Suggested by:   arrowd
    Reviewed by:    arrowd
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D59490
---
 devel/libvirt/Makefile          |  1 +
 devel/libvirt/files/libvirtd.in | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/devel/libvirt/Makefile b/devel/libvirt/Makefile
index cb6234fe8d45..49f5080cd34f 100644
--- a/devel/libvirt/Makefile
+++ b/devel/libvirt/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	libvirt
 DISTVERSION=	12.7.0
+PORTREVISION=	1
 CATEGORIES=	devel
 MASTER_SITES=	http://libvirt.org/sources/ \
 		ftp://libvirt.org/libvirt/
diff --git a/devel/libvirt/files/libvirtd.in b/devel/libvirt/files/libvirtd.in
index 7d8470d3b72c..5f9330ee3cf7 100644
--- a/devel/libvirt/files/libvirtd.in
+++ b/devel/libvirt/files/libvirtd.in
@@ -13,6 +13,9 @@
 #                               For example, to make it listen on TCP ports, set it
 #                               to "--listen".
 #                               Default: ""
+# libvirtd_hostvalidate_enable (bool): Run virt-host-validate(1) before starting
+#                               libvirtd.
+#                               Default: "YES"
 #
 
 . /etc/rc.subr
@@ -20,10 +23,13 @@
 name=libvirtd
 rcvar=libvirtd_enable
 
+start_precmd="libvirtd_hostvalidate"
+
 load_rc_config $name
 
 : ${libvirtd_enable:="NO"}
 : ${libvirtd_flags:=""}
+: ${libvirtd_hostvalidate_enable:="YES"}
 
 command=%%PREFIX%%/sbin/libvirtd
 pidfile=/var/run/${name}.pid
@@ -34,4 +40,17 @@ PATH="${PATH}:/usr/local/sbin:/usr/local/bin"
 
 extra_commands="reload"
 
+libvirtd_hostvalidate()
+{
+	if checkyesno libvirtd_hostvalidate_enable; then
+		# virt-host-validate(1) returns a non-zero exit code when
+		# one or more checks fail. As many of the checks do not
+		# prevent libvirtd from working, but only limit some
+		# features (e.g. console access or pf firewalling), treat
+		# failures as diagnostics rather than preventing libvirtd
+		# from starting.
+		%%PREFIX%%/bin/virt-host-validate || :
+	fi
+}
+
 run_rc_command "$1"