]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add UNIX.IPEER column
authorMasatake YAMATO <yamato@redhat.com>
Sun, 9 Mar 2025 22:26:49 +0000 (07:26 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 14 Mar 2025 21:51:45 +0000 (06:51 +0900)
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 <yamato@redhat.com>
lsfd-cmd/lsfd.1.adoc
lsfd-cmd/lsfd.c
lsfd-cmd/lsfd.h
lsfd-cmd/sock-xinfo.c
tests/expected/lsfd/mkfds-unix-dgram-UNIX.IPEEER-column [new file with mode: 0644]
tests/ts/lsfd/mkfds-unix-dgram

index 4d6fde156a82ac114fd0d52ef0a96d8c80831c89..e23a65deec30d82fbde165b57bd77fa6024a4358 100644 (file)
@@ -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.
 
index 41abeb204ba909b1d0d20454210ec774ec771c08..9e6da180624b3678adb4b1a5c09d66aa327f2e30 100644 (file)
@@ -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") },
index c9156757e1199930cd6ddcc1b87ee8aa11033f17..f6e640ae6bbc30752913bfb17aaa4dcd3d34f4e5 100644 (file)
@@ -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,
index 6023e6fc3c10ac353cffe53ecbed400b74910426..6087563c1cd2c8f96b4401397cad3af5e3b62687 100644 (file)
@@ -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 (file)
index 0000000..38d35fc
--- /dev/null
@@ -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
index 1de791061a1c38f68a94f89f93a26f4d30824e47..0087a8d833a50094c246a06816ce6330a31b1351 100755 (executable)
@@ -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