Skip to contentSkip to conversation

ss: fix end-of-line printing in misc/ss.c

PATCH Superseded Brian Vazquez 3 participants 4 messages Nov 27, 2019 – Dec 4, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: fix end-of-line printing in misc/ss.c

Before commit 5883c6eba517, function field_is_last() was incorrectly reporting which column was the last because it was missing COL_PROC and by purely coincidence it was correctly printing the end-of-line and moving to the first column since the very last field was empty, and end-of-line was added for the last non-empty token since it was seen as the last field.

This commits correcrly prints the end-of-line for the last entrien in the ss command.

Tested:
diff <(./ss.old -nltp) <(misc/ss -nltp)
38c38
< LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))
\ No newline at end of file
---

Quoted 1 line

LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))

Cc Hritik Vijay <[email protected]>
Fixes 5883c6eba517 ("ss: show header for --processes/-p")
---
 misc/ss.c | 5 +++++
 1 file changed, 5 insertions(+)
misc/ss.c +5 -0
index c58e5c4d..95f1d37a 100644
@@ -1290,6 +1290,11 @@ static void render(void)
 
 		token = buf_token_next(token);
 	}
+	/* Deal with final end-of-line when the last non-empty field printed
+	 * is not the last field.
+	 */
+	if (line_started)
+		printf("\n");
 
 	buf_free_all();
 	current_field = columns;
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 16 lines · Brian Vazquez

Before commit 5883c6eba517, function field_is_last() was incorrectly reporting which column was the last because it was missing COL_PROC and by purely coincidence it was correctly printing the end-of-line and moving to the first column since the very last field was empty, and end-of-line was added for the last non-empty token since it was seen as the last field.

This commits correcrly prints the end-of-line for the last entrien in the ss command.

Tested:
diff <(./ss.old -nltp) <(misc/ss -nltp)
38c38
< LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))
\ No newline at end of file
---

Quoted 5 lines
Quoted 1 line

LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))

Cc Hritik Vijay <[email protected]>
Fixes 5883c6eba517 ("ss: show header for --processes/-p")
Quoted 23 lines
---
 misc/ss.c | 5 +++++
 1 file changed, 5 insertions(+)
misc/ss.c +5 -0
index c58e5c4d..95f1d37a 100644
@@ -1290,6 +1290,11 @@ static void render(void)
 
 		token = buf_token_next(token);
 	}
+	/* Deal with final end-of-line when the last non-empty field printed
+	 * is not the last field.
+	 */
+	if (line_started)
+		printf("\n");
 
 	buf_free_all();
 	current_field = columns;
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
#2 lore raw
In reply to Brian Vazquez
Quoted 16 lines · On Tue, 26 Nov 2019 21:21:18 -0800 Brian Vazquez <[email protected]> wrote:

Before commit 5883c6eba517, function field_is_last() was incorrectly reporting which column was the last because it was missing COL_PROC and by purely coincidence it was correctly printing the end-of-line and moving to the first column since the very last field was empty, and end-of-line was added for the last non-empty token since it was seen as the last field.

This commits correcrly prints the end-of-line for the last entrien in the ss command.

Tested:
diff <(./ss.old -nltp) <(misc/ss -nltp)
38c38
< LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))
\ No newline at end of file
---

Quoted 5 lines
Quoted 1 line

LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))

Cc Hritik Vijay <[email protected]>
Fixes 5883c6eba517 ("ss: show header for --processes/-p")

This commit message is really hard to understand and causes warnings in checkpatch. Also, blaming old code for doing the right thing is not necessary. The changelog doesn't need to explain why. The offending commit is already referenced by the fixes line.

Instead, I propose:

The previous change to ss to show header broke the printing of end-of-line for the last entry.

Fixes 5883c6eba517 ("ss: show header for --processes/-p")
#3 lore raw

Thanks for reviewing it!

Quoted 31 lines · Stephen Hemminger
Quoted 16 lines · On Tue, 26 Nov 2019 21:21:18 -0800 Brian Vazquez <[email protected]> wrote:

Before commit 5883c6eba517, function field_is_last() was incorrectly reporting which column was the last because it was missing COL_PROC and by purely coincidence it was correctly printing the end-of-line and moving to the first column since the very last field was empty, and end-of-line was added for the last non-empty token since it was seen as the last field.

This commits correcrly prints the end-of-line for the last entrien in the ss command.

Tested:
diff <(./ss.old -nltp) <(misc/ss -nltp)
38c38
< LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))
\ No newline at end of file
---

Quoted 5 lines
Quoted 1 line

LISTEN 0 128 [::1]:35417 [::]:* users:(("foo",pid=65254,fd=116))

Cc Hritik Vijay <[email protected]>
Fixes 5883c6eba517 ("ss: show header for --processes/-p")

This commit message is really hard to understand and causes warnings in checkpatch. Also, blaming old code for doing the right thing is not necessary. The changelog doesn't need to explain why. The offending commit is already referenced by the fixes line.

Quoted 5 lines

Instead, I propose:

The previous change to ss to show header broke the printing of end-of-line for the last entry.

This makes sense, I'll fix it in next version. Thanks!

Quoted 3 lines
Fixes 5883c6eba517 ("ss: show header for --processes/-p")