From 327dae5081059eb97af0cf319a444b3937ff4db2 Mon Sep 17 00:00:00 2001 From: Alexander Leidinger Date: Sun, 30 Aug 2026 11:44:58 +0200 Subject: [PATCH] rc.subr: svcj - run a service's own restart and status methods in its jail A script that defines non-default restart_cmd or status_cmd should execute them in the service jail. Where there is no jail to enter, restart starts the service instead of failing. Fixes: 2efbd480f1d3 rc: add service jails framework MFC after: 1 week MFC to: stable/15 Assisted-by: Claude Code (Opus 5) --- libexec/rc/rc.subr | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index d919e2d25916..68d5ab308d0a 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -1429,7 +1429,23 @@ run_rc_command() _run_rc_doit "$_cmd $rc_extra_args" || _return=1 fi ;; - restart|status) ;; # no special case needed for svcj or handled somewhere else + restart) + if [ "${_rc_svcj}" = jailing ]; then + _run_rc_doit "$_cmd $rc_extra_args" || _return=1 + elif /usr/sbin/jls -j svcj-${name} jid >/dev/null 2>&1; then + $SERVICE -E _rc_svcj=jailing -j svcj-${name} ${rc_service##*/} ${_rc_prefix}restart $rc_extra_args || _return=1 + else + # nothing to restart, so start it + ( run_rc_command ${_rc_prefix}start $rc_extra_args ) || _return=1 + fi + ;; + status) + if [ "${_rc_svcj}" != jailing ]; then + $SERVICE -E _rc_svcj=jailing -j svcj-${name} ${rc_service##*/} ${_rc_prefix}status $rc_extra_args || _return=1 + else + _run_rc_doit "$_cmd $rc_extra_args" || _return=1 + fi + ;; *) eval _rc_svcj_extra_cmd=\$${name}_${rc_arg}_svcj_enable : ${_rc_svcj_extra_cmd:=NO}