From: Masatake YAMATO Date: Thu, 22 Jun 2023 05:42:34 +0000 (+0900) Subject: lsfd: use ARRAY_STRING and ARRAY_NUMBER json types in some columns X-Git-Tag: v2.40-rc1~373^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42497e7d92280770ca048ff5bb8bf81a431dab13;p=thirdparty%2Futil-linux.git lsfd: use ARRAY_STRING and ARRAY_NUMBER json types in some columns Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 15280407c5..b5a607c8f5 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -145,13 +145,13 @@ static const struct colinfo infos[] = { 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("device type (blk, char, or nodev)") }, [COL_ENDPOINTS] = { "ENDPOINTS", - 0, SCOLS_FL_WRAP, SCOLS_JSON_STRING, + 0, SCOLS_FL_WRAP, SCOLS_JSON_ARRAY_STRING, N_("IPC endpoints information communicated with the fd") }, [COL_EVENTFD_ID] = {"EVENTFD.ID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("eventfd ID") }, [COL_EVENTPOLL_TFDS] = {"EVENTPOLL.TFDS", - 0, SCOLS_FL_WRAP, SCOLS_JSON_STRING, + 0, SCOLS_FL_WRAP, SCOLS_JSON_ARRAY_NUMBER, N_("file descriptors targeted by the eventpoll file") }, [COL_FD] = { "FD", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, @@ -178,10 +178,10 @@ static const struct colinfo infos[] = { 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("inode number") }, [COL_INOTIFY_INODES] = { "INOTIFY.INODES", - 0, SCOLS_FL_WRAP, SCOLS_JSON_STRING, + 0, SCOLS_FL_WRAP, SCOLS_JSON_ARRAY_STRING, N_("list of monitoring inodes (cooked)") }, [COL_INOTIFY_INODES_RAW]={ "INOTIFY.INODES.RAW", - 0, SCOLS_FL_WRAP, SCOLS_JSON_STRING, + 0, SCOLS_FL_WRAP, SCOLS_JSON_ARRAY_STRING, N_("list of monitoring inodes (raw, don't decode devices)") }, [COL_KNAME] = { "KNAME", 0.4, SCOLS_FL_TRUNC, SCOLS_JSON_STRING, @@ -1603,6 +1603,8 @@ static void __attribute__((__noreturn__)) usage(void) for (i = 0; i < ARRAY_SIZE(infos); i++) fprintf(out, " %16s %-10s%s\n", infos[i].name, infos[i].json_type == SCOLS_JSON_STRING? "": + infos[i].json_type == SCOLS_JSON_ARRAY_STRING? "": + infos[i].json_type == SCOLS_JSON_ARRAY_STRING? "": infos[i].json_type == SCOLS_JSON_NUMBER? "": "", _(infos[i].help)); diff --git a/tests/expected/lsfd/mkfds-eventpoll b/tests/expected/lsfd/mkfds-eventpoll index 1d5a69b551..8f035ffba2 100644 --- a/tests/expected/lsfd/mkfds-eventpoll +++ b/tests/expected/lsfd/mkfds-eventpoll @@ -1,3 +1,16 @@ 3 eventpoll tfds=5,7 5 7 ASSOC,TYPE,NAME,EVENTPOLL.TFDS: 0 +{ + "lsfd": [ + { + "assoc": "3", + "type": "eventpoll", + "name": "tfds=5,7", + "eventpoll.tfds": [ + 5, 7 + ] + } + ] +} +ASSOC,TYPE,NAME,EVENTPOLL.TFDS (JSON): 0 diff --git a/tests/expected/lsfd/mkfds-inotify b/tests/expected/lsfd/mkfds-inotify index f456649405..cb55f96692 100644 --- a/tests/expected/lsfd/mkfds-inotify +++ b/tests/expected/lsfd/mkfds-inotify @@ -1,2 +1,4 @@ INOTIFY.INODES.RAW: 0 INOTIFY.INODES.RAW == FSTAB\x0aROOT +INOTIFY.INODES.RAW (JSON): 0 +INOTIFY.INODES.RAW == EXPECTED_JSON diff --git a/tests/ts/lsfd/mkfds-eventpoll b/tests/ts/lsfd/mkfds-eventpoll index 26a25a1815..0d0cc68ce0 100755 --- a/tests/ts/lsfd/mkfds-eventpoll +++ b/tests/ts/lsfd/mkfds-eventpoll @@ -36,6 +36,8 @@ FD2=7 EXPR='(FD == '"$FD0"')' ${TS_CMD_LSFD} -p "${PID}" -n -o ASSOC,TYPE,NAME,EVENTPOLL.TFDS -Q "${EXPR}" echo 'ASSOC,TYPE,NAME,EVENTPOLL.TFDS': $? + ${TS_CMD_LSFD} -J -p "${PID}" -n -o ASSOC,TYPE,NAME,EVENTPOLL.TFDS -Q "${EXPR}" + echo 'ASSOC,TYPE,NAME,EVENTPOLL.TFDS (JSON)': $? kill -CONT ${PID} fi wait ${MKFDS_PID} diff --git a/tests/ts/lsfd/mkfds-inotify b/tests/ts/lsfd/mkfds-inotify index 2097c73bb8..6d29c7c99f 100755 --- a/tests/ts/lsfd/mkfds-inotify +++ b/tests/ts/lsfd/mkfds-inotify @@ -45,6 +45,26 @@ FSTAB="$(stat -c %i /etc/fstab)"@"$(((FSTAB_DEV >> 8) & 255)):$((FSTAB_DEV & 255 echo "FSTAB": "$FSTAB" echo "ROOT": "$ROOT" fi + INODES_RAW_JSON=$(${TS_CMD_LSFD} -J --raw -n -o INOTIFY.INODES.RAW -Q "${EXPR}") + echo "INOTIFY.INODES.RAW (JSON)": $? + EXPECTED_JSON=$(cat<