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.13 by greg, Thu Jul 4 09:54:59 1996 UTC vs.
Revision 2.14 by greg, Sat Jul 6 22:30:05 1996 UTC

# Line 27 | Line 27 | extern int     headismine;     /* boolean true if header belon
27  
28   extern char     *progname;      /* global program name */
29  
30 + extern char     *errfile;       /* global error file name */
31 +
32   static char     *persistfname = NULL;   /* persist file name */
33   static int      persistfd = -1;         /* persist file descriptor */
34  
35 < static char     inpname[TEMPLEN+1], outpname[TEMPLEN+1];
35 > static char     inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1];
36  
37  
38   pfdetach()              /* release persist (and header) resources */
# Line 41 | Line 43 | pfdetach()             /* release persist (and header) resources
43          persistfname = NULL;
44          inpname[0] = '\0';
45          outpname[0] = '\0';
46 +        errname[0] = '\0';
47          headismine = 0;
48   }
49  
# Line 55 | Line 58 | pfclean()              /* clean up persist files */
58                  unlink(inpname);
59          if (outpname[0])
60                  unlink(outpname);
61 +        if (errname[0])
62 +                unlink(errname);
63   }
64  
65  
# Line 78 | Line 83 | char   *pfn;
83          persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644);
84          if (persistfd >= 0) {
85                  persistfname = pfn;
86 +                        /* put something there for faulty lock daemons */
87 +                write(persistfd, "Initializing...\n", 16);
88                  pflock(1);
89                  return;
90          }
# Line 112 | Line 119 | pfhold()               /* holding pattern for idle rendering proces
119                  goto createrr;
120          if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600, 0) < 0)
121                  goto createrr;
122 <        sprintf(buf, "%s %d\n%s\n%s\n", progname, getpid(), inpname, outpname);
123 <        if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0)
124 <                error(SYSTEM, "seek/truncate error on persist file");
122 >        if (errfile == NULL &&
123 >                mknod(mktemp(strcpy(errname,TEMPLATE)), S_IFIFO|0600, 0) < 0)
124 >                goto createrr;
125 >        sprintf(buf, "%s %d\n%s\n%s\n%s\n", progname, getpid(),
126 >                        inpname, outpname, errname);
127 >        if (lseek(persistfd, 0L, 0) < 0)
128 >                error(SYSTEM, "seek error on persist file");
129          n = strlen(buf);
130          if (write(persistfd, buf, n) < n)
131                  error(SYSTEM, "error writing persist file");
132 +        ftruncate(persistfd, (long)n);
133 +        fsync(persistfd);       /* shouldn't be necessary, but.... */
134                                  /* wait TIMELIM for someone to signal us */
135          got_io = 0;
136          signal(SIGIO, sig_io);
# Line 135 | Line 148 | pfhold()               /* holding pattern for idle rendering proces
148                  goto openerr;
149          if (freopen(outpname, "w", stdout) == NULL)
150                  goto openerr;
151 +        if (errname[0]) {
152 +                if (freopen(errname, "w", stderr) == NULL)
153 +                        goto openerr;
154 +                unlink(errname);
155 +                errname[0] = '\0';
156 +        }
157          unlink(inpname);
158          inpname[0] = '\0';
159          unlink(outpname);
# Line 151 | Line 170 | io_process()           /* just act as conduits to and from actu
170   {
171          register char   *cp;
172          register int    nr, n;
173 <        char    buf[512], *pfin, *pfout;
174 <        int     pid;
173 >        char    buf[512], *pfin, *pfout, *pferr;
174 >        int     pid, pid2 = -1;
175                                  /* load and close persist file */
176 <        sleep(5);               /* helps synchronization */
176 >        errno = 0;
177          nr = read(persistfd, buf, sizeof(buf)-1);
178          pfdetach();
179          if (nr <= 0)
180 <                error(SYSTEM, "cannot read persist file");
180 >                error(SYSTEM, "error reading persist file");
181          buf[nr] = '\0';
182          if ((cp = index(buf, ' ')) == NULL)
183                  goto formerr;
# Line 175 | Line 194 | io_process()           /* just act as conduits to and from actu
194          if ((cp = index(cp, '\n')) == NULL)
195                  goto formerr;
196          *cp++ = '\0';
197 +        pferr = cp;
198 +        if ((cp = index(cp, '\n')) == NULL)
199 +                goto formerr;
200 +        *cp++ = '\0';
201          if (cp-buf != nr)
202                  goto formerr;
203          if (strcmp(buf, progname)) {
# Line 186 | Line 209 | io_process()           /* just act as conduits to and from actu
209                  error(SYSTEM, "cannot signal rendering process in io_process");
210          pid = fork();           /* fork i/o process */
211          if (pid < 0)
212 <                error(SYSTEM, "fork failed in io_process");
212 >                goto forkerr;
213                                  /* connect to appropriate pipe */
214          if (pid) {                      /* parent passes renderer output */
215                  close(0);
216 <                if (open(pfout, O_RDONLY) != 0)
217 <                        error(SYSTEM, "cannot open input pipe in io_process");
216 >                if (pferr[0]) {
217 >                        pid2 = fork();          /* fork another for stderr */
218 >                        if (pid2 < 0)
219 >                                goto forkerr;
220 >                }
221 >                if (pid2) {                     /* parent is still stdout */
222 >                        if (open(pfout, O_RDONLY) != 0)
223 >                                error(SYSTEM,
224 >                                "cannot open output pipe in io_process");
225 >                } else {                        /* second child is stderr */
226 >                        if (open(pferr, O_RDONLY) != 0)
227 >                                error(SYSTEM,
228 >                                "cannot open error pipe in io_process");
229 >                        dup2(2, 1);             /* attach stdout to stderr */
230 >                }
231          } else {                        /* child passes renderer input */
232                  close(1);
233                  if (open(pfin, O_WRONLY) != 1)
234 <                        error(SYSTEM, "cannot open output pipe in io_process");
234 >                        error(SYSTEM, "cannot open input pipe in io_process");
235          }
236                                  /* pass input to output */
237                                  /* read as much as we can, write all of it */
238          while ((nr = read(0, cp=buf, sizeof(buf))) > 0)
239                  do {
240                          if ((n = write(1, cp, nr)) <= 0)
241 <                                goto writerr;
241 >                                error(SYSTEM, "write error in io_process");
242                          cp += n;
243                  } while ((nr -= n) > 0);
244          if (nr < 0)
245                  error(SYSTEM, "read error in io_process");
246          close(0);               /* close input */
247          close(1);               /* close output */
248 <        if (pid)                /* parent waits for child */
248 >        if (pid)                /* parent waits for stdin child */
249                  wait(0);
250 <        exit(0);                /* all done, exit (not quit!) */
250 >        if (pid2 > 0)           /* wait for stderr child also */
251 >                wait(0);
252 >        _exit(0);               /* all done, exit (not quit!) */
253   formerr:
254          error(USER, "format error in persist file");
255 < writerr:
256 <        error(SYSTEM, "write error in io_process");
255 > forkerr:
256 >        error(SYSTEM, "fork failed in io_process");
257   }
258  
259   #else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines