Browse Source

- introduce the INRC environment variable so that rc.subr(8) knows if it

gets called from rc.local or rc.shutdown
- notify the user if a given operation was successfull or not by appending
the (ok) or (failed) strings to the end of the daemon name
- hide stdout and stdin unless RC_DEBUG=1 is set, otherwise all the function
names will be printed out and all output sent to stdin or stdout
- since from now on rc.subr is taking care of printing out the daemon names
on startup, we don't need to do this from rc.{local,shutdown} anymore
brainkilling work done by me and ajacoutot@, ok ajacoutot@
OPENBSD_5_0
robert 13 years ago
parent
commit
a429adb42b
4 changed files with 46 additions and 21 deletions
  1. +2
    -1
      src/etc/rc
  2. +40
    -16
      src/etc/rc.d/rc.subr
  3. +2
    -2
      src/etc/rc.local
  4. +2
    -2
      src/etc/rc.shutdown

+ 2
- 1
src/etc/rc View File

@ -1,4 +1,4 @@
# $OpenBSD: rc,v 1.348 2011/01/14 00:05:42 deraadt Exp $
# $OpenBSD: rc,v 1.349 2011/03/17 16:43:51 robert Exp $
# System startup script run by init on autoboot
# or after single-user.
@ -152,6 +152,7 @@ trap : 2
trap : 3 # shouldn't be needed
HOME=/; export HOME
INRC=1; export INRC
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH


+ 40
- 16
src/etc/rc.d/rc.subr View File

@ -1,4 +1,4 @@
# $OpenBSD: rc.subr,v 1.26 2011/03/14 11:28:44 ajacoutot Exp $
# $OpenBSD: rc.subr,v 1.27 2011/03/17 16:43:51 robert Exp $
# Default functions and variables used by rc.d(8) scripts.
@ -23,6 +23,30 @@ rc_stop() {
pkill -f "^${pexp}"
}
rc_do() {
if [ X"${RC_DEBUG}" = X"1" ]; then
echo "doing $@" && "$@"
else
"$@" >/dev/null 2>&1
fi
}
rc_print() {
_ret=$?
echo ${INRC:+'-n'} "${INRC:+ }${_name}($1)"
return ${_ret}
}
rc_wait() {
i=0
while [ $i -lt 5 ]; do
rc_do rc_check || return 0
sleep 1
i=$((i+1))
done
return 1
}
rc_cmd() {
[ $(id -u) -eq 0 -o X"$1" = "Xcheck" ] || \
rc_err "$0: need root privileges"
@ -34,36 +58,36 @@ rc_cmd() {
case "$1" in
check)
rc_check >/dev/null
rc_do rc_check
;;
start)
rc_check || \
rc_do rc_check || \
(
if type rc_pre >/dev/null; then
rc_pre
rc_do rc_pre
fi
[ $? -eq 0 ] && rc_start >/dev/null
[ $? -eq 0 ] && \
rc_do rc_start && \
rc_print ok || rc_print failed
)
;;
stop)
if rc_check; then rc_stop >/dev/null && \
if rc_do rc_check; then rc_do rc_stop || \
( rc_print failed ) && \
(
i=0
while [ $i -lt 5 ]; do
rc_check || break
sleep 1
i=$((i+1))
done
if [ $i -lt 5 ]; then
rc_do rc_wait &&
(
if type rc_post >/dev/null; then \
rc_post
rc_do rc_post
fi
fi
) && rc_print ok || rc_print failed
)
else
return 0
fi
;;
reload)
rc_check && rc_reload >/dev/null
rc_do rc_check && rc_do rc_reload
;;
restart)
/etc/rc.d/${_name} stop && /etc/rc.d/${_name} start


+ 2
- 2
src/etc/rc.local View File

@ -1,4 +1,4 @@
# $OpenBSD: rc.local,v 1.41 2010/11/05 10:03:00 ajacoutot Exp $
# $OpenBSD: rc.local,v 1.42 2011/03/17 16:43:51 robert Exp $
# Site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions
@ -8,7 +8,7 @@
echo -n 'starting local daemons:'
for _r in $rc_scripts; do
[ -x /etc/rc.d/${_r} ] && echo -n " ${_r}" && /etc/rc.d/${_r} start
[ -x /etc/rc.d/${_r} ] && /etc/rc.d/${_r} start
done
# Add your local startup actions here.


+ 2
- 2
src/etc/rc.shutdown View File

@ -1,4 +1,4 @@
# $OpenBSD: rc.shutdown,v 1.10 2010/11/26 08:09:35 ajacoutot Exp $
# $OpenBSD: rc.shutdown,v 1.11 2011/03/17 16:43:51 robert Exp $
#
# If it exists, this script is run at system-shutdown by reboot(8),
# halt(8). If the architecture supports keyboard requested halting,
@ -12,7 +12,7 @@ echo -n 'stopping local daemons:'
while [ -n "${rc_scripts}" ]; do
_r=${rc_scripts##* }
rc_scripts=${rc_scripts%%*( )${_r}}
[ -x /etc/rc.d/${_r} ] && echo -n " ${_r}" && /etc/rc.d/${_r} stop
[ -x /etc/rc.d/${_r} ] && /etc/rc.d/${_r} stop
done
# Add your local shutdown actions here.


Loading…
Cancel
Save