diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-04-07 10:21:48 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-04-07 14:02:38 +0100 |
commit | f216e748410c57c1e2f421cf90b90db076c6531c (patch) | |
tree | 94b829c33bc5e2f19c2120402d0316fb1b0003c8 /src/coredump | |
parent | 9b7205f5dd4658980adf61968344e51b18122e90 (diff) | |
download | systemd-f216e748410c57c1e2f421cf90b90db076c6531c.tar.gz |
coredump: use JSON helpers instead of creating objects manually
Follow-up for 95f71807733
Diffstat (limited to 'src/coredump')
-rw-r--r-- | src/coredump/coredumpctl.c | 2 | ||||
-rw-r--r-- | src/coredump/stacktrace.c | 23 |
2 files changed, 8 insertions, 17 deletions
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 0ba218a39d..0787eeafef 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -769,7 +769,7 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) { if (!json_variant_is_string(w)) continue; - if (!streq(key, "buildid")) + if (!streq(key, "buildId")) continue; fprintf(file, " build-id: %s\n", json_variant_string(w)); diff --git a/src/coredump/stacktrace.c b/src/coredump/stacktrace.c index 9cf2be3365..102ad2e65b 100644 --- a/src/coredump/stacktrace.c +++ b/src/coredump/stacktrace.c @@ -247,29 +247,20 @@ static int module_callback(Dwfl_Module *mod, void **userdata, const char *name, * without the former, but there's no hard rule. */ fprintf(c->f, "Found module %s without build-id.\n", name); else { - _cleanup_free_ char *id_hex = NULL, *id_hex_prefixed = NULL; - - id_hex = hexmem(id, id_len); - if (!id_hex) { - log_oom(); - return DWARF_CB_ABORT; - } - - fprintf(c->f, "Found module %s with build-id: %s\n", name, id_hex); + JsonVariant *build_id; /* We will later parse package metadata json and pass it to our caller. Prepare the * build-id in json format too, so that it can be appended and parsed cleanly. It * will then be added as metadata to the journal message with the stack trace. */ - id_hex_prefixed = strjoin("{\"buildid\":\"", id_hex, "\"}"); - if (!id_hex_prefixed) { - log_oom(); - return DWARF_CB_ABORT; - } - r = json_parse(id_hex_prefixed, 0, &id_json, NULL, NULL); + r = json_build(&id_json, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("buildId", JSON_BUILD_HEX(id, id_len)))); if (r < 0) { - log_error_errno(r, "json_parse on %s failed: %m", id_hex_prefixed); + log_error_errno(r, "json_build on build-id failed: %m"); return DWARF_CB_ABORT; } + + build_id = json_variant_by_key(id_json, "buildId"); + assert_se(build_id); + fprintf(c->f, "Found module %s with build-id: %s\n", name, json_variant_string(build_id)); } /* The .note.package metadata is more difficult. From the module, we need to get a reference |