/* Registration always happens on the system bus */
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *system_bus = NULL;
- if (arg_register || arg_privileged) {
+ if (arg_register || (arg_privileged && !arg_keep_unit)) {
r = sd_bus_default_system(&system_bus);
if (r < 0)
return log_error_errno(r, "Failed to open system bus: %m");
/* Scope allocation happens 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_privileged)
- 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_keep_unit) {
+ if (arg_privileged)
+ 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);
+ }
- if (!arg_keep_unit) {
/* When a new scope is created for this container, then we'll be registered as its controller, in which
* case PID 1 will send us a friendly RequestStop signal, when it is asked to terminate the
* scope. Let's hook into that, and cleanly shut down the container, and print a friendly message. */