From: Masatake YAMATO Date: Thu, 3 Aug 2023 15:51:49 +0000 (+0900) Subject: lsfd: make the sock_xinfo layer be able to prepare an ipc_class for a given socket X-Git-Tag: v2.40-rc1~210^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=046c5d5a2f4b0b8344cf0cad7e05a68a1e313710;p=thirdparty%2Futil-linux.git lsfd: make the sock_xinfo layer be able to prepare an ipc_class for a given socket Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock.c b/misc-utils/lsfd-sock.c index 5ed133e652..7da2f61e58 100644 --- a/misc-utils/lsfd-sock.c +++ b/misc-utils/lsfd-sock.c @@ -28,7 +28,23 @@ 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, }; diff --git a/misc-utils/lsfd-sock.h b/misc-utils/lsfd-sock.h index 61bdaeb7e3..50360b7035 100644 --- a/misc-utils/lsfd-sock.h +++ b/misc-utils/lsfd-sock.h @@ -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 *); };