summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2011-06-10 08:43:27 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2011-06-10 08:43:27 +0000
commita3d261f5383fee7e3ddef82e44b09aacaa4314c9 (patch)
treea24d595e2ccd711d062c1304ef39cb53577cf41a
parentd6c27dddfa7638be0ff326907fb2c61cc0c5e56b (diff)
Finally deal with background processes: "rc_cmd start" will now return
the correct code according whether the daemon did start successfully or not. rc_wait() This function has been extended, first we need to pass in which mode we are running (start or stop) and second we can pass a number of seconds to wait (optionnal, will default to 30s). The function will return the correct code whether we are running during "rc_cmd start" or "rc_cmd stop". rc_cmd() start If we are running in background mode, then we call rc_wait with the "start" argument. The sleep(1) is needed to prevent a race condition where the process will appear in the list before failing and rc_check will see it as running. Call rc_post() when failing to prevent being left in an inconsistent state (because rc_pre() would have run successfully) rc_cmd() stop We are now calling rc_wait with the "stop" argument. "looks good" sthen@, ok robert@
-rw-r--r--etc/rc.d/rc.subr34
1 files changed, 28 insertions, 6 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr
index 8f255cea0f5..1c34625ddde 100644
--- a/etc/rc.d/rc.subr
+++ b/etc/rc.d/rc.subr
@@ -1,4 +1,4 @@
-# $OpenBSD: rc.subr,v 1.36 2011/05/19 09:50:50 ajacoutot Exp $
+# $OpenBSD: rc.subr,v 1.37 2011/06/10 08:43:26 ajacoutot Exp $
# Default functions and variables used by rc.d(8) scripts.
@@ -40,8 +40,19 @@ rc_print() {
rc_wait() {
i=0
- while [ $i -lt 30 ]; do
- rc_do rc_check || return 0
+ [ -n "$2" ] && w=$2 || w=30
+ while [ $i -lt $w ]; do
+ case "$1" in
+ start)
+ rc_do rc_check && return 0
+ ;;
+ stop)
+ rc_do rc_check || return 0
+ ;;
+ *)
+ break
+ ;;
+ esac
sleep 1
i=$((i+1))
done
@@ -69,16 +80,27 @@ rc_cmd() {
if type rc_pre >/dev/null; then
rc_do rc_pre
fi
+ [ $? -eq 0 ] && rc_do rc_start
[ $? -eq 0 ] && \
- rc_do rc_start && \
- rc_print ok || rc_print failed
+ if [ -n "${_bg}" ]; then
+ sleep 1 && rc_do rc_wait start
+ else
+ : # do nothing
+ fi
+ [ $? -eq 0 ] && \
+ rc_print ok || \
+ (
+ type rc_post >/dev/null && rc_do rc_post
+ rc_print failed
+ return 1
+ )
)
;;
stop)
if rc_do rc_check; then rc_do rc_stop || \
( rc_print failed ) && \
(
- rc_do rc_wait &&
+ rc_do rc_wait stop &&
(
if type rc_post >/dev/null; then \
rc_do rc_post