From: Lennart Poettering Date: Mon, 21 Feb 2022 10:04:31 +0000 (+0100) Subject: analyze: split out "capability" verb X-Git-Tag: v251-rc1~249^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6488e8443b43b4a91dacb9ef8c65e13b825b9eff;p=thirdparty%2Fsystemd.git analyze: split out "capability" verb --- diff --git a/src/analyze/analyze-capability.c b/src/analyze/analyze-capability.c new file mode 100644 index 00000000000..a24ebdc9f24 --- /dev/null +++ b/src/analyze/analyze-capability.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "analyze.h" +#include "analyze-capability.h" +#include "cap-list.h" +#include "capability-util.h" +#include "format-table.h" + +int dump_capabilities(int argc, char *argv[], void *userdata) { + _cleanup_(table_unrefp) Table *table = NULL; + unsigned last_cap; + int r; + + table = table_new("name", "number"); + if (!table) + return log_oom(); + + (void) table_set_align_percent(table, table_get_cell(table, 0, 1), 100); + + /* Determine the maximum of the last cap known by the kernel and by us */ + last_cap = MAX((unsigned) CAP_LAST_CAP, cap_last_cap()); + + if (strv_isempty(strv_skip(argv, 1))) + for (unsigned c = 0; c <= last_cap; c++) { + r = table_add_many(table, + TABLE_STRING, capability_to_name(c) ?: "cap_???", + TABLE_UINT, c); + if (r < 0) + return table_log_add_error(r); + } + else { + for (int i = 1; i < argc; i++) { + int c; + + c = capability_from_name(argv[i]); + if (c < 0 || (unsigned) c > last_cap) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Capability \"%s\" not known.", argv[i]); + + r = table_add_many(table, + TABLE_STRING, capability_to_name(c) ?: "cap_???", + TABLE_UINT, (unsigned) c); + if (r < 0) + return table_log_add_error(r); + } + + (void) table_set_sort(table, (size_t) 1); + } + + pager_open(arg_pager_flags); + + return table_print(table, NULL); +} diff --git a/src/analyze/analyze-capability.h b/src/analyze/analyze-capability.h new file mode 100644 index 00000000000..f770f93f782 --- /dev/null +++ b/src/analyze/analyze-capability.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +int dump_capabilities(int argc, char *argv[], void *userdata); diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index acaf19cf4b1..2d47d27d6f1 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -14,6 +14,7 @@ #include "alloc-util.h" #include "analyze.h" #include "analyze-calendar.h" +#include "analyze-capability.h" #include "analyze-condition.h" #include "analyze-dot.h" #include "analyze-dump.h" @@ -1312,51 +1313,6 @@ static int dump_unit_paths(int argc, char *argv[], void *userdata) { return 0; } -static int dump_capabilities(int argc, char *argv[], void *userdata) { - _cleanup_(table_unrefp) Table *table = NULL; - unsigned last_cap; - int r; - - table = table_new("name", "number"); - if (!table) - return log_oom(); - - (void) table_set_align_percent(table, table_get_cell(table, 0, 1), 100); - - /* Determine the maximum of the last cap known by the kernel and by us */ - last_cap = MAX((unsigned) CAP_LAST_CAP, cap_last_cap()); - - if (strv_isempty(strv_skip(argv, 1))) - for (unsigned c = 0; c <= last_cap; c++) { - r = table_add_many(table, - TABLE_STRING, capability_to_name(c) ?: "cap_???", - TABLE_UINT, c); - if (r < 0) - return table_log_add_error(r); - } - else { - for (int i = 1; i < argc; i++) { - int c; - - c = capability_from_name(argv[i]); - if (c < 0 || (unsigned) c > last_cap) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Capability \"%s\" not known.", argv[i]); - - r = table_add_many(table, - TABLE_STRING, capability_to_name(c) ?: "cap_???", - TABLE_UINT, (unsigned) c); - if (r < 0) - return table_log_add_error(r); - } - - (void) table_set_sort(table, (size_t) 1); - } - - pager_open(arg_pager_flags); - - return table_print(table, NULL); -} - void time_parsing_hint(const char *p, bool calendar, bool timestamp, bool timespan) { if (calendar && calendar_spec_from_string(p, NULL) >= 0) log_notice("Hint: this expression is a valid calendar specification. " diff --git a/src/analyze/meson.build b/src/analyze/meson.build index 343f2a89977..8e9e780c71f 100644 --- a/src/analyze/meson.build +++ b/src/analyze/meson.build @@ -3,6 +3,8 @@ systemd_analyze_sources = files(''' analyze-calendar.c analyze-calendar.h + analyze-capability.c + analyze-capability.h analyze-condition.c analyze-condition.h analyze-dot.c