X Tutup
Skip to content

Commit f6e9aa9

Browse files
committed
pid1: convert to the new scheme
In all the other cases, I think the code was clearer with the static table. Here, not so much. And because of the existing dump code, the vtables cannot be made static and need to remain exported. I still think it's worth to do the change to have the cmdline introspection, but I'm disappointed with how this came out.
1 parent 4faa530 commit f6e9aa9

File tree

16 files changed

+189
-119
lines changed

16 files changed

+189
-119
lines changed

src/core/automount.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ const UnitVTable automount_vtable = {
11331133

11341134
.reset_failed = automount_reset_failed,
11351135

1136-
.bus_vtable = bus_automount_vtable,
11371136
.bus_set_property = bus_automount_set_property,
11381137

11391138
.shutdown = automount_shutdown,

src/core/dbus-job.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,58 @@ const sd_bus_vtable bus_job_vtable[] = {
140140
SD_BUS_VTABLE_END
141141
};
142142

143+
static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
144+
Manager *m = userdata;
145+
Job *j;
146+
int r;
147+
148+
assert(bus);
149+
assert(path);
150+
assert(interface);
151+
assert(found);
152+
assert(m);
153+
154+
r = manager_get_job_from_dbus_path(m, path, &j);
155+
if (r < 0)
156+
return 0;
157+
158+
*found = j;
159+
return 1;
160+
}
161+
162+
static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
163+
_cleanup_strv_free_ char **l = NULL;
164+
Manager *m = userdata;
165+
unsigned k = 0;
166+
Iterator i;
167+
Job *j;
168+
169+
l = new0(char*, hashmap_size(m->jobs)+1);
170+
if (!l)
171+
return -ENOMEM;
172+
173+
HASHMAP_FOREACH(j, m->jobs, i) {
174+
l[k] = job_dbus_path(j);
175+
if (!l[k])
176+
return -ENOMEM;
177+
178+
k++;
179+
}
180+
181+
assert(hashmap_size(m->jobs) == k);
182+
183+
*nodes = TAKE_PTR(l);
184+
185+
return k;
186+
}
187+
188+
const BusObjectImplementation job_object = {
189+
"/org/freedesktop/systemd1/job",
190+
"org.freedesktop.systemd1.Job",
191+
.fallback_vtables = BUS_FALLBACK_VTABLES({bus_job_vtable, bus_job_find}),
192+
.node_enumerator = bus_job_enumerate,
193+
};
194+
143195
static int send_new_signal(sd_bus *bus, void *userdata) {
144196
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
145197
_cleanup_free_ char *p = NULL;

src/core/dbus-job.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#pragma once
33

44
#include "sd-bus.h"
5-
#include "sd-bus-vtable.h"
65

76
#include "unit.h"
7+
#include "bus-util.h"
88

99
extern const sd_bus_vtable bus_job_vtable[];
10+
extern const BusObjectImplementation job_object;
1011

1112
int bus_job_method_cancel(sd_bus_message *message, void *job, sd_bus_error *error);
1213
int bus_job_method_get_waiting_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error);

src/core/dbus-unit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#pragma once
33

44
#include "sd-bus.h"
5-
#include "sd-bus-vtable.h"
65

76
#include "unit.h"
87

src/core/dbus.c

Lines changed: 135 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,6 @@ static int mac_selinux_filter(sd_bus_message *message, void *userdata, sd_bus_er
274274
}
275275
#endif
276276

