coredump: add JSON output support to coredumpctl info
Implement support for the --json= flag in the info subcommand (issue #38844). Previously, coredumpctl info always produced human-readable text output regardless of --json=. Add a CoredumpFields struct that holds all journal fields extracted for a coredump entry, along with coredump_fields_done() to release member resources and coredump_fields_load() to populate the struct from a journal entry. Both print_info() and the new print_info_json() use this shared loader, eliminating the duplicate RETRIEVE loop. print_info_json() builds a JSON object with the same fields shown by print_info(). Missing fields are omitted via SD_JSON_BUILD_PAIR_CONDITION, matching the tolerant behavior of print_info() rather than skipping the entry entirely. Signal/Reason handling mirrors print_info(): normal coredumps (MESSAGE_ID == SD_MESSAGE_COREDUMP_STR) emit a numeric Signal field; non-normal entries (kernel oops, etc.) emit a Reason field with the raw text from COREDUMP_SIGNAL. Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,17 @@ coredumpctl info "${CORE_TEST_BIN##*/}"
|
||||
coredumpctl info foo bar baz "${CORE_TEST_BIN##*/}"
|
||||
coredumpctl info COREDUMP_EXE="$CORE_TEST_BIN"
|
||||
coredumpctl info COREDUMP_EXE=aaaaa COREDUMP_EXE= COREDUMP_EXE="$CORE_TEST_BIN"
|
||||
# JSON output for info subcommand (issue #38844)
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq
|
||||
coredumpctl info --json=pretty "$CORE_TEST_BIN" | jq
|
||||
coredumpctl info --json=off "$CORE_TEST_BIN"
|
||||
# Verify that mandatory fields are present and have valid values across all matching entries
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'length > 0'
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'all(.[]; .PID > 0)'
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'all(.[]; .Signal > 0)'
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'all(.[]; has("Executable"))'
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'all(.[]; has("Command"))'
|
||||
coredumpctl info --json=short "$CORE_TEST_BIN" | jq -se 'all(.[]; has("Storage"))'
|
||||
|
||||
# Check that COREDUMP_TID= is present and displayed by coredumpctl info
|
||||
coredumpctl info "$CORE_TEST_BIN" | grep "TID:" >/dev/null
|
||||
@@ -192,6 +203,8 @@ coredumpctl info "${CORE_TEST_UNPRIV_BIN##*/}"
|
||||
"${UNPRIV_CMD[@]}" coredumpctl
|
||||
"${UNPRIV_CMD[@]}" coredumpctl info "$CORE_TEST_UNPRIV_BIN"
|
||||
"${UNPRIV_CMD[@]}" coredumpctl info "${CORE_TEST_UNPRIV_BIN##*/}"
|
||||
# Verify JSON output for unprivileged coredumps
|
||||
"${UNPRIV_CMD[@]}" coredumpctl info --json=short "$CORE_TEST_UNPRIV_BIN" | jq
|
||||
(! "${UNPRIV_CMD[@]}" coredumpctl info --all "$CORE_TEST_BIN")
|
||||
(! "${UNPRIV_CMD[@]}" coredumpctl info --all "${CORE_TEST_BIN##*/}")
|
||||
# We should have a couple of externally stored coredumps
|
||||
|
||||
Reference in New Issue
Block a user