[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250821054547.473917-1-paulway@redhat.com>
Date: Thu, 21 Aug 2025 15:45:47 +1000
From: Paul Wayper <pwayper@...hat.com>
To: Stephen Hemminger <stephen@...workplumber.org>,
Stefano Brivio <sbrivio@...hat.com>,
netdev@...r.kernel.org
Cc: paulway@...hat.com,
jbainbri@...hat.com
Subject: [PATCH iproute2] ss: Don't pad the last (enabled) column
ss will emit spaces on the right hand side of a left-justified, enabled
column even if it's the last column. In situations where one or more
lines are very long - e.g. because of a large PROCESS field value - this
causes a lot of excess output.
Firstly, calculate the last enabled column. Then use this in the check
for whether to emit trailing spaces on the last column.
Also remove the 'EXT' column which does not seem to be used.
Fixes: 59f46b7b5be86 ("ss: Introduce columns lightweight abstraction")
Signed-off-by: Paul Wayper <paulway@...hat.com>
---
misc/ss.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index 989e168ae35026249ccec0e2d4a3df07b0438c7b..27cf7434c616e0030efc8876f00715d4b37dd567 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -123,10 +123,11 @@ enum col_id {
COL_RADDR,
COL_RSERV,
COL_PROC,
- COL_EXT,
COL_MAX
};
+int LAST_COL = COL_MAX;
+
enum col_align {
ALIGN_LEFT,
ALIGN_CENTER,
@@ -152,7 +153,6 @@ static struct column columns[] = {
{ ALIGN_RIGHT, "Peer Address:", " ", 0, 0, 0 },
{ ALIGN_LEFT, "Port", "", 0, 0, 0 },
{ ALIGN_LEFT, "Process", "", 0, 0, 0 },
- { ALIGN_LEFT, "", "", 0, 0, 0 },
};
static struct column *current_field = columns;
@@ -1079,6 +1079,24 @@ static void out(const char *fmt, ...)
va_end(args);
}
+static void check_last_column(void)
+{
+ /* Find the last non-disabled column and set LAST_COL. */
+ for (int i = COL_MAX - 1; i > 0; i--) {
+ struct column c = columns[i];
+
+ if (!c.disabled) {
+ LAST_COL = i;
+ return;
+ }
+ }
+}
+
+static int field_is_last(struct column *f)
+{
+ return f - columns == LAST_COL;
+}
+
static int print_left_spacing(struct column *f, int stored, int printed)
{
int s;
@@ -1104,6 +1122,10 @@ static void print_right_spacing(struct column *f, int printed)
if (!f->width || f->align == ALIGN_RIGHT)
return;
+ /* Don't print trailing space if this is the last column. */
+ if (field_is_last(f))
+ return;
+
s = f->width - printed;
if (f->align == ALIGN_CENTER)
s /= 2;
@@ -1143,11 +1165,6 @@ static void field_flush(struct column *f)
buffer.tail->end = buffer.cur->data;
}
-static int field_is_last(struct column *f)
-{
- return f - columns == COL_MAX - 1;
-}
-
/* Get the next available token in the buffer starting from the current token */
static struct buf_token *buf_token_next(struct buf_token *cur)
{
@@ -1316,6 +1333,9 @@ static void render(void)
if (!buffer.head)
return;
+ /* Find last non-disabled column */
+ check_last_column();
+
token = (struct buf_token *)buffer.head->data;
/* Ensure end alignment of last token, it wasn't necessarily flushed */
--
2.50.1
Powered by blists - more mailing lists