]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: append SOCK.SHUTDOWN value to ENDPOINTS column of UNIX-STREAM sockets
authorMasatake YAMATO <yamato@redhat.com>
Mon, 2 Oct 2023 14:50:21 +0000 (23:50 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 9 Oct 2023 06:42:36 +0000 (15:42 +0900)
An example output:

   # ./lsfd -Q '((PID == 1) || (PID == 1896)) && (TYPE == "UNIX-STREAM") && ((FD == 1) || (FD == 278))' -o+ENDPOINTS
   COMMAND        PID USER ASSOC  XMODE        TYPE SOURCE MNTID INODE NAME                                             ENDPOINTS
   systemd          1 root   278 rw---m UNIX-STREAM sockfs     9 37012 state=connected path=/run/systemd/journal/stdout 1896,ModemManager,1-w
   ModemManager  1896 root     1 rw---- UNIX-STREAM sockfs     9 43126 state=connected                                  1,systemd,278r-
                                                                                                                        1870458,systemd-journal,68r-

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock-xinfo.c
tests/expected/lsfd/mkfds-socketpair-STREAM-ENDPOINT

index a0e82026d779c06d5b7c09d8f6c2b043c015cefb..7ea8f2efe2be2003ffc506ac542dceb6f46668f7 100644 (file)
@@ -538,8 +538,16 @@ static bool unix_shutdown_chars(struct unix_xinfo *ux, char rw[2])
 static inline char *unix_xstrendpoint(struct sock *sock)
 {
        char *str = NULL;
-       xasprintf(&str, "%d,%s,%d",
-                 sock->file.proc->pid, sock->file.proc->command, sock->file.association);
+       char shutdown_chars[3] = { 0 };
+
+       if (!unix_shutdown_chars(((struct unix_xinfo *)sock->xinfo), shutdown_chars)) {
+               shutdown_chars[0] = '?';
+               shutdown_chars[1] = '?';
+       }
+       xasprintf(&str, "%d,%s,%d%c%c",
+                 sock->file.proc->pid, sock->file.proc->command, sock->file.association,
+                 shutdown_chars[0], shutdown_chars[1]);
+
        return str;
 }
 
index ad015d8dec1119b136954b141199e1ca6fb45036..02f6498a9670dc87bf841993053d64fa2928f97a 100644 (file)
@@ -1,3 +1,3 @@
-3 rw- SOCK sockfs 1,test_mkfds,4
-4 rw- SOCK sockfs 1,test_mkfds,3
+3 rw- SOCK sockfs 1,test_mkfds,4rw
+4 rw- SOCK sockfs 1,test_mkfds,3rw
 ASSOC,MODE,STTYPE,SOURCE,ENDPOINTS: 0