[PATCH] utmpdup: Ensure flushing when using follow flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 login-utils/utmpdump.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index 5ccae8655..b9a92b5f6 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -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");
--
2.24.3 (Apple Git-128)





[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux