Permalink
Browse files

Avoid partial writes of config/config.h.

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>
  • Loading branch information...
1 parent a4d3a67 commit 66ff902e6318b118dfff03cbec3d9579f5bd248d @rlbdv rlbdv committed Jan 10, 2013
Showing with 13 additions and 9 deletions.
  1. +1 −1 config/Makefile
  2. +12 −8 config/configure.inc
View
@@ -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 *~ .*~
View
@@ -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
}
#

0 comments on commit 66ff902

Please sign in to comment.