summaryrefslogtreecommitdiff
path: root/src/machine/machined-dbus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-27 02:35:47 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-28 02:08:40 +0100
commit086821244b5113f00a0ef993b78dc56aae2a8f6c (patch)
tree296492582d2fc44697d98505907e3a0ab678451c /src/machine/machined-dbus.c
parent1b9cebf6385b5ea0e5ea099da163687013ac7790 (diff)
machined: add "machinectl remove" for removing images
Diffstat (limited to 'src/machine/machined-dbus.c')
-rw-r--r--src/machine/machined-dbus.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 66594ab0b1..9296377c6f 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -551,7 +551,7 @@ static int method_open_machine_login(sd_bus *bus, sd_bus_message *message, void
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_error_set_errno(error, r);
+ return r;
machine = hashmap_get(m->machines, name);
if (!machine)
@@ -560,6 +560,34 @@ static int method_open_machine_login(sd_bus *bus, sd_bus_message *message, void
return bus_machine_method_open_login(bus, message, machine, error);
}
+static int method_remove_image(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ _cleanup_(image_unrefp) Image* i = NULL;
+ const char *name;
+ int r;
+
+ assert(bus);
+ assert(message);
+
+ r = sd_bus_message_read(message, "s", &name);
+ if (r < 0)
+ return r;
+
+ if (!image_name_is_valid(name))
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
+
+ r = image_find(name, &i);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
+
+ r = image_remove(i);
+ if (r < 0)
+ return r;
+
+ return sd_bus_reply_method_return(message, NULL);
+}
+
const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("GetMachine", "s", "o", method_get_machine, SD_BUS_VTABLE_UNPRIVILEGED),
@@ -577,6 +605,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_METHOD("GetMachineOSRelease", "s", "a{ss}", method_get_machine_os_release, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("OpenMachinePTY", "s", "hs", method_open_machine_pty, 0),
SD_BUS_METHOD("OpenMachineLogin", "s", "hs", method_open_machine_login, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("RemoveImage", "s", NULL, method_remove_image, 0),
SD_BUS_SIGNAL("MachineNew", "so", 0),
SD_BUS_SIGNAL("MachineRemoved", "so", 0),
SD_BUS_VTABLE_END