--- named.dist 2017-05-19 21:44:36.416725000 +0200 +++ named.dist 2017-05-21 11:33:47.295935650 +0200 @@ -27,8 +27,8 @@ return 1 fi - from=$1 - to=$2 + from=$(echo $1 | sed 's#//*#/#g') + to=$(echo $2 | sed 's#//*#/#g') shift 2 opts="${*}" @@ -47,7 +47,7 @@ } _umount() { - local dir=$1 + local dir=$(echo $1 | sed 's#//*#/#g') local ret=0 if [ -n "$(awk "\$2 == \"${dir}\" { print \$2 }" /proc/mounts)" ]; then @@ -64,9 +64,8 @@ _get_pidfile() { # as suggested in bug #107724, bug 335398#c17 - [ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\ - /usr/sbin/named-checkconf -p ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} | grep 'pid-file' | cut -d\" -f2) - [ -z "${PIDFILE}" ] && PIDFILE=${CHROOT}/run/named/named.pid + [ -n "${PIDFILE}" ] || PIDFILE=$(/usr/sbin/named-checkconf -p ${NAMED_CONF#${CHROOT}} | grep 'pid-file' | cut -d\" -f2) + [ -z "${PIDFILE}" ] && PIDFILE=/run/named/named.pid } check_chroot() { @@ -119,6 +118,15 @@ ebegin "Starting ${CHROOT:+chrooted }named" + # create piddir (usually /run/named) if necessary, bug 334535 + _get_pidfile + piddir=${PIDFILE%/*} + checkpath -q -d -o root:named -m 0770 "${piddir}" || { + eerror "Failed to create PID directory at $piddir" + eend 1 + return 1 + } + if [ -n "${CHROOT}" ]; then if [ ${CHROOT_NOCHECK:-0} -eq 0 ]; then check_chroot || { @@ -147,27 +155,15 @@ _mount /etc/bind ${CHROOT}/etc/bind -o bind _mount /var/bind ${CHROOT}/var/bind -o bind _mount /var/log/named ${CHROOT}/var/log/named -o bind + _mount ${piddir} ${CHROOT}/${piddir} -o bind if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; then _mount /usr/share/GeoIP ${CHROOT}/usr/share/GeoIP -o bind fi fi - - # On initial startup, if piddir inside the chroot /var/run/named - # Then the .../var/run part might not exist yet - checkpath -q -d -o root:root -m 0755 "${piddir}/.." fi checkconfig || { eend 1; return 1; } - # create piddir (usually /run/named) if necessary, bug 334535 - _get_pidfile - piddir="${PIDFILE%/*}" - checkpath -q -d -o root:named -m 0770 "${piddir}" || { - eerror "Failed to create PID directory at $piddir" - eend 1 - return 1 - } - # In case someone have $CPU set in /etc/conf.d/named if [ -n "${CPU}" ] && [ "${CPU}" -gt 0 ]; then CPU="-n ${CPU}" @@ -221,6 +217,7 @@ done [ "${CHROOT_GEOIP:-0}" -eq 1 ] && _umount ${CHROOT}/usr/share/GeoIP + _umount ${CHROOT}/${PIDFILE%/*} _umount ${CHROOT}/etc/bind _umount ${CHROOT}/var/log/named _umount ${CHROOT}/var/bind