From e16bdb1bb90ab7f88eeac83c61135c9a1eb94e47 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 3 Jun 2017 17:52:24 +0000 Subject: [PATCH] Unexport print_sockaddr_by_inode_cached Change print_sockaddr_by_inode to be the only function exposed, hide print_sockaddr_by_inode_cached as a part of implementation. * defs.h (print_sockaddr_by_inode_cached): Remove prototype. (print_sockaddr_by_inode): Add struct tcb * and descriptor arguments. * socketutils.c (print_sockaddr_by_inode_cached): Make static. (print_sockaddr_by_inode): Rename to print_sockaddr_by_inode_uncached, make static. (print_sockaddr_by_inode): New function. * util.c (printfd): Update to use new print_sockaddr_by_inode. --- defs.h | 3 +-- socketutils.c | 19 +++++++++++++------ util.c | 17 ++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/defs.h b/defs.h index 3c8c5a76..70ff07bc 100644 --- a/defs.h +++ b/defs.h @@ -596,8 +596,7 @@ printpath(struct tcb *, kernel_ulong_t addr); (sizeof(long long) * 3 * 2 + sizeof("{tv_sec=-, tv_nsec=}")) extern void printfd(struct tcb *, int); extern void print_sockaddr(struct tcb *tcp, const void *, int); -extern bool print_sockaddr_by_inode(const unsigned long, const enum sock_proto); -extern bool print_sockaddr_by_inode_cached(const unsigned long); +extern bool print_sockaddr_by_inode(struct tcb *, int fd, unsigned long inode); extern void print_dirfd(struct tcb *, int); extern int diff --git a/socketutils.c b/socketutils.c index 534c56eb..984c41be 100644 --- a/socketutils.c +++ b/socketutils.c @@ -68,7 +68,7 @@ cache_and_print_inode_details(const unsigned long inode, char *const details) return 1; } -bool +static bool print_sockaddr_by_inode_cached(const unsigned long inode) { const cache_entry *const e = &cache[inode & CACHE_MASK]; @@ -457,11 +457,9 @@ get_proto_by_name(const char *const name) return SOCK_PROTO_UNKNOWN; } -/* Given an inode number of a socket, print out the details - * of the ip address and port. */ - -bool -print_sockaddr_by_inode(const unsigned long inode, const enum sock_proto proto) +static bool +print_sockaddr_by_inode_uncached(const unsigned long inode, + const enum sock_proto proto) { if ((unsigned int) proto >= ARRAY_SIZE(protocols) || (proto != SOCK_PROTO_UNKNOWN && !protocols[proto].print)) @@ -493,3 +491,12 @@ print_sockaddr_by_inode(const unsigned long inode, const enum sock_proto proto) close(fd); return r; } + +/* Given an inode number of a socket, print out its protocol details. */ +bool +print_sockaddr_by_inode(struct tcb *const tcp, const int fd, + const unsigned long inode) +{ + return print_sockaddr_by_inode_cached(inode) ? true : + print_sockaddr_by_inode_uncached(inode, getfdproto(tcp, fd)); +} diff --git a/util.c b/util.c index 50334b4f..e33b0a95 100644 --- a/util.c +++ b/util.c @@ -640,17 +640,12 @@ printfd(struct tcb *tcp, int fd) unsigned long inode; tprintf("%d<", fd); - if (show_fd_path > 1 - && (str = STR_STRIP_PREFIX(path, "socket:[")) != path - && (len = strlen(str)) && str[len - 1] == ']' - && (inode = strtoul(str, NULL, 10))) { - if (!print_sockaddr_by_inode_cached(inode)) { - const enum sock_proto proto = - getfdproto(tcp, fd); - if (!print_sockaddr_by_inode(inode, proto)) - tprints(path); - } - } else { + if (show_fd_path <= 1 + || (str = STR_STRIP_PREFIX(path, "socket:[")) == path + || !(len = strlen(str)) + || str[len - 1] != ']' + || !(inode = strtoul(str, NULL, 10)) + || !print_sockaddr_by_inode(tcp, fd, inode)) { print_quoted_string(path, strlen(path), QUOTE_OMIT_LEADING_TRAILING_QUOTES); } -- 2.50.1