From 4d16621cc360e0141535c38ee2a023723293154f Mon Sep 17 00:00:00 2001 From: ajacoutot <> Date: Wed, 9 Mar 2011 09:10:44 +0000 Subject: [PATCH] Move rc_pre and rc_post out of the rc_start/rc_stop functions into the rc_cmd start/stop actions. This way when rc.d(8) scripts override these functions, we don't loose rc_{pre,post}. Add a max 5 secs loop after rc_stop in the rc_cmd top action. This seems to be a good default for returning to command line only after the daemon has really stopped. This fixes "restart" for some daemons and allows to properly stop some others at shutdown time. Note that this is just a best-effort default, some daemons may need a lot more time to shutdown but this case is usually handled in the rc.d(8) script itself and we obviously do not want to hang the shutdown process. Call rc_cmd start/stop in restart and _not_ rc_start/rc_stop which can get overriden in a script. discussed with and inputs from sthen@ and schwarze@ ok sthen@ robert@ --- src/etc/rc.d/rc.subr | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/etc/rc.d/rc.subr b/src/etc/rc.d/rc.subr index b236373e..f9d7414a 100644 --- a/src/etc/rc.d/rc.subr +++ b/src/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.21 2011/03/06 16:49:48 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.22 2011/03/09 09:10:44 ajacoutot Exp $ rc_err() { echo $1 @@ -6,7 +6,6 @@ rc_err() { } rc_start() { - type rc_pre >/dev/null && rc_pre ${rcexec} "${daemon} ${daemon_flags} >/dev/null ${_bg}" } @@ -20,7 +19,6 @@ rc_reload() { rc_stop() { pkill -f "^${pexp}" - type rc_post >/dev/null && rc_post || return 0 } rc_cmd() { @@ -37,20 +35,26 @@ rc_cmd() { rc_check ;; start) - rc_check || rc_start + if ! rc_check; then + type rc_pre >/dev/null && rc_pre + rc_start + fi ;; stop) rc_stop + i=0 + while [ $i -lt 5 ]; do + rc_check || break + sleep 1 + i=$((i+1)) + done + type rc_post >/dev/null && rc_post || return 0 ;; reload) rc_check && rc_reload ;; restart) - rc_stop - while rc_check; do - sleep 1 - done - rc_start + /etc/rc.d/${_name} stop && /etc/rc.d/${_name} start ;; *) rc_err "usage: $0 {start|check|reload|restart|stop}"