From nobody@FreeBSD.ORG  Thu Dec 30 07:32:47 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 6E45414F40; Thu, 30 Dec 1999 07:32:47 -0800 (PST)
Message-Id: <19991230153247.6E45414F40@hub.freebsd.org>
Date: Thu, 30 Dec 1999 07:32:47 -0800 (PST)
From: arjan@inventionz.org
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: kernel script handling breaks with perl
X-Send-Pr-Version: www-1.0

>Number:         15782
>Category:       misc
>Synopsis:       kernel script handling breaks with perl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cracauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 30 07:40:01 PST 1999
>Closed-Date:    Mon Mar 20 04:33:21 PST 2000
>Last-Modified:  Mon Mar 20 04:34:41 PST 2000
>Originator:     Arjan van der Oest
>Release:        3.3s
>Organization:
>Environment:
none
>Description:
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.






>How-To-Repeat:

>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:

--- 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

(the comment is frm OpenBSD)

Patch & original comment by Jim E. Segrave (jes@nl.demon.net)




>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: arjan@inventionz.org
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: misc/15782: kernel script handling breaks with perl 
Date: Tue, 04 Jan 2000 14:09:57 +0200

 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.
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Mar 20 04:33:21 PST 2000 
State-Changed-Why:  
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 . 


Responsible-Changed-From-To: freebsd-bugs->cracauer 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Mar 20 04:33:21 PST 2000 
Responsible-Changed-Why:  
Martin's fix. 
>Unformatted:
