json: add new flag for forcing a flush after dumping json data to file

This is particularly useful when no trailing \n is generated, i.e. stdio
doesn't flush the output on its own.
This commit is contained in:
Lennart Poettering 2019-05-29 12:24:40 +02:00
parent 0ac0787e30
commit 0b1f2e8a06
2 changed files with 4 additions and 0 deletions

View 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) {

View 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);