diff --git a/src/portable/portabled-bus.c b/src/portable/portabled-bus.c index c31ab092b47..e57e5e8d3e6 100644 --- a/src/portable/portabled-bus.c +++ b/src/portable/portabled-bus.c @@ -3,6 +3,7 @@ #include "alloc-util.h" #include "btrfs-util.h" #include "bus-common-errors.h" +#include "bus-object.h" #include "bus-polkit.h" #include "discover-image.h" #include "fd-util.h" @@ -374,6 +375,13 @@ const sd_bus_vtable manager_vtable[] = { SD_BUS_VTABLE_END }; +const BusObjectImplementation manager_object = { + "/org/freedesktop/portable1", + "org.freedesktop.portable1.Manager", + .vtables = BUS_VTABLES(manager_vtable), + .children = BUS_IMPLEMENTATIONS(&image_object), +}; + static int reply_portable_compose_message(sd_bus_message *reply, const PortableChange *changes, size_t n_changes) { size_t i; int r; diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c index 630648ba3c2..d7a44110c9f 100644 --- a/src/portable/portabled-image-bus.c +++ b/src/portable/portabled-image-bus.c @@ -9,6 +9,7 @@ #include "bus-common-errors.h" #include "bus-get-properties.h" #include "bus-label.h" +#include "bus-object.h" #include "bus-polkit.h" #include "bus-util.h" #include "discover-image.h" @@ -919,3 +920,10 @@ int bus_image_node_enumerator(sd_bus *bus, const char *path, void *userdata, cha return 1; } + +const BusObjectImplementation image_object = { + "/org/freedesktop/portable1/image", + "org.freedesktop.portable1.Image", + .fallback_vtables = BUS_FALLBACK_VTABLES({image_vtable, bus_image_object_find}), + .node_enumerator = bus_image_node_enumerator, +}; diff --git a/src/portable/portabled-image-bus.h b/src/portable/portabled-image-bus.h index e5faf43d907..763a0890f9a 100644 --- a/src/portable/portabled-image-bus.h +++ b/src/portable/portabled-image-bus.h @@ -15,6 +15,7 @@ int bus_image_common_mark_read_only(Manager *m, sd_bus_message *message, const c int bus_image_common_set_limit(Manager *m, sd_bus_message *message, const char *name_or_path, Image *image, sd_bus_error *error); extern const sd_bus_vtable image_vtable[]; +extern const BusObjectImplementation image_object; int bus_image_path(Image *image, char **ret); diff --git a/src/portable/portabled.c b/src/portable/portabled.c index 8a17f09365a..3c8e20e0f36 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -15,6 +15,7 @@ #include "portabled-image-bus.h" #include "portabled.h" #include "process-util.h" +#include "service-util.h" #include "signal-util.h" static Manager* manager_unref(Manager *m); @@ -73,17 +74,9 @@ static int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to connect to system bus: %m"); - r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/portable1", "org.freedesktop.portable1.Manager", manager_vtable, m); + r = bus_add_implementation(m->bus, &manager_object, m); if (r < 0) - return log_error_errno(r, "Failed to add manager object vtable: %m"); - - r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/portable1/image", "org.freedesktop.portable1.Image", image_vtable, bus_image_object_find, m); - if (r < 0) - return log_error_errno(r, "Failed to add image object vtable: %m"); - - r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/portable1/image", bus_image_node_enumerator, m); - if (r < 0) - return log_error_errno(r, "Failed to add image enumerator: %m"); + return r; r = bus_log_control_api_register(m->bus); if (r < 0) @@ -137,6 +130,14 @@ static int run(int argc, char *argv[]) { log_setup(); + r = service_parse_argv("systemd-portabled.service", + "Manage registrations of portable images.", + BUS_IMPLEMENTATIONS(&manager_object, + &log_control_object), + argc, argv); + if (r <= 0) + return r; + umask(0022); if (argc != 1) diff --git a/src/portable/portabled.h b/src/portable/portabled.h index 03a99969162..71ec41d4f1b 100644 --- a/src/portable/portabled.h +++ b/src/portable/portabled.h @@ -4,6 +4,7 @@ #include "sd-bus.h" #include "sd-event.h" +#include "bus-object.h" #include "hashmap.h" #include "list.h" @@ -23,3 +24,5 @@ struct Manager { LIST_HEAD(Operation, operations); unsigned n_operations; }; + +extern const BusObjectImplementation manager_object;