From ab400c0be5577cab2a66d242183887ebbd61717f Mon Sep 17 00:00:00 2001 From: Nicholas Date: Wed, 17 Nov 2021 08:22:03 -0800 Subject: checkin --- src/cmd/rc/exec.c | 74 ++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) (limited to 'src/cmd/rc/exec.c') diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c index 51e352a..bd68bf5 100644 --- a/src/cmd/rc/exec.c +++ b/src/cmd/rc/exec.c @@ -36,8 +36,7 @@ struct Builtin builtin[]={ /* words and lists */ -static -void +static void pushword(char *str) { if(!runner->args) @@ -46,8 +45,7 @@ pushword(char *str) runner->args->word = makeword(str, runner->args->word); } -static -void +static void popword(void) { Word *w; @@ -63,8 +61,7 @@ popword(void) efree(w); } -static -Word* +static Word* copywords(Word *a, Word *tail) { Word *v = nil, **end; @@ -76,8 +73,7 @@ copywords(Word *a, Word *tail) return v; } -static -void +static void freewords(Word *w) { Word *n; @@ -89,8 +85,7 @@ freewords(Word *w) } } -static -void +static void freelist(Word *w) { Word *n; @@ -100,7 +95,6 @@ freelist(Word *w) efree(w); w = n; } - } static void @@ -154,7 +148,7 @@ path(char *w) if(strncmp(w, "/", 1)==0 || strncmp(w, "./", 2)==0 || strncmp(w, "../", 3)==0 - || (path = var("path")->val)==0) + || !(path = var("path")->val)) path=&nullpath; return path; @@ -262,7 +256,7 @@ xforkx(void) initchild(runner, 1); pushword("exec"); xx(); - exit(2); // reach here on failed execs + exit(errno); // reach here on failed execs break; default: // parent initparent(runner, pid, 0); @@ -505,7 +499,7 @@ xcd(void) static Code dotcmd[14] = { - [0] = {.i = 0}, + [0] = {.i = 1}, // offset by 1 to ensure it never gets freed [1] = {.f = Xmark}, [2] = {.f = Xword}, [3] = {.s = "0"}, @@ -557,7 +551,7 @@ xdot(void) } if(fd<0){ - print(shell.err, "failed open: %s: ", base); + print(shell.err, "%s: ", base); setstatus("failed open"); Xerror(".: failed open"); return; @@ -626,41 +620,43 @@ xfg(void) foreground(job, 1); } +static Code bootstrap[32] = +{ + [0] = {.i = 1}, + [1] = {.f = Xmark}, + [2] = {.f = Xword}, + [3] = {.s = "*"}, + [4] = {.f = Xassign}, + [5] = {.f = Xmark}, + [6] = {.f = Xmark}, + [7] = {.f = Xword}, + [8] = {.s = "*"}, + [9] = {.f = Xdollar}, + [10] = {.f = Xword}, + [11] = {.s = nil}, /* XXX: to be filled in by caller */ + [12] = {.f = Xword}, + [13] = {.s = "."}, + [14] = {.f = Xbasic}, + [15] = {.f = Xexit}, + [16] = {.i = 0} +}; + void -xboot(int argc, char *argv[]) +xboot(char *exe, int argc, char *argv[]) { int i; - Code bootstrap[32]; char num[12]; - i = 0; - bootstrap[i++].i = 1; - bootstrap[i++].f = Xmark; - bootstrap[i++].f = Xword; - bootstrap[i++].s="*"; - bootstrap[i++].f = Xassign; - bootstrap[i++].f = Xmark; - bootstrap[i++].f = Xmark; - bootstrap[i++].f = Xword; - bootstrap[i++].s="*"; - bootstrap[i++].f = Xdollar; - bootstrap[i++].f = Xword; - bootstrap[i++].s = "./cmds"; /* /dev/stdin"; */ - bootstrap[i++].f = Xword; - bootstrap[i++].s="."; - bootstrap[i++].f = Xbasic; - bootstrap[i++].f = Xexit; - bootstrap[i].i = 0; - + bootstrap[11].s = exe; run(bootstrap, 1, nil, 0); runner->pid = runner->pgid = shell.pid; pushlist(); // prime bootstrap argv - argv0 = strdup(argv[0]); - for(i = argc-1; i > 0; --i) + /* initialize $* */ + for(i = argc-1; i >= 0; --i) pushword(argv[i]); - /* main interpreter loop */ + /* main loop */ for(;;){ runner->code.i++; (*runner->code.exe[runner->code.i-1].f)(); -- cgit v1.2.1