Jim Meyering wrote: > 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.
Here's what I'm testing now: >From 15f26e296b4948edc6c7d33fc1caa6cb50999364 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Sun, 6 Sep 2009 20:00:14 +0200 Subject: [PATCH 1/2] tests: tail-2/flush-initial: correct race avoidance code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tests/tail-2/flush-initial: Wait for the file to be nonempty, not for the process. Based on a suggestion from Pádraig Brady. --- tests/tail-2/flush-initial | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/tail-2/flush-initial b/tests/tail-2/flush-initial index 2deff84..515b29d 100755 --- a/tests/tail-2/flush-initial +++ b/tests/tail-2/flush-initial @@ -28,9 +28,10 @@ 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 +# Wait for 1 second for the file to be flushed. +for i in $(seq 10); do + test -s out && break + echo sleep .1s sleep .1 done -- 1.6.4.2.409.g85dc3 >From 1deab8819f8058a4f21cba461d5b70b50358481b Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Sun, 6 Sep 2009 18:41:59 +0200 Subject: [PATCH 2/2] build: update gnulib submodule to latest --- gnulib | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/gnulib b/gnulib index c46ae39..5985805 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit c46ae39631773a7fdae7d171cc4ef0bf2123efff +Subproject commit 598580519cc391a0856e5ff7a15c1634d0ad29bc -- 1.6.4.2.409.g85dc3