]> arthur.barton.de Git - bup.git/commitdiff
Avoid partial writes of config/config.h.
authorRob Browning <rlb@defaultvalue.org>
Thu, 10 Jan 2013 02:23:08 +0000 (20:23 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sun, 27 Jan 2013 23:06:48 +0000 (17:06 -0600)
Write to config/config.h.tmp first, then rename it to config/config.h
once it's complete to avoid the possibility of a partially written
file.

Thanks to Paul Schulz <pschulz01@gmail.com> for reporting the problem.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Reviewed-by: Zoran Zaric <zz@zoranzaric.de>
config/Makefile
config/configure.inc

index b383106ecc10f9234abc0c80963ff9f1f49d7587..b13891cada5a3ad5754ef1b51b42b81779dc797d 100644 (file)
@@ -4,5 +4,5 @@ config.h: configure configure.inc $(wildcard *.in)
        MAKE=${MAKE} ./configure
 
 clean:
-       rm -f ${CONFIGURE_FILES} ${GENERATED_FILES}
+       rm -f ${CONFIGURE_FILES} ${CONFIGURE_DETRITUS} ${GENERATED_FILES}
        rm -f *~ .*~
index 2bafea00e8e3d3bf2b85a70d4657154adb2fb0e3..2f293deb44f60eee7cb3e460ebdb53062798bb9f 100644 (file)
@@ -585,7 +585,8 @@ MF_PATH_INCLUDE () {
 #
 AC_INIT () {
     __config_files="config.cmd config.sub config.h config.mak config.log"
-    rm -f $__config_files
+    __config_detritus="config.h.tmp"
+    rm -f $__config_files $__config_detritus
     __cwd=`pwd`
     exec 5>&1 1>$__cwd/config.log 2>&1
     AC_CONFIGURE_FOR=__AC_`echo $1 | sed -e 's/\..$//' | tr 'a-z' 'A-Z' | tr ' ' '_'`_D
@@ -610,7 +611,8 @@ AC_INIT () {
 
     LOG "Configuring for [$1]"
 
-    cat > $__cwd/config.h << EOF
+    rm -f $__cwd/config.h
+    cat > $__cwd/config.h.tmp << EOF
 /*
  * configuration for $1${2:+" ($2)"}, generated `date`
  * by ${LOGNAME:-`whoami`}@`hostname`
@@ -869,7 +871,7 @@ EOF
        TLOG " (found)"
        rc=0
     else
-       echo "typedef int pid_t;" >> $__cwd/config.h
+       echo "typedef int pid_t;" >> $__cwd/config.h.tmp
        TLOG " (not found)"
        rc=1
     fi
@@ -932,7 +934,7 @@ EOF
     rc=1
     LOGN "defining WORD & DWORD scalar types"
     if $AC_CC /tmp/pd$$.c -o /tmp/pd$$; then
-       if /tmp/pd$$  >> $__cwd/config.h; then
+       if /tmp/pd$$  >> $__cwd/config.h.tmp; then
            rc=0
        fi
     fi
@@ -951,6 +953,7 @@ AC_OUTPUT () {
     cd $__cwd
     AC_SUB 'LIBS'    "$AC_LIBS"
     AC_SUB 'CONFIGURE_FILES' "$__config_files"
+    AC_SUB 'CONFIGURE_DETRITUS' "$__config_detritus"
     AC_SUB 'GENERATED_FILES' "$*"
     AC_SUB 'CFLAGS'  "$AC_CFLAGS"
     AC_SUB 'FCFLAGS' "$AC_FCFLAGS"
@@ -969,8 +972,8 @@ AC_OUTPUT () {
        test "$AC_SED_PROG" || AC_PROG_SED
        test "$AC_SED_PROG" || return 1
 
-       echo                                   >> config.h
-       echo "#endif/* ${AC_CONFIGURE_FOR} */" >> config.h
+       echo                                   >> config.h.tmp
+       echo "#endif/* ${AC_CONFIGURE_FOR} */" >> config.h.tmp
 
        rm -f config.cmd
        Q=\'
@@ -996,6 +999,7 @@ EOF
     else
        echo 
     fi
+    cp $__cwd/config.h.tmp $__cwd/config.h
 }
 
 #
@@ -1283,13 +1287,13 @@ AC_MAK() {
 #
 # AC_DEFINE adds a #define to config.h
 AC_DEFINE() {
-    echo "#define $1 ${2:-1}" >> $__cwd/config.h
+    echo "#define $1 ${2:-1}" >> $__cwd/config.h.tmp
 }
 
 #
 # AC_INCLUDE adds a #include to config.h
 AC_INCLUDE() {
-    echo "#include \"$1\"" >> $__cwd/config.h
+    echo "#include \"$1\"" >> $__cwd/config.h.tmp
 }
 
 #