277-
static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
278-
Manager *m = userdata;
279-
Job *j;
280-
int r;
281-
282-
assert(bus);
283-
assert(path);
284-
assert(interface);
285-
assert(found);
286-
assert(m);
287-
288-
r = manager_get_job_from_dbus_path(m, path, &j);
289-
if (r < 0)
290-
return 0;
291-
292-
*found = j;
293-
return 1;
294-
}
295-
296277
static int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_bus_error *error) {
297278
Unit *u = NULL; /* just to appease gcc, initialization is not really necessary */
298279
int r;
@@ -472,32 +453,6 @@ static int bus_kill_context_find(sd_bus *bus, const char *path, const char *inte
472453
return 1;
473454
}
474455

475-
static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
476-
_cleanup_strv_free_ char **l = NULL;
477-
Manager *m = userdata;
478-
unsigned k = 0;
479-
Iterator i;
480-
Job *j;
481-
482-
l = new0(char*, hashmap_size(m->jobs)+1);
483-
if (!l)
484-
return -ENOMEM;
485-
486-
HASHMAP_FOREACH(j, m->jobs, i) {
487-
l[k] = job_dbus_path(j);
488-
if (!l[k])
489-
return -ENOMEM;
490-
491-
k++;
492-
}
493-
494-
assert(hashmap_size(m->jobs) == k);
495-
496-
*nodes = TAKE_PTR(l);
497-
498-
return k;
499-
}
500-
501456
static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
502457
_cleanup_strv_free_ char **l = NULL;
503458
Manager *m = userdata;
@@ -522,8 +477,139 @@ static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, cha
522477
return k;
523478
}
524479

