diff mbox series

[iproute2-next,3/7] ss: Do not call user_ent_hash_build() more than once

Message ID 546e9515257ecb00f09baea80ead5e9311c07f75.1653446538.git.peilin.ye@bytedance.com (mailing list archive)
State Accepted
Commit cd845a85681bf2851b38041587fa75605beebbe9
Delegated to: David Ahern
Headers show
Series ss: Introduce -T, --threads option | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Peilin Ye May 25, 2022, 2:52 a.m. UTC
From: Peilin Ye <peilin.ye@bytedance.com>

Call user_ent_hash_build() once after the getopt_long() loop if -p, -z
or -Z is used.

Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
 misc/ss.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/misc/ss.c b/misc/ss.c
index bccf01bb5efa..dd7b67a76255 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -596,13 +596,6 @@  static void user_ent_hash_build(void)
 	char *pid_context;
 	char *sock_context;
 	const char *no_ctx = "unavailable";
-	static int user_ent_hash_build_init;
-
-	/* If show_users & show_proc_ctx set only do this once */
-	if (user_ent_hash_build_init != 0)
-		return;
-
-	user_ent_hash_build_init = 1;
 
 	strlcpy(name, root, sizeof(name));
 
@@ -5509,7 +5502,6 @@  int main(int argc, char *argv[])
 			break;
 		case 'p':
 			show_users++;
-			user_ent_hash_build();
 			break;
 		case 'b':
 			show_options = 1;
@@ -5644,7 +5636,6 @@  int main(int argc, char *argv[])
 				exit(1);
 			}
 			show_proc_ctx++;
-			user_ent_hash_build();
 			break;
 		case 'N':
 			if (netns_switch(optarg))
@@ -5679,6 +5670,9 @@  int main(int argc, char *argv[])
 		}
 	}
 
+	if (show_users || show_proc_ctx || show_sock_ctx)
+		user_ent_hash_build();
+
 	argc -= optind;
 	argv += optind;