From: Fabien Siron Date: Wed, 22 Jun 2016 13:51:49 +0000 (+0000) Subject: socketutils.c: introduce cache_inode_details X-Git-Tag: v4.18~130 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=103744d27172a2a723919d2c8f59f4db2714e5a5;p=strace socketutils.c: introduce cache_inode_details cache_inode_details gives a way to obtain cache information without printing it. * socketutils.c (cache_and_print_inode_details): Rename to cache_inode_details. Do not print cached information. (inet_parse_response, unix_parse_response, netlink_parse_response): Use cache_inode_details instead of cache_and_print_inode_details. (inet_print, unix_print, netlink_print): Call print_sockaddr_by_inode_cached. Co-authored-by: Dmitry V. Levin --- diff --git a/socketutils.c b/socketutils.c index 38b0b158..133e2160 100644 --- a/socketutils.c +++ b/socketutils.c @@ -57,14 +57,13 @@ static cache_entry cache[CACHE_SIZE]; #define CACHE_MASK (CACHE_SIZE - 1) static int -cache_and_print_inode_details(const unsigned long inode, char *const details) +cache_inode_details(const unsigned long inode, char *const details) { cache_entry *e = &cache[inode & CACHE_MASK]; free(e->details); e->inode = inode; e->details = details; - tprints(details); return 1; } @@ -185,7 +184,7 @@ inet_parse_response(const char *const proto_name, const void *const data, return false; } - return cache_and_print_inode_details(inode, details); + return cache_inode_details(inode, details); } static bool @@ -245,7 +244,8 @@ inet_print(const int fd, const int family, const int protocol, const unsigned long inode, const char *proto_name) { return inet_send_query(fd, family, protocol) - && receive_responses(fd, inode, proto_name, inet_parse_response); + && receive_responses(fd, inode, proto_name, inet_parse_response) + && print_sockaddr_by_inode_cached(inode); } static bool @@ -344,7 +344,7 @@ unix_parse_response(const char *proto_name, const void *data, peer_str, path_str) < 0) return -1; - return cache_and_print_inode_details(inode, details); + return cache_inode_details(inode, details); } static bool @@ -398,14 +398,15 @@ netlink_parse_response(const char *proto_name, const void *data, return -1; } - return cache_and_print_inode_details(inode, details); + return cache_inode_details(inode, details); } static bool unix_print(const int fd, const unsigned long inode) { return unix_send_query(fd, inode) - && receive_responses(fd, inode, "UNIX", unix_parse_response); + && receive_responses(fd, inode, "UNIX", unix_parse_response) + && print_sockaddr_by_inode_cached(inode); } static bool @@ -437,7 +438,8 @@ netlink_print(const int fd, const unsigned long inode) { return netlink_send_query(fd, inode) && receive_responses(fd, inode, "NETLINK", - netlink_parse_response); + netlink_parse_response) + && print_sockaddr_by_inode_cached(inode); } static const struct {