From: Petr Oros <poros@redhat.com>
To: Vitaly Grinberg <vgrinber@redhat.com>, netdev@vger.kernel.org
Cc: stephen@networkplumber.org
Subject: Re: [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode
Date: Sun, 29 Mar 2026 13:47:54 +0200 [thread overview]
Message-ID: <eb41d806-27e3-4b3b-9c83-95e0305d940b@redhat.com> (raw)
In-Reply-To: <20260329-dpll-mon-j-v2-1-c8170a80e6d8@redhat.com>
> Previously, monitor mode wrapped all events in a single JSON array
> inside a top-level object, which made piping the output to external
> tools (such as `jq`) impossible.
> Send a separate JSON object for each event in monitor mode,
> making the output suitable for line-by-line consumers. Skip the
> global JSON wrapper for monitor mode.
>
> Signed-off-by: Vitaly Grinberg <vgrinber@redhat.com>
> ---
> v2:
> - Fixed indentation
> ---
> dpll/dpll.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/dpll/dpll.c b/dpll/dpll.c
> index 9893ca8c..49576d23 100644
> --- a/dpll/dpll.c
> +++ b/dpll/dpll.c
> @@ -571,8 +571,15 @@ int main(int argc, char **argv)
> argc -= optind;
> argv += optind;
>
> - new_json_obj_plain(json);
> - open_json_object(NULL);
> + /* Monitor emits one JSON object per event for streaming;
> + * other commands use a single JSON wrapper object.
> + */
> + bool is_monitor = argc > 0 && strcmp(argv[0], "monitor") == 0;
> +
> + if (!is_monitor) {
> + new_json_obj_plain(json);
> + open_json_object(NULL);
> + }
>
> /* Skip netlink init for help commands */
> bool need_nl = true;
> @@ -602,8 +609,10 @@ dpll_fini:
> if (need_nl)
> dpll_fini(dpll);
> json_cleanup:
> - close_json_object();
> - delete_json_obj_plain();
> + if (!is_monitor) {
> + close_json_object();
> + delete_json_obj_plain();
> + }
> dpll_free:
> dpll_free(dpll);
> return ret;
> @@ -2173,6 +2182,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>
> mnl_attr_parse(nlh, sizeof(struct genlmsghdr), attr_cb, tb);
>
> + new_json_obj_plain(json);
> open_json_object(NULL);
> print_string(PRINT_JSON, "name", NULL, json_name);
> open_json_object("msg");
> @@ -2182,6 +2192,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>
> close_json_object();
> close_json_object();
> + delete_json_obj_plain();
> break;
> }
> case DPLL_CMD_PIN_CREATE_NTF:
> @@ -2200,6 +2211,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
> json_name = "pin-delete-ntf";
> }
>
> + new_json_obj_plain(json);
> open_json_object(NULL);
> print_string(PRINT_JSON, "name", NULL, json_name);
> open_json_object("msg");
> @@ -2209,6 +2221,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>
> close_json_object();
> close_json_object();
> + delete_json_obj_plain();
> break;
> }
> default:
> @@ -2273,8 +2286,6 @@ static int cmd_monitor(struct dpll *dpll)
> goto err_signalfd;
> }
>
> - open_json_array(PRINT_JSON, "monitor");
> -
> pfds[0].fd = signal_fd;
> pfds[0].events = POLLIN;
> pfds[1].fd = netlink_fd;
> @@ -2307,8 +2318,6 @@ static int cmd_monitor(struct dpll *dpll)
> }
> }
>
> - close_json_array(PRINT_JSON, NULL);
> -
> err_signalfd:
> if (signal_fd >= 0)
> close(signal_fd);
>
> ---
> base-commit: 36252727bfc653905bb39bec115a32869452beb1
> change-id: 20260328-dpll-mon-j-d88eb48c1f09
>
> Best regards,
> --
> Vitaly Grinberg <vgrinber@redhat.com>
>
>
Good idea, Thanks
Reviewed-by: Petr Oros <poros@redhat.com>
next prev parent reply other threads:[~2026-03-29 11:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 7:51 [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
2026-03-29 11:47 ` Petr Oros [this message]
2026-03-30 8:50 ` Ivan Vecera
2026-04-05 17:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb41d806-27e3-4b3b-9c83-95e0305d940b@redhat.com \
--to=poros@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=vgrinber@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox