lftp-devel  

Re: output buffering leads to reordered lines when stdout isn't a tty

Alexander V. Lukyanov
Thu, 07 May 2009 00:56:10 -0700

On Tue, May 05, 2009 at 11:33:21PM -0300, Peter Cordes wrote:
>  I think I've found a problem with lftp's output buffering when stdout
> isn't a tty (so stdout is block-buffered by default).  I see this with
> lftp 3.7.13 compiled on AMD64 Ubuntu Jaunty, but I mostly was testing
> with lftp 3.7.3 on Debian lenny, 32bit x86.

I think it can be fixed by flushing stdout before launching external
programs.

Please test this patch.

--
   Alexander.
Index: Filter.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Filter.cc,v
retrieving revision 1.45
diff -u -p -r1.45 Filter.cc
--- Filter.cc   27 Nov 2008 05:56:15 -0000      1.45
+++ Filter.cc   7 May 2009 07:50:51 -0000
@@ -146,6 +146,7 @@ int OutputFilter::getfd()
 
    bool had_pg=(pg!=0);
 
+   fflush(stdout);
    fflush(stderr);
    switch(pid=fork())
    {