[dm-devel] [PATCH 07/15] multipathd: don't buffer output with systemd

Benjamin Marzinski bmarzins at redhat.com
Sun Mar 8 03:31:38 UTC 2015


When stdout isn't hooked up to a tty (like it isn't when you start
multipathd through systemd) the stream is buffered, so messages only
come out in big chunks, or when the program quits. Instead, we should
send the messages out to systemd as we generate them, so that users
know what's happening, and in the event of a crash, they get the most
recent messages.

I realize that there is a performance impact to this.  If people are
against this approach, we could change condlog to print messages above a
certain priority to stderr and messages below that priority to stdout.
If we included a configuration option to change the priority level, then
we could always change it up if we needed to do debugging. However, the
standard level messages are very helpful in quickly diagnosing a number
of problems, so you could make a good argument that we always want
priority 2 messages printed immediately.  And if we intentionally bumped
up the debugging level, we would usually want those messages printed
immediately.  This is exactly what we get with just unbuffering stdout.

Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
---
 multipathd/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index f9e3f33..bc21d04 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2011,9 +2011,11 @@ main (int argc, char *argv[])
 		exit(0);
 	}
 
-	if (logsink < 1)
+	if (logsink < 1) {
+		if (!isatty(fileno(stdout)))
+			setbuf(stdout, NULL);
 		err = 0;
-	else
+	} else
 		err = daemonize();
 
 	if (err < 0)
-- 
1.8.3.1




More information about the dm-devel mailing list