Re: #! and argv[0]: the path is removed before invoking the interpreter

From: Ahmon Dancy (dancy@franz.com)
Date: Wed Feb 16 2000 - 16:50:08 EST


>> I hope the old BSD/Sysv behavior is considered a bug. It
>> unnecessarily exposes the difference between an executable in ELF
>> or aout format and an executable in #! format.

>> argv[0] passed to main() should be the same that was passed to
>> execve().

If your statement is true, then the following (current behavior on
pretty-much every Unix including linux) also needs to be fixed:

bash# /tmp/foo.script
argv[0] = /tmp/foo (or just 'foo' on Linux)

(where /tmp/foo.script is a single-line file containing '#! /tmp/foo')

Why? Because because bash calls execve() with argv[0] set to
'/tmp/foo.script'. This does not match the behavior that you claim
"should be" in your statement above.

Perhaps we should approach this from a different angle. In light of
your recent incorrect statement... what is the disadvantage of not
stripping the dirname from the pathname specified at the '#!'?

I.e., in /usr/src/linux/fs/binfmt_script.c, what is the disadvantage
of changing the code in the following way?:

diff -c ./fs/binfmt_script.c,0 ./fs/binfmt_script.c
*** ./fs/binfmt_script.c,0 Thu Aug 20 14:32:48 1998
--- ./fs/binfmt_script.c Wed Feb 16 10:57:33 2000
***************
*** 47,54 ****
--- 47,57 ----
          i_name_start = i_name = cp;
          i_arg = 0;
          for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
+ #if 0
                   if (*cp == '/')
                          i_name = cp+1;
+ #endif
          }
          while ((*cp == ' ') || (*cp == '\t'))
                  *cp++ = '\0';

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:16 EST