]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: flush output after each monitor event
authorAllison Karlitskaya <allison.karlitskaya@redhat.com>
Tue, 28 Oct 2025 08:41:40 +0000 (09:41 +0100)
committerMike Yuan <me@yhndnzj.com>
Tue, 28 Oct 2025 16:51:19 +0000 (17:51 +0100)
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.

src/udev/udevadm-monitor.c

index 95fe65ff9d1525811e2f25d33fb3c5be5aecd6f3..e729a99e95b365dc0ff5b5615345f70452e6db30 100644 (file)
@@ -55,6 +55,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
                 printf("\n");
         }
 
+        fflush(stdout);
+
         return 0;
 }