diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-04-07 10:35:34 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-04-07 14:03:48 +0100 |
commit | 1f2abb791e3b963e614a8bac0313669484376e49 (patch) | |
tree | 38104bd183cd20a571bff98ede521be3d8530512 /src/coredump | |
parent | 671769c932ed4488035fc328a20c14ed15c8a47d (diff) | |
download | systemd-1f2abb791e3b963e614a8bac0313669484376e49.tar.gz |
coredump: fetch JSON object by key instead of iterating
Follow-up for c546154a4448ddf9
Diffstat (limited to 'src/coredump')
-rw-r--r-- | src/coredump/coredump.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 2e56184025..d5b079a53b 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -797,8 +797,7 @@ log: JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) { _cleanup_free_ char *module_basename = NULL, *exe_basename = NULL; - const char *key; - JsonVariant *w; + JsonVariant *package_name, *package_version; /* The module name, most likely parsed from the ELF core file, * sometimes contains the full path and sometimes does not. */ @@ -813,26 +812,13 @@ log: if (!streq(module_basename, exe_basename)) continue; - /* Cannot nest two JSON_VARIANT_OBJECT_FOREACH as they define the same - * iterator variable '_state' */ - for (struct json_variant_foreach_state _state2 = { (module_json), 0 }; \ - json_variant_is_object(_state2.variant) && \ - _state2.idx < json_variant_elements(_state2.variant) && \ - ({ key = json_variant_string(json_variant_by_index(_state2.variant, _state2.idx)); \ - w = json_variant_by_index(_state2.variant, _state2.idx + 1); \ - true; }); \ - _state2.idx += 2) { - - if (!json_variant_is_string(w)) - continue; - - if (!STR_IN_SET(key, "package", "packageVersion")) - continue; + package_name = json_variant_by_key(module_json, "package"); + if (package_name) + (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(package_name)); - (void) iovw_put_string_field(iovw, - streq(key, "package") ? "COREDUMP_PACKAGE_NAME=" : "COREDUMP_PACKAGE_VERSION=", - json_variant_string(w)); - } + package_version = json_variant_by_key(module_json, "packageVersion"); + if (package_version) + (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(package_version)); } /* Optionally store the entire coredump in the journal */ |