mpris-proxy: Line-buffer stdout
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.
--- tools/mpris-proxy.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/mpris-proxy.c +4 -0
@@ -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
This is an accidental duplicate of
https://lore.kernel.org/linux-bluetooth/[email protected]/
(re-ran the wrong command). Please ignore this copy; v2 with the checkpatch fix is in the original thread.