summaryrefslogtreecommitdiff
path: root/exec/hashexec.c
diff options
context:
space:
mode:
authorThomas Bushnell <thomas@gnu.org>1998-11-05 20:42:00 +0000
committerThomas Bushnell <thomas@gnu.org>1998-11-05 20:42:00 +0000
commita08515735de79eda5994d15abfce3c0fee30a7f9 (patch)
tree0ac8b9bfd9dad849336282cd3a6b7b8dff38dfb4 /exec/hashexec.c
parent3dcaa5f6262e5dec4aeb13d3b6bbb4ef45877a47 (diff)
Thu Nov 5 15:26:50 1998 Thomas Bushnell, BSG <tb@mit.edu>
* hashexec.c (check_hashbang): Keep INTERP_LEN with the correct value (bytes of memory holding INTERP) for later use. (check_hashbang: setup_args): Set argv[0] from the interpreter name, not copied from the existing command line.
Diffstat (limited to 'exec/hashexec.c')
-rw-r--r--exec/hashexec.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/exec/hashexec.c b/exec/hashexec.c
index 61e743b6..e430b454 100644
--- a/exec/hashexec.c
+++ b/exec/hashexec.c
@@ -1,5 +1,5 @@
/* GNU Hurd standard exec server, #! script execution support.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
Written by Roland McGrath.
This file is part of the GNU Hurd.
@@ -166,6 +166,8 @@ check_hashbang (struct execdata *e,
else
++len; /* Include the terminating null. */
+ interp_len = strlen (interp) + 1;
+
user_crdir = user_cwdir = MACH_PORT_NULL;
rwlock_reader_lock (&std_lock);
@@ -298,12 +300,15 @@ check_hashbang (struct execdata *e,
/* Prepare the arguments to pass to the interpreter from the original
arguments and the name of the script file. The args will look
- like `ARGV[0] {ARG} FILE_NAME ARGV[1..n]' (ARG might have been
+ like `INTERP {ARG} FILE_NAME ARGV[1..n]' (ARG might have been
omitted). */
namelen = strlen (file_name) + 1;
- new_argvlen = argvlen + len + namelen;
+ new_argvlen
+ = (argvlen - strlen (argv) - 1) /* existing args - old argv[0] */
+ + interplen + len + namelen; /* New args */
+
e->error = vm_allocate (mach_task_self (),
(vm_address_t *) &new_argv,
new_argvlen, 1);
@@ -313,18 +318,28 @@ check_hashbang (struct execdata *e,
if (! setjmp (args_faulted))
{
char *other_args;
- other_args = memccpy (new_argv, argv, '\0', argvlen);
- p = &new_argv[other_args ? other_args - new_argv : argvlen];
+
+ p = new_argv;
+
+ /* INTERP */
+ memcpy (p, interp, interp_len);
+ p += interp_len;
+
+ /* Maybe ARG */
if (arg)
{
memcpy (p, arg, len);
p += len;
}
+
+ /* FILE_NAME */
memcpy (p, file_name, namelen);
p += namelen;
- if (other_args)
- memcpy (p, other_args - new_argv + argv,
- argvlen - (other_args - new_argv));
+
+ /* Maybe remaining args */
+ other_args = argv + strlen (argv) + 1;
+ if (other_args - argv < argvlen)
+ memcpy (p, other_args, argvlen - (other_args - argv));
}
else
{