coredumpctl: allow to show coredump info in json format in dump and debug command
Previously `coredumpctl dump/debug` silently ignored --json= option. Let's honor the option.
This commit is contained in:
@@ -180,7 +180,7 @@ int verb_dump_core(int argc, char *argv[], uintptr_t _data, void *userdata) {
|
||||
return log_error_errno(errno, "Failed to open \"%s\" for writing: %m", arg_output);
|
||||
}
|
||||
|
||||
print_info(f ? stdout : stderr, j, false);
|
||||
(void) print_entry(f ? stdout : stderr, j, /* need_space= */ false, /* table= */ NULL);
|
||||
|
||||
r = save_core(j, f, NULL, NULL);
|
||||
if (r < 0)
|
||||
|
||||
@@ -63,7 +63,7 @@ int verb_run_debug(int argc, char *argv[], uintptr_t _data, void *userdata) {
|
||||
return r;
|
||||
|
||||
if (!arg_quiet) {
|
||||
print_info(stdout, j, false);
|
||||
(void) print_entry(stdout, j, /* need_space= */ false, /* table= */ NULL);
|
||||
fputs("\n", stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ static int coredump_fields_load(sd_journal *j, CoredumpFields *f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
_cleanup_(coredump_fields_done) CoredumpFields f = {
|
||||
.disk_size = UINT64_MAX,
|
||||
};
|
||||
@@ -598,14 +598,15 @@ static int print_info_json(FILE *file, sd_journal *j) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int print_entry(sd_journal *j, size_t n_found, Table *t) {
|
||||
int print_entry(FILE *f, sd_journal *j, bool need_space, Table *table) {
|
||||
assert(f);
|
||||
assert(j);
|
||||
|
||||
if (t)
|
||||
return print_list(stdout, j, t);
|
||||
if (table)
|
||||
return print_list(f, j, table);
|
||||
if (arg_field)
|
||||
return print_field(stdout, j);
|
||||
return print_field(f, j);
|
||||
if (sd_json_format_enabled(arg_json_format_flags))
|
||||
return print_info_json(stdout, j);
|
||||
return print_info(stdout, j, n_found > 0);
|
||||
return print_info_json(f, j);
|
||||
return print_info(f, j, need_space);
|
||||
}
|
||||
|
||||
@@ -3,5 +3,4 @@
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
int print_info(FILE *file, sd_journal *j, bool need_space);
|
||||
int print_entry(sd_journal *j, size_t n_found, Table *t);
|
||||
int print_entry(FILE *f, sd_journal *j, bool need_space, Table *table);
|
||||
|
||||
@@ -48,7 +48,7 @@ int verb_dump_list(int argc, char *argv[], uintptr_t _data, void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = print_entry(j, 0, t);
|
||||
r = print_entry(stdout, j, /* need_space= */ false, t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
@@ -93,10 +93,12 @@ int verb_dump_list(int argc, char *argv[], uintptr_t _data, void *userdata) {
|
||||
break;
|
||||
}
|
||||
|
||||
r = print_entry(j, n_found++, t);
|
||||
r = print_entry(stdout, j, /* need_space= */ n_found > 0, t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
n_found++;
|
||||
|
||||
if (arg_rows_max != SIZE_MAX && n_found >= arg_rows_max)
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user