[Top][All Lists]

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

Re: avoid a 1-second sleep in every configure script

From: Jim Meyering
Subject: Re: avoid a 1-second sleep in every configure script
Date: Sat, 29 Aug 2009 22:14:19 +0200

Ralf Wildenhues wrote:
> Hello Jim,
> * Jim Meyering wrote on Fri, Aug 14, 2009 at 09:33:11AM CEST:
>> Ralf Wildenhues wrote:
>> > * Jim Meyering wrote on Thu, Jul 30, 2009 at 04:20:52PM CEST:
>> >> I deliberately chose not to use ls, because parsing
>> >> its output is not worth the trouble.
>> >
>> > Could that bring any more portability though?  IOW, is there a portable
>> > (not limited to coreutils) way to get at subsecond time stamps?
>> You can get subsecond time stamps via GNU ls' --full-time option,
>> but if you have that version of ls, you probably also have coreutils'
>> stat program.  If you really want to go for it, Perl is probably the
>> most portable tool.  I haven't tried.  After all, it's just 1 second,
>> and not worth the added complexity.
> Most likely, perl will not be used anywhere else in the configure
> script, so starting it cold-cache will not only bring in a new
> dependency (thus source of errors), but also likely a delay that
> could be in the second-range, too.
>> >From 3cb8feacb35d9a547fb5bf36ce1feab706aff063 Mon Sep 17 00:00:00 2001
>> From: Jim Meyering <address@hidden>
>> Date: Thu, 30 Jul 2009 15:55:04 +0200
>> Subject: [PATCH] AM_SANITY_CHECK: avoid a 1-second sleep, if possible
>> * m4/sanity.m4 (AM_SANITY_CHECK): Use stat to compare timestamps.
>> Perform the 1-second sleep only if necessary.
> Thanks.  Note that with some shells, an error about the 'stat' program
> not existing will escape the 2>/dev/null unless you use '(stat ... )
> 2>/dev/null'; so it also needs subshell here to avoid ugly configure
> output in that case.
> However, after putting this patch off for some days, I'm finally aware
> of what really bothers me about it: we use a nonstandard tool (stat)
> here that we really have no idea about what it does on other systems.
> It might not exist (which would be benign), but it also might be some
> completely unrelated tool (and the GCS don't recommend us doing that).
> The BSDs and IRIX have 'stat' but it doesn't provide the option the
> patch uses.
> 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.
>  # ---------------
>  [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,6 +32,8 @@ esac
>  # (eg FreeBSD returns the mod time of the symlink's containing
>  # directory).
>  if (
> +   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.

Hi Ralf,

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.

reply via email to

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