]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
json: add new flag for forcing a flush after dumping json data to file
authorLennart Poettering <lennart@poettering.net>
Wed, 29 May 2019 10:24:40 +0000 (12:24 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Dec 2019 08:47:00 +0000 (09:47 +0100)
This is particularly useful when no trailing \n is generated, i.e. stdio
doesn't flush the output on its own.

src/shared/json.c
src/shared/json.h

index 38b2bb14e4d7437352388daa4d17768d80b05331..7abbd1917d8a5c3ddfc1a6336631372bbde4ce4d 100644 (file)
@@ -1767,6 +1767,9 @@ void json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const cha
                 fputc('\n', f);
         if (flags & JSON_FORMAT_SSE)
                 fputc('\n', f); /* In case of SSE add a second newline */
+
+        if (flags & JSON_FORMAT_FLUSH)
+                fflush(f);
 }
 
 int json_variant_filter(JsonVariant **v, char **to_remove) {
index 40e74e03a483d924f96f82a8a128e30a0ea1d4b9..749c25253f8d394086405d4c4b286586f8cea0af 100644 (file)
@@ -168,6 +168,7 @@ typedef enum JsonFormatFlags {
         JSON_FORMAT_SOURCE     = 1 << 4, /* prefix with source filename/line/column */
         JSON_FORMAT_SSE        = 1 << 5, /* prefix/suffix with W3C server-sent events */
         JSON_FORMAT_SEQ        = 1 << 6, /* prefix/suffix with RFC 7464 application/json-seq */
+        JSON_FORMAT_FLUSH      = 1 << 7, /* call fflush() after dumping JSON */
 } JsonFormatFlags;
 
 int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);