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.27 by greg, Tue Feb 25 02:47:23 2003 UTC vs.
Revision 2.34 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include "copyright.h"
11  
12 + #include <string.h>
13 + #include <signal.h>
14 + #include <sys/stat.h>
15 +
16 + #include "platform.h"
17 + #include "rtprocess.h" /* getpid() */
18   #include "standard.h"
19   #include "random.h"
20 + #include "ray.h"
21  
22   #ifdef F_SETLKW
23   #include "paths.h"
24   #include "selcall.h"
18 #include <signal.h>
19 #include <sys/stat.h>
25  
26   #ifndef TIMELIM
27   #define TIMELIM         (8*3600)        /* time limit for holding pattern */
28   #endif
29  
25 #ifndef freebsd
26 #define mkfifo(fn,md)   mknod(fn, S_IFIFO|(md), 0)
27 #endif
28
29 extern void     io_process();
30
30   extern int      headismine;     /* boolean true if header belongs to me */
32
31   extern char     *progname;      /* global program name */
34
32   extern char     *errfile;       /* global error file name */
36
33   static char     *persistfname = NULL;   /* persist file name */
34   static int      persistfd = -1;         /* persist file descriptor */
39
35   static char     inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1];
36  
37 + typedef void (sighandler_t)(int);
38 + static sighandler_t sig_io;
39 + static sighandler_t sig_alrm;
40  
41 < void
42 < pfdetach()              /* release persist (and header) resources */
41 >
42 > extern void
43 > pfdetach(void)          /* release persist (and header) resources */
44   {
45          if (persistfd >= 0)
46                  close(persistfd);
# Line 54 | Line 53 | pfdetach()             /* release persist (and header) resources
53   }
54  
55  
56 < void
57 < pfclean()               /* clean up persist files */
56 > extern void
57 > pfclean(void)           /* clean up persist files */
58   {
59          if (persistfd >= 0)
60                  close(persistfd);
# Line 70 | Line 69 | pfclean()              /* clean up persist files */
69   }
70  
71  
72 < void
73 < pflock(lf)              /* place or release exclusive lock on file */
74 < int     lf;
72 > extern void
73 > pflock(         /* place or release exclusive lock on file */
74 >        int     lf
75 > )
76   {
77          struct flock    fls;
78  
# Line 85 | Line 85 | int    lf;
85   }
86  
87  
88 < persistfile(pfn)        /* open persist file and lock it */
89 < char    *pfn;
88 > extern void
89 > persistfile(    /* open persist file and lock it */
90 >        char    *pfn
91 > )
92   {
93          persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644);
94          if (persistfd >= 0) {
# Line 107 | Line 109 | char   *pfn;
109  
110   static int      got_io;
111  
112 < static void sig_io() { got_io++; }
112 > static void sig_io(int i) { got_io++; }
113  
114 < static void sig_alrm() { quit(0); }
114 > static void sig_alrm(int i) { quit(0); }
115  
116  
117 < void
118 < pfhold()                /* holding pattern for idle rendering process */
117 > extern void
118 > pfhold(void)            /* holding pattern for idle rendering process */
119   {
120 <        void    (*oldalrm)();
120 >        sighandler_t    *oldalrm;
121          char    buf[512];
122          register int    n;
123                                  /* close input and output descriptors */
# Line 136 | Line 138 | pfhold()               /* holding pattern for idle rendering proces
138          n = strlen(buf);
139          if (write(persistfd, buf, n) < n)
140                  error(SYSTEM, "error writing persist file");
141 <        lseek(persistfd, (off_t)0L, 0);
141 >        lseek(persistfd, (off_t)0, SEEK_SET);
142                                  /* wait TIMELIM for someone to signal us */
143          got_io = 0;
144          signal(SIGIO, sig_io);
145 <        oldalrm = (void (*)())signal(SIGALRM, sig_alrm);
145 >        oldalrm = signal(SIGALRM, sig_alrm);
146          alarm(TIMELIM);
147          pflock(0);                      /* unlock persist file for attach */
148          while (!got_io)
# Line 183 | Line 185 | openerr:
185   }
186  
187  
188 < void
189 < io_process()            /* just act as go-between for actual process */
188 > extern void
189 > io_process(void)                /* just act as go-between for actual process */
190   {
191          register char   *cp;
192          register int    nr, n;
# Line 204 | Line 206 | io_process()           /* just act as go-between for actual pro
206          }
207          if (nr < 0)
208                  error(SYSTEM, "error reading persist file");
209 + #ifndef _WIN32 /* XXX we need a replacement for that one */
210          ftruncate(persistfd, (off_t)0L);        /* truncate persist file */
211 + #endif
212          pfdetach();                     /* close & release persist file */
213          buf[nr] = '\0';                 /* parse what we got */
214 <        if ((cp = index(buf, ' ')) == NULL)
214 >        if ((cp = strchr(buf, ' ')) == NULL)
215                  goto formerr;
216          *cp++ = '\0';
217          if ((pid = atoi(cp)) <= 0)
218                  goto formerr;
219 <        if ((cp = index(cp, '\n')) == NULL)
219 >        if ((cp = strchr(cp, '\n')) == NULL)
220                  goto formerr;
221          pfin = ++cp;
222 <        if ((cp = index(cp, '\n')) == NULL)
222 >        if ((cp = strchr(cp, '\n')) == NULL)
223                  goto formerr;
224          *cp++ = '\0';
225          pfout = cp;
226 <        if ((cp = index(cp, '\n')) == NULL)
226 >        if ((cp = strchr(cp, '\n')) == NULL)
227                  goto formerr;
228          *cp++ = '\0';
229          pferr = cp;
230 <        if ((cp = index(cp, '\n')) == NULL)
230 >        if ((cp = strchr(cp, '\n')) == NULL)
231                  goto formerr;
232          *cp++ = '\0';
233          if (cp-buf != nr)
# Line 331 | Line 335 | io_process()           /* just act as go-between for actual pro
335                                  } while ((nr -= n) > 0);
336                  }
337          }
338 <        wait(0);                /* wait for feeder process */
338 >        wait(0);                /* wait for feeder process */ /* XXX platform */
339          _exit(status);
340   formerr:
341          error(USER, "format error in persist file");
# Line 343 | Line 347 | writerr:
347  
348   #else
349  
350 < void pfclean() {}
350 > extern void pfclean(void) {}
351  
352   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines