diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-13 15:07:09 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-21 17:38:23 +0200 |
commit | f98e821cda53698190c21289aa38662a68bb6574 (patch) | |
tree | 98a53c062f02327078fb5d1c068875040c475714 /src/machine/machine-varlink.c | |
parent | machined: allow unprivileged registration of VMs/containers (diff) | |
download | systemd-f98e821cda53698190c21289aa38662a68bb6574.tar.xz systemd-f98e821cda53698190c21289aa38662a68bb6574.zip |
machined: support allocating a scope for machines if needed via varlink
On dbus we have two apis: one for registering a new machne when the
client already has a cgroup (RegisterMachine()) and one where it doesn't
and machined shall create it (CreateMachine()).
Let's add the same for the varlink api. To simplify things we just
implement it via a boolean flag to the existign RegisterMachine()
varlink call, since the differences are mostly minor otherwise.
Diffstat (limited to 'src/machine/machine-varlink.c')
-rw-r--r-- | src/machine/machine-varlink.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index ea300d71de..5b3538d416 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -127,16 +127,17 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod int r; static const sd_json_dispatch_field dispatch_table[] = { - { "name", SD_JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), SD_JSON_MANDATORY }, - { "id", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(Machine, id), 0 }, - { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, service), 0 }, - { "class", SD_JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), SD_JSON_MANDATORY }, - { "leader", SD_JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, - { "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, - { "ifIndices", SD_JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, - { "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, - { "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_STRICT }, - { "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, + { "name", SD_JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), SD_JSON_MANDATORY }, + { "id", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(Machine, id), 0 }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, service), 0 }, + { "class", SD_JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), SD_JSON_MANDATORY }, + { "leader", SD_JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, + { "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, + { "ifIndices", SD_JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, + { "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, + { "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_STRICT }, + { "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, + { "allocateUnit", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(Machine, allocate_unit), 0 }, VARLINK_DISPATCH_POLKIT_FIELD, {} }; @@ -171,11 +172,13 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod if (r < 0) return r; - r = cg_pidref_get_unit(&machine->leader, &machine->unit); - if (r < 0) - return r; + if (!machine->allocate_unit) { + r = cg_pidref_get_unit(&machine->leader, &machine->unit); + if (r < 0) + return r; + } - r = machine_start(machine, NULL, NULL); + r = machine_start(machine, /* properties= */ NULL, /* error= */ NULL); if (r < 0) return r; |