From patchwork Fri Nov 11 13:10:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 693664 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tFgJY22GVz9t1b for ; Sat, 12 Nov 2016 00:10:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756279AbcKKNKd (ORCPT ); Fri, 11 Nov 2016 08:10:33 -0500 Received: from orbyte.nwl.cc ([151.80.46.58]:37466 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755700AbcKKNKc (ORCPT ); Fri, 11 Nov 2016 08:10:32 -0500 Received: from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 08CCC653F9; Fri, 11 Nov 2016 14:10:31 +0100 (CET) Received: from xsao (localhost [IPv6:::1]) by mail.nwl.cc (Postfix) with ESMTP id DF29C6533B; Fri, 11 Nov 2016 14:10:30 +0100 (CET) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH 05/18] ss: introduce proc_ctx_print() Date: Fri, 11 Nov 2016 14:10:01 +0100 Message-Id: <20161111131014.21865-6-phil@nwl.cc> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161111131014.21865-1-phil@nwl.cc> References: <20161111131014.21865-1-phil@nwl.cc> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This consolidates identical code in three places. While the function name is not quite perfect as there is different proc_ctx printing code in netlink_show_one() as well, I sadly didn't find a more suitable one. Signed-off-by: Phil Sutter --- misc/ss.c | 49 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index e6053467aaf82..b3475cc96ae7b 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -1719,14 +1719,9 @@ void *parse_markmask(const char *markmask) return res; } -static void inet_stats_print(struct sockstat *s) +static void proc_ctx_print(struct sockstat *s) { - char *buf = NULL; - - sock_state_print(s); - - inet_addr_print(&s->local, s->lport, s->iface); - inet_addr_print(&s->remote, s->rport, 0); + char *buf; if (show_proc_ctx || show_sock_ctx) { if (find_entry(s->ino, &buf, @@ -1743,6 +1738,16 @@ static void inet_stats_print(struct sockstat *s) } } +static void inet_stats_print(struct sockstat *s) +{ + sock_state_print(s); + + inet_addr_print(&s->local, s->lport, s->iface); + inet_addr_print(&s->remote, s->rport, 0); + + proc_ctx_print(s); +} + static int proc_parse_inet_addr(char *loc, char *rem, int family, struct sockstat * s) { @@ -2814,7 +2819,6 @@ static void unix_stats_print(struct sockstat *list, struct filter *f) { struct sockstat *s; char *peer; - char *ctx_buf = NULL; bool use_proc = unix_use_proc(); char port_name[30] = {}; @@ -2863,19 +2867,7 @@ static void unix_stats_print(struct sockstat *list, struct filter *f) sock_addr_print(peer, " ", int_to_str(s->rport, port_name), NULL); - if (show_proc_ctx || show_sock_ctx) { - if (find_entry(s->ino, &ctx_buf, - (show_proc_ctx & show_sock_ctx) ? - PROC_SOCK_CTX : PROC_CTX) > 0) { - printf(" users:(%s)", ctx_buf); - free(ctx_buf); - } - } else if (show_users) { - if (find_entry(s->ino, &ctx_buf, USERS) > 0) { - printf(" users:(%s)", ctx_buf); - free(ctx_buf); - } - } + proc_ctx_print(s); printf("\n"); } } @@ -3071,7 +3063,6 @@ static int unix_show(struct filter *f) static int packet_stats_print(struct sockstat *s, const struct filter *f) { - char *buf = NULL; const char *addr, *port; char ll_name[16]; @@ -3098,19 +3089,7 @@ static int packet_stats_print(struct sockstat *s, const struct filter *f) sock_addr_print(addr, ":", port, NULL); sock_addr_print("", "*", "", NULL); - if (show_proc_ctx || show_sock_ctx) { - if (find_entry(s->ino, &buf, - (show_proc_ctx & show_sock_ctx) ? - PROC_SOCK_CTX : PROC_CTX) > 0) { - printf(" users:(%s)", buf); - free(buf); - } - } else if (show_users) { - if (find_entry(s->ino, &buf, USERS) > 0) { - printf(" users:(%s)", buf); - free(buf); - } - } + proc_ctx_print(s); if (show_details) sock_details_print(s);