Browse Source

Add an ALRM timer to cope with 2 annoying issues in rc.d(8):

- prevent a daemon from hanging the boot
(typo in your flagsm e.g. httpd_flags=-d)
- make sure we can get the status of a backgrounded daemon instead of always
returning success
Side effect of this is that we can kill a knob! rip rc_bg :-)
Ports will need love, and a second commit is coming for that.
The diff is small yet not trivial so I am committing early in the release
process in one shot so it can easily be reverted if needed. I started working on
this during g2k16 in Cambridge then finished it in Brisbane for a2k17 where
robert@, beck@ and sthen@ agreed it was the correct way to go and I should move
ahead with it post 6.1.
If you see any regression, please talk to me!
OPENBSD_6_2
ajacoutot 7 years ago
parent
commit
01a49fe601
2 changed files with 29 additions and 10 deletions
  1. +28
    -8
      src/etc/rc.d/rc.subr
  2. +1
    -2
      src/etc/rc.d/ypbind

+ 28
- 8
src/etc/rc.d/rc.subr View File

@ -1,6 +1,6 @@
# $OpenBSD: rc.subr,v 1.118 2017/02/17 16:42:41 ajacoutot Exp $
# $OpenBSD: rc.subr,v 1.119 2017/05/27 13:51:52 ajacoutot Exp $
# #
# Copyright (c) 2010, 2011, 2014-2016 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011, 2014-2017 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> # Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
# Copyright (c) 2010, 2011, 2014 Robert Nagy <robert@openbsd.org> # Copyright (c) 2010, 2011, 2014 Robert Nagy <robert@openbsd.org>
# #
@ -79,11 +79,28 @@ _rc_exit() {
[ X"$1" = X"ok" ] && exit 0 || exit 1 [ X"$1" = X"ok" ] && exit 0 || exit 1
} }
_rc_alarm()
{
trap - ALRM
kill -ALRM ${_TIMERSUB} 2>/dev/null # timer may not be running anymore
kill $! 2>/dev/null # kill last job if it's running
}
_rc_wait() { _rc_wait() {
local _i=0 local _i=0
if [ X"$1" = X"start" ]; then # prevent hanging the boot sequence
trap "_rc_alarm" ALRM
while [ $_i -lt ${daemon_timeout} ]; do
_rc_do rc_check && break
sleep 1
_i=$((_i+1))
done & wait
pkill -ALRM -P $$
return
fi
while [ $_i -lt ${daemon_timeout} ]; do while [ $_i -lt ${daemon_timeout} ]; do
case "$1" in case "$1" in
reload|start)
reload)
_rc_do rc_check && return 0 ;; _rc_do rc_check && return 0 ;;
stop) stop)
_rc_do rc_check || return 0 ;; _rc_do rc_check || return 0 ;;
@ -150,7 +167,7 @@ _rc_parse_conf() {
[ -n "${FUNCS_ONLY}" ] && return [ -n "${FUNCS_ONLY}" ] && return
rc_start() { rc_start() {
${rcexec} "${daemon} ${daemon_flags} ${_bg}"
${rcexec} "${daemon} ${daemon_flags}"
} }
rc_check() { rc_check() {
@ -166,7 +183,7 @@ rc_stop() {
} }
rc_cmd() { rc_cmd() {
local _bg _n
local _n _ret
[ -n "${1}" ] && echo "${_rc_actions}" | grep -qw -- ${1} || _rc_usage [ -n "${1}" ] && echo "${_rc_actions}" | grep -qw -- ${1} || _rc_usage
@ -179,7 +196,6 @@ rc_cmd() {
_rc_err "$0: $1 is not supported" _rc_err "$0: $1 is not supported"
fi fi
[ X"${rc_bg}" = X"YES" ] && _bg="&"
[ -n "${_RC_DEBUG}" ] || _n="-n" [ -n "${_RC_DEBUG}" ] || _n="-n"
_rc_do _rc_parse_conf ${_RC_RUNFILE} _rc_do _rc_parse_conf ${_RC_RUNFILE}
@ -200,8 +216,12 @@ rc_cmd() {
if type rc_pre >/dev/null; then if type rc_pre >/dev/null; then
_rc_do rc_pre || break _rc_do rc_pre || break
fi fi
_rc_do rc_start || break
_rc_do _rc_wait start || break
_rc_do _rc_wait start & _TIMERSUB=$!
trap "_rc_alarm" ALRM
_rc_do rc_start; _ret=$?
kill -ALRM ${_TIMERSUB}
wait ${_TIMERSUB} 2>/dev/null # don't print Alarm clock
[[ "${_ret}" == @(0|142) ]] && _rc_do rc_check || break
_rc_do _rc_write_runfile _rc_do _rc_write_runfile
_rc_exit ok _rc_exit ok
done done


+ 1
- 2
src/etc/rc.d/ypbind View File

@ -1,12 +1,11 @@
#!/bin/sh #!/bin/sh
# #
# $OpenBSD: ypbind,v 1.5 2015/10/18 03:51:11 deraadt Exp $
# $OpenBSD: ypbind,v 1.6 2017/05/27 13:51:52 ajacoutot Exp $
daemon="/usr/sbin/ypbind" daemon="/usr/sbin/ypbind"
. /etc/rc.d/rc.subr . /etc/rc.d/rc.subr
rc_bg=YES
rc_reload=NO rc_reload=NO
rc_pre() { rc_pre() {


Loading…
Cancel
Save