12 |
|
|
13 |
|
#ifdef F_SETLKW |
14 |
|
#include "paths.h" |
15 |
+ |
#include "selcall.h" |
16 |
|
#include <signal.h> |
16 |
– |
#include <sys/types.h> |
17 |
– |
#include <sys/select.h> |
17 |
|
#include <sys/stat.h> |
19 |
– |
/* select call compatibility stuff */ |
20 |
– |
#ifndef FD_SETSIZE |
21 |
– |
#include <sys/param.h> |
22 |
– |
#define FD_SETSIZE NOFILE /* maximum # select file descriptors */ |
23 |
– |
#endif |
24 |
– |
#ifndef FD_SET |
25 |
– |
#ifndef NFDBITS |
26 |
– |
#define NFDBITS (8*sizeof(int)) /* number of bits per fd_mask */ |
27 |
– |
#endif |
28 |
– |
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
29 |
– |
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
30 |
– |
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) |
31 |
– |
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) |
32 |
– |
#endif |
18 |
|
|
19 |
|
#ifndef TIMELIM |
20 |
|
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
144 |
|
goto openerr; |
145 |
|
if (freopen(outpname, "w", stdout) == NULL) |
146 |
|
goto openerr; |
147 |
+ |
sleep(3); /* give them a chance to open their pipes */ |
148 |
|
if (errname[0]) { |
149 |
|
if (freopen(errname, "w", stderr) == NULL) |
150 |
|
goto openerr; |
169 |
|
register int nr, n; |
170 |
|
char buf[BUFSIZ], *pfin, *pfout, *pferr; |
171 |
|
int pid, nfds; |
172 |
< |
int fdin, fdout, fderr = -1; |
173 |
< |
fd_set readfds, writefds, excepfds; |
172 |
> |
int fdout, fderr = -1; |
173 |
> |
fd_set readfds, excepfds; |
174 |
|
/* load persist file */ |
175 |
|
n = 40; |
176 |
|
while ((nr = read(persistfd, buf, sizeof(buf)-1)) == 0) { |
213 |
|
/* wake up rendering process */ |
214 |
|
if (kill(pid, SIGIO) < 0) |
215 |
|
error(SYSTEM, "cannot signal rendering process in io_process"); |
216 |
< |
/* open named pipes, in order */ |
217 |
< |
if ((fdin = open(pfin, O_WRONLY)) < 0) |
218 |
< |
error(SYSTEM, "cannot open input pipe in io_process"); |
216 |
> |
/* fork child feeder process */ |
217 |
> |
pid = fork(); |
218 |
> |
if (pid < 0) |
219 |
> |
error(SYSTEM, "fork failed in io_process"); |
220 |
> |
if (pid == 0) { /* feeder loop */ |
221 |
> |
int fdin; |
222 |
> |
close(1); /* open input pipe */ |
223 |
> |
if ((fdin = open(pfin, O_WRONLY)) < 0) |
224 |
> |
error(SYSTEM, "cannot open feed pipe in io_process"); |
225 |
> |
/* renderer stdin */ |
226 |
> |
while ((nr = read(0, cp=buf, sizeof(buf))) > 0) { |
227 |
> |
do { |
228 |
> |
if ((n = write(fdin, cp, nr)) <= 0) |
229 |
> |
goto writerr; |
230 |
> |
cp += n; |
231 |
> |
} while ((nr -= n) > 0); |
232 |
> |
} |
233 |
> |
if (nr < 0) |
234 |
> |
goto readerr; |
235 |
> |
_exit(0); |
236 |
> |
} |
237 |
> |
close(0); |
238 |
> |
/* open output pipes, in order */ |
239 |
|
if ((fdout = open(pfout, O_RDONLY)) < 0) |
240 |
|
error(SYSTEM, "cannot open output pipe in io_process"); |
241 |
|
if (pferr[0] && (fderr = open(pferr, O_RDONLY)) < 0) |
242 |
|
error(SYSTEM, "cannot open error pipe in io_process"); |
243 |
< |
for ( ; ; ) { /* loop on select call */ |
243 |
> |
for ( ; ; ) { /* eater loop */ |
244 |
|
FD_ZERO(&readfds); |
239 |
– |
FD_ZERO(&writefds); |
245 |
|
FD_ZERO(&excepfds); |
246 |
|
nfds = 0; |
242 |
– |
if (fdin >= 0) { |
243 |
– |
FD_SET(fdin, &writefds); |
244 |
– |
FD_SET(fdin, &excepfds); |
245 |
– |
nfds = fdin+1; |
246 |
– |
} |
247 |
|
if (fdout >= 0) { |
248 |
|
FD_SET(fdout, &readfds); |
249 |
|
FD_SET(fdout, &excepfds); |
256 |
|
} |
257 |
|
if (nfds == 0) |
258 |
|
break; /* all done, exit */ |
259 |
< |
if (select(nfds, &readfds, &writefds, &excepfds, NULL) < 0) |
259 |
> |
if (select(nfds, &readfds, NULL, &excepfds, NULL) < 0) |
260 |
|
error(SYSTEM, "error in select call in io_process"); |
261 |
|
/* renderer stderr */ |
262 |
|
if (fderr >= 0 && (FD_ISSET(fderr, &readfds) || |
291 |
|
goto writerr; |
292 |
|
cp += n; |
293 |
|
} while ((nr -= n) > 0); |
294 |
– |
} |
295 |
– |
/* renderer stdin */ |
296 |
– |
if (fdin >= 0 && (FD_ISSET(fdin, &writefds) || |
297 |
– |
FD_ISSET(fdin, &excepfds))) { |
298 |
– |
nr = read(0, buf, 512); /* use minimal buffer */ |
299 |
– |
if (nr < 0) |
300 |
– |
goto readerr; |
301 |
– |
if (nr == 0) { |
302 |
– |
close(0); |
303 |
– |
close(fdin); |
304 |
– |
fdin = -1; |
305 |
– |
} else if (write(fdin, buf, nr) < nr) |
306 |
– |
goto writerr; /* what else to do? */ |
294 |
|
} |
295 |
|
} |
296 |
|
_exit(0); /* we ought to return renderer error status! */ |