]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portabled: use service_parse_argv/bus_add_implementation
authorLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 12 Feb 2021 16:35:20 +0000 (16:35 +0000)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Mon, 15 Feb 2021 21:20:14 +0000 (21:20 +0000)
Remove some boilerplate and allow introspection

src/portable/portabled-bus.c
src/portable/portabled-image-bus.c
src/portable/portabled-image-bus.h
src/portable/portabled.c
src/portable/portabled.h

index c31ab092b47361ca8f17263cb65edb7f55c59819..e57e5e8d3e6df449d01f216d30b2160076634070 100644 (file)
@@ -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;
index 630648ba3c23399109a4e6c68854ffe365a2f233..d7a44110c9f9cc0b5ff747c3ebba7fbee507f3be 100644 (file)
@@ -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,
+};
index e5faf43d907213e0cdb6aa28dd42f368592ea8df..763a0890f9adb1ea143d5bd6546919e92be92c0f 100644 (file)
@@ -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);
 
index 8a17f09365abeee92770857fbe1ad33a9b4bcc57..3c8e20e0f36977e702a243cd147ef0930170b80c 100644 (file)
@@ -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)
index 03a99969162bf5d7ebcff0c8489fbc1e69ccec88..71ec41d4f1b67dc17983b66f38732b251269630a 100644 (file)
@@ -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;