| 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/stat.h> |
| 18 |
– |
/* select call compatibility stuff */ |
| 19 |
– |
#ifndef FD_SETSIZE |
| 20 |
– |
#include <sys/param.h> |
| 21 |
– |
#define FD_SETSIZE NOFILE /* maximum # select file descriptors */ |
| 22 |
– |
#endif |
| 23 |
– |
#ifndef FD_SET |
| 24 |
– |
#ifndef NFDBITS |
| 25 |
– |
#define NFDBITS (8*sizeof(int)) /* number of bits per fd_mask */ |
| 26 |
– |
#endif |
| 27 |
– |
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
| 28 |
– |
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
| 29 |
– |
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) |
| 30 |
– |
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) |
| 31 |
– |
#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 |
> |
int status = 0; |
| 174 |
> |
fd_set readfds, excepfds; |
| 175 |
|
/* load persist file */ |
| 176 |
|
n = 40; |
| 177 |
|
while ((nr = read(persistfd, buf, sizeof(buf)-1)) == 0) { |
| 214 |
|
/* wake up rendering process */ |
| 215 |
|
if (kill(pid, SIGIO) < 0) |
| 216 |
|
error(SYSTEM, "cannot signal rendering process in io_process"); |
| 217 |
< |
/* open named pipes, in order */ |
| 218 |
< |
if ((fdin = open(pfin, O_WRONLY)) < 0) |
| 219 |
< |
error(SYSTEM, "cannot open input pipe in io_process"); |
| 217 |
> |
/* fork child feeder process */ |
| 218 |
> |
pid = fork(); |
| 219 |
> |
if (pid < 0) |
| 220 |
> |
error(SYSTEM, "fork failed in io_process"); |
| 221 |
> |
if (pid == 0) { /* feeder loop */ |
| 222 |
> |
int fdin; |
| 223 |
> |
close(1); /* open input pipe */ |
| 224 |
> |
if ((fdin = open(pfin, O_WRONLY)) < 0) |
| 225 |
> |
error(SYSTEM, "cannot open feed pipe in io_process"); |
| 226 |
> |
/* renderer stdin */ |
| 227 |
> |
while ((nr = read(0, cp=buf, sizeof(buf))) > 0) { |
| 228 |
> |
do { |
| 229 |
> |
if ((n = write(fdin, cp, nr)) <= 0) |
| 230 |
> |
goto writerr; |
| 231 |
> |
cp += n; |
| 232 |
> |
} while ((nr -= n) > 0); |
| 233 |
> |
} |
| 234 |
> |
if (nr < 0) |
| 235 |
> |
goto readerr; |
| 236 |
> |
_exit(0); |
| 237 |
> |
} |
| 238 |
> |
close(0); |
| 239 |
> |
/* open output pipes, in order */ |
| 240 |
|
if ((fdout = open(pfout, O_RDONLY)) < 0) |
| 241 |
|
error(SYSTEM, "cannot open output pipe in io_process"); |
| 242 |
|
if (pferr[0] && (fderr = open(pferr, O_RDONLY)) < 0) |
| 243 |
|
error(SYSTEM, "cannot open error pipe in io_process"); |
| 244 |
< |
for ( ; ; ) { /* loop on select call */ |
| 244 |
> |
for ( ; ; ) { /* eater loop */ |
| 245 |
|
FD_ZERO(&readfds); |
| 238 |
– |
FD_ZERO(&writefds); |
| 246 |
|
FD_ZERO(&excepfds); |
| 247 |
|
nfds = 0; |
| 241 |
– |
if (fdin >= 0) { |
| 242 |
– |
FD_SET(fdin, &writefds); |
| 243 |
– |
FD_SET(fdin, &excepfds); |
| 244 |
– |
nfds = fdin+1; |
| 245 |
– |
} |
| 248 |
|
if (fdout >= 0) { |
| 249 |
|
FD_SET(fdout, &readfds); |
| 250 |
|
FD_SET(fdout, &excepfds); |
| 257 |
|
} |
| 258 |
|
if (nfds == 0) |
| 259 |
|
break; /* all done, exit */ |
| 260 |
< |
if (select(nfds, &readfds, &writefds, &excepfds, NULL) < 0) |
| 260 |
> |
if (select(nfds, &readfds, NULL, &excepfds, NULL) < 0) |
| 261 |
|
error(SYSTEM, "error in select call in io_process"); |
| 262 |
|
/* renderer stderr */ |
| 263 |
|
if (fderr >= 0 && (FD_ISSET(fderr, &readfds) || |
| 270 |
|
/* close(2); don't close stderr! */ |
| 271 |
|
fderr = -1; |
| 272 |
|
} else |
| 273 |
< |
do { /* write it all */ |
| 273 |
> |
cp[nr] = '\0'; /* deduce status if we can */ |
| 274 |
> |
n = strlen(progname); |
| 275 |
> |
if (!strncmp(cp, progname, n) && |
| 276 |
> |
cp[n++] == ':' && |
| 277 |
> |
cp[n++] == ' ') { |
| 278 |
> |
register struct erract *ep; |
| 279 |
> |
for (ep = erract; ep < erract+NERRS; |
| 280 |
> |
ep++) |
| 281 |
> |
if (ep->pre[0] && |
| 282 |
> |
!strncmp(cp+n, ep->pre, |
| 283 |
> |
strlen(ep->pre))) { |
| 284 |
> |
status = ep->ec; |
| 285 |
> |
break; |
| 286 |
> |
} |
| 287 |
> |
} |
| 288 |
> |
do { /* write message */ |
| 289 |
|
if ((n = write(2, cp, nr)) <= 0) |
| 290 |
|
goto writerr; |
| 291 |
|
cp += n; |
| 308 |
|
cp += n; |
| 309 |
|
} while ((nr -= n) > 0); |
| 310 |
|
} |
| 294 |
– |
/* renderer stdin */ |
| 295 |
– |
if (fdin >= 0 && (FD_ISSET(fdin, &writefds) || |
| 296 |
– |
FD_ISSET(fdin, &excepfds))) { |
| 297 |
– |
nr = read(0, buf, 512); /* use minimal buffer */ |
| 298 |
– |
if (nr < 0) |
| 299 |
– |
goto readerr; |
| 300 |
– |
if (nr == 0) { |
| 301 |
– |
close(0); |
| 302 |
– |
close(fdin); |
| 303 |
– |
fdin = -1; |
| 304 |
– |
} else if (write(fdin, buf, nr) < nr) |
| 305 |
– |
goto writerr; /* what else to do? */ |
| 306 |
– |
} |
| 311 |
|
} |
| 312 |
< |
_exit(0); /* we ought to return renderer error status! */ |
| 312 |
> |
wait(0); /* wait for feeder process */ |
| 313 |
> |
_exit(status); |
| 314 |
|
formerr: |
| 315 |
|
error(USER, "format error in persist file"); |
| 316 |
|
readerr: |