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.32 by greg, Mon Oct 20 16:01:55 2003 UTC vs.
Revision 2.38 by schorsch, Wed Jun 7 17:52:04 2006 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
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"
18 #include "platform.h"
21   #include "random.h"
22 + #include "ray.h"
23  
24   #ifdef F_SETLKW
25   #include "paths.h"
# Line 26 | Line 29 | static const char      RCSid[] = "$Id$";
29   #define TIMELIM         (8*3600)        /* time limit for holding pattern */
30   #endif
31  
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 < void
91 < persistfile(pfn)        /* open persist file and lock it */
92 < 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 108 | 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 141 | Line 144 | pfhold()               /* holding pattern for idle rendering proces
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 184 | 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 334 | 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 346 | 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