aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2020-12-30 18:40:37 +0000
committerAlexander Motin <mav@FreeBSD.org>2020-12-30 18:45:53 +0000
commitccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8 (patch)
treee4cf7e8ea1de09e4e5b292c87edf8ac520bf1e2f
parent697684325da855f0dcb1ad02b09779575b05a906 (diff)
downloadsrc-ccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8.tar.gz
src-ccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8.zip
Add "-n" flag to sockstat.
sockstat can "hang" on getpwuid() calls in situations when FreeBSD is joined to a directory service (AD/LDAP etc) and the directory service fail to answer in a timely manner when trying to resolve numeric UIDs to user names. Submitted by: Caleb St. John <caleb@ixsystems.com> MFC after: 1 week
-rw-r--r--usr.bin/sockstat/sockstat.16
-rw-r--r--usr.bin/sockstat/sockstat.c8
2 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1
index 571b3e7041bb..8521c50348c9 100644
--- a/usr.bin/sockstat/sockstat.1
+++ b/usr.bin/sockstat/sockstat.1
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 13, 2020
+.Dd December 30, 2020
.Dt SOCKSTAT 1
.Os
.Sh NAME
@@ -35,7 +35,7 @@
.Nd list open sockets
.Sh SYNOPSIS
.Nm
-.Op Fl 46CcLlSsUuvw
+.Op Fl 46CcLlnSsUuvw
.Op Fl j Ar jid
.Op Fl p Ar ports
.Op Fl P Ar protocols
@@ -71,6 +71,8 @@ or do not contain the IPv6 loopback address
.Li ::1 .
.It Fl l
Show listening sockets.
+.It Fl n
+Do not resolve numeric UIDs to user names.
.It Fl p Ar ports
Only show Internet sockets if the local or foreign port number
is on the specified list.
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 5ddbf0775507..26f31d96b8e0 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -79,6 +79,7 @@ static int opt_c; /* Show connected sockets */
static int opt_j; /* Show specified jail */
static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */
static int opt_l; /* Show listening sockets */
+static int opt_n; /* Don't resolve UIDs to user names */
static int opt_q; /* Don't show header */
static int opt_S; /* Show protocol stack if applicable */
static int opt_s; /* Show protocol state if applicable */
@@ -1205,7 +1206,7 @@ display(void)
continue;
s->shown = 1;
pos = 0;
- if ((pwd = getpwuid(xf->xf_uid)) == NULL)
+ if (opt_n || (pwd = getpwuid(xf->xf_uid)) == NULL)
pos += xprintf("%lu ", (u_long)xf->xf_uid);
else
pos += xprintf("%s ", pwd->pw_name);
@@ -1304,7 +1305,7 @@ main(int argc, char *argv[])
int o, i;
opt_j = -1;
- while ((o = getopt(argc, argv, "46Ccj:Llp:P:qSsUuvw")) != -1)
+ while ((o = getopt(argc, argv, "46Ccj:Llnp:P:qSsUuvw")) != -1)
switch (o) {
case '4':
opt_4 = 1;
@@ -1329,6 +1330,9 @@ main(int argc, char *argv[])
case 'l':
opt_l = 1;
break;
+ case 'n':
+ opt_n = 1;
+ break;
case 'p':
parse_ports(optarg);
break;