From nobody@FreeBSD.org  Sun Nov 13 09:03:11 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E22E716A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2005 09:03:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 98D4A43D45
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2005 09:03:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jAD93BaT057253
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2005 09:03:11 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jAD93Bvk057252;
	Sun, 13 Nov 2005 09:03:11 GMT
	(envelope-from nobody)
Message-Id: <200511130903.jAD93Bvk057252@www.freebsd.org>
Date: Sun, 13 Nov 2005 09:03:11 GMT
From: Michael Reynolds <michael.reynolds@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: wrapper support for rc.subr
X-Send-Pr-Version: www-2.3

>Number:         88913
>Category:       conf
>Synopsis:       [patch] wrapper support for rc.subr
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-rc
>State:          analyzed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 13 09:10:16 GMT 2005
>Closed-Date:    
>Last-Modified:  Sat Oct 27 18:19:37 UTC 2012
>Originator:     Michael Reynolds
>Release:        5.4-STABLE
>Organization:
>Environment:
FreeBSD home.box 5.4-STABLE FreeBSD 5.4-STABLE #15: Sat Nov 12 19:54:21 EST 2005     root@home.box:/usr/obj/usr/src/sys/HOME  i386
>Description:
              This proposed patch adds the ability to execute rc daemons inside of wrappers. Could be useful to initialize per daemon MAC policies, resource limits, and the like.
>How-To-Repeat:
              
>Fix:
              See attached file. Patch is against:
# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $
# $FreeBSD: src/etc/rc.subr,v 1.31.2.4 2005/11/06 15:54:43 jhb Exp $

--- rc.subr.diff begins here ---
--- /usr/src/etc/rc.subr	Fri Nov 11 09:46:38 2005
+++ /etc/rc.subr	Sun Nov 13 03:42:26 2005
@@ -525,7 +525,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _wrapper=\$${name}_wrapper	_wrapper_flags=\$${name}_wrapper_flags
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -601,6 +602,13 @@
 				exit 1
 			fi
 
+			if [ -n "$_wrapper" ] ; then
+				if [ ! -x $_wrapper ] ; then
+					info "run_rc_command: cannot run wrapper ($_wrapper) for $command."
+					return 0
+				fi
+			fi
+
 			if [ ! -x ${_chroot}${command} ]; then
 				info "run_rc_command: cannot run ($command)."
 				return 0
@@ -651,12 +659,14 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+$_wrapper $_wrapper_flags \
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
 				_doit="\
 ${_chdir:+cd $_chdir; }\
 ${_nice:+nice -n $_nice }\
+$_wrapper $_wrapper_flags \
 $command $rc_flags $command_args"
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
--- rc.subr.diff ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Wed Feb 22 02:24:42 UTC 2006 
Responsible-Changed-Why:  

Bring to the attention of the list 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88913 
State-Changed-From-To: open->analyzed 
State-Changed-By: crees 
State-Changed-When: Sat Oct 27 18:19:37 UTC 2012 
State-Changed-Why:  
I quite like this.  I've updated the patch for latest rc.subr at 
http://www.bayofrum.net/~crees/patches/88913 -- I left out the tests for 
[ -x wrapper ] because I think that the "failed to start" message 
suffices for an error. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88913 
>Unformatted:
