]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
utmpdup: Ensure flushing when using follow flag
authorAndrew Shapiro <anshapiro@gmail.com>
Mon, 1 Mar 2021 18:18:27 +0000 (13:18 -0500)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Mar 2021 09:49:53 +0000 (10:49 +0100)
The following usages of utmpdump result in no output being flushed to the specified file because the default output buffering is fully buffered:

$ utmpdump --follow --output myOutputFile /var/log/utmp
$ utmpdump --follow /var/log/utmp > myOutputFile

This change configures line buffering for these scenarios so that output will be flushed after each log event.

Signed-off-by: Andrew Shapiro <anshapiro@gmail.com>
login-utils/utmpdump.c

index 5ccae8655c5b57befb29744d1c17953455046dcb..b9a92b5f6766154ea8b938706176ecc87f7786c0 100644 (file)
@@ -367,6 +367,10 @@ int main(int argc, char **argv)
        if (!out)
                out = stdout;
 
+       if (follow && (out != stdout || !isatty(STDOUT_FILENO))) {
+               setvbuf(out, NULL, _IOLBF, 0);
+       }
+
        if (optind < argc) {
                filename = argv[optind];
                in = fopen(filename, "r");