* Jim Meyering wrote on Sat, Aug 29, 2009 at 10:14:19PM CEST: > Ralf Wildenhues wrote: > > I think we can fix most instances of this wait portably, without looking > > at subsecond time stamps: let's just try without sleeping first, and > > only if that fails, try again after sleeping. What do you think about > > the patch below (diff -w shown only, due to large reindentation)? > > > > Only missing bit still is a good testsuite addition to ensure that it > > still catches messed-up time stamps.
> That looks like a fine approach. > I tested it simply by inserting this line > > test $am_try = 1 && touch --ref="$srcdir/configure" conftest.file > > right after the echo timestamp... one, and verified (with inserted > set -x ... set +x) that the sleep 1 was run. > > That's no good for a test-suite addition, I know, but better than nothing. > I suppose a test could set the time of $srcdir/configure > to a second in the future, just before running ./configure, > but even then it'd be a race. Yeah. Let's defer the test to later. (I tested it by touching the configure script with a time 1 hour in the future.) I've committed the patch now, to be merged in branch-1.11 and master, with the only additional change to avoid a second sleep in the error path. Cheers, and thanks again, (and sorry for the multi-second delay ;-) Ralf Avoid sleeping for one second most of the time in sanity check. * m4/sanity.m4 (AM_SANITY_CHECK): Try sanity check first without sleeping for a second, and only if that failed, sleep and try again, to avoid the delay in the common case of a configure script that is older than a second, or a system with sub-second time stamp granularity. Report and different patch by Jim Meyering. diff --git a/m4/sanity.m4 b/m4/sanity.m4 index 3d2f304..db87c8b 100644 --- a/m4/sanity.m4 +++ b/m4/sanity.m4 @@ -1,21 +1,18 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008, 2009 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 5 +# serial 6 # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -35,23 +32,30 @@ esac # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$[*]" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - rm -f conftest.file - if test "$[*]" != "X $srcdir/configure conftest.file" \ - && test "$[*]" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi + for am_try in 1 2; do + echo timestamp > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken + alias in your environment]) + fi + if test "$[2]" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + done test "$[2]" = conftest.file ) then