From e9cceec734dafd433b7038228fe4cf80f7adf5fb Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Sat, 14 Aug 2010 08:34:01 +0200 Subject: [PATCH] Try to update config.cache atomically; respect symlinks. * lib/autoconf/general.m4 (AC_CACHE_SAVE): Use `mv -f' to update the cache file if it is a regular file and not a symlink. Move first to temporary name in the target directory if not in the current directory for atomicity across mount points. * tests/base.at (AC_CACHE_CHECK): Try symlinked cache file. * doc/autoconf.texi (Cache Files): Leftover temporary cache files may be deleted by the user. * NEWS: Update. Signed-off-by: Ralf Wildenhues --- ChangeLog | 12 ++++++++++++ NEWS | 5 +++++ doc/autoconf.texi | 6 ++++++ lib/autoconf/general.m4 | 17 +++++++++++++++-- tests/base.at | 9 +++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a11ab3b..02308674 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-08-27 Ralf Wildenhues + + Try to update config.cache atomically; respect symlinks. + * lib/autoconf/general.m4 (AC_CACHE_SAVE): Use `mv -f' to update + the cache file if it is a regular file and not a symlink. Move + first to temporary name in the target directory if not in the + current directory for atomicity across mount points. + * tests/base.at (AC_CACHE_CHECK): Try symlinked cache file. + * doc/autoconf.texi (Cache Files): Leftover temporary cache + files may be deleted by the user. + * NEWS: Update. + 2010-08-27 Eric Blake m4sh: protect LINENO against stray macro diff --git a/NEWS b/NEWS index 6010e7bc..79ed028b 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,11 @@ GNU Autoconf NEWS - User visible changes. ** The macro m4_define_default is now documented. +** Symlinked config.cache files are supported; configure now tries to + update non-symlinked cache files atomically, so that concurrent configure + runs do not leave behind broken cache files. It is still unspecified + which subset or union of results is cached though. + * Major changes in Autoconf 2.67 (2010-07-21) [stable] Released by Eric Blake, based on git versions 2.66.*. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 95500bec..19f00bd8 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -9809,6 +9809,12 @@ results with the existing cache file.) This may cause problems, however, if the system configuration (e.g., the installed libraries or compilers) changes and the stale cache file is not deleted. +If @command{configure} is interrupted at the right time when it updates +a cache file outside of the build directory where the @command{configure} +script is run, it may leave behind a temporary file named after the +cache file with digits following it. You may safely delete such a file. + + @node Cache Checkpointing @subsection Cache Checkpointing diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index c6f39807..14109213 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -2001,9 +2001,22 @@ _AC_CACHE_DUMP() | :end'] >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then - test "x$cache_file" != "x/dev/null" && + if test "x$cache_file" != "x/dev/null"; then AC_MSG_NOTICE([updating cache $cache_file]) - cat confcache >$cache_file + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else +dnl Try to update the cache file atomically even on different mount points; +dnl at the same time, avoid filename limitation issues in the common case. + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi else AC_MSG_NOTICE([not updating unwritable cache $cache_file]) fi diff --git a/tests/base.at b/tests/base.at index f21e7770..cf120997 100644 --- a/tests/base.at +++ b/tests/base.at @@ -457,6 +457,15 @@ AT_CHECK_CONFIGURE([], [], [stdout]) AT_CHECK([grep cache stdout], [1]) AT_CHECK([LC_ALL=C ls -t config.cache a-stamp-file | sed 1q | grep config.cache], [1]) +# Using a symlinked cache file works. +: > cache +rm -f config.cache +AS_LN_S([cache], [config.cache]) +AT_CHECK_CONFIGURE([-C]) +# Either the system does not support symlinks, or the symlinked-to file +# should be updated. +AT_CHECK([test -s cache || test ! -h config.cache]) + # config.site can specify a site-wide cache, accumulating information. # Also test that we don't run afoul of sourcing a file with leading -. AT_DATA([-config.site], -- 2.47.2