1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include "analyze-malloc.h"
8 #include "bus-internal.h"
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
;
18 r
= sd_bus_call_method(bus
,
20 "/org/freedesktop/MemoryAllocation1",
21 "org.freedesktop.MemoryAllocation1",
27 return log_error_errno(r
, "Failed to call GetMallocInfo on '%s': %s", service
, bus_error_message(&error
, r
));
29 return dump_fd_reply(reply
);
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");
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
);
44 r
= acquire_bus(&bus
, NULL
);
46 return bus_log_connect_error(r
, arg_transport
);
48 r
= sd_bus_can_send(bus
, SD_BUS_TYPE_UNIX_FD
);
50 return log_error_errno(r
, "Unable to determine if bus connection supports fd passing: %m");
52 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
), "Unable to receive FDs over D-Bus.");
54 pager_open(arg_pager_flags
);
56 STRV_FOREACH(service
, services
) {
57 r
= dump_malloc_info(bus
, *service
);