diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-02-22 22:25:21 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-02-22 22:25:21 +0100 |
commit | 258fe87faf0a64947bb91c8ed93f8ea378a36f83 (patch) | |
tree | c0e683a2e9f080ac67f7fd6947483cde52deb4bd /sys/src/cmd/rc/plan9.c | |
parent | a9639c68947a9872cacd8a9629df097fe009503b (diff) |
rc: terminate rc when exec fails, cleanup
The execexec() function should never return, as it irreversably changes
the filedescriptor table for the new program. This means rc's internal
filedesciptors for reading the script get implicitely closed and we cannot
continue the rc interpreter when Execute() fails. So Execute() now sets the
error status, and execexec() runs Xexit() in case Execute() returns.
Diffstat (limited to 'sys/src/cmd/rc/plan9.c')
-rw-r--r-- | sys/src/cmd/rc/plan9.c | 74 |
1 files changed, 19 insertions, 55 deletions
diff --git a/sys/src/cmd/rc/plan9.c b/sys/src/cmd/rc/plan9.c index 6ad3ba3bd..61ddfaba7 100644 --- a/sys/src/cmd/rc/plan9.c +++ b/sys/src/cmd/rc/plan9.c @@ -305,72 +305,36 @@ Updenv(void) /* not used on plan 9 */ int -ForkExecute(char *file, char **argv, int sin, int sout, int serr) -{ - int pid; - - if(access(file, 1) != 0) - return -1; - switch(pid = fork()){ - case -1: - return -1; - case 0: - if(sin >= 0) - dup(sin, 0); - else - close(0); - if(sout >= 0) - dup(sout, 1); - else - close(1); - if(serr >= 0) - dup(serr, 2); - else - close(2); - exec(file, argv); - exits(file); - } - return pid; +ForkExecute(char *, char **, int, int, int) +{ + return -1; } void Execute(word *args, word *path) { char **argv = mkargv(args); - char file[1024], errstr[1024]; - int nc; + char file[1024]; + int nc, mc; Updenv(); - errstr[0] = '\0'; + mc = strlen(argv[1])+1; for(;path;path = path->next){ nc = strlen(path->word); - if(nc < sizeof file - 1){ /* 1 for / */ - strcpy(file, path->word); - if(file[0]){ - strcat(file, "/"); - nc++; - } - if(nc + strlen(argv[1]) < sizeof file){ - strcat(file, argv[1]); - exec(file, argv+1); - rerrstr(errstr, sizeof errstr); - /* - * if file exists and is executable, exec should - * have worked, unless it's a directory or an - * executable for another architecture. in - * particular, if it failed due to lack of - * swap/vm (e.g., arg. list too long) or other - * allocation failure, stop searching and print - * the reason for failure. - */ - if (strstr(errstr, " allocat") != nil || - strstr(errstr, " full") != nil) - break; - } - else werrstr("command name too long"); + if(nc + mc >= sizeof file - 1){ /* 1 for / */ + werrstr("command path name too long"); + continue; + } + if(nc > 0){ + memmove(file, path->word, nc); + file[nc++] = '/'; } + memmove(file+nc, argv[1], mc); + exec(file, argv+1); } - pfmt(err, "%s: %s\n", argv[1], errstr); + rerrstr(file, sizeof file); + setstatus(file); + pfmt(err, "%s: %s\n", argv[1], file); efree((char *)argv); } #define NDIR 256 /* shoud be a better way */ @@ -464,7 +428,7 @@ Again: } if(dir[f].i == dir[f].n) return 0; - strcpy(p, dir[f].dbuf[dir[f].i].name); + strncpy((char*)p, dir[f].dbuf[dir[f].i].name, NDIR); dir[f].i++; return 1; } |