Document setting /etc/resolv.conf to list the local nameserver.
[openresolv] / dnsmasq.in
index 8b104eca02ab00679f0dafe5db65bf4c095e9611..b26973d34a0fd10533618e42566e4de5f2172fac 100755 (executable)
@@ -1,6 +1,5 @@
 #!/bin/sh
-# Copyright 2006 Gentoo Foundation
-# Copyright 2007 Roy Marples
+# Copyright 2007-2008 Roy Marples
 # All rights reserved
 
 # dnsmasq subscriber for resolvconf
 # This allows dnsmasq to forward domains for a specific VPN domain to the
 # VPN nameserver and everything else to the standard name servers.
 
-# A sample dnsmasq config that works as above is like so
+# A sample dnsmasq config that works as above is like so.
+# NOTE: The loopback interface on some systems maybe lo0.
 #domain-needed
 #interface=lo
-#resolv-file=/etc/dnsmasq-resolv.conf
-#conf-file=/etc/dnsmasq-resolvconf.conf
+#resolv-file=@PREFIX@/etc/dnsmasq-resolv.conf
+#conf-file=@PREFIX@/etc/dnsmasq-resolvconf.conf
 
 # The last step is to configure dns configuration for /etc/resolv.conf
-# for the lo interface. In Gentoo we set it up like so in /etc/conf.d/net
-#dns_servers_lo="127.0.0.1"
+# for the lo interface. You can do this in resolvconf as well by adding
+#nameserver 127.0.0.1
+# to resolv.conf.d/base
 
 # Load our variables from resolvconf
 VARS="$(resolvconf -v)"
 eval "${VARS}"
 
-PREFIX=
+PREFIX=@PREFIX@
 DNSMASQRESOLV="${PREFIX}/etc/dnsmasq-resolv.conf"
 DNSMASQCONF="${PREFIX}/etc/dnsmasq-resolvconf.conf"
+DNSMASQPID=/var/run/dnsmasq.pid
 
 NEWCONF="# Generated by resolvconf\n"
 NEWRESOLV="${NEWCONF}"
@@ -64,15 +66,18 @@ NEWRESOLV="${NEWCONF}"
 # so we need to validate a few things first.
 # Check for DBus support in the binary
 DBUS=no
-if [ -s "${PREFIX}"/var/run/dbus.pid -a -s "${PREFIX}"/var/run/dnsmasq.pid ]; then
+DBUSPID=/var/run/dbus/dbus.pid
+[ -s "${DBUSPID}" ] || DBUSPID=/var/run/dbus.pid
+[ -s "${DBUSPID}" ] || DBUSPID=/var/run/dbus/pid
+if [ -s "${DBUSPID}" -a -s ${DNSMASQPID} ]; then
        if dnsmasq --version 2>/dev/null | \
                grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]" \
                ; then
                # Sanity - check that dnsmasq and dbus are running
-               if kill -0 $(cat "${PREFIX}"/var/run/dbus.pid) \
-                       && kill -0 $(cat "${PREFIX}"/var/run/dnsmasq.pid); then
+               if kill -0 $(cat "${DBUSPID}") 2>/dev/null \
+                       && kill -0 $(cat ${DNSMASQPID}) 2>/dev/null; then
                        DBUS=yes
-                       NEWCONF="${NEWCONF}\n# Domain specific servers will be sent over dbus\n\nenable-dbus\n"
+                       NEWCONF="${NEWCONF}\n# Domain specific servers will be sent over dbus\nenable-dbus\n"
                fi
        fi
 fi
@@ -81,8 +86,8 @@ uniqify() {
     local result=
     while [ -n "$1" ]; do
                case " ${result} " in
-                       *" $1 "*) ;;
-                       *) result="${result} $1" ;;
+                       *" $1 "*);;
+                       *) result="${result} $1";;
                esac
                shift
        done
@@ -94,24 +99,24 @@ uniqify() {
 
 for N in ${NEWSEARCH}; do
        case " ${NEWSL} " in
-               *" ${N%,*} "*) ;;
-               *) NEWSL="${NEWSL} ${N%,*}" ;;
+               *" ${N%,*} "*);;
+               *) NEWSL="${NEWSL} ${N%,*}";;
        esac
        case "\n${NEWRESOLV}\n" in
-               *"\nnameserver ${N#*,}\n"*) ;;
-               *) NEWRESOLV="${NEWRESOLV}nameserver ${N#*,}\n" ;;
+               *"\nnameserver ${N#*,}\n"*);;
+               *) NEWRESOLV="${NEWRESOLV}nameserver ${N#*,}\n";;
        esac
 done
 for N in ${NEWNS}; do
        case "\n${NEWRESOLV}\n" in
-               *"\nnameserver ${N}\n") ;;
-               *) NEWRESOLV="${NEWRESOLV}nameserver ${N}\n" ;;
+               *"\nnameserver ${N}\n");;
+               *) NEWRESOLV="${NEWRESOLV}nameserver ${N}\n";;
        esac
 done
 [ -n "${NEWSL}" ] && NEWRESOLV="${NEWRESOLV}search${NEWSL}\n"
 
 DBUSDEST=
-for DN in $(uniqify ${NEWDOMAIN}) ; do
+for DN in $(uniqify ${NEWDOMAIN}); do
        if [ "${DBUS}" = "yes" ]; then
                IP=${DN#*,}
                SIFS=${IFS-y} OIFS=$IFS
@@ -119,9 +124,9 @@ for DN in $(uniqify ${NEWDOMAIN}) ; do
                set -- ${IP}
                NUM="0x$(printf "%02x" $1 $2 $3 $4)"
                if [ "${SIFS}" = "y" ]; then
-                       IFS=$OIFS
-               else
                        unset IFS
+               else
+                       IFS=$OIFS
                fi
                DBUSDEST="${DBUSDEST} uint32:$(printf "%d" ${NUM}) string:${DN%,*}"
        else
@@ -151,11 +156,9 @@ fi
 
 [ "${RELOAD}" = "yes" ] && resolvconf -s dnsmasq restart
 if [ "${DBUS}" = "yes" ]; then
-       [ "${RELOAD}" != "yes" ] && resolvconf -s dnsmasq reload
-       # Send even if emtpy so old servers are cleared
+       [ "${RELOAD}" != "yes" ] && kill -HUP $(cat ${DNSMASQPID})
+       # Send even if empty so old servers are cleared
        dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
                /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \
                ${DBUSDEST}
 fi
-
-# vim: ts=4 :