mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
core: add --dump-bus-properties option to systemd
If systemd is invoked with this option, this dumps all bus properties. This may be useful for shell completion for `systemctl --property`.
This commit is contained in:
parent
19e69a9c7a
commit
bbc1acaba0
@ -96,6 +96,13 @@
|
||||
outputs a terse but complete list of configuration items
|
||||
understood in unit definition files.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--dump-bus-properties</option></term>
|
||||
|
||||
<listitem><para>Dump exposed bus properties. This outputs
|
||||
a terse but complete list of properties exposed to dbus.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--unit=</option></term>
|
||||
|
||||
|
@ -16,11 +16,22 @@
|
||||
#include "bus-error.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
#include "dbus-automount.h"
|
||||
#include "dbus-cgroup.h"
|
||||
#include "dbus-device.h"
|
||||
#include "dbus-execute.h"
|
||||
#include "dbus-job.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-manager.h"
|
||||
#include "dbus-mount.h"
|
||||
#include "dbus-path.h"
|
||||
#include "dbus-scope.h"
|
||||
#include "dbus-service.h"
|
||||
#include "dbus-slice.h"
|
||||
#include "dbus-socket.h"
|
||||
#include "dbus-swap.h"
|
||||
#include "dbus-target.h"
|
||||
#include "dbus-timer.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "dbus.h"
|
||||
#include "fd-util.h"
|
||||
@ -1292,3 +1303,38 @@ uint64_t manager_bus_n_queued_write(Manager *m) {
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static void vtable_dump_bus_properties(FILE *f, const sd_bus_vtable *table) {
|
||||
const sd_bus_vtable *i;
|
||||
|
||||
for (i = table; i->type != _SD_BUS_VTABLE_END; i++) {
|
||||
if (!IN_SET(i->type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY) ||
|
||||
(i->flags & (SD_BUS_VTABLE_DEPRECATED | SD_BUS_VTABLE_HIDDEN)) != 0)
|
||||
continue;
|
||||
|
||||
fprintf(f, "%s\n", i->x.property.member);
|
||||
}
|
||||
}
|
||||
|
||||
void dump_bus_properties(FILE *f) {
|
||||
assert(f);
|
||||
|
||||
vtable_dump_bus_properties(f, bus_automount_vtable);
|
||||
vtable_dump_bus_properties(f, bus_cgroup_vtable);
|
||||
vtable_dump_bus_properties(f, bus_device_vtable);
|
||||
vtable_dump_bus_properties(f, bus_exec_vtable);
|
||||
vtable_dump_bus_properties(f, bus_job_vtable);
|
||||
vtable_dump_bus_properties(f, bus_kill_vtable);
|
||||
vtable_dump_bus_properties(f, bus_manager_vtable);
|
||||
vtable_dump_bus_properties(f, bus_mount_vtable);
|
||||
vtable_dump_bus_properties(f, bus_path_vtable);
|
||||
vtable_dump_bus_properties(f, bus_scope_vtable);
|
||||
vtable_dump_bus_properties(f, bus_service_vtable);
|
||||
vtable_dump_bus_properties(f, bus_slice_vtable);
|
||||
vtable_dump_bus_properties(f, bus_socket_vtable);
|
||||
vtable_dump_bus_properties(f, bus_swap_vtable);
|
||||
vtable_dump_bus_properties(f, bus_target_vtable);
|
||||
vtable_dump_bus_properties(f, bus_timer_vtable);
|
||||
vtable_dump_bus_properties(f, bus_unit_vtable);
|
||||
vtable_dump_bus_properties(f, bus_unit_cgroup_vtable);
|
||||
}
|
||||
|
@ -39,3 +39,5 @@ int bus_verify_set_environment_async(Manager *m, sd_bus_message *call, sd_bus_er
|
||||
int bus_forward_agent_released(Manager *m, const char *path);
|
||||
|
||||
uint64_t manager_bus_n_queued_write(Manager *m);
|
||||
|
||||
void dump_bus_properties(FILE *f);
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "clock-util.h"
|
||||
#include "conf-parser.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "dbus.h"
|
||||
#include "dbus-manager.h"
|
||||
#include "def.h"
|
||||
#include "emergency-action.h"
|
||||
@ -89,7 +90,8 @@ static enum {
|
||||
ACTION_HELP,
|
||||
ACTION_VERSION,
|
||||
ACTION_TEST,
|
||||
ACTION_DUMP_CONFIGURATION_ITEMS
|
||||
ACTION_DUMP_CONFIGURATION_ITEMS,
|
||||
ACTION_DUMP_BUS_PROPERTIES,
|
||||
} arg_action = ACTION_RUN;
|
||||
static char *arg_default_unit = NULL;
|
||||
static bool arg_system = false;
|
||||
@ -775,6 +777,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
ARG_NO_PAGER,
|
||||
ARG_VERSION,
|
||||
ARG_DUMP_CONFIGURATION_ITEMS,
|
||||
ARG_DUMP_BUS_PROPERTIES,
|
||||
ARG_DUMP_CORE,
|
||||
ARG_CRASH_CHVT,
|
||||
ARG_CRASH_SHELL,
|
||||
@ -802,6 +805,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, ARG_VERSION },
|
||||
{ "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
|
||||
{ "dump-bus-properties", no_argument, NULL, ARG_DUMP_BUS_PROPERTIES },
|
||||
{ "dump-core", optional_argument, NULL, ARG_DUMP_CORE },
|
||||
{ "crash-chvt", required_argument, NULL, ARG_CRASH_CHVT },
|
||||
{ "crash-shell", optional_argument, NULL, ARG_CRASH_SHELL },
|
||||
@ -921,6 +925,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_action = ACTION_DUMP_CONFIGURATION_ITEMS;
|
||||
break;
|
||||
|
||||
case ARG_DUMP_BUS_PROPERTIES:
|
||||
arg_action = ACTION_DUMP_BUS_PROPERTIES;
|
||||
break;
|
||||
|
||||
case ARG_DUMP_CORE:
|
||||
if (!optarg)
|
||||
arg_dump_core = true;
|
||||
@ -1064,6 +1072,7 @@ static int help(void) {
|
||||
" --test Determine startup sequence, dump it and exit\n"
|
||||
" --no-pager Do not pipe output into a pager\n"
|
||||
" --dump-configuration-items Dump understood unit configuration items\n"
|
||||
" --dump-bus-properties Dump exposed bus properties\n"
|
||||
" --unit=UNIT Set default unit\n"
|
||||
" --system Run a system instance, even if PID != 1\n"
|
||||
" --user Run a user instance\n"
|
||||
@ -2302,7 +2311,7 @@ int main(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
if (IN_SET(arg_action, ACTION_TEST, ACTION_HELP, ACTION_DUMP_CONFIGURATION_ITEMS))
|
||||
if (IN_SET(arg_action, ACTION_TEST, ACTION_HELP, ACTION_DUMP_CONFIGURATION_ITEMS, ACTION_DUMP_BUS_PROPERTIES))
|
||||
(void) pager_open(arg_no_pager, false);
|
||||
|
||||
if (arg_action != ACTION_RUN)
|
||||
@ -2318,6 +2327,10 @@ int main(int argc, char *argv[]) {
|
||||
unit_dump_config_items(stdout);
|
||||
retval = EXIT_SUCCESS;
|
||||
goto finish;
|
||||
} else if (arg_action == ACTION_DUMP_BUS_PROPERTIES) {
|
||||
dump_bus_properties(stdout);
|
||||
retval = EXIT_SUCCESS;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
assert_se(IN_SET(arg_action, ACTION_RUN, ACTION_TEST));
|
||||
|
Loading…
Reference in New Issue
Block a user