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.");
}
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,
};
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,
®,
- /* graceful= */ arg_register < 0,
- ®istered_system,
- ®istered_runtime);
+ /* graceful= */ arg_register < 0);
if (r < 0)
return r;
}
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. */
assert(reg->name);
assert(reg->service);
assert(reg->class);
+ assert(error);
r = bus_message_new_method_call(bus, &m, bus_machine_mgr, "RegisterMachineEx");
if (r < 0)
}
int register_machine_with_fallback_and_log(
- RuntimeScope scope,
- sd_bus *system_bus,
- sd_bus *user_bus,
+ MachineRegistrationContext *ctx,
const MachineRegistration *reg,
- bool graceful,
- bool *reterr_registered_system,
- bool *reterr_registered_user) {
+ bool graceful) {
- bool registered_system = false, registered_user = false;
int r = 0;
- assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID));
- assert(system_bus || !IN_SET(scope, RUNTIME_SCOPE_SYSTEM, _RUNTIME_SCOPE_INVALID));
- assert(user_bus || !IN_SET(scope, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID));
+ assert(ctx);
+ assert(IN_SET(ctx->scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID));
+ assert(ctx->system_bus || !IN_SET(ctx->scope, RUNTIME_SCOPE_SYSTEM, _RUNTIME_SCOPE_INVALID));
+ assert(ctx->user_bus || !IN_SET(ctx->scope, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID));
assert(reg);
assert(reg->name);
assert(reg->service);
assert(reg->class);
- assert(reterr_registered_system);
- assert(reterr_registered_user);
- if (IN_SET(scope, RUNTIME_SCOPE_SYSTEM, _RUNTIME_SCOPE_INVALID)) {
+ if (IN_SET(ctx->scope, RUNTIME_SCOPE_SYSTEM, _RUNTIME_SCOPE_INVALID)) {
MachineRegistration system_reg = *reg;
- if (scope != RUNTIME_SCOPE_SYSTEM)
+ if (ctx->scope != RUNTIME_SCOPE_SYSTEM)
system_reg.allocate_unit = false;
- int q = register_machine(system_bus, &system_reg, RUNTIME_SCOPE_SYSTEM);
+ int q = register_machine(ctx->system_bus, &system_reg, RUNTIME_SCOPE_SYSTEM);
if (q < 0)
RET_GATHER(r, q);
else
- registered_system = true;
+ ctx->registered_system = true;
}
- if (IN_SET(scope, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID)) {
- int q = register_machine(user_bus, reg, RUNTIME_SCOPE_USER);
+ if (IN_SET(ctx->scope, RUNTIME_SCOPE_USER, _RUNTIME_SCOPE_INVALID)) {
+ int q = register_machine(ctx->user_bus, reg, RUNTIME_SCOPE_USER);
if (q < 0)
RET_GATHER(r, q);
else
- registered_user = true;
+ ctx->registered_user = true;
}
if (r < 0) {
if (graceful) {
log_notice_errno(r, "Failed to register machine in %s context, ignoring: %m",
- machine_registration_scope_string(scope, registered_system, registered_user));
+ machine_registration_scope_string(ctx->scope, ctx->registered_system, ctx->registered_user));
r = 0;
} else
r = log_error_errno(r, "Failed to register machine in %s context: %m",
- machine_registration_scope_string(scope, registered_system, registered_user));
+ machine_registration_scope_string(ctx->scope, ctx->registered_system, ctx->registered_user));
}
- if (reterr_registered_system)
- *reterr_registered_system = registered_system;
- if (reterr_registered_user)
- *reterr_registered_user = registered_user;
-
return r;
}
-int unregister_machine_with_fallback_and_log(
- sd_bus *system_bus,
- sd_bus *user_bus,
- const char *machine_name,
- bool registered_system,
- bool registered_user) {
+void unregister_machine_with_fallback_and_log(
+ const MachineRegistrationContext *ctx,
+ const char *machine_name) {
int r = 0;
bool failed_system = false, failed_user = false;
- if (registered_system) {
- int q = unregister_machine(system_bus, machine_name, RUNTIME_SCOPE_SYSTEM);
+ assert(ctx);
+
+ if (ctx->registered_system) {
+ int q = unregister_machine(ctx->system_bus, machine_name, RUNTIME_SCOPE_SYSTEM);
if (q < 0) {
RET_GATHER(r, q);
failed_system = true;
}
}
- if (registered_user) {
- int q = unregister_machine(user_bus, machine_name, RUNTIME_SCOPE_USER);
+ if (ctx->registered_user) {
+ int q = unregister_machine(ctx->user_bus, machine_name, RUNTIME_SCOPE_USER);
if (q < 0) {
RET_GATHER(r, q);
failed_user = true;
if (r < 0)
log_notice_errno(r, "Failed to unregister machine in %s context, ignoring: %m",
machine_registration_scope_string(
- registered_system && registered_user ? _RUNTIME_SCOPE_INVALID :
- registered_system ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER,
+ ctx->registered_system && ctx->registered_user ? _RUNTIME_SCOPE_INVALID :
+ ctx->registered_system ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER,
!failed_system, !failed_user));
-
- return 0;
}
int unregister_machine(sd_bus *bus, const char *machine_name, RuntimeScope scope) {
#include "sd-id128.h"
+#include "runtime-scope.h"
#include "shared-forward.h"
typedef struct MachineRegistration {
bool allocate_unit;
} MachineRegistration;
+typedef struct MachineRegistrationContext {
+ RuntimeScope scope;
+ sd_bus *system_bus;
+ sd_bus *user_bus;
+ bool registered_system;
+ bool registered_user;
+} MachineRegistrationContext;
+
int register_machine(
sd_bus *bus,
const MachineRegistration *reg,
RuntimeScope scope);
int register_machine_with_fallback_and_log(
- RuntimeScope scope,
- sd_bus *system_bus,
- sd_bus *user_bus,
+ MachineRegistrationContext *ctx,
const MachineRegistration *reg,
- bool graceful,
- bool *reterr_registered_system,
- bool *reterr_registered_user);
+ bool graceful);
int unregister_machine(sd_bus *bus, const char *machine_name, RuntimeScope scope);
-int unregister_machine_with_fallback_and_log(
- sd_bus *system_bus,
- sd_bus *user_bus,
- const char *machine_name,
- bool registered_system,
- bool registered_user);
+void unregister_machine_with_fallback_and_log(
+ const MachineRegistrationContext *ctx,
+ const char *machine_name);
return log_error_errno(r, "Failed to get our own unit: %m");
}
- 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) {
char vm_address[STRLEN("vsock/") + DECIMAL_STR_MAX(unsigned)];
xsprintf(vm_address, "vsock/%u", child_cid);
};
r = register_machine_with_fallback_and_log(
- arg_runtime_scope == RUNTIME_SCOPE_USER ? _RUNTIME_SCOPE_INVALID : RUNTIME_SCOPE_SYSTEM,
- system_bus,
- runtime_bus,
+ &machine_ctx,
®,
- /* graceful= */ arg_register < 0,
- ®istered_system,
- ®istered_runtime);
+ /* graceful= */ arg_register < 0);
if (r < 0)
return r;
}
if (scope_allocated)
terminate_scope(runtime_bus, arg_machine);
- (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 (use_vsock) {
if (exit_status == INT_MAX) {