]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix lxc-info printing duplicate lines
authorDwight Engen <dwight.engen@oracle.com>
Thu, 3 Apr 2014 01:13:05 +0000 (21:13 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 3 Apr 2014 23:37:19 +0000 (18:37 -0500)
When lxc-info's stdout is not line buffered (ie. "lxc-info -n foo |more")
the first three lines will be duplicated. This is because c->get_ips()
comes next and it forks and the child will exit() causing its fds to be
closed which flushes out its (fork duplicated) stdio buffers. The lines are
then duplicated when the parent actually gets around to flushing out its
stdio. This causes problems for programs (such as the lxc-webpanel) which
are popen()ing lxc-info.

The fix here isn't necessarily the right one, but does show what the
problem is. Seems like maybe we should fix this inside of get_ips(), for
other API callers as well.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_info.c

index 96cb9663cb27f96a0a4118ec6762368dc9528f50..24d6f9bd9b4bff7b01f8d4ab73f8466a1de6a55c 100644 (file)
@@ -313,6 +313,7 @@ static int print_info(const char *name, const char *lxcpath)
                }
 
                if (ips) {
+                       fflush(stdout);
                        char **addresses = c->get_ips(c, NULL, NULL, 0);
                        if (addresses) {
                                char *address;