Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Dec 1999 17:05:06 +0100 (CET)
From:      Jim Segrave <jes@nl.demon.net>
To:        freebsd-isp@freebsd.org
Cc:        jes@nl.demon.net
Subject:   Re: FreeBSD and Perl
Message-ID:  <E123Lb0-0003ic-00@jes.noc.nl.demon.net>
In-Reply-To: <Pine.BSF.4.10.9912291501400.72353-100000@bunker.noc.nl.demon.net> from Arjan van der Oest at "Dec 29, 1999 03:02:03 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
> ---------- Forwarded message ----------
> Date: Wed, 29 Dec 1999 08:50:29 -0500 (EST)
> From: Will Andrews <andrews@TECHNOLOGIST.COM>
> To: Arjan van der Oest <arjan@nl.demon.net>
> Cc: freebsd-isp@FreeBSD.ORG
> Subject: RE: FreeBSD and Perl
> 
> On 29-Dec-99 Arjan van der Oest wrote:
> > We used to run our webservers on NetBSD but recently changed over to
> > FreeBSD 3.3r. We've seen a lot of perl scripts break becase they start
> > with the first line : #!/bin/perl -- -*-perl-*-
> 
> This looks familiar. I'm pretty sure that "-*-perl-*-" is just an Emacs way of
> getting syntax highlighting (in addition to some Emacs feaures) for the script
> as a Perl script.

However, it is documented (man perlrun) as being valid in perl that:
       Parsing of the #! switches starts wherever "perl" is
       mentioned in the line.  The sequences "-*" and "- " are
       specifically ignored so that you could, ...

 
> > NetBSD seemed to pass this as a single argument to the interpreter and
> > perl ignored it. FreeBSD now seems to pass this line as two arguments to
> > the interpreter, braking the script because it tries to open script
> > -*-perl-*-.
> 
> You can probably comment this "-*-perl-*-" out on a line below #!/usr/bin/perl
> (not #!/bin/perl since Perl is installed in /usr by default on FreeBSD).
> 
> Like this:
> 
> #!/usr/bin/perl -w
> # -*-perl-*-
> #
> [...code...]


Which doesn't help on a commercial site where thousands of customers
will be getting their own copy of, for example,. formmail.pl which begins:

#!/bin/perl -- -*-perl-*-

# ------------------------------------------------------------
# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
#
# Last updated: March 14, 1994

They will upload it and expect it to work. We aren't really in a
position to keep going and fixing customer's mistakes on a daily
basis.

> 
> > Besides the fact that I see no use of inserting "-- -*-perl-*-" in the
> > scripts, does anyone recognises this problem ? How did you deal with this?
> > We've got a lot of customers who use standard scripts and this line
> > appears in a lot of examples/books/pre-written script, thus causing lots
> > of people calling tech support.
> 
> I'm afraid that the original programmer likes Emacs. ;)
> 
> I stop here at the risk of triggering a holy war. *grin*

It's intersting to note that OpenBSD (and, no, I have no intention of
openeing an OS religious war) has the following comment in their
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.

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)

-- 
Jim Segrave           jes@nl.demon.net


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E123Lb0-0003ic-00>