1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "analyze-fdstore.h"
6 #include "bus-locator.h"
8 #include "format-table.h"
10 static int dump_fdstore(sd_bus
*bus
, const char *arg
) {
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 _cleanup_(table_unrefp
) Table
*table
= NULL
;
14 _cleanup_free_
char *unit
= NULL
;
20 r
= unit_name_mangle_with_suffix(arg
, NULL
, UNIT_NAME_MANGLE_GLOB
, ".service", &unit
);
22 return log_error_errno(r
, "Failed to mangle name '%s': %m", arg
);
27 "DumpUnitFileDescriptorStore",
32 return log_error_errno(r
, "Failed to call DumpUnitFileDescriptorStore: %s",
33 bus_error_message(&error
, r
));
35 r
= sd_bus_message_enter_container(reply
, 'a', "(suuutuusu)");
37 return bus_log_parse_error(r
);
39 table
= table_new("fdname", "type", "devno", "inode", "rdevno", "path", "flags");
43 table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
45 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(3), 100);
48 uint32_t mode
, major
, minor
, rmajor
, rminor
, flags
;
49 const char *fdname
, *path
;
52 r
= sd_bus_message_read(
63 return bus_log_parse_error(r
);
70 TABLE_MODE_INODE_TYPE
, mode
,
71 TABLE_DEVNUM
, makedev(major
, minor
),
73 TABLE_DEVNUM
, makedev(rmajor
, rminor
),
75 TABLE_STRING
, accmode_to_string(flags
));
77 return table_log_add_error(r
);
80 r
= sd_bus_message_exit_container(reply
);
84 if (FLAGS_SET(arg_json_format_flags
, JSON_FORMAT_OFF
) && table_get_rows(table
) <= 0)
85 log_info("No file descriptors in fdstore of '%s'.", unit
);
87 r
= table_print_with_pager(table
, arg_json_format_flags
, arg_pager_flags
, /* show_header= */true);
89 return log_error_errno(r
, "Failed to output table: %m");
95 int verb_fdstore(int argc
, char *argv
[], void *userdata
) {
96 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
99 r
= acquire_bus(&bus
, NULL
);
101 return bus_log_connect_error(r
, arg_transport
);
103 STRV_FOREACH(arg
, strv_skip(argv
, 1)) {
104 r
= dump_fdstore(bus
, *arg
);