480+
static const BusObjectImplementation unit_object = {
481+
"/org/freedesktop/systemd1/unit",
482+
"org.freedesktop.systemd1.Unit",
483+
.fallback_vtables = BUS_FALLBACK_VTABLES(
484+
{ bus_unit_vtable, bus_unit_find }),
485+
.node_enumerator = bus_unit_enumerate,
486+
};
487+
488+
static const BusObjectImplementation bus_automount_object = {
489+
"/org/freedesktop/systemd1/unit",
490+
"org.freedesktop.systemd1.Automount",
491+
.fallback_vtables = BUS_FALLBACK_VTABLES(
492+
{ bus_automount_vtable, bus_unit_interface_find }),
493+
};
494+
495+
static const BusObjectImplementation bus_device_object = {
496+
"/org/freedesktop/systemd1/unit",
497+
"org.freedesktop.systemd1.Device",
498+
.fallback_vtables = BUS_FALLBACK_VTABLES(
499+
{ bus_device_vtable, bus_unit_interface_find }),
500+
};
501+
502+
static const BusObjectImplementation bus_mount_object = {
503+
"/org/freedesktop/systemd1/unit",
504+
"org.freedesktop.systemd1.Mount",
505+
.fallback_vtables = BUS_FALLBACK_VTABLES(
506+
{ bus_mount_vtable, bus_unit_interface_find },
507+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
508+
{ bus_cgroup_vtable, bus_cgroup_context_find },
509+
{ bus_exec_vtable, bus_exec_context_find },
510+
{ bus_kill_vtable, bus_kill_context_find }),
511+
};
512+
513+
static const BusObjectImplementation bus_path_object = {
514+
"/org/freedesktop/systemd1/unit",
515+
"org.freedesktop.systemd1.Path",
516+
.fallback_vtables = BUS_FALLBACK_VTABLES(
517+
{ bus_path_vtable, bus_unit_interface_find }),
518+
};
519+
520+
static const BusObjectImplementation bus_scope_object = {
521+
"/org/freedesktop/systemd1/unit",
522+
"org.freedesktop.systemd1.Scope",
523+
.fallback_vtables = BUS_FALLBACK_VTABLES(
524+
{ bus_scope_vtable, bus_unit_interface_find },
525+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
526+
{ bus_cgroup_vtable, bus_cgroup_context_find },
527+
{ bus_kill_vtable, bus_kill_context_find }),
528+
};
529+
530+
static const BusObjectImplementation bus_service_object = {
531+
"/org/freedesktop/systemd1/unit",
532+
"org.freedesktop.systemd1.Service",
533+
.fallback_vtables = BUS_FALLBACK_VTABLES(
534+
{ bus_service_vtable, bus_unit_interface_find },
535+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
536+
{ bus_cgroup_vtable, bus_cgroup_context_find },
537+
{ bus_exec_vtable, bus_exec_context_find },
538+
{ bus_kill_vtable, bus_kill_context_find }),
539+
};
540+
541+
static const BusObjectImplementation bus_slice_object = {
542+
"/org/freedesktop/systemd1/unit",
543+
"org.freedesktop.systemd1.Slice",
544+
.fallback_vtables = BUS_FALLBACK_VTABLES(
545+
{ bus_slice_vtable, bus_unit_interface_find },
546+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
547+
{ bus_cgroup_vtable, bus_cgroup_context_find }),
548+
};
549+
550+
static const BusObjectImplementation bus_socket_object = {
551+
"/org/freedesktop/systemd1/unit",
552+
"org.freedesktop.systemd1.Socket",
553+
.fallback_vtables = BUS_FALLBACK_VTABLES(
554+
{ bus_socket_vtable, bus_unit_interface_find },
555+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
556+
{ bus_cgroup_vtable, bus_cgroup_context_find },
557+
{ bus_exec_vtable, bus_exec_context_find },
558+
{ bus_kill_vtable, bus_kill_context_find }),
559+
};
560+
561+
static const BusObjectImplementation bus_swap_object = {
562+
"/org/freedesktop/systemd1/unit",
563+
"org.freedesktop.systemd1.Swap",
564+
.fallback_vtables = BUS_FALLBACK_VTABLES(
565+
{ bus_swap_vtable, bus_unit_interface_find },
566+
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
567+
{ bus_cgroup_vtable, bus_cgroup_context_find },
568+
{ bus_exec_vtable, bus_exec_context_find },
569+
{ bus_kill_vtable, bus_kill_context_find }),
570+
};
571+
572+
static const BusObjectImplementation bus_target_object = {
573+
"/org/freedesktop/systemd1/unit",
574+
"org.freedesktop.systemd1.Target",
575+
.fallback_vtables = BUS_FALLBACK_VTABLES(
576+
{ bus_target_vtable, bus_unit_interface_find }),
577+
};
578+
579+
static const BusObjectImplementation bus_timer_object = {
580+
"/org/freedesktop/systemd1/unit",
581+
"org.freedesktop.systemd1.Timer",
582+
.fallback_vtables = BUS_FALLBACK_VTABLES(
583+
{ bus_timer_vtable, bus_unit_interface_find }),
584+
};
585+
586+
static const BusObjectImplementation bus_manager_object = {
587+
"/org/freedesktop/systemd1",
588+
"org.freedesktop.systemd1.Manager",
589+
.vtables = BUS_VTABLES(bus_manager_vtable),
590+
.children = BUS_IMPLEMENTATIONS(
591+
&job_object,
592+
&unit_object,
593+
&bus_automount_object,
594+
&bus_device_object,
595+
&bus_mount_object,
596+
&bus_path_object,
597+
&bus_scope_object,
598+
&bus_service_object,
599+
&bus_slice_object,
600+
&bus_socket_object,
601+
&bus_swap_object,
602+
&bus_target_object,
603+
&bus_timer_object),
604+
};
605+
606+
static const BusObjectImplementation manager_log_control_object = {
607+
"/org/freedesktop/LogControl1",
608+
"org.freedesktop.LogControl1",
609+
.vtables = BUS_VTABLES(bus_manager_log_control_vtable),
610+
};
611+
525612
static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
526-
UnitType t;
527613
int r;
528614

529615
assert(m);
@@ -535,63 +621,11 @@ static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
535621
return log_error_errno(r, "Failed to add SELinux access filter: %m");
536622
#endif
537623

