shared: introduce MachineRegistrationContext to track bus and registration state

Bundle scope, buses, and registration success booleans into a
MachineRegistrationContext struct. This eliminates the reterr_registered_system and
reterr_registered_user output parameters from
register_machine_with_fallback_and_log() and the corresponding input
parameters from unregister_machine_with_fallback_and_log().

The struct carries state from registration to unregistration so the
caller no longer needs to manually thread individual booleans between
the two calls.

register_machine_with_fallback_and_log() goes from 7 to 3 parameters,
unregister_machine_with_fallback_and_log() goes from 5 to 2.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
Christian Brauner
2026-04-06 21:42:15 +02:00
committed by Daan De Meyer
parent 2af171653f
commit 454d9c1be1
4 changed files with 58 additions and 69 deletions
+9 -9
View File
@@ -1754,7 +1754,7 @@ static int verify_arguments(void) {
if (!(arg_clone_ns_flags & CLONE_NEWPID) ||
!(arg_clone_ns_flags & CLONE_NEWUTS)) {
arg_register = false;
arg_register = 0;
if (arg_start_mode != START_PID1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--boot cannot be used without namespacing.");
}
@@ -5782,7 +5782,11 @@ static int run_container(
scope_allocated = true;
}
bool registered_system = false, registered_runtime = false;
MachineRegistrationContext machine_ctx = {
.scope = arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? RUNTIME_SCOPE_SYSTEM : _RUNTIME_SCOPE_INVALID,
.system_bus = system_bus,
.user_bus = runtime_bus,
};
if (arg_register != 0) {
const MachineRegistration reg = {
.name = arg_machine,
@@ -5795,13 +5799,9 @@ static int run_container(
};
r = register_machine_with_fallback_and_log(
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? RUNTIME_SCOPE_SYSTEM : _RUNTIME_SCOPE_INVALID,
system_bus,
runtime_bus,
&machine_ctx,
&reg,
/* graceful= */ arg_register < 0,
&registered_system,
&registered_runtime);
/* graceful= */ arg_register < 0);
if (r < 0)
return r;
}
@@ -6015,7 +6015,7 @@ static int run_container(
r = wait_for_container(pid, &container_status);
/* Tell machined that we are gone. */
(void) unregister_machine_with_fallback_and_log(system_bus, runtime_bus, arg_machine, registered_system, registered_runtime);
unregister_machine_with_fallback_and_log(&machine_ctx, arg_machine);
if (r < 0)
/* We failed to wait for the container, or the container exited abnormally. */