Merge remote-tracking branch 'origin/front' into front
This commit is contained in:
commit
a0ac839193
4 changed files with 62 additions and 77 deletions
|
@ -67,6 +67,11 @@ and any initial arguments to that program, for example
|
||||||
ls | mc
|
ls | mc
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
|
There may be up to 256 bytes of arguments passed to the interpreter.
|
||||||
|
These are tokenized into up to 32 arguments by
|
||||||
|
.IR tokenize (2)
|
||||||
|
before being passed as the interpreters argument vector.
|
||||||
|
.PP
|
||||||
When a C program is executed,
|
When a C program is executed,
|
||||||
it is called as follows:
|
it is called as follows:
|
||||||
.IP
|
.IP
|
||||||
|
|
|
@ -62,7 +62,7 @@ changeuser, convkeys, printnetkey, status, enable, disable, authsrv, guard.srv,
|
||||||
.PP
|
.PP
|
||||||
.B auth/box
|
.B auth/box
|
||||||
[
|
[
|
||||||
.B -d
|
.B -s
|
||||||
] [
|
] [
|
||||||
.B -rc
|
.B -rc
|
||||||
.I file
|
.I file
|
||||||
|
@ -298,9 +298,8 @@ the child namespace; the
|
||||||
flag specifies a string of driver
|
flag specifies a string of driver
|
||||||
characters to keep. The
|
characters to keep. The
|
||||||
.B -s
|
.B -s
|
||||||
flag gives a base set of namespace
|
flag initializes the namespace to what rc expects,
|
||||||
components, ones expected by rc, then passes
|
and passes its arguments unmodified to /bin/rc.
|
||||||
the first argument as a script file to rc.
|
|
||||||
.PP
|
.PP
|
||||||
.I As
|
.I As
|
||||||
executes
|
executes
|
||||||
|
|
|
@ -243,35 +243,19 @@ sysrfork(va_list list)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
shargs(char *s, int n, char **ap)
|
shargs(char *s, int n, char **ap, int nap)
|
||||||
{
|
{
|
||||||
|
char *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(n <= 2 || s[0] != '#' || s[1] != '!')
|
if(n <= 2 || s[0] != '#' || s[1] != '!')
|
||||||
return -1;
|
return -1;
|
||||||
s += 2;
|
s += 2;
|
||||||
n -= 2; /* skip #! */
|
n -= 2; /* skip #! */
|
||||||
for(i=0;; i++){
|
if((p = memchr(s, '\n', n)) == nil)
|
||||||
if(i >= n)
|
return 0;
|
||||||
return 0;
|
*p = 0;
|
||||||
if(s[i]=='\n')
|
i = tokenize(s, ap, nap-1);
|
||||||
break;
|
|
||||||
}
|
|
||||||
s[i] = 0;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for(;;) {
|
|
||||||
while(*s==' ' || *s=='\t')
|
|
||||||
s++;
|
|
||||||
if(*s == 0)
|
|
||||||
break;
|
|
||||||
ap[i++] = s++;
|
|
||||||
while(*s && *s!=' ' && *s!='\t')
|
|
||||||
s++;
|
|
||||||
if(*s == 0)
|
|
||||||
break;
|
|
||||||
*s++ = 0;
|
|
||||||
}
|
|
||||||
ap[i] = nil;
|
ap[i] = nil;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -300,12 +284,15 @@ beswav(uvlong v)
|
||||||
uintptr
|
uintptr
|
||||||
sysexec(va_list list)
|
sysexec(va_list list)
|
||||||
{
|
{
|
||||||
struct {
|
union {
|
||||||
Exec;
|
struct {
|
||||||
uvlong hdr[1];
|
Exec;
|
||||||
} ehdr;
|
uvlong hdr[1];
|
||||||
char line[sizeof(ehdr)];
|
} ehdr;
|
||||||
char *progarg[sizeof(line)/2+1];
|
char buf[256];
|
||||||
|
} u;
|
||||||
|
char line[256];
|
||||||
|
char *progarg[32+1];
|
||||||
volatile char *args, *elem, *file0;
|
volatile char *args, *elem, *file0;
|
||||||
char **argv, **argp, **argp0;
|
char **argv, **argp, **argp0;
|
||||||
char *a, *e, *charp, *file;
|
char *a, *e, *charp, *file;
|
||||||
|
@ -353,22 +340,22 @@ sysexec(va_list list)
|
||||||
if(!indir)
|
if(!indir)
|
||||||
kstrdup(&elem, up->genbuf);
|
kstrdup(&elem, up->genbuf);
|
||||||
|
|
||||||
n = devtab[tc->type]->read(tc, &ehdr, sizeof(ehdr), 0);
|
n = devtab[tc->type]->read(tc, u.buf, sizeof(u.buf), 0);
|
||||||
if(n >= sizeof(Exec)) {
|
if(n >= sizeof(Exec)) {
|
||||||
magic = beswal(ehdr.magic);
|
magic = beswal(u.ehdr.magic);
|
||||||
if(magic == AOUT_MAGIC) {
|
if(magic == AOUT_MAGIC) {
|
||||||
if(magic & HDR_MAGIC) {
|
if(magic & HDR_MAGIC) {
|
||||||
if(n < sizeof(ehdr))
|
if(n < sizeof(u.ehdr))
|
||||||
error(Ebadexec);
|
error(Ebadexec);
|
||||||
entry = beswav(ehdr.hdr[0]);
|
entry = beswav(u.ehdr.hdr[0]);
|
||||||
text = UTZERO+sizeof(ehdr);
|
text = UTZERO+sizeof(u.ehdr);
|
||||||
} else {
|
} else {
|
||||||
entry = beswal(ehdr.entry);
|
entry = beswal(u.ehdr.entry);
|
||||||
text = UTZERO+sizeof(Exec);
|
text = UTZERO+sizeof(Exec);
|
||||||
}
|
}
|
||||||
if(entry < text)
|
if(entry < text)
|
||||||
error(Ebadexec);
|
error(Ebadexec);
|
||||||
text += beswal(ehdr.text);
|
text += beswal(u.ehdr.text);
|
||||||
if(text <= entry || text >= (USTKTOP-USTKSIZE))
|
if(text <= entry || text >= (USTKTOP-USTKSIZE))
|
||||||
error(Ebadexec);
|
error(Ebadexec);
|
||||||
|
|
||||||
|
@ -393,8 +380,8 @@ sysexec(va_list list)
|
||||||
/*
|
/*
|
||||||
* Process #! /bin/sh args ...
|
* Process #! /bin/sh args ...
|
||||||
*/
|
*/
|
||||||
memmove(line, &ehdr, n);
|
memmove(line, u.buf, n);
|
||||||
n = shargs(line, n, progarg);
|
n = shargs(line, n, progarg, nelem(progarg));
|
||||||
if(n < 1)
|
if(n < 1)
|
||||||
error(Ebadexec);
|
error(Ebadexec);
|
||||||
/*
|
/*
|
||||||
|
@ -411,8 +398,8 @@ sysexec(va_list list)
|
||||||
|
|
||||||
t = (text+align) & ~align;
|
t = (text+align) & ~align;
|
||||||
text -= UTZERO;
|
text -= UTZERO;
|
||||||
data = beswal(ehdr.data);
|
data = beswal(u.ehdr.data);
|
||||||
bss = beswal(ehdr.bss);
|
bss = beswal(u.ehdr.bss);
|
||||||
align = BY2PG-1;
|
align = BY2PG-1;
|
||||||
d = (t + data + align) & ~align;
|
d = (t + data + align) & ~align;
|
||||||
bssend = t + data + bss;
|
bssend = t + data + bss;
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <auth.h>
|
#include <auth.h>
|
||||||
|
|
||||||
static int debug;
|
static int debug;
|
||||||
|
static char cwd[8192];
|
||||||
|
static char *parts[256];
|
||||||
|
static int mflags[nelem(parts)];
|
||||||
|
static int nparts;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
binderr(char *new, char *old, int flag)
|
binderr(char *new, char *old, int flag)
|
||||||
|
@ -32,20 +36,14 @@ binderr(char *new, char *old, int flag)
|
||||||
fprint(2, "bind %s %s %s\n", dash, new, old);
|
fprint(2, "bind %s %s %s\n", dash, new, old);
|
||||||
}
|
}
|
||||||
if(bind(new, old, flag) < 0)
|
if(bind(new, old, flag) < 0)
|
||||||
sysfatal("bind: %r");
|
sysfatal("bind %s: %r", new);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resolvenames(char **names, int nname)
|
resolvenames(char **names, int nname)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char buf[8192];
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = open(".", OREAD|OCEXEC);
|
|
||||||
if(fd < 0)
|
|
||||||
sysfatal("could not open .: %r");
|
|
||||||
fd2path(fd, buf, sizeof buf);
|
|
||||||
for(i = 0; i < nname; i++){
|
for(i = 0; i < nname; i++){
|
||||||
if(names[i] == nil)
|
if(names[i] == nil)
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,10 +53,9 @@ resolvenames(char **names, int nname)
|
||||||
case '/':
|
case '/':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
names[i] = cleanname(smprint("%s/%s", buf, names[i]));
|
names[i] = cleanname(smprint("%s/%s", cwd, names[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -103,7 +100,8 @@ sandbox(char **names, int *flags, int nname)
|
||||||
free(d);
|
free(d);
|
||||||
binderr(skel, dir, MBEFORE);
|
binderr(skel, dir, MBEFORE);
|
||||||
}
|
}
|
||||||
binderr(names[j], targ, flags[j]);
|
if(flags[j] != -1)
|
||||||
|
binderr(names[j], targ, flags[j]);
|
||||||
}
|
}
|
||||||
binderr(newroot, "/", MREPL);
|
binderr(newroot, "/", MREPL);
|
||||||
}
|
}
|
||||||
|
@ -133,16 +131,11 @@ skelfs(void)
|
||||||
sysfatal("/mnt/d mount setup: %r");
|
sysfatal("/mnt/d mount setup: %r");
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *parts[256];
|
|
||||||
static int mflags[nelem(parts)];
|
|
||||||
static int nparts;
|
|
||||||
static char *rc[] = { "/bin/rc", nil , nil};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
push(char *path, int flag)
|
push(char *path, int flag)
|
||||||
{
|
{
|
||||||
if(nparts == nelem(parts))
|
if(nparts == nelem(parts))
|
||||||
sysfatal("component overflow");
|
sysfatal("too many bound paths");
|
||||||
parts[nparts] = path;
|
parts[nparts] = path;
|
||||||
mflags[nparts++] = flag;
|
mflags[nparts++] = flag;
|
||||||
}
|
}
|
||||||
|
@ -150,23 +143,23 @@ push(char *path, int flag)
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage %s: [ -d ] [ -r file ] [ -c dir ] [ -e devs ] [ -. path ] cmd args...\n", argv0);
|
fprint(2, "usage %s: [ -r file ] [ -c dir ] [ -e devs ] cmd args...\n", argv0);
|
||||||
exits("usage");
|
exits("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char devs[1024];
|
char **argp, devs[128];
|
||||||
int dfd;
|
int i, narg, dfd;
|
||||||
char *path;
|
|
||||||
char *a;
|
char *a;
|
||||||
int sflag;
|
int sflag;
|
||||||
|
|
||||||
nparts = 0;
|
nparts = 0;
|
||||||
path = "/";
|
narg = 0;
|
||||||
memset(devs, 0, sizeof devs);
|
memset(devs, 0, sizeof devs);
|
||||||
sflag = 0;
|
sflag = 0;
|
||||||
|
argp = argv;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'D':
|
case 'D':
|
||||||
debug++;
|
debug++;
|
||||||
|
@ -184,9 +177,6 @@ main(int argc, char **argv)
|
||||||
case 'e':
|
case 'e':
|
||||||
snprint(devs, sizeof devs, "%s%s", devs, EARGF(usage()));
|
snprint(devs, sizeof devs, "%s%s", devs, EARGF(usage()));
|
||||||
break;
|
break;
|
||||||
case '.':
|
|
||||||
path = EARGF(usage());
|
|
||||||
break;
|
|
||||||
case 's':
|
case 's':
|
||||||
sflag = 1;
|
sflag = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -195,18 +185,19 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(argc == 0)
|
if(argc == 0 && !sflag)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
if(getwd(cwd, sizeof(cwd)) == nil)
|
||||||
|
sysfatal("getwd: %r");
|
||||||
|
push(cwd, -1);
|
||||||
if(sflag){
|
if(sflag){
|
||||||
snprint(devs, sizeof devs, "%s%s", devs, "|d");
|
snprint(devs, sizeof devs, "%s%s", devs, "|d");
|
||||||
push("/srv", MREPL|MCREATE);
|
push("/srv", MREPL|MCREATE);
|
||||||
push("/env", MREPL|MCREATE);
|
push("/env", MREPL|MCREATE);
|
||||||
push("/rc", MREPL);
|
push("/rc", MREPL);
|
||||||
push("/bin", MREPL);
|
push("/bin", MREPL);
|
||||||
push(argv[0], MREPL);
|
argp[narg++] = "/bin/rc";
|
||||||
rc[1] = argv[0];
|
|
||||||
argv = rc;
|
|
||||||
} else {
|
} else {
|
||||||
if(access(argv[0], AEXIST) == -1){
|
if(access(argv[0], AEXIST) == -1){
|
||||||
if((argv[0] = smprint("/bin/%s", argv[0])) == nil)
|
if((argv[0] = smprint("/bin/%s", argv[0])) == nil)
|
||||||
|
@ -216,6 +207,9 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
push(argv[0], MREPL);
|
push(argv[0], MREPL);
|
||||||
}
|
}
|
||||||
|
for(i = 0; i < argc; i++)
|
||||||
|
argp[narg++] = argv[i];
|
||||||
|
argp[narg] = nil;
|
||||||
|
|
||||||
rfork(RFNAMEG|RFFDG);
|
rfork(RFNAMEG|RFFDG);
|
||||||
skelfs();
|
skelfs();
|
||||||
|
@ -225,7 +219,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
resolvenames(parts, nparts);
|
resolvenames(parts, nparts);
|
||||||
sandbox(parts, mflags, nparts);
|
sandbox(parts, mflags, nparts);
|
||||||
|
|
||||||
if(debug)
|
if(debug)
|
||||||
fprint(2, "chdev %s\n", devs);
|
fprint(2, "chdev %s\n", devs);
|
||||||
|
|
||||||
|
@ -238,8 +232,8 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
close(dfd);
|
close(dfd);
|
||||||
|
|
||||||
if(chdir(path) < 0)
|
if(chdir(cwd) < 0)
|
||||||
sysfatal("can not cd to %s", path);
|
sysfatal("chdir %s: %r", cwd);
|
||||||
exec(argv[0], argv);
|
exec(argp[0], argp);
|
||||||
sysfatal("exec: %r");
|
sysfatal("exec: %r");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue