From 1c38ab8e2d4980a670eb3045e9318ea37a925518 Mon Sep 17 00:00:00 2001 From: ajacoutot <> Date: Sun, 9 Oct 2011 08:48:53 +0000 Subject: [PATCH] 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@ --- src/etc/rc.d/rc.subr | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/etc/rc.d/rc.subr b/src/etc/rc.d/rc.subr index ac3c8b16..5c45d5fa 100644 --- a/src/etc/rc.d/rc.subr +++ b/src/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 # Copyright (c) 2010, 2011 Ingo Schwarze @@ -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}