From b9aaa7f4801def92bb4753a780fe1c5302c4de16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 26 Feb 2017 18:07:39 -0500 Subject: [PATCH] coredumpctl: print a hint when no journal files are found [guest@fedora ~]$ coredumpctl No coredumps found. [guest@fedora ~]$ ./coredumpctl Hint: You are currently not seeing messages from other users and the system. Users in groups 'adm', 'systemd-journal', 'wheel' can see all messages. Pass -q to turn off this notice. No coredumps found. Fixes #1733. --- man/coredumpctl.xml | 8 ++++++++ src/coredump/coredumpctl.c | 24 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/man/coredumpctl.xml b/man/coredumpctl.xml index 2c657fed03..ca8156f77c 100644 --- a/man/coredumpctl.xml +++ b/man/coredumpctl.xml @@ -138,6 +138,14 @@ + + + + + Suppresses info messages about lack + of access to journal files and possible in-flight coredumps. + + diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 942c970d8a..93d5e1c9d1 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -36,6 +36,7 @@ #include "fileio.h" #include "fs-util.h" #include "journal-internal.h" +#include "journal-util.h" #include "log.h" #include "macro.h" #include "pager.h" @@ -67,6 +68,7 @@ static int arg_one = false; static FILE* arg_output = NULL; static bool arg_reverse = false; static char** arg_matches = NULL; +static bool arg_quiet = false; static int add_match(sd_journal *j, const char *match) { _cleanup_free_ char *p = NULL; @@ -136,6 +138,7 @@ static void help(void) { " -F --field=FIELD List all values a certain field takes\n" " -o --output=FILE Write output to FILE\n" " -D --directory=DIR Use journal files from directory\n\n" + " -q --quiet Do not show info messages and privilege warning\n" "Commands:\n" " list [MATCHES...] List available coredumps (default)\n" " info [MATCHES...] Show detailed information about one or more coredumps\n" @@ -164,13 +167,14 @@ static int parse_argv(int argc, char *argv[]) { { "reverse", no_argument, NULL, 'r' }, { "since", required_argument, NULL, 'S' }, { "until", required_argument, NULL, 'U' }, + { "quiet", no_argument, NULL, 'q' }, {} }; assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "ho:F:1D:S:U:r", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ho:F:1D:rS:U:q", options, NULL)) >= 0) switch(c) { case 'h': arg_action = ACTION_NONE; @@ -233,6 +237,10 @@ static int parse_argv(int argc, char *argv[]) { arg_reverse = true; break; + case 'q': + arg_quiet = true; + break; + case '?': return -EINVAL; @@ -699,7 +707,8 @@ static int dump_list(sd_journal *j) { } if (!arg_field && n_found <= 0) { - log_notice("No coredumps found."); + if (!arg_quiet) + log_notice("No coredumps found."); return -ESRCH; } } @@ -861,8 +870,8 @@ static int dump_core(sd_journal* j) { return r; r = sd_journal_previous(j); - if (r > 0) - log_warning("More than one entry matches, ignoring rest."); + if (r > 0 && !arg_quiet) + log_notice("More than one entry matches, ignoring rest."); return 0; } @@ -956,6 +965,9 @@ static int check_units_active(void) { int c = 0, r; const char *id, *state, *substate; + if (arg_quiet) + return false; + r = sd_bus_default_system(&bus); if (r < 0) return log_error_errno(r, "Failed to acquire bus: %m"); @@ -1036,6 +1048,10 @@ int main(int argc, char *argv[]) { } } + r = journal_access_check_and_warn(j, arg_quiet); + if (r < 0) + goto end; + r = add_matches(j); if (r < 0) goto end;