From: Mike Yuan Date: Thu, 26 Mar 2026 10:59:45 +0000 (+0100) Subject: machine: introduce MACHINE_CLASS_CAN_REGISTER X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90cc5b0159619fee309f5ed354506f86c7e43fee;p=thirdparty%2Fsystemd.git machine: introduce MACHINE_CLASS_CAN_REGISTER Follow-up for 6df5f80bd374be1b45c52d740e88f0236da922c7 Similar to SESSION_CAN_* macros in logind-session.h --- diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index 73edd781b58..40e9136b270 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -155,7 +155,7 @@ int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink if (r != 0) return r; - if (!IN_SET(machine->class, MACHINE_CONTAINER, MACHINE_VM)) + if (!MACHINE_CLASS_CAN_REGISTER(machine->class)) return sd_varlink_error_invalid_parameter_name(link, "class"); if (manager->runtime_scope != RUNTIME_SCOPE_USER) { diff --git a/src/machine/machine.h b/src/machine/machine.h index 7941eb365c1..899218f48d5 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -25,6 +25,8 @@ typedef enum MachineClass { _MACHINE_CLASS_INVALID = -EINVAL, } MachineClass; +#define MACHINE_CLASS_CAN_REGISTER(class) IN_SET((class), MACHINE_CONTAINER, MACHINE_VM) + typedef enum KillWhom { KILL_LEADER, KILL_SUPERVISOR, diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 87f0c15ee13..4e39594a44d 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -256,6 +256,7 @@ static int machine_add_from_params( assert(manager); assert(message); assert(name); + assert(c == _MACHINE_CLASS_INVALID || MACHINE_CLASS_CAN_REGISTER(c)); assert(ret); if (leader_pidref->pid == 1) @@ -433,7 +434,7 @@ static int method_create_or_register_machine( c = _MACHINE_CLASS_INVALID; else { c = machine_class_from_string(class); - if (c < 0 || !IN_SET(c, MACHINE_CONTAINER, MACHINE_VM)) + if (c < 0 || !MACHINE_CLASS_CAN_REGISTER(c)) return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter"); } @@ -608,7 +609,7 @@ static int method_create_or_register_machine_ex( c = _MACHINE_CLASS_INVALID; else { c = machine_class_from_string(class); - if (c < 0 || !IN_SET(c, MACHINE_CONTAINER, MACHINE_VM)) + if (c < 0 || !MACHINE_CLASS_CAN_REGISTER(c)) return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter"); }