4
extern jmp_buf mainloop;
7
String plan9cmd; /* null terminated */
16
snprint(buf, sizeof buf, "%.*S", f->name.n, f->name.s);
19
putenv("samfile", buf);
23
plan9(File *f, int type, String *s, int nest)
30
int pipe1[2], pipe2[2];
32
if(s->s[0]==0 && plan9cmd.s[0]==0)
35
Strduplstr(&plan9cmd, s);
40
if(type!='!' && pipe(pipe1)==-1)
43
snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1);
44
if((pid=fork()) == 0){
46
if(downloaded){ /* also put nasty fd's into errfile */
47
fd = create(errfile, 1, 0666L);
49
fd = create("/dev/null", 1, 0666L);
52
/* 2 now points at err file */
57
fd = open("/dev/null", 0);
63
if(type=='<' || type=='|')
73
if((pid = fork())==0){
75
* It's ok if we get SIGPIPE here
79
if(retcode=!setjmp(mainloop)){ /* assignment = */
81
for(l = 0; l<plan9buf.nc; l+=m){
85
bufread(&plan9buf, l, genbuf, m);
87
c = Strtoc(tmprstr(genbuf, m+1));
88
Write(pipe2[1], c, strlen(c));
92
exits(retcode? "error" : 0);
95
fprint(2, "Can't fork?!\n");
103
close(0); /* so it won't read from terminal */
104
open("/dev/null", 0);
106
execl(SHPATH, SH, "-c", Strtoc(&plan9cmd), (char *)0);
111
if(type=='<' || type=='|'){
113
if(downloaded && addr.r.p1 != addr.r.p2)
114
outTl(Hsnarflen, addr.r.p2-addr.r.p1);
115
snarf(f, addr.r.p1, addr.r.p2, &snarfbuf, 0);
116
logdelete(f, addr.r.p1, addr.r.p2);
120
f->ndot.r.p2 = addr.r.p2+readio(f, &nulls, 0, FALSE);
121
f->ndot.r.p1 = addr.r.p2;
131
retcode = waitfor(pid);
132
if(type=='|' || type=='<')
145
char buf[BLOCKSIZE-10];
150
if(statfile(errfile, 0, 0, 0, &l, 0) > 0 && l != 0){
151
if((f=open(errfile, 0)) != -1){
152
if((n=read(f, buf, sizeof buf-1)) > 0){
153
for(nl=0,p=buf; nl<25 && p<&buf[n]; p++)
159
dprint("(sam: more in %s)\n", errfile);