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.26 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.38 by schorsch, Wed Jun 7 17:52:04 2006 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in ray.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
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"
73 #include <signal.h>
74 #include <sys/stat.h>
27  
28   #ifndef TIMELIM
29   #define TIMELIM         (8*3600)        /* time limit for holding pattern */
30   #endif
31  
80 #ifndef freebsd
81 #define mkfifo(fn,md)   mknod(fn, S_IFIFO|(md), 0)
82 #endif
83
84 extern void     io_process();
85
32   extern int      headismine;     /* boolean true if header belongs to me */
87
33   extern char     *progname;      /* global program name */
89
34   extern char     *errfile;       /* global error file name */
91
35   static char     *persistfname = NULL;   /* persist file name */
36   static int      persistfd = -1;         /* persist file descriptor */
94
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 109 | 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 125 | 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 140 | 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 162 | 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 191 | 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 238 | 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 259 | 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 386 | 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 398 | 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