The config file is not required to exist (unless specified via -d).

(reported by rhialto@falu.nl)  Don't fail to start if it doesn't.

Make sure the directory for the config file exists inside the chroot before
attempting to copy into it ("confdir" was calculated, but never used...)

While here, fix getopts usage (obviously only ever previously tested when
the -c arg was the first option...) and don't use test(1)'s -o operator
(especially not when one of the other args is an unknown string).
If -c is given (and we will chroot), require filename to be full path.

Misc minor style cleanups.
This commit is contained in:
kre 2016-11-18 23:10:05 +00:00
parent 01ce88d0f3
commit 1675d6af19

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# $NetBSD: rtadvd,v 1.8 2013/07/09 09:34:58 roy Exp $ # $NetBSD: rtadvd,v 1.9 2016/11/18 23:10:05 kre Exp $
# #
# PROVIDE: rtadvd # PROVIDE: rtadvd
@ -21,28 +21,47 @@ rtadvd_prereload()
{ {
local chdir="$(getent passwd _rtadvd | cut -d: -f6)" local chdir="$(getent passwd _rtadvd | cut -d: -f6)"
local conf=/etc/rtadvd.conf myflags o confdir local conf=/etc/rtadvd.conf myflags o confdir
local cflag=false
[ -z "$chdir" -o "$chdir" = / ] && return 0 [ -z "${chdir}" ] || [ "/${chdir}" = // ] && return 0
if [ -n "$flags" ]; then if [ -n "${flags}" ]; then
myflags=$flags myflags=${flags}
else else
eval myflags=\$${name}_flags eval myflags=\$${name}_flags
fi fi
set -- ${myflags} set -- ${myflags}
while getopts c:dDfM:Rs o; do while getopts c:dDfM:Rs o; do
case "$1" in # ignore other args, they are processed by rtadvd itself
-c) conf="$OPTARG";; case "${o}" in
c) conf="${OPTARG}"
case "${conf}" in
/*) ;;
*) echo "${name}: config file (${conf}) must be" \
"full pathname"
return 1
;;
esac
cflag=true;;
esac esac
shift
done done
confdir=$(dirname "$conf")
echo "$name: copying $conf to $chdir$conf"
cp "$conf" "$chdir$conf"
# Provide a link to the chrooted dump file ${cflag} || test -f "${conf}" && {
ln -snf "$chdir/var/run/$name.dump" /var/run confdir=$(dirname "${conf}")
echo "${name}: copying ${conf} to ${chdir}${conf}"
mkdir -p "${chdir}${confdir}"
cp "${conf}" "${chdir}${conf}" || return 1
}
# Make sure /var/run exists in the chroot
mkdir -p "${chdir}/var/run"
# Provide links to the chrooted dump & pid files
ln -snf "${chdir}/var/run/${name}.dump" /var/run
# Note: actual chroot is done by rtadvd itself
return 0
} }
rtadvd_prestart() rtadvd_prestart()