2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
1993-12-20 16:16:46 +00:00
|
|
|
* Copyright (c) 1993, David Greenman
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1995-09-08 13:24:33 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1993-12-20 16:16:46 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
2005-02-25 10:17:53 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/proc.h>
|
2008-08-26 10:53:32 +00:00
|
|
|
#include <sys/sbuf.h>
|
1998-10-16 03:55:01 +00:00
|
|
|
#include <sys/systm.h>
|
1995-10-08 00:06:22 +00:00
|
|
|
#include <sys/sysproto.h>
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <sys/exec.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/imgact.h>
|
|
|
|
#include <sys/kernel.h>
|
1993-12-20 16:16:46 +00:00
|
|
|
|
1993-12-20 19:31:41 +00:00
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
1993-12-20 16:16:46 +00:00
|
|
|
#define SHELLMAGIC 0x2123 /* #! */
|
1993-12-20 19:31:41 +00:00
|
|
|
#else
|
|
|
|
#define SHELLMAGIC 0x2321
|
|
|
|
#endif
|
|
|
|
|
1993-12-20 16:16:46 +00:00
|
|
|
/*
|
2005-05-28 22:42:41 +00:00
|
|
|
* At the time of this writing, MAXSHELLCMDLEN == PAGE_SIZE. This is
|
|
|
|
* significant because the caller has only mapped in one page of the
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
* file we're reading.
|
2005-05-28 22:42:41 +00:00
|
|
|
*/
|
|
|
|
#if MAXSHELLCMDLEN > PAGE_SIZE
|
|
|
|
#error "MAXSHELLCMDLEN is larger than a single page!"
|
|
|
|
#endif
|
|
|
|
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
/*
|
|
|
|
* MAXSHELLCMDLEN must be at least MAXINTERP plus the size of the `#!'
|
|
|
|
* prefix and terminating newline.
|
|
|
|
*/
|
|
|
|
CTASSERT(MAXSHELLCMDLEN >= MAXINTERP + 3);
|
|
|
|
|
2005-05-28 22:42:41 +00:00
|
|
|
/**
|
|
|
|
* Shell interpreter image activator. An interpreter name beginning at
|
|
|
|
* imgp->args->begin_argv is the minimal successful exit requirement.
|
|
|
|
*
|
|
|
|
* If the given file is a shell-script, then the first line will start
|
|
|
|
* with the two characters `#!' (aka SHELLMAGIC), followed by the name
|
|
|
|
* of the shell-interpreter to run, followed by zero or more tokens.
|
|
|
|
*
|
|
|
|
* The interpreter is then started up such that it will see:
|
|
|
|
* arg[0] -> The name of interpreter as specified after `#!' in the
|
|
|
|
* first line of the script. The interpreter name must
|
|
|
|
* not be longer than MAXSHELLCMDLEN bytes.
|
|
|
|
* arg[1] -> *If* there are any additional tokens on the first line,
|
|
|
|
* then we add a new arg[1], which is a copy of the rest of
|
|
|
|
* that line. The copy starts at the first token after the
|
|
|
|
* interpreter name. We leave it to the interpreter to
|
|
|
|
* parse the tokens in that value.
|
|
|
|
* arg[x] -> the full pathname of the script. This will either be
|
|
|
|
* arg[2] or arg[1], depending on whether or not tokens
|
|
|
|
* were found after the interpreter name.
|
|
|
|
* arg[x+1] -> all the arguments that were specified on the original
|
|
|
|
* command line.
|
|
|
|
*
|
|
|
|
* This processing is described in the execve(2) man page.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HISTORICAL NOTE: From 1993 to mid-2005, FreeBSD parsed out the tokens as
|
|
|
|
* found on the first line of the script, and setup each token as a separate
|
|
|
|
* value in arg[]. This extra processing did not match the behavior of other
|
|
|
|
* OS's, and caused a few subtle problems. For one, it meant the kernel was
|
|
|
|
* deciding how those values should be parsed (wrt characters for quoting or
|
|
|
|
* comments, etc), while the interpreter might have other rules for parsing.
|
|
|
|
* It also meant the interpreter had no way of knowing which arguments came
|
|
|
|
* from the first line of the shell script, and which arguments were specified
|
2005-06-09 00:27:02 +00:00
|
|
|
* by the user on the command line. That extra processing was dropped in the
|
|
|
|
* 6.x branch on May 28, 2005 (matching __FreeBSD_version 600029).
|
1993-12-20 16:16:46 +00:00
|
|
|
*/
|
2000-04-26 20:58:40 +00:00
|
|
|
int
|
2017-11-04 15:41:08 +00:00
|
|
|
exec_shell_imgact(struct image_params *imgp)
|
1993-12-20 16:16:46 +00:00
|
|
|
{
|
1995-11-06 12:52:37 +00:00
|
|
|
const char *image_header = imgp->image_header;
|
2008-08-26 10:53:32 +00:00
|
|
|
const char *ihp, *interpb, *interpe, *maxp, *optb, *opte, *fname;
|
2005-01-30 06:43:17 +00:00
|
|
|
int error, offset;
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
size_t length;
|
2005-02-25 10:17:53 +00:00
|
|
|
struct vattr vattr;
|
2008-08-26 10:53:32 +00:00
|
|
|
struct sbuf *sname;
|
1993-12-20 16:16:46 +00:00
|
|
|
|
|
|
|
/* a shell script? */
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
if (((const short *)image_header)[0] != SHELLMAGIC)
|
|
|
|
return (-1);
|
1993-12-20 16:16:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't allow a shell script to be the shell for a shell
|
|
|
|
* script. :-)
|
|
|
|
*/
|
2014-09-04 21:31:25 +00:00
|
|
|
if (imgp->interpreted & IMGACT_SHELL)
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
return (ENOEXEC);
|
1993-12-20 16:16:46 +00:00
|
|
|
|
2014-09-04 21:31:25 +00:00
|
|
|
imgp->interpreted |= IMGACT_SHELL;
|
1993-12-20 16:16:46 +00:00
|
|
|
|
2005-02-25 10:17:53 +00:00
|
|
|
/*
|
|
|
|
* At this point we have the first page of the file mapped.
|
|
|
|
* However, we don't know how far into the page the contents are
|
|
|
|
* valid -- the actual file might be much shorter than the page.
|
|
|
|
* So find out the file size.
|
2017-11-04 15:41:08 +00:00
|
|
|
*/
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(imgp->vp, &vattr, imgp->proc->p_ucred);
|
2005-02-25 10:17:53 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2005-05-28 22:42:41 +00:00
|
|
|
/*
|
|
|
|
* Copy shell name and arguments from image_header into a string
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
* buffer.
|
2005-05-28 22:42:41 +00:00
|
|
|
*/
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
maxp = &image_header[MIN(vattr.va_size, MAXSHELLCMDLEN)];
|
2005-05-28 22:42:41 +00:00
|
|
|
ihp = &image_header[2];
|
1993-12-20 16:16:46 +00:00
|
|
|
|
2005-05-28 22:42:41 +00:00
|
|
|
/*
|
|
|
|
* Find the beginning and end of the interpreter_name. If the
|
|
|
|
* line does not include any interpreter, or if the name which
|
|
|
|
* was found is too long, we bail out.
|
|
|
|
*/
|
|
|
|
while (ihp < maxp && ((*ihp == ' ') || (*ihp == '\t')))
|
|
|
|
ihp++;
|
|
|
|
interpb = ihp;
|
|
|
|
while (ihp < maxp && ((*ihp != ' ') && (*ihp != '\t') && (*ihp != '\n')
|
|
|
|
&& (*ihp != '\0')))
|
|
|
|
ihp++;
|
|
|
|
interpe = ihp;
|
|
|
|
if (interpb == interpe)
|
|
|
|
return (ENOEXEC);
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
if (interpe - interpb >= MAXINTERP)
|
2005-05-28 22:42:41 +00:00
|
|
|
return (ENAMETOOLONG);
|
1993-12-20 16:16:46 +00:00
|
|
|
|
2005-05-28 22:42:41 +00:00
|
|
|
/*
|
|
|
|
* Find the beginning of the options (if any), and the end-of-line.
|
|
|
|
* Then trim the trailing blanks off the value. Note that some
|
|
|
|
* other operating systems do *not* trim the trailing whitespace...
|
|
|
|
*/
|
|
|
|
while (ihp < maxp && ((*ihp == ' ') || (*ihp == '\t')))
|
|
|
|
ihp++;
|
|
|
|
optb = ihp;
|
|
|
|
while (ihp < maxp && ((*ihp != '\n') && (*ihp != '\0')))
|
|
|
|
ihp++;
|
|
|
|
opte = ihp;
|
Fix exec_imgact_shell()'s handling of two error cases: (1) Previously, if
the first line of a script exceeded MAXSHELLCMDLEN characters, then
exec_imgact_shell() silently truncated the line and passed on the truncated
interpreter name or argument. Now, exec_imgact_shell() will fail and return
ENOEXEC, which is the commonly used errno among Unix variants for this type
of error. (2) Previously, exec_imgact_shell()'s check on the length of the
interpreter's name was ineffective. In other words, exec_imgact_shell()
could not possibly fail and return ENAMETOOLONG. The reason being that the
length of the interpreter name had to exceed MAXSHELLCMDLEN characters in
order that ENAMETOOLONG be returned. But, the search for the end of the
interpreter name stops after at most MAXSHELLCMDLEN - 2 characters are
scanned. (In the end, this particular error is eventually discovered
outside of exec_imgact_shell() and ENAMETOOLONG is returned. So, the real
effect of this second change is that the error is detected earlier, in
exec_imgact_shell().)
Update the definition of MAXINTERP to the actual limit on the size of
the interpreter name that has been in effect since r142453 (from
2005).
In collaboration with: kib
2010-09-21 16:24:51 +00:00
|
|
|
if (opte == maxp)
|
|
|
|
return (ENOEXEC);
|
2005-06-19 02:21:03 +00:00
|
|
|
while (--ihp > optb && ((*ihp == ' ') || (*ihp == '\t')))
|
2005-05-28 22:42:41 +00:00
|
|
|
opte = ihp;
|
|
|
|
|
2008-08-26 10:53:32 +00:00
|
|
|
if (imgp->args->fname != NULL) {
|
|
|
|
fname = imgp->args->fname;
|
|
|
|
sname = NULL;
|
|
|
|
} else {
|
|
|
|
sname = sbuf_new_auto();
|
|
|
|
sbuf_printf(sname, "/dev/fd/%d", imgp->args->fd);
|
|
|
|
sbuf_finish(sname);
|
|
|
|
fname = sbuf_data(sname);
|
|
|
|
}
|
|
|
|
|
2005-05-28 22:42:41 +00:00
|
|
|
/*
|
|
|
|
* We need to "pop" (remove) the present value of arg[0], and "push"
|
|
|
|
* either two or three new values in the arg[] list. To do this,
|
|
|
|
* we first shift all the other values in the `begin_argv' area to
|
|
|
|
* provide the exact amount of room for the values added. Set up
|
|
|
|
* `offset' as the number of bytes to be added to the `begin_argv'
|
|
|
|
* area, and 'length' as the number of bytes being removed.
|
|
|
|
*/
|
|
|
|
offset = interpe - interpb + 1; /* interpreter */
|
2005-06-19 02:21:03 +00:00
|
|
|
if (opte > optb) /* options (if any) */
|
2005-05-28 22:42:41 +00:00
|
|
|
offset += opte - optb + 1;
|
2008-08-26 10:53:32 +00:00
|
|
|
offset += strlen(fname) + 1; /* fname of script */
|
2005-05-28 22:42:41 +00:00
|
|
|
length = (imgp->args->argc == 0) ? 0 :
|
|
|
|
strlen(imgp->args->begin_argv) + 1; /* bytes to delete */
|
|
|
|
|
2011-03-06 22:59:30 +00:00
|
|
|
if (offset > imgp->args->stringspace + length) {
|
2008-08-26 10:53:32 +00:00
|
|
|
if (sname != NULL)
|
|
|
|
sbuf_delete(sname);
|
2005-05-28 22:42:41 +00:00
|
|
|
return (E2BIG);
|
2008-08-26 10:53:32 +00:00
|
|
|
}
|
2005-05-28 22:42:41 +00:00
|
|
|
|
|
|
|
bcopy(imgp->args->begin_argv + length, imgp->args->begin_argv + offset,
|
|
|
|
imgp->args->endp - (imgp->args->begin_argv + length));
|
|
|
|
|
|
|
|
offset -= length; /* calculate actual adjustment */
|
|
|
|
imgp->args->begin_envv += offset;
|
|
|
|
imgp->args->endp += offset;
|
|
|
|
imgp->args->stringspace -= offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there was no arg[0] when we started, then the interpreter_name
|
|
|
|
* is adding an argument (instead of replacing the arg[0] we started
|
|
|
|
* with). And we're always adding an argument when we include the
|
|
|
|
* full pathname of the original script.
|
|
|
|
*/
|
|
|
|
if (imgp->args->argc == 0)
|
|
|
|
imgp->args->argc = 1;
|
|
|
|
imgp->args->argc++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The original arg[] list has been shifted appropriately. Copy in
|
|
|
|
* the interpreter name and options-string.
|
|
|
|
*/
|
|
|
|
length = interpe - interpb;
|
Change the order in which the file name, arguments, environment, and
shell command are stored in exec*()'s demand-paged string buffer. For
a "buildworld" on an 8GB amd64 multiprocessor, the new order reduces
the number of global TLB shootdowns by 31%. It also eliminates about
330k page faults on the kernel address space.
Change exec_shell_imgact() to use "args->begin_argv" consistently as
the start of the argument and environment strings. Previously, it
would sometimes use "args->buf", which is the start of the overall
buffer, but no longer the start of the argument and environment
strings. While I'm here, eliminate unnecessary passing of "&length"
to copystr(), where we don't actually care about the length of the
copied string.
Clean up the initialization of the exec map. In particular, use the
correct size for an entry, and express that size in the same way that
is used when an entry is allocated. The old size was one page too
large. (This discrepancy originated in 2004 when I rewrote
exec_map_first_page() to use sf_buf_alloc() instead of the exec map
for mapping the first page of the executable.)
Reviewed by: kib
2010-07-25 17:43:38 +00:00
|
|
|
bcopy(interpb, imgp->args->begin_argv, length);
|
|
|
|
*(imgp->args->begin_argv + length) = '\0';
|
2005-05-28 22:42:41 +00:00
|
|
|
offset = length + 1;
|
2005-06-19 02:21:03 +00:00
|
|
|
if (opte > optb) {
|
2005-05-28 22:42:41 +00:00
|
|
|
length = opte - optb;
|
Change the order in which the file name, arguments, environment, and
shell command are stored in exec*()'s demand-paged string buffer. For
a "buildworld" on an 8GB amd64 multiprocessor, the new order reduces
the number of global TLB shootdowns by 31%. It also eliminates about
330k page faults on the kernel address space.
Change exec_shell_imgact() to use "args->begin_argv" consistently as
the start of the argument and environment strings. Previously, it
would sometimes use "args->buf", which is the start of the overall
buffer, but no longer the start of the argument and environment
strings. While I'm here, eliminate unnecessary passing of "&length"
to copystr(), where we don't actually care about the length of the
copied string.
Clean up the initialization of the exec map. In particular, use the
correct size for an entry, and express that size in the same way that
is used when an entry is allocated. The old size was one page too
large. (This discrepancy originated in 2004 when I rewrote
exec_map_first_page() to use sf_buf_alloc() instead of the exec map
for mapping the first page of the executable.)
Reviewed by: kib
2010-07-25 17:43:38 +00:00
|
|
|
bcopy(optb, imgp->args->begin_argv + offset, length);
|
|
|
|
*(imgp->args->begin_argv + offset + length) = '\0';
|
2005-05-28 22:42:41 +00:00
|
|
|
offset += length + 1;
|
|
|
|
imgp->args->argc++;
|
|
|
|
}
|
|
|
|
|
2005-01-29 23:12:00 +00:00
|
|
|
/*
|
|
|
|
* Finally, add the filename onto the end for the interpreter to
|
|
|
|
* use and copy the interpreter's name to imgp->interpreter_name
|
|
|
|
* for exec to use.
|
|
|
|
*/
|
Change the order in which the file name, arguments, environment, and
shell command are stored in exec*()'s demand-paged string buffer. For
a "buildworld" on an 8GB amd64 multiprocessor, the new order reduces
the number of global TLB shootdowns by 31%. It also eliminates about
330k page faults on the kernel address space.
Change exec_shell_imgact() to use "args->begin_argv" consistently as
the start of the argument and environment strings. Previously, it
would sometimes use "args->buf", which is the start of the overall
buffer, but no longer the start of the argument and environment
strings. While I'm here, eliminate unnecessary passing of "&length"
to copystr(), where we don't actually care about the length of the
copied string.
Clean up the initialization of the exec map. In particular, use the
correct size for an entry, and express that size in the same way that
is used when an entry is allocated. The old size was one page too
large. (This discrepancy originated in 2004 when I rewrote
exec_map_first_page() to use sf_buf_alloc() instead of the exec map
for mapping the first page of the executable.)
Reviewed by: kib
2010-07-25 17:43:38 +00:00
|
|
|
error = copystr(fname, imgp->args->begin_argv + offset,
|
|
|
|
imgp->args->stringspace, NULL);
|
2005-01-29 23:12:00 +00:00
|
|
|
|
|
|
|
if (error == 0)
|
2010-07-27 17:31:03 +00:00
|
|
|
imgp->interpreter_name = imgp->args->begin_argv;
|
1993-12-20 16:16:46 +00:00
|
|
|
|
2008-08-26 10:53:32 +00:00
|
|
|
if (sname != NULL)
|
|
|
|
sbuf_delete(sname);
|
2005-01-29 23:12:00 +00:00
|
|
|
return (error);
|
1993-12-20 16:16:46 +00:00
|
|
|
}
|
1993-12-20 19:31:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell kern_execve.c about it, with a little help from the linker.
|
|
|
|
*/
|
1999-01-29 22:59:43 +00:00
|
|
|
static struct execsw shell_execsw = { exec_shell_imgact, "#!" };
|
1998-10-16 03:55:01 +00:00
|
|
|
EXEC_SET(shell, shell_execsw);
|