On 2013-09-16 Mon 13:00 PM |, Antoine Jacoutot wrote:
> 
> Heh, very interesting trick ;-)
> But I don't think that is 100% full proof as is.
> 
> e.g.
> $ head -n 1 /usr/local/bin/xml2-config | cut -d! -f2
>  /bin/sh
> You have a white space before the interpreter.
> 
> If you can improve that and make sure it works with all similar rc scripts 
> then I think it is definitely something that should be looked into.
> Thanks.
> 

Well spotted Antoine.

I wrote a test script with various shebang lines of:

#![space]/bin/ksh
#![space][space]/bin/ksh
#![space][tab]/bin/ksh -x
#![tab]/bin/ksh -x
#![space]/usr/bin/perl
#![space][space]/usr/bin/perl
#![space][tab]/usr/bin/perl -T
#![tab][tab][tab]/usr/bin/perl -T

This seems to work with these test scenarios
(as seen in /var/run/rc.d/rcshebangtester):

Index: rc.subr
===================================================================
RCS file: /cvs/src/etc/rc.d/rc.subr,v
retrieving revision 1.70
diff -u -r1.70 rc.subr
--- rc.subr     11 Jul 2013 09:34:33 -0000      1.70
+++ rc.subr     16 Sep 2013 12:09:42 -0000
@@ -221,4 +221,9 @@
 unset _rcflags _rcuser
 
 pexp="${daemon}${daemon_flags:+ ${daemon_flags}}"
+file ${daemon} | fgrep -q script &&
+{
+       shebang=$(head -n 1 ${daemon} | cut -d! -f2 | sed 's/^[[:blank:]]*//')
+       pexp="${shebang} ${pexp}"
+}
 rcexec="su -l -c ${daemon_class} -s /bin/sh ${daemon_user} -c"


Would it also be worthwhile verifying the 1st element of $shebang is
executable before prefixing $pexp?


Cheers,
-- 
Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7

Reply via email to