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.38 by schorsch, Wed Jun 7 17:52:04 2006 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 + #include <sys/types.h>
16 + #include <sys/wait.h>
17 +
18 + #include "platform.h"
19 + #include "rtprocess.h" /* getpid() */
20   #include "standard.h"
21   #include "random.h"
22 + #include "ray.h"
23  
24   #ifdef F_SETLKW
25   #include "paths.h"
26   #include "selcall.h"
18 #include <signal.h>
19 #include <sys/stat.h>
27  
28   #ifndef TIMELIM
29   #define TIMELIM         (8*3600)        /* time limit for holding pattern */
30   #endif
31  
25 #ifndef freebsd
26 #define mkfifo(fn,md)   mknod(fn, S_IFIFO|(md), 0)
27 #endif
28
29 extern void     io_process();
30
32   extern int      headismine;     /* boolean true if header belongs to me */
32
33   extern char     *progname;      /* global program name */
34
34   extern char     *errfile;       /* global error file name */
36
35   static char     *persistfname = NULL;   /* persist file name */
36   static int      persistfd = -1;         /* persist file descriptor */
39
37   static char     inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1];
38  
39 + typedef void (sighandler_t)(int);
40 + static sighandler_t sig_io;
41 + static sighandler_t sig_alrm;
42  
43 < void
44 < pfdetach()              /* release persist (and header) resources */
43 >
44 > extern void
45 > pfdetach(void)          /* release persist (and header) resources */
46   {
47          if (persistfd >= 0)
48                  close(persistfd);
# Line 54 | Line 55 | pfdetach()             /* release persist (and header) resources
55   }
56  
57  
58 < void
59 < pfclean()               /* clean up persist files */
58 > extern void
59 > pfclean(void)           /* clean up persist files */
60   {
61          if (persistfd >= 0)
62                  close(persistfd);
# Line 70 | Line 71 | pfclean()              /* clean up persist files */
71   }
72  
73  
74 < void
75 < pflock(lf)              /* place or release exclusive lock on file */
76 < int     lf;
74 > extern void
75 > pflock(         /* place or release exclusive lock on file */
76 >        int     lf
77 > )
78   {
79          struct flock    fls;
80  
# Line 85 | Line 87 | int    lf;
87   }
88  
89  
90 < persistfile(pfn)        /* open persist file and lock it */
91 < char    *pfn;
90 > extern void
91 > persistfile(    /* open persist file and lock it */
92 >        char    *pfn
93 > )
94   {
95          persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644);
96          if (persistfd >= 0) {
# Line 107 | Line 111 | char   *pfn;
111  
112   static int      got_io;
113  
114 < static void sig_io() { got_io++; }
114 > static void sig_io(int i) { got_io++; }
115  
116 < static void sig_alrm() { quit(0); }
116 > static void sig_alrm(int i) { quit(0); }
117  
118  
119 < void
120 < pfhold()                /* holding pattern for idle rendering process */
119 > extern void
120 > pfhold(void)            /* holding pattern for idle rendering process */
121   {
122 <        void    (*oldalrm)();
122 >        sighandler_t    *oldalrm;
123          char    buf[512];
124          register int    n;
125                                  /* close input and output descriptors */
126 <        close(fileno(stdin));
127 <        close(fileno(stdout));
126 >        close(0);
127 >        close(1);
128          if (errfile == NULL)
129 <                close(fileno(stderr));
129 >                close(2);
130                                  /* create named pipes for input and output */
131          if (mkfifo(mktemp(strcpy(inpname,TEMPLATE)), 0600) < 0)
132                  goto createrr;
# Line 136 | Line 140 | pfhold()               /* holding pattern for idle rendering proces
140          n = strlen(buf);
141          if (write(persistfd, buf, n) < n)
142                  error(SYSTEM, "error writing persist file");
143 <        lseek(persistfd, (off_t)0L, 0);
143 >        lseek(persistfd, (off_t)0, SEEK_SET);
144                                  /* wait TIMELIM for someone to signal us */
145          got_io = 0;
146          signal(SIGIO, sig_io);
147 <        oldalrm = (void (*)())signal(SIGALRM, sig_alrm);
147 >        oldalrm = signal(SIGALRM, sig_alrm);
148          alarm(TIMELIM);
149          pflock(0);                      /* unlock persist file for attach */
150          while (!got_io)
# Line 183 | Line 187 | openerr:
187   }
188  
189  
190 < void
191 < io_process()            /* just act as go-between for actual process */
190 > extern void
191 > io_process(void)                /* just act as go-between for actual process */
192   {
193          register char   *cp;
194          register int    nr, n;
# Line 204 | Line 208 | io_process()           /* just act as go-between for actual pro
208          }
209          if (nr < 0)
210                  error(SYSTEM, "error reading persist file");
211 + #ifndef _WIN32 /* XXX we need a replacement for that one */
212          ftruncate(persistfd, (off_t)0L);        /* truncate persist file */
213 + #endif
214          pfdetach();                     /* close & release persist file */
215          buf[nr] = '\0';                 /* parse what we got */
216 <        if ((cp = index(buf, ' ')) == NULL)
216 >        if ((cp = strchr(buf, ' ')) == NULL)
217                  goto formerr;
218          *cp++ = '\0';
219          if ((pid = atoi(cp)) <= 0)
220                  goto formerr;
221 <        if ((cp = index(cp, '\n')) == NULL)
221 >        if ((cp = strchr(cp, '\n')) == NULL)
222                  goto formerr;
223          pfin = ++cp;
224 <        if ((cp = index(cp, '\n')) == NULL)
224 >        if ((cp = strchr(cp, '\n')) == NULL)
225                  goto formerr;
226          *cp++ = '\0';
227          pfout = cp;
228 <        if ((cp = index(cp, '\n')) == NULL)
228 >        if ((cp = strchr(cp, '\n')) == NULL)
229                  goto formerr;
230          *cp++ = '\0';
231          pferr = cp;
232 <        if ((cp = index(cp, '\n')) == NULL)
232 >        if ((cp = strchr(cp, '\n')) == NULL)
233                  goto formerr;
234          *cp++ = '\0';
235          if (cp-buf != nr)
# Line 331 | Line 337 | io_process()           /* just act as go-between for actual pro
337                                  } while ((nr -= n) > 0);
338                  }
339          }
340 <        wait(0);                /* wait for feeder process */
340 >        kill(pid, SIGTERM);     /* no more process to feed, so... */
341 >        waitpid(pid, 0, 0);     /* wait for feeder process */
342          _exit(status);
343   formerr:
344          error(USER, "format error in persist file");
# Line 343 | Line 350 | writerr:
350  
351   #else
352  
353 < void pfclean() {}
353 > extern void pfclean(void) {}
354  
355   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines