From Andre.Albsmeier@siemens.com  Thu Nov 17 14:44:03 2011
Return-Path: <Andre.Albsmeier@siemens.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C407A106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2011 14:44:03 +0000 (UTC)
	(envelope-from Andre.Albsmeier@siemens.com)
Received: from thoth.sbs.de (thoth.sbs.de [192.35.17.2])
	by mx1.freebsd.org (Postfix) with ESMTP id 57CE08FC13
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2011 14:44:02 +0000 (UTC)
Received: from mail2.siemens.de (localhost [127.0.0.1])
	by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id pAHEU56M001526
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2011 15:30:05 +0100
Received: from curry.mchp.siemens.de (curry.mchp.siemens.de [139.25.40.130])
	by mail2.siemens.de (8.13.6/8.13.6) with ESMTP id pAHEU4eH022366
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2011 15:30:04 +0100
Received: (from localhost)
	by curry.mchp.siemens.de (8.14.5/8.14.4) id pAHEU4cE009416
	for FreeBSD-gnats-submit@freebsd.org; Thu, 17 Nov 2011 15:30:04 +0100 (CET)
Message-Id: <201111171430.pAHEU4f1039739@curry.mchp.siemens.de>
Date: Thu, 17 Nov 2011 15:30:04 +0100 (CET)
From: Andre Albsmeier <Andre.Albsmeier@siemens.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: .sh scripts in /usr/loca/etc/rc.d get executed, not sourced
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         162642
>Category:       conf
>Synopsis:       .sh scripts in /usr/local/etc/rc.d get executed, not sourced
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-rc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 17 14:50:15 UTC 2011
>Closed-Date:    
>Last-Modified:  Thu Nov 17 18:57:41 UTC 2011
>Originator:     Andre Albsmeier
>Release:        FreeBSD 7.4-STABLE i386
>Organization:
>Environment:

System: FreeBSD 7.4-STABLE Tue Nov 8 12:24:13 CET 2011

>Description:

man rc.subr says:

     run_rc_script file argument
           Start the script file with an argument of argument, and handle the
           return value from the script.

           Various shell variables are unset before file is started:

                 name, command, command_args, command_interpreter,
                 extra_commands, pidfile, rcvar, required_dirs,
                 required_files, required_vars, argument_cmd, argument_precmd.
                 argument_postcmd.

           The startup behaviour of file depends upon the following checks:

           1.   If file ends in .sh, it is sourced into the current shell.

           2.   If file appears to be a backup or scratch file (e.g., with a
                suffix of ~, #, .OLD, or .orig), ignore it.

           3.   If file is not executable, ignore it.

           4.   If the rc.conf(5) variable rc_fast_and_loose is empty, source
                file in a sub shell, otherwise source file into the current
                shell.

This is only true for .sh scripts sitting in /etc/rc.d
but not for other locations.

>How-To-Repeat:

put test.sh into /usr/local/etc/rc.d and it will get executed
in a subshell but not executed in the current shell.

>Fix:

--- rc.subr.ORI	2011-11-17 15:21:59.000000000 +0100
+++ rc.subr	2011-11-17 15:26:04.000000000 +0100
@@ -938,7 +938,7 @@
 	eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
 
 	case "$_file" in
-	/etc/rc.d/*.sh)			# run in current shell
+	*.sh)			# run in current shell
 		set $_arg; . $_file
 		;;
 	*[~#]|*.OLD|*.bak|*.orig|*,v)	# scratch file; skip

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 17 18:57:29 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

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