Browse Source

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@
OPENBSD_5_0
ajacoutot 13 years ago
parent
commit
04a7f743a5
1 changed files with 28 additions and 6 deletions
  1. +28
    -6
      src/etc/rc.d/rc.subr

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

@ -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


Loading…
Cancel
Save