Skip to contentSkip to conversation

bpftool: Enable line buffering for stdout

PATCH In review Paul Chaignon 2 participants 2 messages Dec 20, 2021 – Dec 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 bpftool: Enable line buffering for stdout

The output of bpftool prog tracelog is currently buffered, which is inconvenient when piping the output into other commands. A simple tracelog | grep will typically not display anything. This patch fixes it by enabling line buffering on stdout for the whole bpftool binary.

Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")

---
Changes in v3:
- Title changed from "bpftool: Flush tracelog output".
- Enable line buffering for all of bpftool, as suggested by Andrii.
- Rebased on bpf.
Changes in v2:
- Resending to fix a format error.

 tools/bpf/bpftool/main.c | 2 ++
 1 file changed, 2 insertions(+)
tools/bpf/bpftool/main.c +2 -0
index 28237d7cef67..8fbcff9d557d 100644
@@ -400,6 +400,8 @@ int main(int argc, char **argv)
 	};
 	int opt, ret;
 
+	setlinebuf(stdout);
+
 	last_do_help = do_help;
 	pretty_output = false;
 	json_output = false;
Signature · 1 line
2.25.1
Acked-by on v3 1/1
#1 lore raw
Quoted 8 lines · Paul Chaignon

The output of bpftool prog tracelog is currently buffered, which is inconvenient when piping the output into other commands. A simple tracelog | grep will typically not display anything. This patch fixes it by enabling line buffering on stdout for the whole bpftool binary.

Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")