1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

coredumpctl: Add -r/--reverse option

Like journalctl, users sometimes want to see coredump list in reverse
order.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
This commit is contained in:
Namhyung Kim 2017-02-13 22:55:25 +09:00
parent 06b76011d7
commit df65f77bb5

View File

@ -59,6 +59,7 @@ static bool arg_no_pager = false;
static int arg_no_legend = false; static int arg_no_legend = false;
static int arg_one = false; static int arg_one = false;
static FILE* arg_output = NULL; static FILE* arg_output = NULL;
static bool arg_reverse = false;
static Set *new_matches(void) { static Set *new_matches(void) {
Set *set; Set *set;
@ -133,6 +134,7 @@ static void help(void) {
" --no-pager Do not pipe output into a pager\n" " --no-pager Do not pipe output into a pager\n"
" --no-legend Do not print the column headers.\n" " --no-legend Do not print the column headers.\n"
" -1 Show information about most recent entry only\n" " -1 Show information about most recent entry only\n"
" -r --reverse Show the newest entries first\n"
" -F --field=FIELD List all values a certain field takes\n" " -F --field=FIELD List all values a certain field takes\n"
" -o --output=FILE Write output to FILE\n" " -o --output=FILE Write output to FILE\n"
" -D --directory=DIR Use journal files from directory\n\n" " -D --directory=DIR Use journal files from directory\n\n"
@ -162,13 +164,14 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
{ "output", required_argument, NULL, 'o' }, { "output", required_argument, NULL, 'o' },
{ "field", required_argument, NULL, 'F' }, { "field", required_argument, NULL, 'F' },
{ "directory", required_argument, NULL, 'D' }, { "directory", required_argument, NULL, 'D' },
{ "reverse", no_argument, NULL, 'r' },
{} {}
}; };
assert(argc >= 0); assert(argc >= 0);
assert(argv); assert(argv);
while ((c = getopt_long(argc, argv, "ho:F:1D:", options, NULL)) >= 0) while ((c = getopt_long(argc, argv, "ho:F:1D:r", options, NULL)) >= 0)
switch(c) { switch(c) {
case 'h': case 'h':
@ -216,6 +219,10 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
arg_directory = optarg; arg_directory = optarg;
break; break;
case 'r':
arg_reverse = true;
break;
case '?': case '?':
return -EINVAL; return -EINVAL;
@ -602,10 +609,18 @@ static int dump_list(sd_journal *j) {
return print_entry(j, 0); return print_entry(j, 0);
} else { } else {
SD_JOURNAL_FOREACH(j) { if (!arg_reverse) {
r = print_entry(j, n_found++); SD_JOURNAL_FOREACH(j) {
if (r < 0) r = print_entry(j, n_found++);
return r; if (r < 0)
return r;
}
} else {
SD_JOURNAL_FOREACH_BACKWARDS(j) {
r = print_entry(j, n_found++);
if (r < 0)
return r;
}
} }
if (!arg_field && n_found <= 0) { if (!arg_field && n_found <= 0) {