mirror of
https://github.com/systemd/systemd.git
synced 2025-02-14 05:57:40 +03:00
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.
This commit is contained in:
parent
4faa530cf6
commit
f6e9aa9e45
@ -1133,7 +1133,6 @@ const UnitVTable automount_vtable = {
|
||||
|
||||
.reset_failed = automount_reset_failed,
|
||||
|
||||
.bus_vtable = bus_automount_vtable,
|
||||
.bus_set_property = bus_automount_set_property,
|
||||
|
||||
.shutdown = automount_shutdown,
|
||||
|
@ -140,6 +140,58 @@ const sd_bus_vtable bus_job_vtable[] = {
|
||||
SD_BUS_VTABLE_END
|
||||
};
|
||||
|
||||
static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
|
||||
Manager *m = userdata;
|
||||
Job *j;
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
assert(path);
|
||||
assert(interface);
|
||||
assert(found);
|
||||
assert(m);
|
||||
|
||||
r = manager_get_job_from_dbus_path(m, path, &j);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
*found = j;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
Manager *m = userdata;
|
||||
unsigned k = 0;
|
||||
Iterator i;
|
||||
Job *j;
|
||||
|
||||
l = new0(char*, hashmap_size(m->jobs)+1);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
HASHMAP_FOREACH(j, m->jobs, i) {
|
||||
l[k] = job_dbus_path(j);
|
||||
if (!l[k])
|
||||
return -ENOMEM;
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
assert(hashmap_size(m->jobs) == k);
|
||||
|
||||
*nodes = TAKE_PTR(l);
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
const BusObjectImplementation job_object = {
|
||||
"/org/freedesktop/systemd1/job",
|
||||
"org.freedesktop.systemd1.Job",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES({bus_job_vtable, bus_job_find}),
|
||||
.node_enumerator = bus_job_enumerate,
|
||||
};
|
||||
|
||||
static int send_new_signal(sd_bus *bus, void *userdata) {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
@ -2,11 +2,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-bus-vtable.h"
|
||||
|
||||
#include "unit.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
extern const sd_bus_vtable bus_job_vtable[];
|
||||
extern const BusObjectImplementation job_object;
|
||||
|
||||
int bus_job_method_cancel(sd_bus_message *message, void *job, sd_bus_error *error);
|
||||
int bus_job_method_get_waiting_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
|
@ -2,7 +2,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-bus-vtable.h"
|
||||
|
||||
#include "unit.h"
|
||||
|
||||
|
236
src/core/dbus.c
236
src/core/dbus.c
@ -274,25 +274,6 @@ static int mac_selinux_filter(sd_bus_message *message, void *userdata, sd_bus_er
|
||||
}
|
||||
#endif
|
||||
|
||||
static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
|
||||
Manager *m = userdata;
|
||||
Job *j;
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
assert(path);
|
||||
assert(interface);
|
||||
assert(found);
|
||||
assert(m);
|
||||
|
||||
r = manager_get_job_from_dbus_path(m, path, &j);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
*found = j;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_bus_error *error) {
|
||||
Unit *u = NULL; /* just to appease gcc, initialization is not really necessary */
|
||||
int r;
|
||||
@ -472,32 +453,6 @@ static int bus_kill_context_find(sd_bus *bus, const char *path, const char *inte
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
Manager *m = userdata;
|
||||
unsigned k = 0;
|
||||
Iterator i;
|
||||
Job *j;
|
||||
|
||||
l = new0(char*, hashmap_size(m->jobs)+1);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
HASHMAP_FOREACH(j, m->jobs, i) {
|
||||
l[k] = job_dbus_path(j);
|
||||
if (!l[k])
|
||||
return -ENOMEM;
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
assert(hashmap_size(m->jobs) == k);
|
||||
|
||||
*nodes = TAKE_PTR(l);
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
Manager *m = userdata;
|
||||
@ -522,8 +477,139 @@ static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, cha
|
||||
return k;
|
||||
}
|
||||
|
||||
static const BusObjectImplementation unit_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Unit",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_unit_vtable, bus_unit_find }),
|
||||
.node_enumerator = bus_unit_enumerate,
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_automount_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Automount",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_automount_vtable, bus_unit_interface_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_device_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Device",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_device_vtable, bus_unit_interface_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_mount_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Mount",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_mount_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find },
|
||||
{ bus_exec_vtable, bus_exec_context_find },
|
||||
{ bus_kill_vtable, bus_kill_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_path_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Path",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_path_vtable, bus_unit_interface_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_scope_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Scope",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_scope_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find },
|
||||
{ bus_kill_vtable, bus_kill_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_service_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Service",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_service_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find },
|
||||
{ bus_exec_vtable, bus_exec_context_find },
|
||||
{ bus_kill_vtable, bus_kill_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_slice_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Slice",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_slice_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_socket_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Socket",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_socket_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find },
|
||||
{ bus_exec_vtable, bus_exec_context_find },
|
||||
{ bus_kill_vtable, bus_kill_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_swap_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Swap",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_swap_vtable, bus_unit_interface_find },
|
||||
{ bus_unit_cgroup_vtable, bus_unit_cgroup_find },
|
||||
{ bus_cgroup_vtable, bus_cgroup_context_find },
|
||||
{ bus_exec_vtable, bus_exec_context_find },
|
||||
{ bus_kill_vtable, bus_kill_context_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_target_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Target",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_target_vtable, bus_unit_interface_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_timer_object = {
|
||||
"/org/freedesktop/systemd1/unit",
|
||||
"org.freedesktop.systemd1.Timer",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES(
|
||||
{ bus_timer_vtable, bus_unit_interface_find }),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation bus_manager_object = {
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
.vtables = BUS_VTABLES(bus_manager_vtable),
|
||||
.children = BUS_IMPLEMENTATIONS(
|
||||
&job_object,
|
||||
&unit_object,
|
||||
&bus_automount_object,
|
||||
&bus_device_object,
|
||||
&bus_mount_object,
|
||||
&bus_path_object,
|
||||
&bus_scope_object,
|
||||
&bus_service_object,
|
||||
&bus_slice_object,
|
||||
&bus_socket_object,
|
||||
&bus_swap_object,
|
||||
&bus_target_object,
|
||||
&bus_timer_object),
|
||||
};
|
||||
|
||||
static const BusObjectImplementation manager_log_control_object = {
|
||||
"/org/freedesktop/LogControl1",
|
||||
"org.freedesktop.LogControl1",
|
||||
.vtables = BUS_VTABLES(bus_manager_log_control_vtable),
|
||||
};
|
||||
|
||||
static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
|
||||
UnitType t;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -535,63 +621,11 @@ static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
|
||||
return log_error_errno(r, "Failed to add SELinux access filter: %m");
|
||||
#endif
|
||||
|
||||
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", bus_manager_vtable, m);
|
||||
r = bus_add_implementation(bus, &bus_manager_object, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register Manager vtable: %m");
|
||||
return r;
|
||||
|
||||
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/LogControl1", "org.freedesktop.LogControl1", bus_manager_log_control_vtable, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register service API vtable: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/job", "org.freedesktop.systemd1.Job", bus_job_vtable, bus_job_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register Job vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/job", bus_job_enumerate, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add job enumerator: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", "org.freedesktop.systemd1.Unit", bus_unit_vtable, bus_unit_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register Unit vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/unit", bus_unit_enumerate, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add job enumerator: %m");
|
||||
|
||||
for (t = 0; t < _UNIT_TYPE_MAX; t++) {
|
||||
const char *interface;
|
||||
|
||||
assert_se(interface = unit_dbus_interface_from_type(t));
|
||||
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, unit_vtable[t]->bus_vtable, bus_unit_interface_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register type specific vtable for %s: %m", interface);
|
||||
|
||||
if (unit_vtable[t]->cgroup_context_offset > 0) {
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_unit_cgroup_vtable, bus_unit_cgroup_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register control group unit vtable for %s: %m", interface);
|
||||
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_cgroup_vtable, bus_cgroup_context_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register control group vtable for %s: %m", interface);
|
||||
}
|
||||
|
||||
if (unit_vtable[t]->exec_context_offset > 0) {
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_exec_vtable, bus_exec_context_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register execute vtable for %s: %m", interface);
|
||||
}
|
||||
|
||||
if (unit_vtable[t]->kill_context_offset > 0) {
|
||||
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", interface, bus_kill_vtable, bus_kill_context_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register kill vtable for %s: %m", interface);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return bus_add_implementation(bus, &manager_log_control_object, m);
|
||||
}
|
||||
|
||||
static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
|
||||
|
@ -1081,8 +1081,6 @@ const UnitVTable device_vtable = {
|
||||
.active_state = device_active_state,
|
||||
.sub_state_to_string = device_sub_state_to_string,
|
||||
|
||||
.bus_vtable = bus_device_vtable,
|
||||
|
||||
.following = device_following,
|
||||
.following_set = device_following_set,
|
||||
|
||||
|
@ -2110,7 +2110,6 @@ const UnitVTable mount_vtable = {
|
||||
|
||||
.control_pid = mount_control_pid,
|
||||
|
||||
.bus_vtable = bus_mount_vtable,
|
||||
.bus_set_property = bus_mount_set_property,
|
||||
.bus_commit_properties = bus_mount_commit_properties,
|
||||
|
||||
|
@ -830,6 +830,5 @@ const UnitVTable path_vtable = {
|
||||
|
||||
.reset_failed = path_reset_failed,
|
||||
|
||||
.bus_vtable = bus_path_vtable,
|
||||
.bus_set_property = bus_path_set_property,
|
||||
};
|
||||
|
@ -652,7 +652,6 @@ const UnitVTable scope_vtable = {
|
||||
|
||||
.notify_cgroup_empty = scope_notify_cgroup_empty_event,
|
||||
|
||||
.bus_vtable = bus_scope_vtable,
|
||||
.bus_set_property = bus_scope_set_property,
|
||||
.bus_commit_properties = bus_scope_commit_properties,
|
||||
|
||||
|
@ -4484,7 +4484,6 @@ const UnitVTable service_vtable = {
|
||||
|
||||
.bus_name_owner_change = service_bus_name_owner_change,
|
||||
|
||||
.bus_vtable = bus_service_vtable,
|
||||
.bus_set_property = bus_service_set_property,
|
||||
.bus_commit_properties = bus_service_commit_properties,
|
||||
|
||||
|
@ -458,7 +458,6 @@ const UnitVTable slice_vtable = {
|
||||
.active_state = slice_active_state,
|
||||
.sub_state_to_string = slice_sub_state_to_string,
|
||||
|
||||
.bus_vtable = bus_slice_vtable,
|
||||
.bus_set_property = bus_slice_set_property,
|
||||
.bus_commit_properties = bus_slice_commit_properties,
|
||||
|
||||
|
@ -3462,7 +3462,6 @@ const UnitVTable socket_vtable = {
|
||||
|
||||
.control_pid = socket_control_pid,
|
||||
|
||||
.bus_vtable = bus_socket_vtable,
|
||||
.bus_set_property = bus_socket_set_property,
|
||||
.bus_commit_properties = bus_socket_commit_properties,
|
||||
|
||||
|
@ -1655,7 +1655,6 @@ const UnitVTable swap_vtable = {
|
||||
|
||||
.control_pid = swap_control_pid,
|
||||
|
||||
.bus_vtable = bus_swap_vtable,
|
||||
.bus_set_property = bus_swap_set_property,
|
||||
.bus_commit_properties = bus_swap_commit_properties,
|
||||
|
||||
|
@ -207,8 +207,6 @@ const UnitVTable target_vtable = {
|
||||
.active_state = target_active_state,
|
||||
.sub_state_to_string = target_sub_state_to_string,
|
||||
|
||||
.bus_vtable = bus_target_vtable,
|
||||
|
||||
.status_message_formats = {
|
||||
.finished_start_job = {
|
||||
[JOB_DONE] = "Reached target %s.",
|
||||
|
@ -925,6 +925,5 @@ const UnitVTable timer_vtable = {
|
||||
.time_change = timer_time_change,
|
||||
.timezone_change = timer_timezone_change,
|
||||
|
||||
.bus_vtable = bus_timer_vtable,
|
||||
.bus_set_property = bus_timer_set_property,
|
||||
};
|
||||
|
@ -600,9 +600,6 @@ typedef struct UnitVTable {
|
||||
* of this type will immediately fail. */
|
||||
bool (*supported)(void);
|
||||
|
||||
/* The bus vtable */
|
||||
const sd_bus_vtable *bus_vtable;
|
||||
|
||||
/* The strings to print in status messages */
|
||||
UnitStatusMessageFormats status_message_formats;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user