]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
json-stream: expose log helpers for consumers
authorChristian Brauner <brauner@kernel.org>
Sat, 11 Apr 2026 12:00:07 +0000 (14:00 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 15 Apr 2026 08:14:47 +0000 (10:14 +0200)
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) <brauner@kernel.org>
src/libsystemd/sd-json/json-stream.c
src/libsystemd/sd-json/json-stream.h

index e8cd2c55ddd3c4ad8fba1cea099afb972c3b9c4d..d8475ae87342434853d6285c7440d7012cebf145 100644 (file)
@@ -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;
index 92a09d494191a3b154810fb4d7f946f5f1367ef4..671b0f8985c9ca0a8b2c3232691b814fb6dea2b5 100644 (file)
@@ -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);