machine: introduce MACHINE_CLASS_CAN_REGISTER

Follow-up for 6df5f80bd3

Similar to SESSION_CAN_* macros in logind-session.h
This commit is contained in:
Mike Yuan
2026-03-27 11:47:42 +01:00
committed by Daan De Meyer
parent a8b9ec68c3
commit 90cc5b0159
3 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -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) {
+2
View File
@@ -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,
+3 -2
View File
@@ -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");
}