From: Allison Karlitskaya Date: Tue, 28 Oct 2025 08:41:40 +0000 (+0100) Subject: udevadm: flush output after each monitor event X-Git-Tag: v259-rc1~233 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=516df12af9679ab25c39813d6787b0f044a53990;p=thirdparty%2Fsystemd.git udevadm: flush output after each monitor event If you're using `udevadm monitor` from a script, without a tty, then libc defaults to being fully-buffered, and won't flush stdout after newlines. This is fine for tools that dump a bunch of data and then exit immediately. It's a problem for tools like `udevadm monitor` which have long pauses: the buffered data can get stuck in the buffer for an unbounded amount of time. In the Cockpit project we've been working around this for some time with `stdbuf` which is a `LD_PRELOAD` hack to change the libc buffering behaviour, but we'd like to stop doing that. Let's make sure we flush the buffer after each event. --- diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 95fe65ff9d1..e729a99e95b 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -55,6 +55,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, printf("\n"); } + fflush(stdout); + return 0; }