From ebc64de22f84f62dc48e5d16ec5d12ca82222b74 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 28 Oct 2024 13:26:01 +0100 Subject: [PATCH] udevadm: automatically anable JSON-SEQ in case JSON is used for "udevadm info -a" We are going to output a series of JSON objects, hence let's automatically enable JSON-SEQ output mode, as we usually do. "jq --seq" supports this natively, hence this should not really restrict us. Follow-up for: 67ea8a4c0edef33b1775536bc81d5de2c8ac4d88 --- man/udevadm.xml | 5 +++++ src/udev/udevadm-info.c | 2 ++ test/units/TEST-17-UDEV.10.sh | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/man/udevadm.xml b/man/udevadm.xml index 556f845dcee..eb77356d869 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -167,6 +167,11 @@ Print all sysfs properties of the specified device that can be used in udev rules to match the specified device. It prints all devices along the chain, up to the root of sysfs that can be used in udev rules. + + This switch supports JSON output mode (see below). Note that + because this switch generates multiple JSON objects, JSON-SEQ mode is automatically enabled + (RFC7464). (Note: tools such as jq + natively support JSON-SEQ via the switch.) diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 30f34b49585..57f063b0108 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -274,6 +274,8 @@ static int print_device_chain_in_json(sd_device *device) { assert(device); + arg_json_format_flags |=SD_JSON_FORMAT_SEQ; + r = print_all_attributes_in_json(device, /* is_parent = */ false); if (r < 0) return r; diff --git a/test/units/TEST-17-UDEV.10.sh b/test/units/TEST-17-UDEV.10.sh index 1808e1975b6..7ca05f5287f 100755 --- a/test/units/TEST-17-UDEV.10.sh +++ b/test/units/TEST-17-UDEV.10.sh @@ -71,8 +71,8 @@ udevadm info --query symlink --root /sys/class/net/$netdev (! udevadm info -q hello -r /sys/class/net/$netdev) udevadm info -a /sys/class/net/$netdev udevadm info -a --json=off /sys/class/net/$netdev -udevadm info -a --json=pretty /sys/class/net/$netdev | jq . >/dev/null -udevadm info -a --json=short /sys/class/net/$netdev | jq . >/dev/null +udevadm info -a --json=pretty /sys/class/net/$netdev | jq --seq . >/dev/null +udevadm info -a --json=short /sys/class/net/$netdev | jq --seq . >/dev/null udevadm info -t >/dev/null udevadm info --tree /sys/class/net/$netdev udevadm info -x /sys/class/net/$netdev