]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: make the sock_xinfo layer be able to prepare an ipc_class for a given socket
authorMasatake YAMATO <yamato@redhat.com>
Thu, 3 Aug 2023 15:51:49 +0000 (00:51 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 2 Oct 2023 12:01:32 +0000 (21:01 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock.c
misc-utils/lsfd-sock.h

index 5ed133e65238a904be7a61f351a8922dfeee9398..7da2f61e589dbf326e59eb621de7932b2b008f3c 100644 (file)
 static void attach_sock_xinfo(struct file *file)
 {
        struct sock *sock = (struct sock *)file;
+
        sock->xinfo = get_sock_xinfo(file->stat.st_ino);
+       if (sock->xinfo) {
+               struct ipc *ipc = get_ipc(file);
+               if (ipc)
+                       add_endpoint(&sock->endpoint, ipc);
+       }
+}
+
+static const struct ipc_class *sock_get_ipc_class(struct file *file)
+{
+       struct sock *sock = (struct sock *)file;
+
+       if (sock->xinfo && sock->xinfo->class->get_ipc_class)
+               return sock->xinfo->class->get_ipc_class(sock->xinfo, sock);
+
+       return NULL;
 }
 
 static bool sock_fill_column(struct proc *proc __attribute__((__unused__)),
@@ -116,13 +132,13 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)),
 static void init_sock_content(struct file *file)
 {
        int fd;
+       struct sock *sock = (struct sock *)file;
 
        assert(file);
 
        fd = file->association;
 
        if (fd >= 0 || fd == -ASSOC_MEM || fd == -ASSOC_SHM) {
-               struct sock *sock = (struct sock *)file;
                char path[PATH_MAX] = {'\0'};
                char buf[256];
                ssize_t len;
@@ -143,6 +159,8 @@ static void init_sock_content(struct file *file)
                        sock->protoname = xstrdup(buf);
                }
        }
+
+       init_endpoint(&sock->endpoint);
 }
 
 static void free_sock_content(struct file *file)
@@ -173,4 +191,5 @@ const struct file_class sock_class = {
        .free_content = free_sock_content,
        .initialize_class = initialize_sock_class,
        .finalize_class = finalize_sock_class,
+       .get_ipc_class = sock_get_ipc_class,
 };
index 61bdaeb7e3a00d57062351883563fb2dc0393fba..50360b70351e73fd1dfa9160d81c41684b6739fe 100644 (file)
@@ -43,6 +43,7 @@ struct sock {
        struct file file;
        char *protoname;
        struct sock_xinfo *xinfo;
+       struct ipc_endpoint endpoint;
 };
 
 struct sock_xinfo_class {
@@ -60,6 +61,7 @@ struct sock_xinfo_class {
                            int,
                            size_t,
                            char **str);
+       struct ipc_class *(*get_ipc_class)(struct sock_xinfo *, struct sock *);
 
        void (*free)(struct sock_xinfo *);
 };