From 1272be04be0cb803eec87f602edb2e3e6f111aea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:34 +0200 Subject: Merging upstream version 2.40. Signed-off-by: Daniel Baumann --- misc-utils/lsfd-sock.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'misc-utils/lsfd-sock.c') diff --git a/misc-utils/lsfd-sock.c b/misc-utils/lsfd-sock.c index 3264516..4c75e6e 100644 --- a/misc-utils/lsfd-sock.c +++ b/misc-utils/lsfd-sock.c @@ -22,17 +22,29 @@ #include #include -#include "xalloc.h" -#include "nls.h" -#include "libsmartcols.h" - #include "lsfd.h" #include "lsfd-sock.h" 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__)), @@ -43,6 +55,15 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)), { char *str = NULL; struct sock *sock = (struct sock *)file; + + if (sock->xinfo && sock->xinfo->class + && sock->xinfo->class->fill_column) { + if (sock->xinfo->class->fill_column(proc, sock->xinfo, sock, ln, + column_id, column_index, + &str)) + goto out; + } + switch(column_id) { case COL_TYPE: if (!sock->protoname) @@ -99,17 +120,14 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)), ? "1" : "0"); break; + case COL_SOCK_SHUTDOWN: + str = xstrdup("??"); + break; default: - if (sock->xinfo && sock->xinfo->class - && sock->xinfo->class->fill_column) { - if (sock->xinfo->class->fill_column(proc, sock->xinfo, sock, ln, - column_id, column_index, - &str)) - break; - } return false; } + out: if (!str) err(EXIT_FAILURE, _("failed to add output data")); if (scols_line_refer_data(ln, column_index, str)) @@ -120,13 +138,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; @@ -147,6 +165,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) @@ -177,4 +197,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, }; -- cgit v1.2.3