From: Christian Brauner Date: Mon, 6 Apr 2026 18:21:52 +0000 (+0200) Subject: vmspawn: only open runtime bus when needed for registration or scope allocation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b77bbeb2053a0c38b0d4e10e1bc2f382243cd8c;p=thirdparty%2Fsystemd.git vmspawn: only open runtime bus when needed for registration or scope allocation The runtime bus (user bus in user scope, system bus in system scope) is only needed for scope allocation (!arg_keep_unit) or machine registration (arg_register != 0). When both are disabled the bus was still opened unconditionally which causes unnecessary failures if the user bus is unavailable. Gate the runtime bus opening on the same condition nspawn already uses. Signed-off-by: Christian Brauner (Amutable) --- diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index c6289830fb7..9610199c029 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -2246,21 +2246,23 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { (void) sd_bus_set_allow_interactive_authorization(system_bus, arg_ask_password); } - /* Scope allocation happens on the user bus if we are unpriv, otherwise system bus. */ + /* Scope allocation and machine registration happen on the user bus if we are unpriv, otherwise system bus. */ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *user_bus = NULL; _cleanup_(sd_bus_unrefp) sd_bus *runtime_bus = NULL; - if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM) - runtime_bus = sd_bus_ref(system_bus); - else { - r = sd_bus_default_user(&user_bus); - if (r < 0) - return log_error_errno(r, "Failed to open user bus: %m"); + if (arg_register != 0 || !arg_keep_unit) { + if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM) + runtime_bus = sd_bus_ref(system_bus); + else { + r = sd_bus_default_user(&user_bus); + if (r < 0) + return log_error_errno(r, "Failed to open user bus: %m"); - r = sd_bus_set_close_on_exit(user_bus, false); - if (r < 0) - return log_error_errno(r, "Failed to disable close-on-exit behaviour: %m"); + r = sd_bus_set_close_on_exit(user_bus, false); + if (r < 0) + return log_error_errno(r, "Failed to disable close-on-exit behaviour: %m"); - runtime_bus = sd_bus_ref(user_bus); + runtime_bus = sd_bus_ref(user_bus); + } } bool use_kvm = arg_kvm > 0;