1 1.1 lukem #!/bin/sh 2 1.1 lukem # 3 1.11 skrll # $NetBSD: rtadvd,v 1.11 2020/07/04 06:24:53 skrll Exp $ 4 1.1 lukem # 5 1.1 lukem 6 1.1 lukem # PROVIDE: rtadvd 7 1.2 lukem # REQUIRE: DAEMON 8 1.5 thorpej # BEFORE: LOGIN 9 1.1 lukem 10 1.6 mycroft $_rc_subr_loaded . /etc/rc.subr 11 1.1 lukem 12 1.8 roy name=rtadvd 13 1.4 lukem rcvar=$name 14 1.8 roy command="/usr/sbin/$name" 15 1.7 roy pidfile="/var/run/$name.pid" 16 1.8 roy extra_commands=reload 17 1.8 roy start_precmd=rtadvd_prestart 18 1.8 roy reload_precmd=rtadvd_prereload 19 1.1 lukem 20 1.8 roy rtadvd_prereload() 21 1.1 lukem { 22 1.8 roy local chdir="$(getent passwd _rtadvd | cut -d: -f6)" 23 1.8 roy local conf=/etc/rtadvd.conf myflags o confdir 24 1.9 kre local cflag=false 25 1.11 skrll 26 1.9 kre [ -z "${chdir}" ] || [ "/${chdir}" = // ] && return 0 27 1.8 roy 28 1.9 kre if [ -n "${flags}" ]; then 29 1.9 kre myflags=${flags} 30 1.8 roy else 31 1.8 roy eval myflags=\$${name}_flags 32 1.8 roy fi 33 1.8 roy set -- ${myflags} 34 1.8 roy while getopts c:dDfM:Rs o; do 35 1.9 kre # ignore other args, they are processed by rtadvd itself 36 1.9 kre case "${o}" in 37 1.9 kre c) conf="${OPTARG}" 38 1.9 kre case "${conf}" in 39 1.9 kre /*) ;; 40 1.9 kre *) echo "${name}: config file (${conf}) must be" \ 41 1.9 kre "full pathname" 42 1.9 kre return 1 43 1.9 kre ;; 44 1.9 kre esac 45 1.9 kre cflag=true;; 46 1.8 roy esac 47 1.8 roy done 48 1.8 roy 49 1.9 kre ${cflag} || test -f "${conf}" && { 50 1.9 kre confdir=$(dirname "${conf}") 51 1.9 kre echo "${name}: copying ${conf} to ${chdir}${conf}" 52 1.9 kre mkdir -p "${chdir}${confdir}" 53 1.9 kre cp "${conf}" "${chdir}${conf}" || return 1 54 1.9 kre } 55 1.9 kre 56 1.9 kre # Make sure /var/run exists in the chroot 57 1.9 kre mkdir -p "${chdir}/var/run" 58 1.9 kre 59 1.10 kre # Provide a link to the chrooted dump file 60 1.9 kre ln -snf "${chdir}/var/run/${name}.dump" /var/run 61 1.9 kre 62 1.9 kre # Note: actual chroot is done by rtadvd itself 63 1.9 kre 64 1.9 kre return 0 65 1.8 roy } 66 1.8 roy 67 1.8 roy rtadvd_prestart() 68 1.8 roy { 69 1.8 roy if [ "$ip6mode" != router ]; then 70 1.1 lukem warn \ 71 1.1 lukem "${name} cannot be used on IPv6 host, only on an IPv6 router." 72 1.1 lukem return 1 73 1.1 lukem fi 74 1.8 roy 75 1.8 roy rtadvd_prereload 76 1.1 lukem } 77 1.1 lukem 78 1.3 lukem load_rc_config $name 79 1.1 lukem run_rc_command "$1" 80