9 |
|
*/ |
10 |
|
|
11 |
|
#include "standard.h" |
12 |
+ |
|
13 |
+ |
#ifdef F_SETLKW |
14 |
+ |
|
15 |
|
#include "paths.h" |
16 |
|
#include <signal.h> |
17 |
|
#include <sys/types.h> |
18 |
|
#include <sys/stat.h> |
19 |
|
|
20 |
+ |
#ifndef TIMELIM |
21 |
+ |
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
22 |
+ |
#endif |
23 |
+ |
|
24 |
|
extern char *strcpy(), *index(); |
25 |
|
|
26 |
|
extern int headismine; /* boolean true if header belongs to me */ |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
< |
sig_noop() {} |
93 |
> |
int sig_noop() {} |
94 |
|
|
95 |
|
|
96 |
|
pfhold() /* holding pattern for idle rendering process */ |
99 |
|
register int n; |
100 |
|
/* close input and output descriptors */ |
101 |
|
close(fileno(stdin)); |
95 |
– |
fflush(stdout); |
102 |
|
close(fileno(stdout)); |
103 |
|
/* create named pipes for input and output */ |
104 |
|
if (mknod(mktemp(strcpy(inpname,TEMPLATE)), S_IFIFO|0600) < 0) |
111 |
|
n = strlen(buf); |
112 |
|
if (write(persistfd, buf, n) < n) |
113 |
|
error(SYSTEM, "error writing persist file in pfhold"); |
114 |
< |
/* wait for someone to signal us */ |
115 |
< |
signal(SIGALRM, sig_noop); |
114 |
> |
/* wait TIMELIM for someone to signal us */ |
115 |
> |
signal(SIGIO, sig_noop); |
116 |
> |
alarm(TIMELIM); |
117 |
|
pflock(0); |
118 |
|
pause(); |
119 |
+ |
alarm(0); |
120 |
+ |
signal(SIGIO, SIG_DFL); |
121 |
|
pflock(1); |
122 |
|
/* someone wants us; reopen stdin and stdout */ |
123 |
|
if (freopen(inpname, "r", stdin) == NULL) |
164 |
|
if (cp-buf != nr) |
165 |
|
goto formerr; |
166 |
|
/* wake up rendering process */ |
167 |
< |
if (kill(pid, SIGALRM) < 0) |
167 |
> |
if (kill(pid, SIGIO) < 0) |
168 |
|
error(SYSTEM, "cannot signal rendering process in io_process"); |
169 |
|
pid = fork(); /* fork i/o process */ |
170 |
|
if (pid < 0) |
171 |
|
error(SYSTEM, "fork failed in io_process"); |
172 |
|
/* connect to appropriate pipe */ |
173 |
|
if (pid) { /* parent passes renderer output */ |
174 |
< |
if (freopen(pfout, "r", stdin) == NULL) |
174 |
> |
close(0); |
175 |
> |
if (open(pfout, O_RDONLY) != 0) |
176 |
|
error(SYSTEM, "cannot open input pipe in io_process"); |
177 |
|
} else { /* child passes renderer input */ |
178 |
< |
if (freopen(pfin, "w", stdout) == NULL) |
179 |
< |
error(SYSTEM, "cannot open input pipe in io_process"); |
178 |
> |
close(1); |
179 |
> |
if (open(pfin, O_WRONLY) != 1) |
180 |
> |
error(SYSTEM, "cannot open output pipe in io_process"); |
181 |
|
} |
182 |
|
/* pass input to output */ |
183 |
|
cp = buf; n = sizeof(buf); |
184 |
< |
while ((nr = read(fileno(stdin), cp, n)) > 0) { |
184 |
> |
/* do as much as we can each way */ |
185 |
> |
while ((nr = read(0, cp, n)) > 0) { |
186 |
|
nr += cp-buf; |
187 |
< |
if ((n = write(fileno(stdout), buf, nr)) <= 0) |
188 |
< |
error(SYSTEM, "write error in io_process"); |
187 |
> |
if ((n = write(1, buf, nr)) <= 0) |
188 |
> |
goto writerr; |
189 |
|
cp = buf; |
190 |
|
while (n < nr) |
191 |
|
*cp++ = buf[n++]; |
192 |
|
n = sizeof(buf) - (cp-buf); |
193 |
|
} |
194 |
< |
fclose(stdin); |
195 |
< |
fclose(stdout); |
194 |
> |
if (nr < 0) |
195 |
> |
error(SYSTEM, "read error in io_process"); |
196 |
> |
close(0); /* close input */ |
197 |
> |
nr = cp-buf; /* write remainder */ |
198 |
> |
cp = buf; |
199 |
> |
while (nr > 0) { |
200 |
> |
if ((n = write(1, cp, nr)) <= 0) |
201 |
> |
goto writerr; |
202 |
> |
cp += n; |
203 |
> |
nr -= n; |
204 |
> |
} |
205 |
> |
close(1); /* close output */ |
206 |
|
if (pid) /* parent waits for child */ |
207 |
|
wait(0); |
208 |
|
exit(0); /* all done, exit (not quit!) */ |
209 |
|
formerr: |
210 |
|
error(USER, "format error in persist file"); |
211 |
+ |
writerr: |
212 |
+ |
error(SYSTEM, "write error in io_process"); |
213 |
|
} |
214 |
+ |
|
215 |
+ |
#endif |