Harden the locking mechanism
[openresolv] / named.in
index 3ed7a556139b2d02ebde20e646b24c666b86f487..3301896416bb215f5a8356e44ae6ee4eefac425b 100644 (file)
--- a/named.in
+++ b/named.in
@@ -1,5 +1,5 @@
 #!/bin/sh
 #!/bin/sh
-# Copyright (c) 2007-2016 Roy Marples
+# Copyright (c) 2007-2020 Roy Marples
 # All rights reserved
 
 # named subscriber for resolvconf
 # All rights reserved
 
 # named subscriber for resolvconf
 
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
-[ -z "$named_zones" -a -z "$named_options" ] && exit 0
+[ -z "${named_zones}${named_options}" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
 NL="
 "
 
 # Platform specific kludges
 [ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
 NL="
 "
 
 # Platform specific kludges
-if [ -z "$named_service" -a -z "$named_restart" -a \
-       -d "$RCDIR" -a ! -x "$RCDIR"/named ]
+if [ -z "${named_service}${named_restart}" ] &&
+   [ -d "$RCDIR" ] && ! [ -x "$RCDIR"/named ]
 then
        if [ -x "$RCDIR"/bind9 ]; then
                # Debian and derivatives
 then
        if [ -x "$RCDIR"/bind9 ]; then
                # Debian and derivatives
@@ -46,6 +46,11 @@ then
        fi
 fi
 : ${named_service:=named}
        fi
 fi
 : ${named_service:=named}
+
+: ${named_pid:=/var/run/$named_service.pid}
+[ -s "$named_pid" ] || named_pid=/var/run/$named_service/$named_service.pid
+[ -s "$named_pid" ] || unset named_pid
+
 newoptions="# Generated by resolvconf$NL"
 newzones="$newoptions"
 
 newoptions="# Generated by resolvconf$NL"
 newzones="$newoptions"
 
@@ -100,12 +105,13 @@ if [ -n "$named_zones" ]; then
        fi
 fi
 
        fi
 fi
 
+# named does not seem to work with SIGHUP which is a same
 if $changed; then
        if [ -n "$named_restart" ]; then
                eval $named_restart
        elif [ -n "$RESTARTCMD" ]; then
                set -- ${named_service}
 if $changed; then
        if [ -n "$named_restart" ]; then
                eval $named_restart
        elif [ -n "$RESTARTCMD" ]; then
                set -- ${named_service}
-               eval $RESTARTCMD
+               eval "$RESTARTCMD"
        else
                @SBINDIR@/resolvconf -r ${named_service}
        fi
        else
                @SBINDIR@/resolvconf -r ${named_service}
        fi