summaryrefslogtreecommitdiff
path: root/src/oom/oomd-manager-bus.c
blob: 0f39a60d9ec3f356ad7628cde7ee65ab720cb41c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: LGPL-2.1+ */

#include <linux/capability.h>

#include "bus-common-errors.h"
#include "bus-polkit.h"
#include "fd-util.h"
#include "oomd-manager-bus.h"
#include "oomd-manager.h"
#include "user-util.h"

static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) {
        _cleanup_free_ char *dump = NULL;
        _cleanup_close_ int fd = -1;
        Manager *m = userdata;
        int r;

        assert(message);
        assert(m);

        r = manager_get_dump_string(m, &dump);
        if (r < 0)
                return r;

        fd = acquire_data_fd(dump, strlen(dump), 0);
        if (fd < 0)
                return fd;

        return sd_bus_reply_method_return(message, "h", fd);
}

static const sd_bus_vtable manager_vtable[] = {
        SD_BUS_VTABLE_START(0),
        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),
};