From: Masatake YAMATO Date: Sun, 9 Mar 2025 22:26:49 +0000 (+0900) Subject: lsfd: add UNIX.IPEER column X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44de6a5e52c2bff9651a245cc81e4b01879cab58;p=thirdparty%2Futil-linux.git lsfd: add UNIX.IPEER column An example output: # ./lsfd -Q 'TYPE == "UNIX" && SOCK.TYPE == "dgram"' \ -oCOMMAND,PID,TYPE,INODE,UNIX.IPEER,NAME | head COMMAND PID TYPE INODE UNIX.IPEER NAME systemd 1 UNIX 3239 13482 state=connected type=dgram systemd 1 UNIX 1649064 1649065 state=connected type=dgram systemd 1 UNIX 1649065 1649064 state=connected type=dgram systemd 1 UNIX 13465 0 state=connected path=/run/systemd/notify type=dgram ... Signed-off-by: Masatake YAMATO --- diff --git a/lsfd-cmd/lsfd.1.adoc b/lsfd-cmd/lsfd.1.adoc index 4d6fde156..e23a65dee 100644 --- a/lsfd-cmd/lsfd.1.adoc +++ b/lsfd-cmd/lsfd.1.adoc @@ -554,6 +554,12 @@ Remote UDP port. UID <``number``>:: User ID number. +UNIX.IPEER < number >:: +Inode number for the peer of the UNIX domain socket. ++ +If *lsfd* runs in a container, it may not fill _UNIX.IPEER_ column. +See the description of _UNIX_ in _ENDPOINTS_ column for more details. + UNIX.PATH <``string``>:: Filesystem pathname for UNIX domain socket. diff --git a/lsfd-cmd/lsfd.c b/lsfd-cmd/lsfd.c index 41abeb204..9e6da1806 100644 --- a/lsfd-cmd/lsfd.c +++ b/lsfd-cmd/lsfd.c @@ -429,6 +429,9 @@ static const struct colinfo infos[] = { [COL_UID] = { "UID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("user ID number of the process") }, + [COL_UNIX_IPEER] = { "UNIX.IPEER", + 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, + N_("inode number for the peer of the UNIX domain socket") }, [COL_UNIX_PATH] = { "UNIX.PATH", 0.4, SCOLS_FL_TRUNC, SCOLS_JSON_STRING, N_("filesystem pathname for UNIX domain socket") }, diff --git a/lsfd-cmd/lsfd.h b/lsfd-cmd/lsfd.h index c9156757e..f6e640ae6 100644 --- a/lsfd-cmd/lsfd.h +++ b/lsfd-cmd/lsfd.h @@ -140,6 +140,7 @@ enum { COL_UDPLITE_LPORT, COL_UDPLITE_RPORT, COL_UID, /* process */ + COL_UNIX_IPEER, COL_UNIX_PATH, COL_USER, /* process */ COL_VSOCK_LADDR, diff --git a/lsfd-cmd/sock-xinfo.c b/lsfd-cmd/sock-xinfo.c index 6023e6fc3..6087563c1 100644 --- a/lsfd-cmd/sock-xinfo.c +++ b/lsfd-cmd/sock-xinfo.c @@ -676,6 +676,12 @@ static bool unix_fill_column(struct proc *proc __attribute__((__unused__)), return true; } break; + case COL_UNIX_IPEER: + if (ux->unix_ipc) { + xasprintf(str, "%llu", (unsigned long long)ux->unix_ipc->ipeer); + return true; + } + break; case COL_ENDPOINTS: if (ux->unix_ipc == NULL) break; diff --git a/tests/expected/lsfd/mkfds-unix-dgram-UNIX.IPEEER-column b/tests/expected/lsfd/mkfds-unix-dgram-UNIX.IPEEER-column new file mode 100644 index 000000000..38d35fc6b --- /dev/null +++ b/tests/expected/lsfd/mkfds-unix-dgram-UNIX.IPEEER-column @@ -0,0 +1,6 @@ +inode_s: 0 +inode_c: 0 +ipeer_s: 0 +ipeer_c: 0 +ipeer_s == 0: 0 +ipeer_s == inode_s: 0 diff --git a/tests/ts/lsfd/mkfds-unix-dgram b/tests/ts/lsfd/mkfds-unix-dgram index 1de791061..0087a8d83 100755 --- a/tests/ts/lsfd/mkfds-unix-dgram +++ b/tests/ts/lsfd/mkfds-unix-dgram @@ -102,4 +102,38 @@ else ts_finalize_subtest fi +ts_init_subtest "UNIX.IPEEER-column" +if ts_is_in_docker; then + ts_skip_subtest "unsupported in docker environment" +else + { + coproc MKFDS { "$TS_HELPER_MKFDS" unix-dgram $FDS $FDC \ + path=test_mkfds-unix-dgram \ + abstract=true ; } + + if read -r -u "${MKFDS[0]}" PID; then + inode_s=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDS" -o INODE) + echo inode_s: $? + inode_c=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDC" -o INODE) + echo inode_c: $? + + ipeer_s=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDS" -o UNIX.IPEER) + echo ipeer_s: $? + + ipeer_c=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDC" -o UNIX.IPEER) + echo ipeer_c: $? + + test "$ipeer_s" = 0 + echo "ipeer_s == 0:" $? + + test "$ipeer_c" = "$inode_s" + echo "ipeer_s == inode_s:" $? + + echo DONE >&"${MKFDS[1]}" + fi + wait "${MKFDS_PID}" + } > "$TS_OUTPUT" 2>&1 + ts_finalize_subtest +fi + ts_finalize