summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2011-10-09 08:48:54 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2011-10-09 08:48:54 +0000
commitcffc827aec5cab1f84092afb3dc5863683342634 (patch)
tree4b3bc565175943101290ecfead913b7feb4e1327
parent50f41f9d81f2edccc4fb75dcb4592d3f15aafa71 (diff)
Finally make it possible to restart/stop a daemon after having changed
its _flags in rc.conf(8). When the rc.d(8) system starts a daemon, it will record its pexp under /var/run/rc.d/rcscriptname and use that to interact with it (errors in creating /var/run/rc.d or missing pexp file are non fatal, the framework will just fallback to what it currently does). deraadt@ doesn't mind a long as it doesn't come in the way of people manually managing their daemons. discussed with and input from sthen@ halex@ robert@ schwarze@ ok sthen@ robert@
-rw-r--r--etc/rc.d/rc.subr23
1 files changed, 22 insertions, 1 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr
index ac3c8b169f2..5c45d5fa058 100644
--- a/etc/rc.d/rc.subr
+++ b/etc/rc.d/rc.subr
@@ -1,4 +1,4 @@
-# $OpenBSD: rc.subr,v 1.51 2011/10/07 07:26:49 ajacoutot Exp $
+# $OpenBSD: rc.subr,v 1.52 2011/10/09 08:48:53 ajacoutot Exp $
#
# Copyright (c) 2010, 2011 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,6 +28,19 @@ rc_usage() {
rc_err "usage: $0 [-df] {start|check|reload|restart|stop}"
}
+rc_write_runfile() {
+ [ -d ${_RC_RUNDIR} ] || mkdir -p ${_RC_RUNDIR} && \
+ print -rn -- "${pexp}" > ${_RC_RUNFILE}
+}
+
+rc_read_runfile() {
+ [ -f ${_RC_RUNFILE} ] && pexp=$(< ${_RC_RUNFILE})
+}
+
+rc_rm_runfile() {
+ [ -f ${_RC_RUNFILE} ] && rm ${_RC_RUNFILE}
+}
+
rc_start() {
${rcexec} "${daemon} ${daemon_flags} ${_bg}"
}
@@ -88,6 +101,8 @@ rc_cmd() {
[ X"${rc_bg}" = X"YES" ] && local _bg="&"
[ -n "${_RC_DEBUG}" ] || local _n="-n"
+ rc_do rc_read_runfile
+
case "$1" in
check)
rc_do rc_check
@@ -106,10 +121,12 @@ rc_cmd() {
sleep 1
rc_do rc_wait start || break
fi
+ rc_do rc_write_runfile
rc_exit ok
done
# handle failure
type rc_post >/dev/null && rc_do rc_post
+ rc_do rc_rm_runfile
rc_exit failed
;;
stop)
@@ -120,6 +137,7 @@ rc_cmd() {
if type rc_post >/dev/null; then \
rc_do rc_post || rc_exit failed
fi
+ rc_do rc_rm_runfile
rc_exit ok
;;
reload)
@@ -156,6 +174,9 @@ done
shift $((OPTIND-1))
_name=$(basename $0)
+_RC_RUNDIR=/var/run/rc.d
+_RC_RUNFILE=${_RC_RUNDIR}/${_name}
+
eval _rcflags=\${${_name}_flags}
eval _rcuser=\${${_name}_user}