Import openresolv-3.8.0 with the following changes:

*  init system detection moved from configure into resolvconf.
  *  Fixed multiple domains not bein separated correctly.
This commit is contained in:
roy 2016-04-11 10:40:21 +00:00
parent 79169177cf
commit 917ddb683c
7 changed files with 247 additions and 85 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2012 Roy Marples
# Copyright (c) 2007-2016 Roy Marples
# All rights reserved
# dnsmasq subscriber for resolvconf
@ -37,7 +37,6 @@ NL="
[ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid
[ -s "$dnsmasq_pid" ] || unset dnsmasq_pid
: ${dnsmasq_service:=dnsmasq}
: ${dnsmasq_restart:=@RESTARTCMD ${dnsmasq_service}@}
newconf="# Generated by resolvconf$NL"
newresolv="$newconf"
@ -180,7 +179,15 @@ if [ -n "$dnsmasq_resolv" ]; then
fi
if $changed; then
eval $dnsmasq_restart
# dnsmasq does not re-read the configuration file on SIGHUP
if [ -n "$dnsmasq_restart" ]; then
eval $dnsmasq_restart
elif [ -n "$RESTARTCMD" ]; then
set -- ${dnsmasq_service}
eval $RESTARTCMD
else
@SBINDIR@/resolvconf -r ${dnsmasq_service}
fi
fi
if $dbus; then
if [ -s "$dnsmasq_pid" ]; then

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2014 Roy Marples
# Copyright (c) 2007-2016 Roy Marples
# All rights reserved
# libc subscriber for resolvconf
@ -97,7 +97,6 @@ elif [ -d "$SYSCONFDIR"/resolvconf ]; then
fi
: ${resolv_conf:=/etc/resolv.conf}
: ${libc_service:=nscd}
: ${libc_restart:=@RESTARTCMD ${libc_service}@}
: ${list_resolv:=@SBINDIR@/resolvconf -l}
if [ "${resolv_conf_head-x}" = x -a -f "$SYSCONFDIR"/resolv.conf.head ]; then
resolv_conf_head="$(cat "${SYSCONFDIR}"/resolv.conf.head)"
@ -229,7 +228,14 @@ fi
# Create our resolv.conf now
(umask 022; printf %s "$newconf" >"$resolv_conf")
eval $libc_restart
if [ -n "$libc_restart" ]; then
eval $libc_restart
elif [ -n "$RESTARTCMD" ]; then
set -- ${libc_service}
eval $RESTARTCMD
else
@SBINDIR@/resolvconf -r ${libc_service}
fi
retval=0
# Notify users of the resolver

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2012 Roy Marples
# Copyright (c) 2007-2016 Roy Marples
# All rights reserved
# named subscriber for resolvconf
@ -35,18 +35,22 @@ NL="
# Platform specific kludges
if [ -z "$named_service" -a -z "$named_restart" -a \
-d "@RCDIR@" -a ! -x "@RCDIR@"/named ]
-d "$RCDIR" -a ! -x "$RCDIR"/named ]
then
if [ -x "@RCDIR@"/bind9 ]; then
if [ -x "$RCDIR"/bind9 ]; then
# Debian and derivatives
named_service=bind9
elif [ -x "@RCDIR@"/rc.bind ]; then
elif [ -x "$RCDIR"/rc.bind ]; then
# Slackware
named_service=rc.bind
fi
fi
: ${named_service:=named}
: ${named_restart:=@RESTARTCMD ${named_service}@}
: ${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"
@ -101,6 +105,14 @@ if [ -n "$named_zones" ]; then
fi
fi
# named does not seem to work with SIGHUP which is a same
if $changed; then
eval $named_restart
if [ -n "$named_restart" ]; then
eval $named_restart
elif [ -n "$RESTARTCMD" ]; then
set -- ${named_service}
eval $RESTARTCMD
else
@SBINDIR@/resolvconf -r ${named_service}
fi
fi

View File

@ -1,4 +1,4 @@
.\" Copyright (c) 2007-2015 Roy Marples
.\" Copyright (c) 2007-2016 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 27, 2015
.Dd February 23, 2016
.Dt RESOLVCONF 8
.Os
.Sh NAME
@ -125,24 +125,28 @@ file(s) for all the
on the
.Ar interface .
.Pp
Here are some more options that
.Nm
has:-
Here are some options for the above commands:-
.Bl -tag -width indent
.It Fl I
Initialise the state directory
.Pa @VARDIR@ .
This only needs to be called if the initial system boot sequence does not
automatically clean it out; for example the state directory is moved
somewhere other than
.Pa /var/run .
If used, it should only be called once as early in the system boot sequence
as possible and before
.Nm
is used to add interfaces.
.It Fl f
Ignore non existant interfaces.
Only really useful for deleting interfaces.
.It Fl m Ar metric
Set the metric of the interface when adding it, default of 0.
Lower metrics take precedence.
This affects the default order of interfaces when listed.
.It Fl p
Marks the interface
.Pa resolv.conf
as private.
.It Fl x
Mark the interface
.Pa resolv.conf
as exclusive when adding, otherwise only use the latest exclusive interface.
.El
.Pp
.Nm
has some more commands for general usage:-
.Bl -tag -width indent
.It Fl i Ar pattern
List the interfaces and protocols, optionally matching
.Ar pattern ,
@ -157,14 +161,6 @@ If
.Ar pattern
is specified then we list the files for the interfaces and protocols
that match it.
.It Fl m Ar metric
Set the metric of the interface when adding it, default of 0.
Lower metrics take precedence.
This affects the default order of interfaces when listed.
.It Fl p
Marks the interface
.Pa resolv.conf
as private.
.It Fl u
Force
.Nm
@ -172,15 +168,31 @@ to update all its subscribers.
.Nm
does not update the subscribers when adding a resolv.conf that matches
what it already has for that interface.
.It Fl x
Mark the interface
.Pa resolv.conf
as exclusive when adding, otherwise only use the latest exclusive interface.
.El
.Pp
.Nm
also has some options designed to be used by its subscribers:-
also has some commands designed to be used by it's subscribers and
system startup:-
.Bl -tag -width indent
.It Fl I
Initialise the state directory
.Pa @VARDIR@ .
This only needs to be called if the initial system boot sequence does not
automatically clean it out; for example the state directory is moved
somewhere other than
.Pa /var/run .
If used, it should only be called once as early in the system boot sequence
as possible and before
.Nm
is used to add interfaces.
.It Fl R
Echo the command used to restart a service.
.It Fl r Ar service
If the
.Ar service
is running then restart it.
If the service does not exist or is not running then zero is returned,
otherwise the result of restarting the service.
.It Fl v
Echo variables DOMAINS, SEARCH and NAMESERVERS so that the subscriber can
configure the resolver easily.

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 21, 2016
.Dd February 23, 2016
.Dt RESOLVCONF.CONF 5
.Os
.Sh NAME
@ -284,23 +284,23 @@ variables, documented below.
.Pp
.Bl -tag -width indent
.It Sy dnsmasq_service
Location of the dnsmasq service.
Name of the dnsmasq service.
.It Sy dnsmasq_restart
Command to restart the dnsmasq service.
.It Sy dnsmasq_pid
Location of the dnsmasq pidfile.
.It Sy libc_service
Location of the libc service.
Name of the libc service.
.It Sy libc_restart
Command to restart the libc service.
.It Sy named_service
Location of the named service.
Name of the named service.
.It Sy named_restart
Command to restart the named service.
.It Sy pdnsd_restart
Command to restart the pdnsd service.
.It Sy unbound_service
Location of the unbound service.
Name of the unbound service.
.It Sy unbound_restart
Command to restart the unbound service.
.It Sy unbound_pid

View File

@ -25,9 +25,12 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RESOLVCONF="$0"
OPENRESOLV_VERSION="3.8.0"
SYSCONFDIR=@SYSCONFDIR@
LIBEXECDIR=@LIBEXECDIR@
VARDIR=@VARDIR@
RCDIR=@RCDIR@
RESTARTCMD=@RESTARTCMD@
# Disregard dhcpcd setting
unset interface_order state_dir
@ -71,55 +74,45 @@ error_exit()
usage()
{
cat <<-EOF
Usage: ${RESOLVCONF##*/} [options]
Usage: ${RESOLVCONF##*/} [options] command [argument]
Inform the system about any DNS updates.
Options:
Commands:
-a \$INTERFACE Add DNS information to the specified interface
(DNS supplied via stdin in resolv.conf format)
-m metric Give the added DNS information a metric
-p Mark the interface as private
-x Mark the interface as exclusive
-d \$INTERFACE Delete DNS information from the specified interface
-f Ignore non existant interfaces
-I Init the state dir
-u Run updates from our current DNS information
-l [\$PATTERN] Show DNS information, optionally from interfaces
that match the specified pattern
-h Show this help cruft
-i [\$PATTERN] Show interfaces that have supplied DNS information
optionally from interfaces that match the specified
pattern
-l [\$PATTERN] Show DNS information, optionally from interfaces
that match the specified pattern
-u Run updates from our current DNS information
Options:
-f Ignore non existant interfaces
-m metric Give the added DNS information a metric
-p Mark the interface as private
-x Mark the interface as exclusive
Subscriber and System Init Commands:
-I Init the state dir
-r \$SERVICE Restart the system service
(restarting a non-existent or non-running service
should have no output and return 0)
-R Show the system service restart command
-v [\$PATTERN] echo NEWDOMAIN, NEWSEARCH and NEWNS variables to
the console
-h Show this help cruft
-V [\$PATTERN] Same as -v, but only uses configuration in
$SYSCONFDIR/resolvconf.conf
EOF
[ -z "$1" ] && exit 0
echo
error_exit "$*"
}
echo_resolv()
{
local line= OIFS="$IFS"
[ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1
echo "# resolv.conf from $1"
# Our variable maker works of the fact each resolv.conf per interface
# is separated by blank lines.
# So we remove them when echoing them.
while read -r line; do
IFS="$OIFS"
if [ -n "$line" ]; then
# We need to set IFS here to preserve any whitespace
IFS=''
printf "%s\n" "$line"
fi
done < "$IFACEDIR/$1"
echo
IFS="$OIFS"
}
# Strip any trailing dot from each name as a FQDN does not belong
# in resolv.conf(5)
# If you think otherwise, capture a DNS trace and you'll see libc
@ -127,10 +120,11 @@ echo_resolv()
# This also solves setting up duplicate zones in our subscribers.
strip_trailing_dots()
{
local n=
local n= d=
for n; do
printf "%s" "${n%.}"
printf "$d%s" "${n%.}"
d=" "
done
printf "\n"
}
@ -260,6 +254,108 @@ config_mkdirs()
return $e
}
# With the advent of alternative init systems, it's possible to have
# more than one installed. So we need to try and guess what one we're
# using unless overriden by configure.
# Note that restarting a service is a last resort - the subscribers
# should make a reasonable attempt to reconfigre the service via some
# method, normally SIGHUP.
detect_init()
{
[ -n "$RESTARTCMD" ] && return 0
# Detect the running init system.
# As systemd and OpenRC can be installed on top of legacy init
# systems we try to detect them first.
local status="@STATUSARG@"
: ${status:=status}
if [ -x /bin/systemctl -a -S /run/systemd/private ]; then
RESTARTCMD="if /bin/systemctl --quiet is-active; then
/bin/systemctl restart \$1.service;
fi"
elif [ -x /usr/bin/systemctl -a -S /run/systemd/private ]; then
RESTARTCMD="if /usr/bin/systemctl --quiet is-active; then
/usr/bin/systemctl restart \$1.service;
fi"
elif [ -x /sbin/rc-service -a \
-s /libexec/rc/init.d/softlevel -o -s /run/openrc/softlevel ]
then
RESTARTCMD="/sbin/rc-service -i \$1 -- -Ds restart"
elif [ -x /usr/sbin/invoke-rc.d ]; then
RCDIR=/etc/init.d
RESTARTCMD="if /usr/sbin/invoke-rc.d --quiet \$1 status 1>/dev/null 2>&1; then
/usr/sbin/invoke-rc.d \$1 restart;
fi"
elif [ -x /sbin/service ]; then
# Old RedHat
RCDIR=/etc/init.d
RESTARTCMD="if /sbin/service \$1; then
/sbin/service \$1 restart;
fi"
elif [ -x /usr/sbin/service ]; then
# Could be FreeBSD
RESTARTCMD="if /usr/sbin/service \$1 $status 1>/dev/null 2>&1; then
/usr/sbin/service \$1 restart;
fi"
elif [ -x /bin/sv ]; then
RESTARTCMD="/bin/sv try-restart \$1"
elif [ -x /usr/bin/sv ]; then
RESTARTCMD="/usr/bin/sv try-restart \$1"
elif [ -e /etc/arch-release -a -d /etc/rc.d ]; then
RCDIR=/etc/rc.d
RESTARTCMD="if [ -e /var/run/daemons/\$1 ]; then
/etc/rc.d/\$1 restart;
fi"
elif [ -e /etc/slackware-version -a -d /etc/rc.d ]; then
RESTARTCMD="if /etc/rc.d/rc.\$1 status 1>/dev/null 2>&1; then
/etc/rc.d/rc.\$1 restart;
fi"
elif [ -e /etc/rc.d/rc.subr -a -d /etc/rc.d ]; then
# OpenBSD
RESTARTCMD="if /etc/rc.d/\$1 check 1>/dev/null 2>&1; then
/etc/rc.d/\$1 restart;
fi"
else
for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
[ -d $x ] || continue
RESTARTCMD="if $x/\$1 $status 1>/dev/null 2>&1; then
$x/\$1 restart;
fi"
break
done
fi
if [ -z "$RESTARTCMD" ]; then
if [ "$NOINIT_WARNED" != true ]; then
warn "could not detect a useable init system"
_NOINIT_WARNED=true
fi
return 1
fi
_NOINIT_WARNED=
return 0
}
echo_resolv()
{
local line= OIFS="$IFS"
[ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1
echo "# resolv.conf from $1"
# Our variable maker works of the fact each resolv.conf per interface
# is separated by blank lines.
# So we remove them when echoing them.
while read -r line; do
IFS="$OIFS"
if [ -n "$line" ]; then
# We need to set IFS here to preserve any whitespace
IFS=''
printf "%s\n" "$line"
fi
done < "$IFACEDIR/$1"
IFS="$OIFS"
}
list_resolv()
{
[ -d "$IFACEDIR" ] || return 0
@ -319,6 +415,7 @@ list_resolv()
cd "$IFACEDIR"
retval=1
excl=true
for i in $(uniqify $list); do
# Only list interfaces which we really have
if ! [ -f "$i" ]; then
@ -333,6 +430,7 @@ list_resolv()
printf %s "$i "
else
echo_resolv "$i"
echo
fi
[ $? = 0 -a "$retval" = 1 ] && retval=0
done
@ -498,7 +596,7 @@ make_vars()
force=false
VFLAG=
while getopts a:Dd:fhIilm:puvVx OPT; do
while getopts a:Dd:fhIilm:pRruvVx OPT; do
case "$OPT" in
f) force=true;;
h) usage;;
@ -540,6 +638,18 @@ if [ "$cmd" = l -o "$cmd" = i ]; then
exit $?
fi
# Restart a service or echo the command to restart a service
if [ "$cmd" = r -o "$cmd" = R ]; then
detect_init || exit 1
if [ "$cmd" = r ]; then
set -- $args
eval $RESTARTCMD
else
echo "$RESTARTCMD"
fi
exit $?
fi
# Not normally needed, but subscribers should be able to run independently
if [ "$cmd" = v -o -n "$VFLAG" ]; then
make_vars "$iface"
@ -764,6 +874,10 @@ case "${resolvconf:-YES}" in
*) exit 0;;
esac
# Try and detect a suitable init system for our scripts
detect_init
export RESTARTCMD RCDIR _NOINIT_WARNED
eval "$(make_vars)"
export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS
: ${list_resolv:=list_resolv -l}

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2009-2014 Roy Marples
# Copyright (c) 2009-2016 Roy Marples
# All rights reserved
# unbound subscriber for resolvconf
@ -37,7 +37,6 @@ NL="
: ${unbound_pid:=/var/run/unbound.pid}
: ${unbound_service:=unbound}
: ${unbound_restart:=@RESTARTCMD ${unbound_service}@}
newconf="# Generated by resolvconf$NL"
for d in $DOMAINS; do
@ -71,6 +70,18 @@ else
@SBINDIR@/resolvconf -D "$unbound_conf"
fi
restart_unbound()
{
if [ -n "$unbound_restart" ]; then
eval $unbound_restart
elif [ -n "$RESTARTCMD" ]; then
set -- ${unbound_service}
eval $RESTARTCMD
else
@SBINDIR@/resolvconf -r ${unbound_service}
fi
}
if [ ! -f "$unbound_conf" ] || \
[ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
then
@ -78,9 +89,9 @@ then
# If we can't sent a HUP then force a restart
if [ -s "$unbound_pid" ]; then
if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then
eval $unbound_restart
restart_unbound
fi
else
eval $unbound_restart
restart_unbound
fi
fi