summaryrefslogtreecommitdiffstats
path: root/src/machine
diff options
context:
space:
mode:
authorIvan Kruglov <mail@ikruglov.com>2024-10-07 11:27:16 +0200
committerIvan Kruglov <mail@ikruglov.com>2024-10-07 14:45:49 +0200
commit6bb6354b4fe85090fdfb2b2d8c92f6e2da6b6550 (patch)
tree9a750346131dab37a03db5cb600ac75dacff0f2f /src/machine
parentmachine: introduce io.systemd.Machine.Unregister varlink method (diff)
downloadsystemd-6bb6354b4fe85090fdfb2b2d8c92f6e2da6b6550.tar.xz
systemd-6bb6354b4fe85090fdfb2b2d8c92f6e2da6b6550.zip
machine: introduce io.systemd.Machine.Terminate varlink method
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/machine-varlink.c22
-rw-r--r--src/machine/machine-varlink.h1
-rw-r--r--src/machine/machined-varlink.c7
3 files changed, 29 insertions, 1 deletions
diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c
index 810e94925c..06c59887aa 100644
--- a/src/machine/machine-varlink.c
+++ b/src/machine/machine-varlink.c
@@ -297,3 +297,25 @@ int vl_method_unregister_internal(sd_varlink *link, sd_json_variant *parameters,
return sd_varlink_reply(link, NULL);
}
+
+int vl_method_terminate_internal(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
+ Machine *machine = ASSERT_PTR(userdata);
+ Manager *manager = ASSERT_PTR(machine->manager);
+ int r;
+
+ r = varlink_verify_polkit_async(
+ link,
+ manager->bus,
+ "org.freedesktop.machine1.manage-machines",
+ (const char**) STRV_MAKE("name", machine->name,
+ "verb", "terminate"),
+ &manager->polkit_registry);
+ if (r <= 0)
+ return r;
+
+ r = machine_stop(machine);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to stop machine: %m");
+
+ return sd_varlink_reply(link, NULL);
+}
diff --git a/src/machine/machine-varlink.h b/src/machine/machine-varlink.h
index 4f772d04b7..8b0efc2a63 100644
--- a/src/machine/machine-varlink.h
+++ b/src/machine/machine-varlink.h
@@ -21,3 +21,4 @@ int lookup_machine_by_name_or_pid(sd_varlink *link, Manager *manager, const char
int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);
int vl_method_unregister_internal(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);
+int vl_method_terminate_internal(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);
diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c
index 94d8c16799..fbf03ad4a1 100644
--- a/src/machine/machined-varlink.c
+++ b/src/machine/machined-varlink.c
@@ -502,6 +502,10 @@ static int vl_method_unregister(sd_varlink *link, sd_json_variant *parameters, s
return lookup_machine_and_call_method(link, parameters, flags, userdata, vl_method_unregister_internal);
}
+static int vl_method_terminate(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
+ return lookup_machine_and_call_method(link, parameters, flags, userdata, vl_method_terminate_internal);
+}
+
static int manager_varlink_init_userdb(Manager *m) {
_cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL;
int r;
@@ -566,7 +570,8 @@ static int manager_varlink_init_machine(Manager *m) {
s,
"io.systemd.Machine.Register", vl_method_register,
"io.systemd.Machine.List", vl_method_list,
- "io.systemd.Machine.Unregister", vl_method_unregister);
+ "io.systemd.Machine.Unregister", vl_method_unregister,
+ "io.systemd.Machine.Terminate", vl_method_terminate);
if (r < 0)
return log_error_errno(r, "Failed to register varlink methods: %m");