]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oomd: add names to dbus parameters and implement --bus-introspection
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Oct 2020 13:03:49 +0000 (15:03 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Oct 2020 13:03:49 +0000 (15:03 +0200)
src/oom/oomd-manager-bus.c
src/oom/oomd-manager-bus.h
src/oom/oomd-manager.c
src/oom/oomd.c

index 67c5fbf92f12af2bdc972c1a85fbd0169d9ef537..0f39a60d9ec3f356ad7628cde7ee65ab720cb41c 100644 (file)
@@ -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),
+};
index 60ccf3b3739d5fb6a07dadaf51fdde96e029c4f1..6dd576d5af507f7f7df796c25b2df270af12465d 100644 (file)
@@ -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;
index 49b57a86a4f4c62af565372c0991249b94edc07b..9eb8ab9f5a413aebe9f0c63bde4ec36fee932c38 100644 (file)
@@ -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)
index 43e1feaa20580daea879a47e6a89479cdb760d73..2c0031aeace184763b468172435d48975ba6c600 100644 (file)
@@ -2,12 +2,15 @@
 
 #include <getopt.h>
 
+#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;