From nobody Wed Dec 18 13:46:51 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YCw2g56ZJz5hN07; Wed, 18 Dec 2024 13:46:51 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YCw2g4ZX6z4D61; Wed, 18 Dec 2024 13:46:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734529611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kYoo0hzQY70IgTvT+mj9gdA40TFvM4F/o8srrmzydl0=; b=lhcmyboE1AQpw9TazpuqNMfkp4cBK15AJxzeB+1IqsTE4Qp90hWunmiBYVr7Tz7UqVBTL6 Agaw6zqj+Uq6wZj623PV9s1hn2U2UaAxgFFaGBzde4UmPJMTWoZ8WnHQxGvC5Vhh7Qlnqi CWqXPvdAV9spgJh7id3MzIu/AfgeCoDh+Ou6x7zMcAlaVX/tsp5gRetRTz+F8kccu4lvU8 n5Pz1GlQ6HBdubeJlJU95q22eZs3eGX+QrC9IJCyTr+aVtcEOkNKA2W2EMHisZevjfrJro vFhEPFn9QKSYN/1lWBx8EscdNVvO7wyv6TzNzex+QOiNdCGd/u/rI15UrgdT2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734529611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kYoo0hzQY70IgTvT+mj9gdA40TFvM4F/o8srrmzydl0=; b=nTCUjd4qhE/VyPHOBGW8U0RijAZitKYPRbqpk4l4a9Qo0kRjSfyumondXnxJbZOaf4gnBf VN0BctUI1SfcIhKEb4wc0huL+n4r4dhuOr1xiujITDJLbcU8reY91Jjlq6M2aOFBzS+woM IWsrSGgP9iujgCyU3IbEBhsAc5UqKe74uXhvZ4hjisIn2eRNI45RnSdsdPkxVM7J+IIC0j cqENrsxsEWctzICBc9riOyRT9g5MYlO2TKu1+ejTp0fPtu+JKHECTGuRt6RBeWwpQP2CaD qtAW4cPDGC9d6KvnOEOMzG8shoVe60u51MWNh1qwni4YmeQveXllxulkgz/vaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734529611; a=rsa-sha256; cv=none; b=CpSOqvo5tjDlKMU2gLeoPreKAUndn2A/87hiWuZAQl32MQEca4aFA22z+JU+HJ06uZ0kaB K/z5b6UPmA5EUUkbZc3HPmla+JcvoLwEdXa9vqGEoDuBpRx7142OZgc3O6W95G0Xx34JdK V1OQEo/BRbAkRsknlHPqRuaxD4Rid8GeN3lHHygQXeGY92Oxn17l39Z4/SscVdswS/DwGm 2nVE33Y67SZ3Is5QF6AvFGmJid5eHj4TDGhfq8IBDWZb8Xg6KFkTzkSMV2VxF4SzvGTvOF bH8xFU7NLMma23z57weRamRwtELAT4qD8SNhzI4n0ofxApO88smhtiYVAQ4Fdg== 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 4YCw2g46T2z19QM; Wed, 18 Dec 2024 13:46:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BIDkpwS019159; Wed, 18 Dec 2024 13:46:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BIDkpOK019157; Wed, 18 Dec 2024 13:46:51 GMT (envelope-from git) Date: Wed, 18 Dec 2024 13:46:51 GMT Message-Id: <202412181346.4BIDkpOK019157@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 60786eb3fe7f - stable/14 - sockstat: Ensure that there is always a space between columns List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 60786eb3fe7fc0198baba9b153eec7fa5af1f9e9 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=60786eb3fe7fc0198baba9b153eec7fa5af1f9e9 commit 60786eb3fe7fc0198baba9b153eec7fa5af1f9e9 Author: Mark Johnston AuthorDate: 2024-12-04 01:12:39 +0000 Commit: Mark Johnston CommitDate: 2024-12-18 13:43:34 +0000 sockstat: Ensure that there is always a space between columns PR: 282978 Reviewed by: asomers MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47840 (cherry picked from commit fbd3448614fbd7bd92e7d34c3bfd2592a07391e3) --- usr.bin/sockstat/sockstat.c | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index c1886deb89e7..11434a6efa68 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -1130,14 +1130,12 @@ displaysock(struct sock *s, int pos) switch (s->family) { case AF_INET: case AF_INET6: - if (laddr != NULL) { + if (laddr != NULL) pos += printaddr(&laddr->address); - if (s->family == AF_INET6 && pos >= 58) - pos += xprintf(" "); - } offset += opt_w ? 46 : 22; - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); if (faddr != NULL) pos += printaddr(&faddr->address); offset += opt_w ? 46 : 22; @@ -1209,8 +1207,9 @@ displaysock(struct sock *s, int pos) abort(); } if (opt_f) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("%d", s->fibnum); offset += 7; } @@ -1221,12 +1220,14 @@ displaysock(struct sock *s, int pos) sp = RB_FIND(socks_t, &socks, &(struct sock) { .socket = s->splice_socket }); if (sp != NULL) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += printaddr(&sp->laddr->address); } else { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("??"); offset += opt_w ? 46 : 22; } @@ -1236,8 +1237,9 @@ displaysock(struct sock *s, int pos) if (opt_i) { if (s->proto == IPPROTO_TCP || s->proto == IPPROTO_UDP) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("%" PRIu64, s->inp_gencnt); } offset += 9; @@ -1251,8 +1253,9 @@ displaysock(struct sock *s, int pos) (s->proto == IPPROTO_TCP && s->state != TCPS_CLOSED && s->state != TCPS_LISTEN))) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("%u", ntohs(faddr->encaps_port)); } @@ -1264,8 +1267,9 @@ displaysock(struct sock *s, int pos) s->state != SCTP_CLOSED && s->state != SCTP_BOUND && s->state != SCTP_LISTEN) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("%s", sctp_path_state(faddr->state)); } @@ -1275,8 +1279,9 @@ displaysock(struct sock *s, int pos) if (opt_s) { if (s->proto == IPPROTO_SCTP || s->proto == IPPROTO_TCP) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); switch (s->proto) { case IPPROTO_SCTP: pos += xprintf("%s", @@ -1296,8 +1301,9 @@ displaysock(struct sock *s, int pos) } if (opt_S) { if (s->proto == IPPROTO_TCP) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); pos += xprintf("%.*s", TCP_FUNCTION_NAME_LEN_MAX, s->stack); @@ -1306,8 +1312,9 @@ displaysock(struct sock *s, int pos) } if (opt_C) { if (s->proto == IPPROTO_TCP) { - while (pos < offset) + do pos += xprintf(" "); + while (pos < offset); xprintf("%.*s", TCP_CA_NAME_MAX, s->cc); } offset += TCP_CA_NAME_MAX + 1; @@ -1372,18 +1379,21 @@ display(void) pos = 0; if (opt_n || (pwd = cap_getpwuid(cappwd, xf->xf_uid)) == NULL) - pos += xprintf("%lu ", (u_long)xf->xf_uid); + pos += xprintf("%lu", (u_long)xf->xf_uid); else - pos += xprintf("%s ", pwd->pw_name); - while (pos < 9) + pos += xprintf("%s", pwd->pw_name); + do pos += xprintf(" "); + while (pos < 9); pos += xprintf("%.10s", getprocname(xf->xf_pid)); - while (pos < 20) + do pos += xprintf(" "); - pos += xprintf("%5lu ", (u_long)xf->xf_pid); - while (pos < 26) + while (pos < 20); + pos += xprintf("%5lu", (u_long)xf->xf_pid); + do pos += xprintf(" "); - pos += xprintf("%-3d ", xf->xf_fd); + while (pos < 26); + pos += xprintf("%-3d", xf->xf_fd); displaysock(s, pos); } } @@ -1392,7 +1402,7 @@ display(void) SLIST_FOREACH(s, &nosocks, socket_list) { if (!check_ports(s)) continue; - pos = xprintf("%-8s %-10s %-5s %-2s ", + pos = xprintf("%-8s %-10s %-5s %-3s", "?", "?", "?", "?"); displaysock(s, pos); } @@ -1401,7 +1411,7 @@ display(void) continue; if (!check_ports(s)) continue; - pos = xprintf("%-8s %-10s %-5s %-2s ", + pos = xprintf("%-8s %-10s %-5s %-3s", "?", "?", "?", "?"); displaysock(s, pos); }