summaryrefslogtreecommitdiffstats
path: root/src/coredump
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-05-02 14:26:21 +0200
committerLennart Poettering <lennart@poettering.net>2024-06-12 18:42:22 +0200
commit309a747fa6cfeac0a0165543f23a924866727c9b (patch)
treea51242aa3ac87243c0614bf93d27e9083182e485 /src/coredump
parentjson: merge json_dispatch_path() + json_dispatch_absolute_path() (diff)
downloadsystemd-309a747fa6cfeac0a0165543f23a924866727c9b.tar.xz
systemd-309a747fa6cfeac0a0165543f23a924866727c9b.zip
libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle). I made most of the json.h APIs public, and just placed them in sd-json.h. Sometimes I wasn't so sure however, since the underlying data structures would have to be made public too. If in doubt I didn#t risk it, and moved the relevant API to src/libsystemd/sd-json/json-util.h instead (without any sd_* symbol prefixes). This is mostly a giant search/replace patch.
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredump.c18
-rw-r--r--src/coredump/coredumpctl.c16
2 files changed, 19 insertions, 15 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index a8ee8e05de..9a1f3c23fe 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -10,6 +10,7 @@
#include "sd-daemon.h"
#include "sd-journal.h"
+#include "sd-json.h"
#include "sd-login.h"
#include "sd-messages.h"
@@ -32,6 +33,7 @@
#include "iovec-util.h"
#include "journal-importer.h"
#include "journal-send.h"
+#include "json-util.h"
#include "log.h"
#include "macro.h"
#include "main-func.h"
@@ -773,14 +775,14 @@ static int submit_coredump(
struct iovec_wrapper *iovw,
int input_fd) {
- _cleanup_(json_variant_unrefp) JsonVariant *json_metadata = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *json_metadata = NULL;
_cleanup_close_ int coredump_fd = -EBADF, coredump_node_fd = -EBADF;
_cleanup_free_ char *filename = NULL, *coredump_data = NULL;
_cleanup_free_ char *stacktrace = NULL;
const char *module_name;
uint64_t coredump_size = UINT64_MAX, coredump_compressed_size = UINT64_MAX;
bool truncated = false, written = false;
- JsonVariant *module_json;
+ sd_json_variant *module_json;
int r;
assert(context);
@@ -870,7 +872,7 @@ static int submit_coredump(
if (json_metadata) {
_cleanup_free_ char *formatted_json = NULL;
- r = json_variant_format(json_metadata, 0, &formatted_json);
+ r = sd_json_variant_format(json_metadata, 0, &formatted_json);
if (r < 0)
return log_error_errno(r, "Failed to format JSON package metadata: %m");
@@ -881,19 +883,19 @@ static int submit_coredump(
* let's avoid guessing the module name and skip the loop. */
if (context->meta[META_EXE])
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) {
- JsonVariant *t;
+ sd_json_variant *t;
/* We only add structured fields for the 'main' ELF module, and only if we can identify it. */
if (!path_equal_filename(module_name, context->meta[META_EXE]))
continue;
- t = json_variant_by_key(module_json, "name");
+ t = sd_json_variant_by_key(module_json, "name");
if (t)
- (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(t));
+ (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", sd_json_variant_string(t));
- t = json_variant_by_key(module_json, "version");
+ t = sd_json_variant_by_key(module_json, "version");
if (t)
- (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(t));
+ (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", sd_json_variant_string(t));
}
/* Optionally store the entire coredump in the journal */
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 3a3cd7dca2..8de86a7897 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -8,6 +8,7 @@
#include "sd-bus.h"
#include "sd-journal.h"
+#include "sd-json.h"
#include "sd-messages.h"
#include "alloc-util.h"
@@ -26,6 +27,7 @@
#include "glob-util.h"
#include "journal-internal.h"
#include "journal-util.h"
+#include "json-util.h"
#include "log.h"
#include "macro.h"
#include "main-func.h"
@@ -56,7 +58,7 @@ static const char *arg_directory = NULL;
static char *arg_root = NULL;
static char *arg_image = NULL;
static char **arg_file = NULL;
-static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
+static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
static PagerFlags arg_pager_flags = 0;
static int arg_legend = true;
static size_t arg_rows_max = SIZE_MAX;
@@ -804,26 +806,26 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
/* Print out the build-id of the 'main' ELF module, by matching the JSON key
* with the 'exe' field. */
if (exe && pkgmeta_json) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
- r = json_parse(pkgmeta_json, 0, &v, NULL, NULL);
+ r = sd_json_parse(pkgmeta_json, 0, &v, NULL, NULL);
if (r < 0) {
_cleanup_free_ char *esc = cescape(pkgmeta_json);
log_warning_errno(r, "json_parse on \"%s\" failed, ignoring: %m", strnull(esc));
} else {
const char *module_name;
- JsonVariant *module_json;
+ sd_json_variant *module_json;
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, v) {
- JsonVariant *build_id;
+ sd_json_variant *build_id;
/* We only print the build-id for the 'main' ELF module */
if (!path_equal_filename(module_name, exe))
continue;
- build_id = json_variant_by_key(module_json, "buildId");
+ build_id = sd_json_variant_by_key(module_json, "buildId");
if (build_id)
- fprintf(file, " build-id: %s\n", json_variant_string(build_id));
+ fprintf(file, " build-id: %s\n", sd_json_variant_string(build_id));
break;
}