Bug 15782

Summary: kernel script handling breaks with perl
Product: Base System Reporter: arjan <arjan>
Component: miscAssignee: Martin Cracauer <cracauer>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description arjan 1999-12-30 15:40:01 UTC
While moving our webserver from OpenBSD to FreeBSD (hurray !), we've
seen a lot of perl scripts break on the first line 
"#!/usr/bin/perl -*-perl-*-". Apperantly, the FreeBSD kernel does not 
ignore the extra text and tries to invoke this as a script, breaking the
original script. In the OpenBSD kernel is lists this comment in the 
kernel script handling module :
                /*
                 * collect the shell argument.  everything after the 
                 * shell name is passed as ONE argument; that's the 
                 * correct (historical) behaviour.
                 */

Now I don't know that this is a good idea, but Laary Wall decided Perl
would expect one argument, including whitespace for #!perl
scripts. FreeBSD decided to parse the initial line of script files
into arguments. The two are incompatible.

Fix: I do think if FreeBSD is going to parse the line into separate
arguments, it would be a good idea to actually do the parsing
properly, not simply break strings on whitespace. That's harder to do
and may well not be worth the effort. On the other hand, the following
patch in imgact_shell.c make Perl happy:



(the comment is frm OpenBSD)

Patch & original comment by Jim E. Segrave (jes@nl.demon.net)--SPorDBNmfQBEFilzf4KZNbbPywh2aq6kuPbhtPMuAdM03B0x
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

--- imgact_shell.c  Wed Dec 29 13:12:47 1999
+++ /sys/kern/imgact_shell.c    Fri Oct 16 05:55:00 1998
@@ -116,30 +107,12 @@
        while ((*ihp == ' ') || (*ihp == '\t')) ihp++;
 
        if (ihp < line_endp) {
-
-/**********************
- jes - web patches
- **********************/
            /*
             * Copy to end of token. No need to watch stringspace
             *  because this is at the front of the string buffer
             *  and the maximum shell command length is tiny.
             */
-/**********************************
- above comment is no longer true
- **********************************/
-
-               /*
-                * collect the shell argument.  everything after the 
-                * shell name is passed as ONE argument; that's the 
-                * correct (historical) behaviour.
-                */
-
-#if 0
            while ((ihp < line_endp) && (*ihp != ' ') && (*ihp != '\t')) {
-#else
-           while (ihp < line_endp) {
-#endif
Comment 1 Sheldon Hearn 2000-01-04 12:09:57 UTC
On Thu, 30 Dec 1999 07:32:47 PST, arjan@inventionz.org wrote:

> While moving our webserver from OpenBSD to FreeBSD (hurray !), we've
> seen a lot of perl scripts break on the first line 
> "#!/usr/bin/perl -*-perl-*-"

What is that supposed to do?  What is the -* option?  I can't see how
this is supposed to work.

> Now I don't know that this is a good idea, but Laary Wall decided Perl
> would expect one argument, including whitespace for #!perl
> scripts.

Where did you get this information?  Take a look at the example given in
the "Switches" subsection of the perlrun(5) manual page.

Ciao,
Sheldon.
Comment 2 Sheldon Hearn freebsd_committer freebsd_triage 2000-03-20 12:33:21 UTC
State Changed
From-To: open->closed

Fixed in rev 1.21 of src/sys/kern/imgact_shell.c and merged onto 
the RELENG_3 branch in rev 1.17.2.2 . 


Comment 3 Sheldon Hearn freebsd_committer freebsd_triage 2000-03-20 12:33:21 UTC
Responsible Changed
From-To: freebsd-bugs->cracauer

Martin's fix.