]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/analyze/analyze-malloc.c
man/run0: remove @ syntax for --machine=
[thirdparty/systemd.git] / src / analyze / analyze-malloc.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "sd-bus.h"
4
5 #include "analyze-malloc.h"
6 #include "analyze.h"
7 #include "bus-error.h"
8 #include "bus-internal.h"
9
10 static int dump_malloc_info(sd_bus *bus, char *service) {
11 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
12 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
13 int r;
14
15 assert(bus);
16 assert(service);
17
18 r = sd_bus_call_method(bus,
19 service,
20 "/org/freedesktop/MemoryAllocation1",
21 "org.freedesktop.MemoryAllocation1",
22 "GetMallocInfo",
23 &error,
24 &reply,
25 NULL);
26 if (r < 0)
27 return log_error_errno(r, "Failed to call GetMallocInfo on '%s': %s", service, bus_error_message(&error, r));
28
29 return dump_fd_reply(reply);
30 }
31
32 int verb_malloc(int argc, char *argv[], void *userdata) {
33 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
34 char **services = STRV_MAKE("org.freedesktop.systemd1");
35 int r;
36
37 if (!strv_isempty(strv_skip(argv, 1))) {
38 services = strv_skip(argv, 1);
39 STRV_FOREACH(service, services)
40 if (!service_name_is_valid(*service))
41 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "D-Bus service name '%s' is not valid.", *service);
42 }
43
44 r = acquire_bus(&bus, NULL);
45 if (r < 0)
46 return bus_log_connect_error(r, arg_transport);
47
48 r = sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD);
49 if (r < 0)
50 return log_error_errno(r, "Unable to determine if bus connection supports fd passing: %m");
51 if (r == 0)
52 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Unable to receive FDs over D-Bus.");
53
54 pager_open(arg_pager_flags);
55
56 STRV_FOREACH(service, services) {
57 r = dump_malloc_info(bus, *service);
58 if (r < 0)
59 return r;
60 }
61
62 return EXIT_SUCCESS;
63 }