diff --git a/Makefile b/Makefile index 868a752..ee9e30d 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ SED_RCDIR= -e 's:@RCDIR@:${RCDIR}:g' SED_RESTARTCMD= -e 's:@RESTARTCMD@:${RESTARTCMD}:g' SED_RCDIR= -e 's:@RCDIR@:${RCDIR}:g' SED_STATUSARG= -e 's:@STATUSARG@:${STATUSARG}:g' +SED_STAT_FMT= -e 's:@STAT_FMT@:${STAT_FMT}:g' DISTPREFIX?= ${PKG}-${VERSION} DISTFILE?= ${DISTPREFIX}.tar.xz @@ -46,6 +47,8 @@ DISTINFOMD= ${DISTINFO}.md DISTSIGN= ${DISTFILE}.asc SHA256?= sha256 PGP?= gpg +STAT_FMT?= stat -c + GITREF?= HEAD @@ -57,6 +60,7 @@ all: ${TARGET} ${SED} ${SED_SBINDIR} ${SED_SYSCONFDIR} ${SED_LIBEXECDIR} \ ${SED_VARDIR} \ ${SED_RCDIR} ${SED_RESTARTCMD} ${SED_RCDIR} ${SED_STATUSARG} \ + ${SED_STAT_FMT} \ $< > $@ clean: diff --git a/configure b/configure index 90599ee..3f99ec0 100755 --- a/configure +++ b/configure @@ -95,6 +95,7 @@ linux*) # cksum doesn't support -a and netpgp is rare echo "CKSUM= sha256sum --tag" >>$CONFIG_MK echo "PGP= gpg2" >>$CONFIG_MK + echo "STAT_FMT= stat -c" >>$CONFIG_MK ;; esac @@ -106,6 +107,10 @@ dragonfly*|freebsd*) if [ -z "$STATUSARG" ]; then STATUSARG="onestatus" fi + echo "STAT_FMT= stat -f" >>$CONFIG_MK + ;; +*bsd*) + echo "STAT_FMT= stat -f" >>$CONFIG_MK ;; esac @@ -164,4 +169,5 @@ echo echo " RESTARTCMD = $RESTARTCMD" echo " RCDIR = $RCDIR" echo " STATUSARG = $STATUSARG" +echo " STAT_FMT = $STAT_FMT" echo diff --git a/libc.in b/libc.in index ebcbba1..36381d3 100644 --- a/libc.in +++ b/libc.in @@ -227,23 +227,53 @@ if $backup; then fi fi -# There are pros and cons for writing directly to resolv.conf -# instead of a temporary file and then moving it over. -# The default is to write to resolv.conf as it has the least -# issues and has been the long standing default behaviour. -case "${resolv_conf_mv:-NO}" in -[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) +resolv_conf_mk_tmp() +{ # Protect against symlink attack, ensure new file does not exist rm -f "$resolv_conf_tmp" # Keep original file owner, group and mode [ -r "$resolv_conf" ] && cp -p "$resolv_conf" "$resolv_conf_tmp" +} + +resolv_conf_do_mv() +{ # Create our resolv.conf now if (umask 022; printf %s "$newconf" >"$resolv_conf_tmp"); then mv "$resolv_conf_tmp" "$resolv_conf" fi +} + +resolv_conf_do_print() +{ + (umask 022; printf %s "$newconf" >"$resolv_conf") +} + +# There are pros and cons for writing directly to resolv.conf +# instead of a temporary file and then moving it over. +# The default is to write to resolv.conf as it has the least +# issues and has been the long standing default behaviour. +case "${resolv_conf_mv:-NO}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + resolv_conf_mk_tmp + resolv_conf_do_mv + ;; +# Do mv only if resolv_conf_tmp and resolv_conf are on +# the same filesystem. Use print method for bind-mounted file +[Aa][Uu][Tt][Oo]) + if [ -r "$resolv_conf" ] && [ -n "@STAT_FMT@" ]; then + resolv_conf_mk_tmp + if [ "$(@STAT_FMT@ %d "$resolv_conf_tmp")" = "$(@STAT_FMT@ %d "$resolv_conf")" ]; then + resolv_conf_do_mv + else + rm -f "$resolv_conf_tmp" + resolv_conf_do_print + fi + else + resolv_conf_do_print + fi ;; *) - (umask 022; printf %s "$newconf" >"$resolv_conf") + resolv_conf_do_print ;; esac