From: Zbigniew Jędrzejewski-Szmek Date: Thu, 15 Oct 2020 13:03:49 +0000 (+0200) Subject: oomd: add names to dbus parameters and implement --bus-introspection X-Git-Tag: v247-rc1~64^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9a00f5a3bccf8b43e0d7672185da8df5ff0fdfa;p=thirdparty%2Fsystemd.git oomd: add names to dbus parameters and implement --bus-introspection --- diff --git a/src/oom/oomd-manager-bus.c b/src/oom/oomd-manager-bus.c index 67c5fbf92f1..0f39a60d9ec 100644 --- a/src/oom/oomd-manager-bus.c +++ b/src/oom/oomd-manager-bus.c @@ -29,8 +29,19 @@ static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus return sd_bus_reply_method_return(message, "h", fd); } -const sd_bus_vtable manager_vtable[] = { +static const sd_bus_vtable manager_vtable[] = { SD_BUS_VTABLE_START(0), - SD_BUS_METHOD("DumpByFileDescriptor", NULL, "h", bus_method_dump_by_fd, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD_WITH_NAMES("DumpByFileDescriptor", + NULL,, + "h", + SD_BUS_PARAM(fd), + bus_method_dump_by_fd, + SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; + +const BusObjectImplementation manager_object = { + "/org/freedesktop/oom1", + "org.freedesktop.oom1.Manager", + .vtables = BUS_VTABLES(manager_vtable), +}; diff --git a/src/oom/oomd-manager-bus.h b/src/oom/oomd-manager-bus.h index 60ccf3b3739..6dd576d5af5 100644 --- a/src/oom/oomd-manager-bus.h +++ b/src/oom/oomd-manager-bus.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -#include "sd-bus.h" +#include "bus-object.h" typedef struct Manager Manager; -extern const sd_bus_vtable manager_vtable[]; +extern const BusObjectImplementation manager_object; diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 49b57a86a4f..9eb8ab9f5a4 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -455,9 +455,9 @@ static int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to connect to bus: %m"); - r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/oom1", "org.freedesktop.oom1.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"); + return r; r = bus_log_control_api_register(m->bus); if (r < 0) diff --git a/src/oom/oomd.c b/src/oom/oomd.c index 43e1feaa205..2c0031aeace 100644 --- a/src/oom/oomd.c +++ b/src/oom/oomd.c @@ -2,12 +2,15 @@ #include +#include "bus-log-control-api.h" +#include "bus-object.h" #include "cgroup-util.h" #include "conf-parser.h" #include "daemon-util.h" #include "log.h" #include "main-func.h" #include "oomd-manager.h" +#include "oomd-manager-bus.h" #include "parse-util.h" #include "pretty-print.c" #include "psi-util.h" @@ -47,6 +50,7 @@ static int help(void) { " -h --help Show this help\n" " --version Show package version\n" " --dry-run Only print destructive actions instead of doing them\n" + " --bus-introspect=PATH Write D-Bus XML introspection data\n" "\nSee the %s for details.\n" , program_invocation_short_name , link @@ -59,12 +63,14 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_DRY_RUN, + ARG_BUS_INTROSPECT, }; static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, { "dry-run", no_argument, NULL, ARG_DRY_RUN }, + { "bus-introspect", required_argument, NULL, ARG_BUS_INTROSPECT }, {} }; @@ -87,6 +93,13 @@ static int parse_argv(int argc, char *argv[]) { arg_dry_run = true; break; + case ARG_BUS_INTROSPECT: + return bus_introspect_implementations( + stdout, + optarg, + BUS_IMPLEMENTATIONS(&manager_object, + &log_control_object)); + case '?': return -EINVAL;