Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: freebsd problems with carriage return



2009-03-25 04:18:51 -0400, Benjamin R. Haskell:
[...]
> I think it's a difference in how FreeBSD and Linux handle some 
> tty/job-control settings.  (Though it's not terribly surprising to me... 
> one of those "I'm going to behave differently when you pipe me" things.)  

Except that as far as I can see from the source code, it does an
explicit fflush() after each progress line, so it shouldn't be a
stdio buffering issue. Unless the OP's using an old version of
rsync on FreeBSD?

[...]
> On FreeBSD for me, the status updates are visible when not piped (either 
> displayed to terminal, or redirected to a file).  But, rsync --progress 
> from to | cat -v only shows the final status.
> 
> I noticed in the rsync code (progress.c) that it declines to print the 
> partial status lines (the ones that end with '\r' so that they can be 
> overwritten) depending on the outcome of:
> 
>  210         tc_pgrp = tcgetpgrp(STDOUT_FILENO);
>  211         if (tc_pgrp != pgrp && tc_pgrp != -1)
>  212                 return;

The above is meant not to print the progress if the output is to
a terminal and rsync is not in the foreground process group of
the terminal.

For a pipe, tcgetpgrp should return -1 so that test should fail
(unless there's a bug in FreeBSD? ktrace would probably tell
us).

[...]
> Maybe something in 'stty' will affect the outcome of the above call (but 
> you'd have to ask someone who knows way more about it than I do).  There 
> are at least a handful of differences in the various settings between 
> FreeBSD and Linux for the systems I'm using right now.
[...]

It shouldn't have anything to do with stty as we're not
accessing the terminal here. And stty doesn't affect the
foreground process group of the terminal, it's the shell's job
control that does.

The fact that you don't get the output when stdout is a pipe is
probably the place to look at. But I don't know why rsync would
decide not to output the progress when stdout is pipe as opposed
to when it's a regular file.

Now, looking at:
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/sys_pipe.c?rev=1.201

pipe_ioctl(...
[...]
         /* This is deprecated, FIOGETOWN should be used instead. */
         case TIOCGPGRP:
                 *(int *)data = -fgetown(&mpipe->pipe_sigio);
                 break;

So tcgetpgrp() is valid on a pipe on FreeBSD, so it contradicts
its man page.

That would be the reason. To fix that, you'd have to patch rsync
to add a isatty() check, or better, remove that check
altogether, as if the user reguested progress with --progress, I
don't agree that rsync should disable it in any circumstance.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author