8
char *shell = "/bin/sh";
9
char *shellname = "sh";
11
extern char **environ;
16
fprint(2, "%s: %r\n", s);
25
for(p = environ; *p; p++){
26
/* rsc 5/5/2004 -- This misparses fn#cd={whatever}
40
if (symlook(*p, S_INTERNAL, 0))
44
symlook(s, S_EXPORTED, (void*)"")->value = (void*)"";
49
* done on child side of fork, so parent's env is not affected
50
* and we don't care about freeing memory because we're going
51
* to exec immediately after this.
54
exportenv(Envy *e, Shell *sh)
58
static char buf[16384];
61
for(i = 0; e->name; e++, i++) {
62
p = (char**) Realloc(p, (i+2)*sizeof(char*));
64
snprint(buf, sizeof buf, "%s=%s", e->name, wtos(e->values, sh->iws));
66
snprint(buf, sizeof buf, "%s=", e->name);
84
snprint(msg, ERRMAX, "signal %d, core dumped", status&0x7f);
86
snprint(msg, ERRMAX, "signal %d", status&0x7f);
87
} else if(status&0xff00)
88
snprint(msg, ERRMAX, "exit(%d)", (status>>8)&0xff);
94
expunge(int pid, char *msg)
96
if(strcmp(msg, "interrupt"))
105
shargv(Word *cmd, int extra, char ***pargv)
112
for(w=cmd; w; w=w->next)
115
argv = Malloc((n+extra+1)*sizeof(argv[0]));
117
for(w=cmd; w; w=w->next)
125
execsh(char *args, char *cmd, Bufblock *buf, Envy *e, Shell *sh, Word *shellcmd)
128
int tot, n, pid, in[2], out[2];
130
if(buf && pipe(out) < 0){
162
n = shargv(shellcmd, 1, &argv);
165
execvp(argv[0], argv);
172
fprint(1, "starting: %s\n", cmd);
175
n = write(in[1], cmd, p-cmd);
187
if (buf->current >= buf->end)
189
n = read(out[0], buf->current, buf->end-buf->current);
195
if (tot && buf->current[-1] == '\n')
203
pipecmd(char *cmd, Envy *e, int *fd, Shell *sh, Word *shellcmd)
210
fprint(1, "pipecmd='%s'\n", cmd);/**/
212
if(fd && pipe(pfd) < 0){
229
n = shargv(shellcmd, 2, &argv);
233
execvp(argv[0], argv);
259
SIGFPE, "sys: fp: fptrap",
260
SIGPIPE, "sys: write on closed pipe",
261
SIGILL, "sys: trap: illegal instruction",
262
// SIGSEGV, "sys: segmentation violation",
271
for(i = 0; sigmsgs[i].msg; i++)
272
if(sigmsgs[i].sig == sig)
273
killchildren(sigmsgs[i].msg);
275
/* should never happen */
276
signal(sig, SIG_DFL);
285
for(i = 0; sigmsgs[i].msg; i++)
286
signal(sigmsgs[i].sig, notifyf);
292
static char temp[] = "/tmp/mkargXXXXXX";
293
static char buf[100];
307
if(access(name, 0) >= 0)
308
return utimes(name, 0);
309
return close(creat(name, 0666));
313
rcopy(char **to, Resub *match, int n)
318
*to = match->s.sp; /* stem0 matches complete target */
319
for(to++, match++; --n > 0; to++, match++){
320
if(match->s.sp && match->e.ep){
324
*to = strdup(match->s.sp);
337
if(stat(name, &st) < 0)