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:
Yu Watanabe
2026-08-26 02:13:11 +09:00
parent 6f8b23398c
commit 8972b051a7
5 changed files with 15 additions and 13 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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);
}
+8 -7
View File
@@ -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);
}
+1 -2
View File
@@ -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);
+4 -2
View File
@@ -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;
}