From owner-dev-commits-src-all@freebsd.org Wed Dec 30 18:46:05 2020 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B59424CBFBF; Wed, 30 Dec 2020 18:46:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D5gGj4kpwz4WSD; Wed, 30 Dec 2020 18:46:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8B0EE22BAE; Wed, 30 Dec 2020 18:46:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BUIk5eC039806; Wed, 30 Dec 2020 18:46:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BUIk54R039805; Wed, 30 Dec 2020 18:46:05 GMT (envelope-from git) Date: Wed, 30 Dec 2020 18:46:05 GMT Message-Id: <202012301846.0BUIk54R039805@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: ccdd2b2b3cc2 - main - Add "-n" flag to sockstat. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2020 18:46:05 -0000 The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=ccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8 commit ccdd2b2b3cc2f86cd08a355be2fb58e435ec8ff8 Author: Alexander Motin AuthorDate: 2020-12-30 18:40:37 +0000 Commit: Alexander Motin CommitDate: 2020-12-30 18:45:53 +0000 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 MFC after: 1 week --- usr.bin/sockstat/sockstat.1 | 6 ++++-- usr.bin/sockstat/sockstat.c | 8 ++++++-- 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;