[lxc-devel] [PATCH] lxc: line buffered output for lxc-monitor

Greg Kurz gkurz at fr.ibm.com
Wed Dec 7 08:47:05 UTC 2011


A typical usage is to start lxc-monitor in popen() and parse the ouput.
Unfortunately, glibc defaults to block buffering for pipes and you may
have to wait several lines before anything is written to stdout... this
prevent the use of lxc-monitor to implement automatons. Let's go line
buffered !

Signed-off-by: Greg Kurz <gkurz at fr.ibm.com>
---

 src/lxc/lxc_monitor.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 1da0906..3802d2e 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -84,6 +84,8 @@ int main(int argc, char *argv[])
 	if (fd < 0)
 		return -1;
 
+	setlinebuf(stdout);
+
 	for (;;) {
 		if (lxc_monitor_read(fd, &msg) < 0)
 			return -1;





More information about the lxc-devel mailing list