auth/box: -s, -. flags
-. decides where we chdir to before execing, we can't sit where we are because our directory may not exist. If not specified we go to '/'. -s is used to source a rc script instead of execing cmd. This is primarily to enable: '#!/bin/auth/box -s' Shebang line size is a bit tight(32), so we have this shorthand to use rc along with setting up the required namespace components.
This commit is contained in:
parent
34dab15f40
commit
cd64b7129c
2 changed files with 60 additions and 25 deletions
|
@ -296,7 +296,11 @@ removes access to all kernel drivers from
|
||||||
the child namespace; the
|
the child namespace; the
|
||||||
.B -e
|
.B -e
|
||||||
flag specifies a string of driver
|
flag specifies a string of driver
|
||||||
characters to keep.
|
characters to keep. The
|
||||||
|
.B -s
|
||||||
|
flag gives a base set of namespace
|
||||||
|
components, ones expected by rc, then passes
|
||||||
|
the first argument as a script file to rc.
|
||||||
.PP
|
.PP
|
||||||
.I As
|
.I As
|
||||||
executes
|
executes
|
||||||
|
|
|
@ -10,11 +10,11 @@ binderr(char *new, char *old, int flag)
|
||||||
char dash[4] = { '-' };
|
char dash[4] = { '-' };
|
||||||
|
|
||||||
if(debug){
|
if(debug){
|
||||||
if(flag & MCREATE){
|
if(flag & MCREATE)
|
||||||
dash[2] = 'c';
|
dash[2] = 'c';
|
||||||
flag &= ~MCREATE;
|
|
||||||
}
|
|
||||||
switch(flag){
|
switch(flag){
|
||||||
|
case MCREATE|MREPL:
|
||||||
case MREPL:
|
case MREPL:
|
||||||
dash[0] = ' ';
|
dash[0] = ' ';
|
||||||
if(dash[2] == 'c')
|
if(dash[2] == 'c')
|
||||||
|
@ -133,26 +133,40 @@ 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
|
||||||
|
push(char *path, int flag)
|
||||||
|
{
|
||||||
|
if(nparts == nelem(parts))
|
||||||
|
sysfatal("component overflow");
|
||||||
|
parts[nparts] = path;
|
||||||
|
mflags[nparts++] = flag;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage %s: [ -d ] [ -r file ] [ -c dir ] [ -e devs ] cmd args...\n", argv0);
|
fprint(2, "usage %s: [ -d ] [ -r file ] [ -c dir ] [ -e devs ] [ -. path ] cmd args...\n", argv0);
|
||||||
exits("usage");
|
exits("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *b;
|
|
||||||
Dir *d;
|
|
||||||
char devs[1024];
|
char devs[1024];
|
||||||
int dfd;
|
int dfd;
|
||||||
char *parts[256];
|
char *path;
|
||||||
int mflags[256];
|
char *a;
|
||||||
int nparts;
|
int sflag;
|
||||||
|
|
||||||
nparts = 0;
|
nparts = 0;
|
||||||
|
path = "/";
|
||||||
memset(devs, 0, sizeof devs);
|
memset(devs, 0, sizeof devs);
|
||||||
|
sflag = 0;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'D':
|
case 'D':
|
||||||
debug++;
|
debug++;
|
||||||
|
@ -160,35 +174,48 @@ main(int argc, char **argv)
|
||||||
debug++;
|
debug++;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
parts[nparts] = EARGF(usage());
|
a = EARGF(usage());
|
||||||
mflags[nparts++] = MREPL;
|
push(a, MREPL);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
parts[nparts] = EARGF(usage());
|
a = EARGF(usage());
|
||||||
mflags[nparts++] = MCREATE|MREPL;
|
push(a, MREPL|MCREATE);
|
||||||
break;
|
break;
|
||||||
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':
|
||||||
|
sflag = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(argc == 0)
|
if(argc == 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
b = argv[0];
|
if(sflag){
|
||||||
d = dirstat(b);
|
snprint(devs, sizeof devs, "%s%s", devs, "|d");
|
||||||
if(d == nil){
|
push("/srv", MREPL|MCREATE);
|
||||||
b = smprint("/bin/%s", b);
|
push("/env", MREPL|MCREATE);
|
||||||
d = dirstat(b);
|
push("/rc", MREPL);
|
||||||
if(d == nil)
|
push("/bin", MREPL);
|
||||||
sysfatal("could not stat %s %r", argv[0]);
|
push(argv[0], MREPL);
|
||||||
|
rc[1] = argv[0];
|
||||||
|
argv = rc;
|
||||||
|
} else {
|
||||||
|
if(access(argv[0], AEXIST) == -1){
|
||||||
|
if((argv[0] = smprint("/bin/%s", argv[0])) == nil)
|
||||||
|
sysfatal("smprint: %r");
|
||||||
|
if(access(argv[0], AEXIST) == -1)
|
||||||
|
sysfatal("could not stat %s %r", argv[0]);
|
||||||
|
}
|
||||||
|
push(argv[0], MREPL);
|
||||||
}
|
}
|
||||||
free(d);
|
|
||||||
parts[nparts] = b;
|
|
||||||
mflags[nparts++] = MREPL;
|
|
||||||
argv[0] = b;
|
|
||||||
|
|
||||||
rfork(RFNAMEG|RFFDG);
|
rfork(RFNAMEG|RFFDG);
|
||||||
skelfs();
|
skelfs();
|
||||||
|
@ -210,5 +237,9 @@ main(int argc, char **argv)
|
||||||
sysfatal("could not write chdev: %r");
|
sysfatal("could not write chdev: %r");
|
||||||
}
|
}
|
||||||
close(dfd);
|
close(dfd);
|
||||||
|
|
||||||
|
if(chdir(path) < 0)
|
||||||
|
sysfatal("can not cd to %s", path);
|
||||||
exec(argv[0], argv);
|
exec(argv[0], argv);
|
||||||
|
sysfatal("exec: %r");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue