| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "bus-object.h" |
| 7 |
#include "fd-util.h" |
| 8 |
#include "memfd-util.h" |
| 9 |
#include "oomd-manager.h" |
| 10 |
#include "oomd-manager-bus.h" |
| 11 |
|
| 12 |
static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 13 |
_cleanup_free_ char *dump = NULL; |
| 14 |
_cleanup_close_ int fd = -EBADF; |
| 15 |
Manager *m = ASSERT_PTR(userdata); |
| 16 |
int r; |
| 17 |
|
| 18 |
assert(message); |
| 19 |
|
| 20 |
r = manager_get_dump_string(m, &dump); |
| 21 |
if (r < 0) |
| 22 |
return r; |
| 23 |
|
| 24 |
fd = memfd_new_and_seal_string("oomd-dump", dump); |
| 25 |
if (fd < 0) |
| 26 |
return fd; |
| 27 |
|
| 28 |
return sd_bus_reply_method_return(message, "h", fd); |
| 29 |
} |
| 30 |
|
| 31 |
static const sd_bus_vtable manager_vtable[] = { |
| 32 |
SD_BUS_VTABLE_START(0), |
| 33 |
SD_BUS_METHOD_WITH_NAMES("DumpByFileDescriptor", |
| 34 |
NULL,, |
| 35 |
"h", |
| 36 |
SD_BUS_PARAM(fd), |
| 37 |
bus_method_dump_by_fd, |
| 38 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 39 |
SD_BUS_SIGNAL_WITH_NAMES("Killed", |
| 40 |
"ss", |
| 41 |
SD_BUS_PARAM(cgroup) |
| 42 |
SD_BUS_PARAM(reason), |
| 43 |
0), |
| 44 |
SD_BUS_VTABLE_END |
| 45 |
}; |
| 46 |
|
| 47 |
const BusObjectImplementation manager_object = { |
| 48 |
"/org/freedesktop/oom1", |
| 49 |
"org.freedesktop.oom1.Manager", |
| 50 |
.vtables = BUS_VTABLES(manager_vtable), |
| 51 |
}; |