summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-21 11:00:53 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-21 17:22:23 +0100
commit73cb64c44dd02a7471840d65237026d860a029d5 (patch)
tree2e1646f55c14a3be67ee1bc6b3c7af6e7c7b82e5 /src
parentab86ccbab0717cb8ff3b458956435fd11d08f2df (diff)
downloadsystemd-73cb64c44dd02a7471840d65237026d860a029d5.tar.gz
analyze: split out "exit-status" verb
Diffstat (limited to 'src')
-rw-r--r--src/analyze/analyze-exit-status.c52
-rw-r--r--src/analyze/analyze-exit-status.h4
-rw-r--r--src/analyze/analyze.c47
-rw-r--r--src/analyze/meson.build2
4 files changed, 59 insertions, 46 deletions
diff --git a/src/analyze/analyze-exit-status.c b/src/analyze/analyze-exit-status.c
new file mode 100644
index 0000000000..d3d9aded8e
--- /dev/null
+++ b/src/analyze/analyze-exit-status.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "analyze.h"
+#include "analyze-exit-status.h"
+#include "exit-status.h"
+#include "format-table.h"
+
+int dump_exit_status(int argc, char *argv[], void *userdata) {
+ _cleanup_(table_unrefp) Table *table = NULL;
+ int r;
+
+ table = table_new("name", "status", "class");
+ if (!table)
+ return log_oom();
+
+ r = table_set_align_percent(table, table_get_cell(table, 0, 1), 100);
+ if (r < 0)
+ return log_error_errno(r, "Failed to right-align status: %m");
+
+ if (strv_isempty(strv_skip(argv, 1)))
+ for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) {
+ if (!exit_status_mappings[i].name)
+ continue;
+
+ r = table_add_many(table,
+ TABLE_STRING, exit_status_mappings[i].name,
+ TABLE_INT, (int) i,
+ TABLE_STRING, exit_status_class(i));
+ if (r < 0)
+ return table_log_add_error(r);
+ }
+ else
+ for (int i = 1; i < argc; i++) {
+ int status;
+
+ status = exit_status_from_string(argv[i]);
+ if (status < 0)
+ return log_error_errno(status, "Invalid exit status \"%s\".", argv[i]);
+
+ assert(status >= 0 && (size_t) status < ELEMENTSOF(exit_status_mappings));
+ r = table_add_many(table,
+ TABLE_STRING, exit_status_mappings[status].name ?: "-",
+ TABLE_INT, status,
+ TABLE_STRING, exit_status_class(status) ?: "-");
+ if (r < 0)
+ return table_log_add_error(r);
+ }
+
+ pager_open(arg_pager_flags);
+
+ return table_print(table, NULL);
+}
diff --git a/src/analyze/analyze-exit-status.h b/src/analyze/analyze-exit-status.h
new file mode 100644
index 0000000000..d26db235a1
--- /dev/null
+++ b/src/analyze/analyze-exit-status.h
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int dump_exit_status(int argc, char *argv[], void *userdata);
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index cb46e273bd..acaf19cf4b 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -18,6 +18,7 @@
#include "analyze-dot.h"
#include "analyze-dump.h"
#include "analyze-elf.h"
+#include "analyze-exit-status.h"
#include "analyze-filesystems.h"
#include "analyze-security.h"
#include "analyze-service-watchdogs.h"
@@ -1311,52 +1312,6 @@ static int dump_unit_paths(int argc, char *argv[], void *userdata) {
return 0;
}
-static int dump_exit_status(int argc, char *argv[], void *userdata) {
- _cleanup_(table_unrefp) Table *table = NULL;
- int r;
-
- table = table_new("name", "status", "class");
- if (!table)
- return log_oom();
-
- r = table_set_align_percent(table, table_get_cell(table, 0, 1), 100);
- if (r < 0)
- return log_error_errno(r, "Failed to right-align status: %m");
-
- if (strv_isempty(strv_skip(argv, 1)))
- for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) {
- if (!exit_status_mappings[i].name)
- continue;
-
- r = table_add_many(table,
- TABLE_STRING, exit_status_mappings[i].name,
- TABLE_INT, (int) i,
- TABLE_STRING, exit_status_class(i));
- if (r < 0)
- return table_log_add_error(r);
- }
- else
- for (int i = 1; i < argc; i++) {
- int status;
-
- status = exit_status_from_string(argv[i]);
- if (status < 0)
- return log_error_errno(status, "Invalid exit status \"%s\".", argv[i]);
-
- assert(status >= 0 && (size_t) status < ELEMENTSOF(exit_status_mappings));
- r = table_add_many(table,
- TABLE_STRING, exit_status_mappings[status].name ?: "-",
- TABLE_INT, status,
- TABLE_STRING, exit_status_class(status) ?: "-");
- if (r < 0)
- return table_log_add_error(r);
- }
-
- pager_open(arg_pager_flags);
-
- return table_print(table, NULL);
-}
-
static int dump_capabilities(int argc, char *argv[], void *userdata) {
_cleanup_(table_unrefp) Table *table = NULL;
unsigned last_cap;
diff --git a/src/analyze/meson.build b/src/analyze/meson.build
index c992e20c46..343f2a8997 100644
--- a/src/analyze/meson.build
+++ b/src/analyze/meson.build
@@ -11,6 +11,8 @@ systemd_analyze_sources = files('''
analyze-dump.h
analyze-elf.c
analyze-elf.h
+ analyze-exit-status.c
+ analyze-exit-status.h
analyze-filesystems.c
analyze-filesystems.h
analyze-security.c