[iproute2,net-next,1/3] ss: Discard empty descriptor at the end of buffer, if any, before rendering

Message ID 664b3a17a1902a5fc25e5888aaf38fbc6152122d.1540910943.git.sbrivio@redhat.com
State Under Review
Delegated to: David Ahern
Headers show
Series
  • ss: Allow selection of columns to be displayed
Related show

Commit Message

Stefano Brivio Oct. 30, 2018, 3:05 p.m.
This will allow us to disable display of any given column.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 misc/ss.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Patch

diff --git a/misc/ss.c b/misc/ss.c
index c8970438ce73..c3f61ef66258 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1245,8 +1245,15 @@  static void render(void)
 
 	token = (struct buf_token *)buffer.head->data;
 
-	/* Ensure end alignment of last token, it wasn't necessarily flushed */
-	buffer.tail->end += buffer.cur->len % 2;
+	if (!buffer.cur->len) {
+		/* Last token was flushed, a new empty descriptor was appended:
+		 * discard it
+		 */
+		buffer.tail->end -= sizeof(buffer.cur->len);
+	} else {
+		/* Last token wasn't flushed: ensure end alignment */
+		buffer.tail->end += buffer.cur->len % 2;
+	}
 
 	render_calc_width();