From c89b578f33dae9f66149ff2e32405d84abb2d4d6 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Tue, 22 Oct 2024 12:03:50 -0400 Subject: [PATCH 1/2] varlinkctl: do not clobber format flags in verb_call Currently, when SD_JSON_FORMAT_OFF is set in verb_call, the json format flags are set to SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO, rather than or'ing those flags in. This means that other flags that may have been set, e.g. SD_JSON_FORMAT_SEQ when --more is set, will be clobbered. Fix this by masking SD_JSON_FORMAT_OFF out, and then or'ing the new flags in. --- src/varlinkctl/varlinkctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index f88a105093..f204b0f3c9 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -539,8 +539,10 @@ static int verb_call(int argc, char *argv[], void *userdata) { parameter = argc > 3 && !streq(argv[3], "-") ? argv[3] : NULL; /* No JSON mode explicitly configured? Then default to the same as -j */ - if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) - arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO; + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { + arg_json_format_flags &= ~SD_JSON_FORMAT_OFF; + arg_json_format_flags |= SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO; + } /* For pipeable text tools it's kinda customary to finish output off in a newline character, and not * leave incomplete lines hanging around. */ From ebc8b9e45b11c8e6c66b91e36cba6591ad6f9b38 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Tue, 22 Oct 2024 12:09:55 -0400 Subject: [PATCH 2/2] varlinkctl: set SD_JSON_FORMAT_FLUSH when --more is set This makes it possible to process continuous replies with jq etc. --- src/varlinkctl/varlinkctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index f204b0f3c9..b6c6c0da42 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -194,9 +194,9 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached(); } - /* If more than one reply is expected, imply JSON-SEQ output */ + /* If more than one reply is expected, imply JSON-SEQ output, and set SD_JSON_FORMAT_FLUSH */ if (FLAGS_SET(arg_method_flags, SD_VARLINK_METHOD_MORE)) - arg_json_format_flags |= SD_JSON_FORMAT_SEQ; + arg_json_format_flags |= SD_JSON_FORMAT_SEQ|SD_JSON_FORMAT_FLUSH; strv_sort_uniq(arg_graceful);