mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
coredumpctl: fetch JSON object by key instead of iterating
Follow-up for d1b5a0c691
This commit is contained in:
parent
1f2abb791e
commit
b7ddd44497
@ -735,18 +735,9 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
const char *module_name;
|
||||
JsonVariant *module_json;
|
||||
|
||||
/* Cannot nest two JSON_VARIANT_OBJECT_FOREACH as they define the same
|
||||
* iterator variable '_state' */
|
||||
for (struct json_variant_foreach_state _state2 = { (v), 0 }; \
|
||||
json_variant_is_object(_state2.variant) && \
|
||||
_state2.idx < json_variant_elements(_state2.variant) && \
|
||||
({ module_name = json_variant_string(json_variant_by_index(_state2.variant, _state2.idx)); \
|
||||
module_json = json_variant_by_index(_state2.variant, _state2.idx + 1); \
|
||||
true; }); \
|
||||
_state2.idx += 2) {
|
||||
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, v) {
|
||||
_cleanup_free_ char *module_basename = NULL, *exe_basename = NULL;
|
||||
const char *key;
|
||||
JsonVariant *w;
|
||||
JsonVariant *build_id;
|
||||
|
||||
/* The module name, most likely parsed from the ELF core file,
|
||||
* sometimes contains the full path and sometimes does not. */
|
||||
@ -765,17 +756,9 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
if (!streq(module_basename, exe_basename))
|
||||
continue;
|
||||
|
||||
JSON_VARIANT_OBJECT_FOREACH(key, w, module_json) {
|
||||
if (!json_variant_is_string(w))
|
||||
continue;
|
||||
|
||||
if (!streq(key, "buildId"))
|
||||
continue;
|
||||
|
||||
fprintf(file, " build-id: %s\n", json_variant_string(w));
|
||||
|
||||
break;
|
||||
}
|
||||
build_id = json_variant_by_key(module_json, "buildId");
|
||||
if (build_id)
|
||||
fprintf(file, " build-id: %s\n", json_variant_string(build_id));
|
||||
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user