274 |
|
int |
275 |
|
in_rchild() |
276 |
|
{ |
277 |
< |
#ifdef _WIN32 |
278 |
< |
error(WARNING, "multiprocessing unsupported -- running solo"); |
279 |
< |
nproc = 1; |
280 |
< |
return(1); |
281 |
< |
#else |
282 |
< |
/* try to fork ourselves */ |
283 |
< |
while (nchild < nproc) { |
284 |
< |
int p0[2], p1[2]; |
285 |
< |
int pid; |
286 |
< |
/* prepare i/o pipes */ |
277 |
> |
int rval; |
278 |
> |
|
279 |
> |
while (nchild < nproc) { /* fork until target reached */ |
280 |
|
errno = 0; |
281 |
< |
if (pipe(p0) < 0 || pipe(p1) < 0) |
282 |
< |
error(SYSTEM, "pipe() call failed!"); |
283 |
< |
pid = fork(); /* fork parent process */ |
284 |
< |
if (pid == 0) { /* if in child, set up & return true */ |
292 |
< |
close(p0[1]); close(p1[0]); |
281 |
> |
rval = open_process(&kida[nchild].pr, NULL); |
282 |
> |
if (rval < 0) |
283 |
> |
error(SYSTEM, "open_process() call failed"); |
284 |
> |
if (rval == 0) { /* if in child, set up & return true */ |
285 |
|
lu_doall(&modconttab, set_stdout, NULL); |
286 |
|
lu_done(&ofiletab); |
287 |
|
while (nchild--) { /* don't share other pipes */ |
288 |
|
close(kida[nchild].pr.w); |
289 |
|
fclose(kida[nchild].infp); |
290 |
|
} |
299 |
– |
dup2(p0[0], 0); close(p0[0]); |
300 |
– |
dup2(p1[1], 1); close(p1[1]); |
291 |
|
inpfmt = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
292 |
|
outfmt = 'd'; |
293 |
|
header = 0; |
300 |
|
waitflush = xres = 0; |
301 |
|
account = accumulate = 0; |
302 |
|
} |
303 |
< |
return(1); /* child return value */ |
303 |
> |
return(1); /* return "true" in child */ |
304 |
|
} |
305 |
< |
if (pid < 0) |
306 |
< |
error(SYSTEM, "fork() call failed!"); |
307 |
< |
/* connect parent's pipes */ |
308 |
< |
close(p0[0]); close(p1[1]); |
319 |
< |
kida[nchild].pr.r = p1[0]; |
320 |
< |
kida[nchild].pr.w = p0[1]; |
321 |
< |
kida[nchild].pr.pid = pid; |
322 |
< |
kida[nchild].pr.running = 1; |
323 |
< |
kida[nchild].infp = fdopen(p1[0], "rb"); |
305 |
> |
if (rval != PIPE_BUF) |
306 |
> |
error(CONSISTENCY, "bad value from open_process()"); |
307 |
> |
/* connect to child's output */ |
308 |
> |
kida[nchild].infp = fdopen(kida[nchild].pr.r, "rb"); |
309 |
|
if (kida[nchild].infp == NULL) |
310 |
|
error(SYSTEM, "out of memory in in_rchild()"); |
311 |
|
#ifdef getc_unlocked |
313 |
|
#endif |
314 |
|
kida[nchild++].nr = 0; /* mark as available */ |
315 |
|
} |
316 |
< |
return(0); /* parent return value */ |
332 |
< |
#endif |
316 |
> |
return(0); /* return "false" in parent */ |
317 |
|
} |
318 |
|
|
319 |
|
|
325 |
|
|
326 |
|
while (nchild > 0) { |
327 |
|
nchild--; |
344 |
– |
fclose(kida[nchild].infp); |
345 |
– |
kida[nchild].pr.r = -1; /* close(-1) error is ignored */ |
328 |
|
if ((status = close_process(&kida[nchild].pr)) > 0) { |
329 |
|
sprintf(errmsg, |
330 |
|
"rendering process returned bad status (%d)", |
331 |
|
status); |
332 |
|
error(WARNING, errmsg); |
333 |
|
} |
334 |
+ |
fclose(kida[nchild].infp); |
335 |
|
} |
336 |
|
} |
337 |
|
|