From owner-freebsd-rc@FreeBSD.ORG Sun Mar 4 13:54:47 2007 Return-Path: X-Original-To: freebsd-rc@FreeBSD.org Delivered-To: freebsd-rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5ED3C16A400; Sun, 4 Mar 2007 13:54:47 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.freebsd.org (Postfix) with ESMTP id 96F6413C474; Sun, 4 Mar 2007 13:54:46 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.4) with ESMTP id l24DsibR051346; Sun, 4 Mar 2007 16:54:44 +0300 (MSK) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.4/Submit) id l24Dsi67051341; Sun, 4 Mar 2007 16:54:44 +0300 (MSK) (envelope-from yar) Date: Sun, 4 Mar 2007 16:54:43 +0300 From: Yar Tikhiy To: Doug Barton Message-ID: <20070304135443.GK40430@comp.chem.msu.su> References: <200703031011.l23ABYhb039755@repoman.freebsd.org> <45EA68AF.6000700@FreeBSD.org> <20070304130408.GJ40430@comp.chem.msu.su> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070304130408.GJ40430@comp.chem.msu.su> User-Agent: Mutt/1.5.9i Cc: freebsd-rc@FreeBSD.org Subject: Re: cvs commit: doc/en_US.ISO8859-1/articles/rc-scripting article.sgml X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Mar 2007 13:54:47 -0000 On Sun, Mar 04, 2007 at 04:04:08PM +0300, Yar Tikhiy wrote: > On Sat, Mar 03, 2007 at 10:35:27PM -0800, Doug Barton wrote: > > Yar Tikhiy wrote: > > >yar 2007-03-03 10:11:34 UTC > > > > > > FreeBSD doc repository > > > > > > Modified files: > > > en_US.ISO8859-1/articles/rc-scripting article.sgml > > > Log: > > > Explain how an rc.d script can use extra command-line arguments. > > > > > > Revision Changes Path > > > 1.9 +138 -0 > > > doc/en_US.ISO8859-1/articles/rc-scripting/article.sgml > > > > > >http://www.FreeBSD.org/cgi/cvsweb.cgi/doc/en_US.ISO8859-1/articles/rc-scripting/article.sgml.diff?&r1=1.8&r2=1.9&f=h > > > > Yar, > > > > This good stuff, thanks! I have one quibble with the last paragraph. > > The shift in rc.subr isn't "apparent" as you phrase it, it's literal: > > Yeah, I tried to hide a thing from the reader which he should already > have known: the shift command. :-) > > > run_rc_command() > > { > > ... > > # Don't repeat the first argument when passing additional command- > > # line arguments to the command subroutines. > > # > > shift 1 > > rc_extra_args="$*" > > Oh my... Now I see why existing rc.d scripts use this bogus command: > > run_rc_command "$*" > > It's because rc.subr will mess up the arguments anyway. Perhaps > we should investigate if "$@" can be used consistently to preserve > original boundaries between arguments to an rc.d script... Now we > have little chance there as the final command is eval, which is the > ultimate killer of the original boundaries. I'm uncertain if the > eval is really necessary to invoke rc.d methods. I failed to take into account initially that $foo_cmd can be a random shell expression, not only a function name. That's why we need the final eval. OTOH, letting extra arguments is usually wrong if $foo_cmd isn't a function name. E.g., let's consider the following bones of a script: name=foo start_cmd="echo Hello world; exit 0" run_rc_command "$@" If we issue ``foo start 1 2 3'', the ultimate shell command executed will be ``echo Hello world; exit 0 1 2 3'', which is bogus... Nevertheless we seem to be doomed to mishandle rc.d arguments with embedded whitespace. Sigh. -- Yar