Skip to contentSkip to conversation

mpris-proxy: Line-buffer stdout

PATCH Superseded Seonggon Cho 1 participant 2 messages Sep 29 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mpris-proxy: Line-buffer stdout

mpris-proxy reports adapter and player changes with printf() but never flushes stdout. When it runs as a service (tools/mpris-proxy.service) stdout is a pipe to the journal, so glibc fully buffers it and nothing is written until 4 KiB have accumulated or the process exits.

On a system whose Bluetooth adapter went away and came back every two minutes, the "Bluetooth Adapter /org/bluez/hci0 removed" and "... found" messages reached the journal in bursts of exactly 100 lines (about 4096 bytes), all carrying the timestamp of the flush rather than of the event, i.e. up to about 80 minutes late.

Set stdout to line buffered at startup, as bt_shell_init() already does, so every message reaches the journal with an accurate timestamp.

Assisted-by Claude:claude-fable-5-1
---
 tools/mpris-proxy.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/mpris-proxy.c +4 -0
index 1d7a421e9..4a8dd71e2 100644
@@ -2954,6 +2954,10 @@ int main(int argc, char *argv[])
 	guint owner_watch, properties_watch, signal_watch;
 	struct sigaction sa;
 
+	/* stdout is a pipe to the journal when running as a service, so make
+	 * it line buffered to get the messages out as they happen. */
+	setlinebuf(stdout);
+
 	context = g_option_context_new(NULL);
 	g_option_context_add_main_entries(context, options, NULL);
 
Signature · 1 line
2.55.0