Re: startperl insanity

[email protected] (Nicholas Clark) Thu, 11 Aug 2005 15:39:01 +0100
Newsgroups perl.perl5.porters,perl.ponie.dev
Message-ID <[email protected]>
On Wed, Aug 10, 2005 at 09:56:37PM -0500, Graham Barr wrote:
> 
> On Aug 10, 2005, at 4:43 PM, Nicholas Clark wrote:

> >which somewhat makes sense, as the #! for dprofpp, h2ph and h2xs is
> >
> >#!/Users/nick/Sandpit/frob/spong
> >    eval 'exec /Users/nick/Sandpit/blead25277/bin/perl5.9.3 -S $0  
> >${1+"$@"}'
> >        if $running_under_some_shell;
> 
> Thats a bug in the .PL script that generates them. perlrun describes  
> this
> 
>     #!/bin/sh -- # -*- perl -*- -p
>     eval 'exec /usr/bin/perl $0 -S ${1+"$@"}'
>         if $running_under_some_shell;
> 
> So those .PL scripts should probably have
> 
> print OUT <<"!GROK!THIS!";
> $Config{startperl} -- # -*- perl -*-
>     eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
>         if \$running_under_some_shell;
> !GROK!THIS!
> 
> Or the exec should have -x and the line #!perl added after the if

By the time there's the -*- perl -*- in place, the #! redispatcher code is
happy, in that it doesn't attempt to re-exec. Adding another #!perl and an
-x earlier doesn't seem to make a difference.

Taking out the -*- perl -*- causes an infinite loop

10 /usr/bin/sh gets to the eval exec, and does that, exec'ing perl
20 perl gets to the first #! line
30 that doesn't say perl, so it re-execs whatever was on the #! line
   (/usr/bin/sh)
40 goto 10

So I think that adding -*- perl -*- (and the preceding gubbins)	would solve
it, but I don't have access to enough Unix variants to be confident that
that would work everywhere. For now, I've removed the redispatch code from
ponie.

Nicholas Clark