Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Sep 2004 13:21:54 +0100
From:      Ceri Davies <ceri@submonkey.net>
To:        S?awek ?ak <zaks@prioris.mini.pw.edu.pl>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Bug in #! processing
Message-ID:  <20040930122154.GS2493@submonkey.net>
In-Reply-To: <86mzz8x8zv.fsf@thirst.unx.era.pl>
References:  <861xgm5ltz.fsf@thirst.unx.era.pl> <20040928194853.GT2493@submonkey.net> <86k6ud2t6t.fsf@thirst.unx.era.pl> <20040929131136.GA2493@submonkey.net> <86mzz8x8zv.fsf@thirst.unx.era.pl>

next in thread | previous in thread | raw e-mail | index | archive | help

--zdA3Jw0ChSeS2+06
Content-Type: multipart/mixed; boundary="wjfWYMzGYPVGkkPO"
Content-Disposition: inline


--wjfWYMzGYPVGkkPO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Sep 30, 2004 at 01:59:48PM +0200, S?awek ?ak wrote:
> Ceri Davies <ceri@submonkey.net> writes:
> > On Wed, Sep 29, 2004 at 01:47:06PM +0200, S?awek ?ak wrote:
>=20
> >>     You should speel buggy as 'POSIX' in this case I guess.
>=20
> > You're actually guessing though, right?  I can't find this in the
> > standard; if you know it's there then I'd appreciate a reference.
>=20
>     No reference on this. Vague memories of brokedness only.

Good, I'm not losing my eyesight then.  In theory this means that we're
free to do whatever we want, as the commit log for revision 1.21 of
imgact_shell.c suggests.

> > I believe that the FreeBSD behaviour is closer to "correct" than
> > anything else we're seeing in this thread.  I should be able to specify
> >
> > 	#!/usr/bin/perl -w -0
> >
> > or whatever without having everything other than the first argument
> > ignored.
>=20
>     Would be nice. I admit.

It *is* nice, and I do use it.

> I like the bahavior of FreeBSD besides special
>     treatment of # on the first line after #!. Allowing for comments on t=
he
>     first line is a strange excuse. Have you ever seen a script commentin=
g on
>     the interpreter execution or had a need to do so?

No, but since this has been possible in FreeBSD for over 4.5 years, you
can guarantee that someone is using it.

> >>     It is confirmed by other
> >>     supposedly compliant systems. I've checked before AIX 5.2, Solaris=
 8/9. Two
> >>     raisins in the pie are Tru64 5.1B and HP-UX 11, which return some =
erm,
> >>     strange results. For such script:
> >>=20
> >> #!./main 1 2 3 -#!
> >> print ok
> >>=20
> >>     You get:
> >>=20
> >> Main.c test
> >> ./main
> >> 1 2 3 -#!
> >> ./tst.sh
> >
> > Linux 2.4.20 does this too.
>=20
>     That's as silly as can get. When called as:
>=20
>            interpreter -a1 -a2 -a3 script
>=20
>     the argument parsing done by interpreter must be different then when =
invoked
>     via #! mechanics. Argh!

Yeah, it seems pretty gross. At least they get there though, unlike the
Solaris/AIX examples ;-)

> >>     The behavior I'd like to have, and which seems correct is not both=
ering with
> >>     second, 3rd and so on occurence of #! in the first line of script.=
 Feasible?
> >>     I guess so. The only commercial product on my systems uses -#! swi=
tch on all
> >>     platforms as a script file mark.
> >
> > That seems wrong too.  #! shouldn't be magic anywhere other than at the
> > beginning of a file.
>=20
>     Do you think that -#! argument is magic? Why is it so? It's not magic=
 and
>     should be passed without exec(2) interference.

I don't think it should be, but you seemed to suggest that it should be
in the paragraph above.  I may have misunderstood, in which case we're
agreed on this.

> >>     I don't see any explanation for current
> >>     behavior therefore I'm reporting it.
> >
> > The explanation is that we only process that line up to a '#' or
> > newline.  Backing out revision 1.21 of sys/kern/imgact_shell.c is one
> > fix, or perhaps allowing a '#' character to be escaped.  I'm not sure if
> > I see an overwhelming reason for either.
>=20
>     I don't see a convincing use for comments on the first line of script=
=2E Hash
>     is special already when treated as comment character. # is not a comm=
ent in
>     any `scripting language'. It is a shell legacy and shouldn't be force=
d on
>     the remaining universe.

I agree(ish); I don't think that the kernel should do anything special
here either and I think that the "correct" thing to do would be to back
out that revision.  Unfortunately the FreeBSD userbase can write a lot
of scripts in 4 and a half years and we probably can't get away with it.
Perhaps it could be done in -CURRENT, but I'd really like to see some
other opinions.  For clarity, what I'm proposing is the application of
the attached diff.  Opinions from anyone?

Ceri
--=20
It is not tinfoil, it is my new skin.  I am a robot.

--wjfWYMzGYPVGkkPO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="imgact_shell.diff"

Index: sys/kern/imgact_shell.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/imgact_shell.c,v
retrieving revision 1.26
diff -u -r1.26 imgact_shell.c
--- sys/kern/imgact_shell.c	11 Jun 2003 00:56:54 -0000	1.26
+++ sys/kern/imgact_shell.c	29 Sep 2004 13:04:02 -0000
@@ -73,7 +73,7 @@
 	/*
 	 * Find end of line; return if the line > MAXSHELLCMDLEN long.
 	 */
-	for (ihp = &image_header[2]; *ihp != '\n' && *ihp != '#'; ++ihp) {
+	for (ihp = &image_header[2]; *ihp != '\n'; ++ihp) {
 		if (ihp >= &image_header[MAXSHELLCMDLEN])
 			return(ENAMETOOLONG);
 	}

--wjfWYMzGYPVGkkPO--

--zdA3Jw0ChSeS2+06
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQFBW/piocfcwTS3JF8RAnuKAKCHxjzwDGNzjW/UJb1GmviIy2TL8ACghV5T
y19YPyquhvSJT0rijkFYBUY=
=W3vV
-----END PGP SIGNATURE-----

--zdA3Jw0ChSeS2+06--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040930122154.GS2493>