538-
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", bus_manager_vtable, m);
539-
if (r < 0)
540-
return log_error_errno(r, "Failed to register Manager vtable: %m");
541-
542-
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/LogControl1", "org.freedesktop.LogControl1", bus_manager_log_control_vtable, m);
543-
if (r < 0)
544-
return log_error_errno(r, "Failed to register service API vtable: %m");
545-
546-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/job", "org.freedesktop.systemd1.Job", bus_job_vtable, bus_job_find, m);
547-
if (r < 0)
548-
return log_error_errno(r, "Failed to register Job vtable: %m");
549-
550-
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/job", bus_job_enumerate, m);
551-
if (r < 0)
552-
return log_error_errno(r, "Failed to add job enumerator: %m");
553-
554-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", "org.freedesktop.systemd1.Unit", bus_unit_vtable, bus_unit_find, m);
624+
r = bus_add_implementation(bus, &bus_manager_object, m);
555625
if (r < 0)
556-
return log_error_errno(r, "Failed to register Unit vtable: %m");
557-
558-
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/unit", bus_unit_enumerate, m);
559-
if (r < 0)
560-
return log_error_errno(r, "Failed to add job enumerator: %m");
561-
562-
for (t = 0; t < _UNIT_TYPE_MAX; t++) {
563-
const char *interface;
564-
565-
assert_se(interface = unit_dbus_interface_from_type(t));
566-
567-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, unit_vtable[t]->bus_vtable, bus_unit_interface_find, m);
568-
if (r < 0)
569-
return log_error_errno(r, "Failed to register type specific vtable for %s: %m", interface);
570-
571-
if (unit_vtable[t]->cgroup_context_offset > 0) {
572-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_unit_cgroup_vtable, bus_unit_cgroup_find, m);
573-
if (r < 0)
574-
return log_error_errno(r, "Failed to register control group unit vtable for %s: %m", interface);
575-
576-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_cgroup_vtable, bus_cgroup_context_find, m);
577-
if (r < 0)
578-
return log_error_errno(r, "Failed to register control group vtable for %s: %m", interface);
579-
}
580-
581-
if (unit_vtable[t]->exec_context_offset > 0) {
582-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_exec_vtable, bus_exec_context_find, m);
583-
if (r < 0)
584-
return log_error_errno(r, "Failed to register execute vtable for %s: %m", interface);
585-
}
586-
587-
if (unit_vtable[t]->kill_context_offset > 0) {
588-
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_kill_vtable, bus_kill_context_find, m);
589-
if (r < 0)
590-
return log_error_errno(r, "Failed to register kill vtable for %s: %m", interface);
591-
}
592-
}
626+
return r;
593627

594-
return 0;
628+
return bus_add_implementation(bus, &manager_log_control_object, m);
595629
}
596630

597631
static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {

src/core/device.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,6 @@ const UnitVTable device_vtable = {
10811081
.active_state = device_active_state,
10821082
.sub_state_to_string = device_sub_state_to_string,
10831083

1084-
.bus_vtable = bus_device_vtable,
1085-
10861084
.following = device_following,
10871085
.following_set = device_following_set,
10881086

src/core/mount.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,6 @@ const UnitVTable mount_vtable = {
21102110

21112111
.control_pid = mount_control_pid,
21122112

2113-
.bus_vtable = bus_mount_vtable,
21142113
.bus_set_property = bus_mount_set_property,
21152114
.bus_commit_properties = bus_mount_commit_properties,
21162115

src/core/path.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,5 @@ const UnitVTable path_vtable = {
830830

831831
.reset_failed = path_reset_failed,
832832

833-
.bus_vtable = bus_path_vtable,
834833
.bus_set_property = bus_path_set_property,
835834
};

src/core/scope.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ const UnitVTable scope_vtable = {
652652

653653
.notify_cgroup_empty = scope_notify_cgroup_empty_event,
654654

655-
.bus_vtable = bus_scope_vtable,
656655
.bus_set_property = bus_scope_set_property,
657656
.bus_commit_properties = bus_scope_commit_properties,
658657

src/core/service.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4484,7 +4484,6 @@ const UnitVTable service_vtable = {
44844484

44854485
.bus_name_owner_change = service_bus_name_owner_change,
44864486

4487-
.bus_vtable = bus_service_vtable,
44884487
.bus_set_property = bus_service_set_property,
44894488
.bus_commit_properties = bus_service_commit_properties,
44904489

0 commit comments

Comments
 (0)
X Tutup