bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] simply and fix a race in 2 tail --follow tests


From: Pádraig Brady
Subject: [PATCH] simply and fix a race in 2 tail --follow tests
Date: Thu, 3 Sep 2009 01:26:22 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

I had noticed these tests were a little verbose and
had meant to simplify them. Coincidentally today
I triggered a race in tail-2/pid, so the attached
patch kills two birds with the one stone.

cheers,
Pádraig.
>From ba37fb2e96334b3cc784a4387d74f726be9be98d Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Thu, 3 Sep 2009 00:39:17 +0100
Subject: [PATCH] tests: simplify and fix a race in 2 tail --follow tests

* tests/tail-2/pid: Use the timeout command to determine process
longevity, rather than querying /proc/$pid/status.
That was racy in any case as I presume the test was copied
from tail-2/tail-n0f and wasn't updated to handle the case
where the background process was in the R (running) state.
* tests/tail-2/wait: Likewise.
---
 tests/tail-2/pid  |   37 +++------------------
 tests/tail-2/wait |   93 ++++++++---------------------------------------------
 2 files changed, 19 insertions(+), 111 deletions(-)

diff --git a/tests/tail-2/pid b/tests/tail-2/pid
index 86e3d60..a797666 100755
--- a/tests/tail-2/pid
+++ b/tests/tail-2/pid
@@ -23,48 +23,21 @@ fi
 
 . $srcdir/test-lib.sh
 
-require_proc_pid_status_
-
 touch here || framework_failure
 
-
 fail=0
 
-# Use tail itself to create a background process.
-
+# Use tail itself to create a background process to monitor.
 tail -f here &
 bg_pid=$!
 
-tail -s0.1 -f here --pid=$bg_pid &
-
-pid=$!
-
-sleep 0.5
-
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo "$0: process dead? (state=$state)" 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+# Ensure that tail --pid=PID does not exit when PID is alive.
+timeout 1 tail -s.1 -f here --pid=$bg_pid
+test $? = 124 || fail=1
 
+# Cleanup background process
 kill $bg_pid
 
-sleep 0.5
-
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) echo $0: process still active 1>&2; fail=1 ;;
-    *) ;;
-  esac
-  kill $pid
-fi
-
 # Ensure that tail --pid=PID exits successfully when PID is dead.
 # Use an unlikely-to-be-live PID
 getlimits_
diff --git a/tests/tail-2/wait b/tests/tail-2/wait
index a902b54..eb04ac2 100755
--- a/tests/tail-2/wait
+++ b/tests/tail-2/wait
@@ -24,97 +24,32 @@ fi
 
 . $srcdir/test-lib.sh
 
-require_proc_pid_status_
-
 touch here || framework_failure
 touch k || framework_failure
-(touch unreadable && chmod a-r unreadable) || framework_failure
+{ touch unreadable && chmod a-r unreadable; } || framework_failure
+cat unreadable && framework_failure
 
 fail=0
 
-tail -s0.1 -f not_here &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) echo $0: process still active 1>&2; fail=1 ;;
-    *) ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -f not_here
+test $? = 124 && fail=1
 
-# Check if the file is really not accessible before use it.
-if ! cat unreadable; then
-    tail -s0.1 -f unreadable &
-    pid=$!
-    sleep .5
-    state=$(get_process_status_ $pid)
-
-    if test -n "$state"; then
-        case $state in
-            S*) echo $0: process still active 1>&2; fail=1 ;;
-            *) ;;
-        esac
-        kill $pid
-    fi
-fi
-
-(tail -s0.1 -f here 2>tail.err) &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *)  echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -f unreadable
+test $? = 124 && fail=1
 
+timeout 1 tail -s0.1 -f here 2>tail.err
+test $? = 124 || fail=1
 
 # `tail -F' must wait in any case.
 
-(tail -s0.1 -F here 2>>tail.err) &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F here 2>>tail.err
+test $? = 124 || fail=1
 
-tail -s0.1 -F unreadable &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F unreadable
+test $? = 124 || fail=1
 
-tail -s0.1 -F not_here &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F not_here
+test $? = 124 || fail=1
 
 test -s tail.err && fail=1
 
-- 
1.6.2.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]