]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (refactor) add a helper function building ENDPOINTS strings for UNIX socket
authorMasatake YAMATO <yamato@redhat.com>
Sun, 9 Mar 2025 21:40:01 +0000 (06:40 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 14 Mar 2025 14:26:23 +0000 (23:26 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/sock-xinfo.c

index 4d9dfb81780d705e06270ba185b052c0af4772ef..c5227e3331ce6ff4c5db8658e691fcd76b91bb53 100644 (file)
@@ -629,6 +629,22 @@ static struct ipc *unix_get_peer_ipc(struct unix_xinfo *ux,
        return get_ipc(&dummy_peer_sock.file);
 }
 
+static void unix_fill_column_append_endpoints(struct ipc *peer_ipc, char **str)
+{
+       struct list_head *e;
+
+       list_for_each_backwardly(e, &peer_ipc->endpoints) {
+               struct sock *peer_sock = list_entry(e, struct sock, endpoint.endpoints);
+               char *estr;
+
+               if (*str)
+                       xstrputc(str, '\n');
+               estr = unix_xstrendpoint(peer_sock);
+               xstrappend(str, estr);
+               free(estr);
+       }
+}
+
 static bool unix_fill_column(struct proc *proc __attribute__((__unused__)),
                             struct sock_xinfo *sock_xinfo,
                             struct sock *sock,
@@ -639,7 +655,6 @@ static bool unix_fill_column(struct proc *proc __attribute__((__unused__)),
 {
        struct unix_xinfo *ux = (struct unix_xinfo *)sock_xinfo;
        struct ipc *peer_ipc;
-       struct list_head *e;
        char shutdown_chars[3] = { 0 };
 
        switch (column_id) {
@@ -654,9 +669,7 @@ static bool unix_fill_column(struct proc *proc __attribute__((__unused__)),
                if (!peer_ipc)
                        break;
 
-               list_for_each_backwardly(e, &peer_ipc->endpoints) {
-                       struct sock *peer_sock = list_entry(e, struct sock, endpoint.endpoints);
-                       char *estr;
+               unix_fill_column_append_endpoints(peer_ipc, str);
 
                        if (*str)
                                xstrputc(str, '\n');