diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2017-05-27 13:51:53 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2017-05-27 13:51:53 +0000 |
commit | ba6de20e90515cc69a5c2e5fe2dc78c1ff28fd32 (patch) | |
tree | f4c775dd440c6ac6392125bc8ca50c81f93d362b /etc/rc.d/rc.subr | |
parent | 41cb525caed553a689caf64c212e92ab8e34ec51 (diff) |
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!
Diffstat (limited to 'etc/rc.d/rc.subr')
-rw-r--r-- | etc/rc.d/rc.subr | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index 12544734efa..3579c7d594d 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -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, 2014 Robert Nagy <robert@openbsd.org> # @@ -79,11 +79,28 @@ _rc_exit() { [ 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() { 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 case "$1" in - reload|start) + reload) _rc_do rc_check && return 0 ;; stop) _rc_do rc_check || return 0 ;; @@ -150,7 +167,7 @@ _rc_parse_conf() { [ -n "${FUNCS_ONLY}" ] && return rc_start() { - ${rcexec} "${daemon} ${daemon_flags} ${_bg}" + ${rcexec} "${daemon} ${daemon_flags}" } rc_check() { @@ -166,7 +183,7 @@ rc_stop() { } rc_cmd() { - local _bg _n + local _n _ret [ -n "${1}" ] && echo "${_rc_actions}" | grep -qw -- ${1} || _rc_usage @@ -179,7 +196,6 @@ rc_cmd() { _rc_err "$0: $1 is not supported" fi - [ X"${rc_bg}" = X"YES" ] && _bg="&" [ -n "${_RC_DEBUG}" ] || _n="-n" _rc_do _rc_parse_conf ${_RC_RUNFILE} @@ -200,8 +216,12 @@ rc_cmd() { if type rc_pre >/dev/null; then _rc_do rc_pre || break 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_exit ok done |