[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tail: flush initial output before possibly blocking
From: |
Jim Meyering |
Subject: |
Re: [PATCH] tail: flush initial output before possibly blocking |
Date: |
Sun, 06 Sep 2009 12:05:30 +0200 |
Pádraig Brady wrote:
> Jim Meyering wrote:
>> I noticed that tail -f "didn't work" when run via ssh.
>> I.e., it printed nothing, when I expected it to print the
>> last 10 lines.
>
> well spotted.
>
> I was wondering about the loop in the test though.
> Can the `kill -0` ever fail. Even if that's not redundant
> I'm not sure the file is guaranteed to be written at this stage?
> How about:
>
> diff --git a/tests/tail-2/flush-initial b/tests/tail-2/flush-initial
> index 2deff84..378440c 100755
> --- a/tests/tail-2/flush-initial
> +++ b/tests/tail-2/flush-initial
> @@ -28,10 +28,11 @@ echo line > in || fail=1
> stdbuf --output=1K tail -f in > out &
> tail_pid=$!
>
> -# Wait for the backgrounded `tail' to start.
> -while :; do
> - env kill -0 $tail_pid && break
> - sleep .1
> +# wait for a second for the file to be flushed
> +count=0
> +until test -s out -o $count = 10; do
> + count=$((count+1))
> + sleep .1
> done
You're right. Thanks!
Maybe this instead?
for i in $(seq 10); do
test -s out && break
sleep .1
done
Note that $((...)) isn't as portable as we'd like, and neither
is test's "-o" operator. The only use of $((...)) in coreutils
is in bootstrap. There are no uses of test's -o operator.