automake-patches
[Top][All Lists]
Advanced

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

[PATCH] Remove a race condition from test cond5.test.


From: Stefano Lattarini
Subject: [PATCH] Remove a race condition from test cond5.test.
Date: Mon, 19 Jul 2010 22:41:13 +0200
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

And here is a follow-up patch to reduce possible race conditions 
w.r.t. reuse of process PIDs.  The patch is against the maint branch.

Regards,
   Stefano
From cfa655a2007dd65cf58149efe393ae33947de956 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Mon, 19 Jul 2010 22:34:18 +0200
Subject: [PATCH] Remove a race condition from test cond5.test.

* tests/cond5.test: Do not blindly try to kill the pid of the
backgrounded Automake process after the sleep, since it might
have terminated by itself, and its PID reused by a new and
unrelated process.  Instead, rely on a more complex but more
correct combo of wrapper script(s) and temporary file(s).
Necessity of this fix suggested by Ralf Wildenhues.
---
 ChangeLog        |   10 ++++++++++
 tests/cond5.test |   29 +++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 251ff2e..6e30507 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-07-19  Stefano Lattarini  <address@hidden>
+
+       Remove a race condition from test cond5.test.
+       * tests/cond5.test: Do not blindly try to kill the pid of the
+       backgrounded Automake process after the sleep, since it might
+       have terminated by itself, and its PID reused by a new and
+       unrelated process.  Instead, rely on a more complex but more
+       correct combo of wrapper script(s) and temporary file(s).
+       Necessity of this fix suggested by Ralf Wildenhues.
+
 2010-07-18  Stefano Lattarini  <address@hidden>
 
        Improve and extend test cond5.test.
diff --git a/tests/cond5.test b/tests/cond5.test
index 84afdd0..37ceaed 100755
--- a/tests/cond5.test
+++ b/tests/cond5.test
@@ -44,25 +44,42 @@ END
 
 # The bug is that automake hangs.  So we give it an appropriate grace
 # time, then kill it if necessary.
-$ACLOCAL
-$AUTOMAKE 2>stderr &
+# We use a hacky wrapper script to avoid (or reduce to a really low
+# minimum) race conditions w.r.t. process PID.
+
+cat > no-race.sh <<'END'
+#!/bin/sh
+"$@" 2>stderr &
 pid=$!
+echo $pid > prog-not-finished
+wait $pid
+rc=$?
+rm -f prog-not-finished
+echo $rc > rc
+exit $rc
+END
+
+$ACLOCAL
+: > prog-not-finished  # to be sure it will truly be there from the start
+$SHELL -x ./no-race.sh $AUTOMAKE &
 
 # Make at most 30 tries, one every 10 seconds (= 300 seconds = 5 min).
 try=1
 while test $try -le 30; do
-  if kill -0 $pid; then
-    : process $pid is still alive, wait and retry
+  if test -f prog-not-finished; then
+    : process `cat prog-not-finished` is still alive, wait and retry
     sleep 10
     try=`expr $try + 1`
   else
     cat stderr >&2
     # Automake must fail with a proper error message.
+    test x"1" = x"`cat rc`"
     grep 'variable.*OPT_SRC.*recursively defined' stderr
     Exit 0
   fi
 done
 # The automake process probably hung.  Kill it, and exit with failure.
-echo "$me: automake process $pid hung"
-kill $pid
+# And yes, the repated command substitutions with `cat' are meant.
+echo "$me: automake process `cat prog-not-finished` hung"
+(kill `cat prog-not-finished`) # some shells require this subshell
 Exit 1
-- 
1.7.1


reply via email to

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