mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 16:21:26 +03:00
portabled: use service_parse_argv/bus_add_implementation
Remove some boilerplate and allow introspection
This commit is contained in:
parent
5e8bc852d5
commit
3b91bae3ce
@ -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;
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user