From: Christian Brauner Date: Sat, 11 Apr 2026 12:00:07 +0000 (+0200) Subject: json-stream: expose log helpers for consumers X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=88a01ed2e3426e2db84968fe4fd2d182ebd7db11;p=thirdparty%2Fsystemd.git json-stream: expose log helpers for consumers Move json_stream_description(), json_stream_log(), and json_stream_log_errno() from json-stream.c into json-stream.h so that consumers like the QMP client can use the same description-prefixed logging that json-stream itself uses internally. Signed-off-by: Christian Brauner (Amutable) --- diff --git a/src/libsystemd/sd-json/json-stream.c b/src/libsystemd/sd-json/json-stream.c index e8cd2c55ddd..d8475ae8734 100644 --- a/src/libsystemd/sd-json/json-stream.c +++ b/src/libsystemd/sd-json/json-stream.c @@ -35,10 +35,6 @@ struct JsonStreamQueueItem { int fds[]; }; -static const char* json_stream_description(const JsonStream *s) { - return (s ? s->description : NULL) ?: "json-stream"; -} - /* Returns the size of the framing delimiter in bytes: strlen(delimiter) for multi-char * delimiters (e.g. "\r\n"), or 1 for the default NUL-byte delimiter (delimiter == NULL). */ static size_t json_stream_delimiter_size(const JsonStream *s) { @@ -54,12 +50,6 @@ static usec_t json_stream_now(const JsonStream *s) { return now(CLOCK_MONOTONIC); } -#define json_stream_log(s, fmt, ...) \ - log_debug("%s: " fmt, json_stream_description(s), ##__VA_ARGS__) - -#define json_stream_log_errno(s, error, fmt, ...) \ - log_debug_errno((error), "%s: " fmt, json_stream_description(s), ##__VA_ARGS__) - sd_json_variant** json_stream_queue_item_get_data(JsonStreamQueueItem *q) { assert(q); return &q->data; diff --git a/src/libsystemd/sd-json/json-stream.h b/src/libsystemd/sd-json/json-stream.h index 92a09d49419..671b0f8985c 100644 --- a/src/libsystemd/sd-json/json-stream.h +++ b/src/libsystemd/sd-json/json-stream.h @@ -6,6 +6,7 @@ #include "sd-forward.h" #include "list.h" +#include "log.h" /* JsonStream provides the transport layer used by sd-varlink (and other consumers like * the QMP client) for exchanging length-delimited JSON messages over a pair of file @@ -132,6 +133,16 @@ void json_stream_done(JsonStream *s); int json_stream_set_description(JsonStream *s, const char *description); const char* json_stream_get_description(const JsonStream *s); +static inline const char* json_stream_description(const JsonStream *s) { + return (s ? s->description : NULL) ?: "json-stream"; +} + +#define json_stream_log(s, fmt, ...) \ + log_debug("%s: " fmt, json_stream_description(s), ##__VA_ARGS__) + +#define json_stream_log_errno(s, error, fmt, ...) \ + log_debug_errno((error), "%s: " fmt, json_stream_description(s), ##__VA_ARGS__) + /* fd ownership */ int json_stream_attach_fds(JsonStream *s, int input_fd, int output_fd);