]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/analyze/analyze-exit-status.c
NEWS: finalize for v256~rc3
[thirdparty/systemd.git] / src / analyze / analyze-exit-status.c
CommitLineData
73cb64c4
LP
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3#include "analyze.h"
4#include "analyze-exit-status.h"
5#include "exit-status.h"
6#include "format-table.h"
7
ef38bedb 8int verb_exit_status(int argc, char *argv[], void *userdata) {
73cb64c4
LP
9 _cleanup_(table_unrefp) Table *table = NULL;
10 int r;
11
12 table = table_new("name", "status", "class");
13 if (!table)
14 return log_oom();
15
16 r = table_set_align_percent(table, table_get_cell(table, 0, 1), 100);
17 if (r < 0)
18 return log_error_errno(r, "Failed to right-align status: %m");
19
20 if (strv_isempty(strv_skip(argv, 1)))
21 for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) {
22 if (!exit_status_mappings[i].name)
23 continue;
24
25 r = table_add_many(table,
26 TABLE_STRING, exit_status_mappings[i].name,
27 TABLE_INT, (int) i,
28 TABLE_STRING, exit_status_class(i));
29 if (r < 0)
30 return table_log_add_error(r);
31 }
32 else
33 for (int i = 1; i < argc; i++) {
34 int status;
35
36 status = exit_status_from_string(argv[i]);
37 if (status < 0)
38 return log_error_errno(status, "Invalid exit status \"%s\".", argv[i]);
39
40 assert(status >= 0 && (size_t) status < ELEMENTSOF(exit_status_mappings));
41 r = table_add_many(table,
42 TABLE_STRING, exit_status_mappings[status].name ?: "-",
43 TABLE_INT, status,
44 TABLE_STRING, exit_status_class(status) ?: "-");
45 if (r < 0)
46 return table_log_add_error(r);
47 }
48
bf4ffc43 49 r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
fddad5f4 50 if (r < 0)
bf4ffc43 51 return log_error_errno(r, "Failed to output table: %m");
fddad5f4
ZJS
52
53 return EXIT_SUCCESS;
73cb64c4 54}