Add a new 'skip_system_hooks' boolean option to the daemon configuration file. When set to true, session (non-root) daemons will only search for hooks in the user directory (~/.config/libvirt/hooks), skipping the system-wide /etc/libvirt/hooks directory.
The default is false, preserving backward compatibility by searching both system and user hook directories. Signed-off-by: Marc-André Lureau <[email protected]> --- src/remote/libvirtd.aug.in | 1 + src/remote/libvirtd.conf.in | 9 +++++++++ src/remote/remote_daemon.c | 1 + src/remote/remote_daemon_config.c | 3 +++ src/remote/remote_daemon_config.h | 2 ++ src/remote/test_libvirtd.aug.in | 1 + 6 files changed, 17 insertions(+) diff --git a/src/remote/libvirtd.aug.in b/src/remote/libvirtd.aug.in index 1f3bb5d0e212..85fb2fe7ca93 100644 --- a/src/remote/libvirtd.aug.in +++ b/src/remote/libvirtd.aug.in @@ -93,6 +93,7 @@ module @DAEMON_NAME_UC@ = let misc_entry = str_entry "host_uuid" | str_entry "host_uuid_source" | int_entry "ovs_timeout" + | bool_entry "skip_system_hooks" (* Each entry in the config is one of the following three ... *) let entry = sock_acl_entry diff --git a/src/remote/libvirtd.conf.in b/src/remote/libvirtd.conf.in index e4460e61ef1a..403adbefb475 100644 --- a/src/remote/libvirtd.conf.in +++ b/src/remote/libvirtd.conf.in @@ -558,3 +558,12 @@ # potential infinite waits blocking libvirt. # #ovs_timeout = 5 + +################################################################### +# Hooks: +# For non-root (session) daemons, hooks are searched in both the +# system directory (@SYSCONFDIR@/libvirt/hooks) and the user directory +# ($XDG_CONFIG_HOME/libvirt/hooks), with system hooks executed first. +# Set skip_system_hooks to 1 to only use user hooks. +# +#skip_system_hooks = 0 diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index ee3d10bc2312..b76e28c5db7c 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -1115,6 +1115,7 @@ int main(int argc, char **argv) { virAuditLog(config->audit_logging > 0); /* setup the hooks if any */ + virHookSetSkipSystemHooks(config->skip_system_hooks); if (virHookInitialize() < 0) { ret = VIR_DAEMON_ERR_HOOKS; goto cleanup; diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_config.c index bb6078967f96..9a4a6da4219d 100644 --- a/src/remote/remote_daemon_config.c +++ b/src/remote/remote_daemon_config.c @@ -396,6 +396,9 @@ daemonConfigLoadOptions(struct daemonConfig *data, if (virConfGetValueUInt(conf, "ovs_timeout", &data->ovs_timeout) < 0) return -1; + if (virConfGetValueBool(conf, "skip_system_hooks", &data->skip_system_hooks) < 0) + return -1; + return 0; } diff --git a/src/remote/remote_daemon_config.h b/src/remote/remote_daemon_config.h index e699889191cb..39357977b406 100644 --- a/src/remote/remote_daemon_config.h +++ b/src/remote/remote_daemon_config.h @@ -96,6 +96,8 @@ struct daemonConfig { unsigned int admin_keepalive_count; unsigned int ovs_timeout; + + bool skip_system_hooks; }; diff --git a/src/remote/test_libvirtd.aug.in b/src/remote/test_libvirtd.aug.in index a37b0daa55c9..bbd308d2be8a 100644 --- a/src/remote/test_libvirtd.aug.in +++ b/src/remote/test_libvirtd.aug.in @@ -75,3 +75,4 @@ module Test_@DAEMON_NAME@ = { "admin_keepalive_interval" = "5" } { "admin_keepalive_count" = "5" } { "ovs_timeout" = "5" } + { "skip_system_hooks" = "0" } -- 2.56.0.rc0.29.g47ce80527c56
