1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-23 13:44:10 +00:00

hoist OPTIND reset from rc.d(8) services to rc.subr(8)

See unbound r1.10 and r.11 for context;  in base only unbound and spamlogd
use getopts and the problem is in rc.subr's getopts, parsing options when
the service script is used directly:  /etc/rc.d/unbound [-dqf] ...

Reset getopts in rc.subr once for anything that comes afterwards instead of
in every script using it.

'rcctl [-dqf] ...' and netstart are not affected as they run rc.subr in its
own process and use FUNCS_ONLY=1, respectively.

tested by obsd@mulh.net
OK aja
This commit is contained in:
kn
2025-12-06 11:04:45 +00:00
parent 76bac5ddc6
commit 666b00faca
3 changed files with 6 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
# $OpenBSD: rc.subr,v 1.166 2025/08/16 10:23:45 ajacoutot Exp $
# $OpenBSD: rc.subr,v 1.167 2025/12/06 11:04:45 kn Exp $
#
# Copyright (c) 2010, 2011, 2014-2022 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -347,6 +347,7 @@ while getopts "dfq" c; do
esac
done
shift $((OPTIND-1))
OPTIND=1
[[ -n ${_RC_DEBUG} && -n ${_RC_QUIET} ]] && _rc_usage
_RC_RUNDIR=/var/run/rc.d

View File

@@ -1,6 +1,6 @@
#!/bin/ksh
#
# $OpenBSD: spamlogd,v 1.8 2025/11/29 10:44:46 kn Exp $
# $OpenBSD: spamlogd,v 1.9 2025/12/06 11:04:45 kn Exp $
daemon="/usr/libexec/spamlogd"
@@ -9,7 +9,7 @@ daemon="/usr/libexec/spamlogd"
rc_reload=NO
rc_pre() {
local _opt pflog=pflog0 OPTIND=1
local _opt pflog=pflog0
while getopts :l: _opt $daemon_flags; do
[[ $_opt == l ]] && pflog=$OPTARG

View File

@@ -1,6 +1,6 @@
#!/bin/ksh
#
# $OpenBSD: unbound,v 1.11 2025/11/29 10:44:46 kn Exp $
# $OpenBSD: unbound,v 1.12 2025/12/06 11:04:45 kn Exp $
daemon="/usr/sbin/unbound"
daemon_flags="-c /var/unbound/etc/unbound.conf"
@@ -8,7 +8,7 @@ daemon_flags="-c /var/unbound/etc/unbound.conf"
. /etc/rc.d/rc.subr
rc_pre() {
local _anchor _config _opt OPTIND=1
local _anchor _config _opt
while getopts :c: _opt $daemon_flags; do
[[ $_opt == c ]] && _config=$OPTARG