Skip to content

Commit 52117f5

Browse files
committed
analyze: add --quiet option
This is useful for shell completion, but also for users who don't care about the extra output.
1 parent ae568b1 commit 52117f5

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

man/systemd-analyze.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,12 @@ $ systemd-analyze verify /tmp/source:alias.service
11971197
<xi:include href="user-system-options.xml" xpointer="host" />
11981198
<xi:include href="user-system-options.xml" xpointer="machine" />
11991199

1200+
<varlistentry>
1201+
<term><option>--quiet</option></term>
1202+
1203+
<listitem><para>Suppress hints and other non-essential output.</para></listitem>
1204+
</varlistentry>
1205+
12001206
<xi:include href="standard-options.xml" xpointer="help" />
12011207
<xi:include href="standard-options.xml" xpointer="version" />
12021208
<xi:include href="standard-options.xml" xpointer="no-pager" />

shell-completion/bash/systemd-analyze

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ _systemd_analyze() {
5050

5151
local -A OPTS=(
5252
[STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
53-
--man=no --generators=yes'
53+
--man=no --generators=yes --quiet'
5454
[ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
5555
)
5656

shell-completion/zsh/_systemd-analyze

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ _arguments \
103103
'--to-pattern=[When generating a dependency graph, filter only destinations]:GLOB' \
104104
{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
105105
{-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
106+
'--quiet[Do not show hints]' \
106107
'*::systemd-analyze commands:_systemd-analyze_commands'

src/analyze/analyze.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static unsigned arg_iterations = 1;
104104
static usec_t arg_base_time = USEC_INFINITY;
105105
static char *arg_unit = NULL;
106106
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
107+
static bool arg_quiet = false;
107108

108109
STATIC_DESTRUCTOR_REGISTER(arg_dot_from_patterns, strv_freep);
109110
STATIC_DESTRUCTOR_REGISTER(arg_dot_to_patterns, strv_freep);
@@ -1361,7 +1362,7 @@ static int dot(int argc, char *argv[], void *userdata) {
13611362
" red = Conflicts\n"
13621363
" green = After\n");
13631364

1364-
if (on_tty())
1365+
if (on_tty() && !arg_quiet)
13651366
log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
13661367
"-- Try a shell pipeline like 'systemd-analyze dot | dot -Tsvg > systemd.svg'!\n");
13671368

@@ -1713,7 +1714,8 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
17131714
if (set_put_strdup(&known, sys) < 0)
17141715
return log_oom();
17151716

1716-
k = load_kernel_syscalls(&kernel);
1717+
if (!arg_quiet)
1718+
k = load_kernel_syscalls(&kernel);
17171719

17181720
for (int i = 0; i < _SYSCALL_FILTER_SET_MAX; i++) {
17191721
const SyscallFilterSet *set = syscall_filter_sets + i;
@@ -1727,6 +1729,9 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
17271729
first = false;
17281730
}
17291731

1732+
if (arg_quiet) /* Let's not show the extra stuff in quiet mode */
1733+
return 0;
1734+
17301735
if (!set_isempty(known)) {
17311736
_cleanup_free_ char **l = NULL;
17321737
char **syscall;
@@ -1748,7 +1753,8 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
17481753
if (k < 0) {
17491754
fputc('\n', stdout);
17501755
fflush(stdout);
1751-
log_notice_errno(k, "# Not showing unlisted system calls, couldn't retrieve kernel system call list: %m");
1756+
if (!arg_quiet)
1757+
log_notice_errno(k, "# Not showing unlisted system calls, couldn't retrieve kernel system call list: %m");
17521758
} else if (!set_isempty(kernel)) {
17531759
_cleanup_free_ char **l = NULL;
17541760
char **syscall;
@@ -1930,6 +1936,9 @@ static int dump_filesystems(int argc, char *argv[], void *userdata) {
19301936
first = false;
19311937
}
19321938

1939+
if (arg_quiet) /* Let's not show the extra stuff in quiet mode */
1940+
return 0;
1941+
19331942
if (!set_isempty(known)) {
19341943
_cleanup_free_ char **l = NULL;
19351944
char **filesystem;
@@ -2452,9 +2461,8 @@ static int help(int argc, char *argv[], void *userdata) {
24522461
" unit-paths List load directories for units\n"
24532462
" exit-status [STATUS...] List exit status definitions\n"
24542463
" capability [CAP...] List capability definitions\n"
2455-
" syscall-filter [NAME...] Print list of syscalls in seccomp\n"
2456-
" filter\n"
2457-
" filesystems [NAME...] Print list of filesystems\n"
2464+
" syscall-filter [NAME...] List syscalls in seccomp filters\n"
2465+
" filesystems [NAME...] List known filesystems\n"
24582466
" condition CONDITION... Evaluate conditions and asserts\n"
24592467
" verify FILE... Check unit files for correctness\n"
24602468
" calendar SPEC... Validate repetitive calendar time\n"
@@ -2463,12 +2471,10 @@ static int help(int argc, char *argv[], void *userdata) {
24632471
" timespan SPAN... Validate a time span\n"
24642472
" security [UNIT...] Analyze security of unit\n"
24652473
"\nOptions:\n"
2466-
" -h --help Show this help\n"
24672474
" --recursive-errors=MODE Control which units are verified\n"
24682475
" --offline=BOOL Perform a security review on unit file(s)\n"
24692476
" --threshold=N Exit with a non-zero status when overall\n"
24702477
" exposure level is over threshold value\n"
2471-
" --version Show package version\n"
24722478
" --security-policy=PATH Use custom JSON security policy instead\n"
24732479
" of built-in one\n"
24742480
" --json=pretty|short|off Generate JSON output of the security\n"
@@ -2491,6 +2497,9 @@ static int help(int argc, char *argv[], void *userdata) {
24912497
" --iterations=N Show the specified number of iterations\n"
24922498
" --base-time=TIMESTAMP Calculate calendar times relative to\n"
24932499
" specified time\n"
2500+
" -h --help Show this help\n"
2501+
" --version Show package version\n"
2502+
" -q --quiet Do not emit hints\n"
24942503
"\nSee the %s for details.\n",
24952504
program_invocation_short_name,
24962505
ansi_highlight(),
@@ -2532,6 +2541,7 @@ static int parse_argv(int argc, char *argv[]) {
25322541
static const struct option options[] = {
25332542
{ "help", no_argument, NULL, 'h' },
25342543
{ "version", no_argument, NULL, ARG_VERSION },
2544+
{ "quiet", no_argument, NULL, 'q' },
25352545
{ "order", no_argument, NULL, ARG_ORDER },
25362546
{ "require", no_argument, NULL, ARG_REQUIRE },
25372547
{ "root", required_argument, NULL, ARG_ROOT },
@@ -2569,6 +2579,13 @@ static int parse_argv(int argc, char *argv[]) {
25692579
case 'h':
25702580
return help(0, NULL, NULL);
25712581

2582+
case ARG_VERSION:
2583+
return version();
2584+
2585+
case 'q':
2586+
arg_quiet = true;
2587+
break;
2588+
25722589
case ARG_RECURSIVE_ERRORS:
25732590
if (streq(optarg, "help")) {
25742591
DUMP_STRING_TABLE(recursive_errors, RecursiveErrors, _RECURSIVE_ERRORS_MAX);
@@ -2581,9 +2598,6 @@ static int parse_argv(int argc, char *argv[]) {
25812598
arg_recursive_errors = r;
25822599
break;
25832600

2584-
case ARG_VERSION:
2585-
return version();
2586-
25872601
case ARG_ROOT:
25882602
r = parse_path_argument(optarg, /* suppress_root= */ true, &arg_root);
25892603
if (r < 0)

0 commit comments

Comments
 (0)