ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/persist.c
(Generate patch)

Comparing ray/src/rt/persist.c (file contents):
Revision 2.2 by greg, Thu Jan 21 10:09:04 1993 UTC vs.
Revision 2.11 by greg, Mon Nov 8 09:35:32 1993 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
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>
# Line 96 | Line 99 | pfhold()               /* holding pattern for idle rendering proces
99          register int    n;
100                                  /* close input and output descriptors */
101          close(fileno(stdin));
99        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)
104 >        if (mknod(mktemp(strcpy(inpname,TEMPLATE)), S_IFIFO|0600, 0) < 0)
105                  goto createrr;
106 <        if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600) < 0)
106 >        if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600, 0) < 0)
107                  goto createrr;
108          sprintf(buf, "%d\n%s\n%s\n", getpid(), inpname, outpname);
109 <        if (lseek(persistfd, 0L, 0) < 0)
110 <                error(SYSTEM, "seek error on persist file in pfhold");
109 >        if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0)
110 >                error(SYSTEM, "seek/truncate error on persist file");
111          n = strlen(buf);
112          if (write(persistfd, buf, n) < n)
113 <                error(SYSTEM, "error writing persist file in pfhold");
113 >                error(SYSTEM, "error writing persist file");
114                                  /* wait TIMELIM for someone to signal us */
115          signal(SIGIO, sig_noop);
116          alarm(TIMELIM);
# Line 169 | Line 171 | io_process()           /* just act as conduits to and from actu
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) {
185 <                nr += cp-buf;
186 <                if ((n = write(fileno(stdout), buf, nr)) <= 0)
187 <                        error(SYSTEM, "write error in io_process");
188 <                cp = buf;
189 <                while (n < nr)
190 <                        *cp++ = buf[n++];
191 <                n = sizeof(buf) - (cp-buf);
192 <        }
193 <        fclose(stdin);
190 <        fclose(stdout);
183 >                                /* read as much as we can, write all of it */
184 >        while ((nr = read(0, cp=buf, sizeof(buf))) > 0)
185 >                do {
186 >                        if ((n = write(1, cp, nr)) <= 0)
187 >                                goto writerr;
188 >                        cp += n;
189 >                } while ((nr -= n) > 0);
190 >        if (nr < 0)
191 >                error(SYSTEM, "read error in io_process");
192 >        close(0);               /* close input */
193 >        close(1);               /* close output */
194          if (pid)                /* parent waits for child */
195                  wait(0);
196          exit(0);                /* all done, exit (not quit!) */
197   formerr:
198          error(USER, "format error in persist file");
199 + writerr:
200 +        error(SYSTEM, "write error in io_process");
201   }
202 +
203 + #else
204 +
205 + pfclean() {}
206 +
207 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines