public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next] dpll: Send object per event in JSON monitor mode
@ 2026-03-28  8:45 Vitaly Grinberg
  2026-03-28 16:17 ` Vitaly Grinberg
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Grinberg @ 2026-03-28  8:45 UTC (permalink / raw)
  To: netdev; +Cc: stephen

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>
---
 dpll/dpll.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/dpll/dpll.c b/dpll/dpll.c
index 7b05bf86..6736c85e 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;
@@ -1840,6 +1849,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");
@@ -1849,6 +1859,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:
@@ -1867,6 +1878,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");
@@ -1876,6 +1888,7 @@ static int cmd_monitor_cb(const struct nlmsghdr
*nlh, void *data)

  close_json_object();
  close_json_object();
+ delete_json_obj_plain();
  break;
  }
  default:
@@ -1941,8 +1954,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;
@@ -1975,8 +1986,6 @@ static int cmd_monitor(struct dpll *dpll)
  }
  }

- close_json_array(PRINT_JSON, NULL);
-
 err_signalfd:
  if (signal_fd >= 0)
  close(signal_fd);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2-next] dpll: Send object per event in JSON monitor mode
  2026-03-28  8:45 [PATCH iproute2-next] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
@ 2026-03-28 16:17 ` Vitaly Grinberg
  0 siblings, 0 replies; 2+ messages in thread
From: Vitaly Grinberg @ 2026-03-28 16:17 UTC (permalink / raw)
  To: vgrinber, netdev; +Cc: stephen

Hello,
Please ignore this version; I found an indentation problem and will be sending a v2 shortly.
Best regards,
Vitaly


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-28 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28  8:45 [PATCH iproute2-next] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
2026-03-28 16:17 ` Vitaly Grinberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox