--- ray/src/rt/persist.c 1993/01/21 17:01:24 2.3 +++ ray/src/rt/persist.c 1993/05/28 13:37:39 2.10 @@ -9,6 +9,9 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include "standard.h" + +#ifdef F_SETLKW + #include "paths.h" #include #include @@ -96,7 +99,6 @@ pfhold() /* holding pattern for idle rendering proces register int n; /* close input and output descriptors */ close(fileno(stdin)); - fflush(stdout); close(fileno(stdout)); /* create named pipes for input and output */ if (mknod(mktemp(strcpy(inpname,TEMPLATE)), S_IFIFO|0600) < 0) @@ -104,11 +106,11 @@ pfhold() /* holding pattern for idle rendering proces if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600) < 0) goto createrr; sprintf(buf, "%d\n%s\n%s\n", getpid(), inpname, outpname); - if (lseek(persistfd, 0L, 0) < 0) - error(SYSTEM, "seek error on persist file in pfhold"); + if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0) + error(SYSTEM, "seek/truncate error on persist file"); n = strlen(buf); if (write(persistfd, buf, n) < n) - error(SYSTEM, "error writing persist file in pfhold"); + error(SYSTEM, "error writing persist file"); /* wait TIMELIM for someone to signal us */ signal(SIGIO, sig_noop); alarm(TIMELIM); @@ -126,7 +128,6 @@ pfhold() /* holding pattern for idle rendering proces inpname[0] = '\0'; unlink(outpname); outpname[0] = '\0'; - clean_slate(); /* reset time and ray counters */ return; createrr: error(SYSTEM, "cannot create named pipes in pfhold"); @@ -170,28 +171,37 @@ io_process() /* just act as conduits to and from actu error(SYSTEM, "fork failed in io_process"); /* connect to appropriate pipe */ if (pid) { /* parent passes renderer output */ - if (freopen(pfout, "r", stdin) == NULL) + close(0); + if (open(pfout, O_RDONLY) != 0) error(SYSTEM, "cannot open input pipe in io_process"); } else { /* child passes renderer input */ - if (freopen(pfin, "w", stdout) == NULL) - error(SYSTEM, "cannot open input pipe in io_process"); + close(1); + if (open(pfin, O_WRONLY) != 1) + error(SYSTEM, "cannot open output pipe in io_process"); } /* pass input to output */ - cp = buf; n = sizeof(buf); - while ((nr = read(fileno(stdin), cp, n)) > 0) { - nr += cp-buf; - if ((n = write(fileno(stdout), buf, nr)) <= 0) - error(SYSTEM, "write error in io_process"); - cp = buf; - while (n < nr) - *cp++ = buf[n++]; - n = sizeof(buf) - (cp-buf); - } - fclose(stdin); - fclose(stdout); + /* read as much as we can, write all of it */ + while ((nr = read(0, cp=buf, sizeof(buf))) > 0) + do { + if ((n = write(1, cp, nr)) <= 0) + goto writerr; + cp += n; + } while ((nr -= n) > 0); + if (nr < 0) + error(SYSTEM, "read error in io_process"); + close(0); /* close input */ + close(1); /* close output */ if (pid) /* parent waits for child */ wait(0); exit(0); /* all done, exit (not quit!) */ formerr: error(USER, "format error in persist file"); +writerr: + error(SYSTEM, "write error in io_process"); } + +#else + +pfclean() {} + +#endif