| 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 |
+ |
|
| 17 |
+ |
#include "platform.h" |
| 18 |
+ |
#ifndef NON_POSIX /* XXX need abstraction for process management */ |
| 19 |
+ |
#include <sys/wait.h> |
| 20 |
+ |
#endif |
| 21 |
+ |
|
| 22 |
+ |
#include "rtprocess.h" /* getpid() */ |
| 23 |
|
#include "standard.h" |
| 24 |
|
#include "random.h" |
| 25 |
+ |
#include "ray.h" |
| 26 |
|
|
| 27 |
|
#ifdef F_SETLKW |
| 28 |
|
#include "paths.h" |
| 29 |
|
#include "selcall.h" |
| 73 |
– |
#include <signal.h> |
| 74 |
– |
#include <sys/stat.h> |
| 30 |
|
|
| 31 |
|
#ifndef TIMELIM |
| 32 |
|
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
| 33 |
|
#endif |
| 34 |
|
|
| 80 |
– |
#ifndef freebsd |
| 81 |
– |
#define mkfifo(fn,md) mknod(fn, S_IFIFO|(md), 0) |
| 82 |
– |
#endif |
| 83 |
– |
|
| 84 |
– |
extern void io_process(); |
| 85 |
– |
|
| 35 |
|
extern int headismine; /* boolean true if header belongs to me */ |
| 87 |
– |
|
| 36 |
|
extern char *progname; /* global program name */ |
| 89 |
– |
|
| 37 |
|
extern char *errfile; /* global error file name */ |
| 91 |
– |
|
| 38 |
|
static char *persistfname = NULL; /* persist file name */ |
| 39 |
|
static int persistfd = -1; /* persist file descriptor */ |
| 94 |
– |
|
| 40 |
|
static char inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1]; |
| 41 |
|
|
| 42 |
+ |
typedef void (rsighandler_t)(int); |
| 43 |
+ |
static rsighandler_t sig_io; |
| 44 |
+ |
static rsighandler_t sig_alrm; |
| 45 |
|
|
| 46 |
+ |
|
| 47 |
|
void |
| 48 |
< |
pfdetach() /* release persist (and header) resources */ |
| 48 |
> |
pfdetach(void) /* release persist (and header) resources */ |
| 49 |
|
{ |
| 50 |
|
if (persistfd >= 0) |
| 51 |
|
close(persistfd); |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
void |
| 62 |
< |
pfclean() /* clean up persist files */ |
| 62 |
> |
pfclean(void) /* clean up persist files */ |
| 63 |
|
{ |
| 64 |
|
if (persistfd >= 0) |
| 65 |
|
close(persistfd); |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
void |
| 78 |
< |
pflock(lf) /* place or release exclusive lock on file */ |
| 79 |
< |
int lf; |
| 78 |
> |
pflock( /* place or release exclusive lock on file */ |
| 79 |
> |
int lf |
| 80 |
> |
) |
| 81 |
|
{ |
| 82 |
|
struct flock fls; |
| 83 |
|
|
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
< |
persistfile(pfn) /* open persist file and lock it */ |
| 94 |
< |
char *pfn; |
| 93 |
> |
void |
| 94 |
> |
persistfile( /* open persist file and lock it */ |
| 95 |
> |
char *pfn |
| 96 |
> |
) |
| 97 |
|
{ |
| 98 |
|
persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644); |
| 99 |
|
if (persistfd >= 0) { |
| 114 |
|
|
| 115 |
|
static int got_io; |
| 116 |
|
|
| 117 |
< |
static void sig_io() { got_io++; } |
| 117 |
> |
static void sig_io(int i) { got_io++; } |
| 118 |
|
|
| 119 |
< |
static void sig_alrm() { quit(0); } |
| 119 |
> |
static void sig_alrm(int i) { quit(0); } |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
void |
| 123 |
< |
pfhold() /* holding pattern for idle rendering process */ |
| 123 |
> |
pfhold(void) /* holding pattern for idle rendering process */ |
| 124 |
|
{ |
| 125 |
< |
void (*oldalrm)(); |
| 125 |
> |
rsighandler_t *oldalrm; |
| 126 |
|
char buf[512]; |
| 127 |
< |
register int n; |
| 127 |
> |
int n; |
| 128 |
|
/* close input and output descriptors */ |
| 129 |
< |
close(fileno(stdin)); |
| 130 |
< |
close(fileno(stdout)); |
| 129 |
> |
close(0); |
| 130 |
> |
close(1); |
| 131 |
|
if (errfile == NULL) |
| 132 |
< |
close(fileno(stderr)); |
| 132 |
> |
close(2); |
| 133 |
|
/* create named pipes for input and output */ |
| 134 |
|
if (mkfifo(mktemp(strcpy(inpname,TEMPLATE)), 0600) < 0) |
| 135 |
|
goto createrr; |
| 143 |
|
n = strlen(buf); |
| 144 |
|
if (write(persistfd, buf, n) < n) |
| 145 |
|
error(SYSTEM, "error writing persist file"); |
| 146 |
< |
lseek(persistfd, (off_t)0L, 0); |
| 146 |
> |
lseek(persistfd, (off_t)0, SEEK_SET); |
| 147 |
|
/* wait TIMELIM for someone to signal us */ |
| 148 |
|
got_io = 0; |
| 149 |
|
signal(SIGIO, sig_io); |
| 150 |
< |
oldalrm = (void (*)())signal(SIGALRM, sig_alrm); |
| 150 |
> |
oldalrm = signal(SIGALRM, sig_alrm); |
| 151 |
|
alarm(TIMELIM); |
| 152 |
|
pflock(0); /* unlock persist file for attach */ |
| 153 |
|
while (!got_io) |
| 157 |
|
signal(SIGIO, SIG_DFL); |
| 158 |
|
pflock(1); /* grab persist file back */ |
| 159 |
|
/* someone wants us; reopen stdin and stdout */ |
| 208 |
– |
/* |
| 209 |
– |
if (freopen(inpname, "r", stdin) == NULL) |
| 210 |
– |
goto openerr; |
| 211 |
– |
if (freopen(outpname, "w", stdout) == NULL) |
| 212 |
– |
goto openerr; |
| 213 |
– |
*/ |
| 160 |
|
close(0); |
| 161 |
|
if (open(inpname, O_RDONLY) != 0) |
| 162 |
|
error(INTERNAL, "unexpected stdin file number"); |
| 179 |
|
return; |
| 180 |
|
createrr: |
| 181 |
|
error(SYSTEM, "cannot create named pipes in pfhold"); |
| 236 |
– |
openerr: |
| 237 |
– |
error(SYSTEM, "cannot open named pipes in pfhold"); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
void |
| 186 |
< |
io_process() /* just act as go-between for actual process */ |
| 186 |
> |
io_process(void) /* just act as go-between for actual process */ |
| 187 |
|
{ |
| 188 |
< |
register char *cp; |
| 189 |
< |
register int nr, n; |
| 188 |
> |
char *cp; |
| 189 |
> |
int nr, n; |
| 190 |
|
char buf[BUFSIZ], *pfin, *pfout, *pferr; |
| 191 |
|
int pid, nfds; |
| 192 |
|
int fdout, fderr = -1; |
| 203 |
|
} |
| 204 |
|
if (nr < 0) |
| 205 |
|
error(SYSTEM, "error reading persist file"); |
| 206 |
+ |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
| 207 |
|
ftruncate(persistfd, (off_t)0L); /* truncate persist file */ |
| 208 |
+ |
#endif |
| 209 |
|
pfdetach(); /* close & release persist file */ |
| 210 |
|
buf[nr] = '\0'; /* parse what we got */ |
| 211 |
< |
if ((cp = index(buf, ' ')) == NULL) |
| 211 |
> |
if ((cp = strchr(buf, ' ')) == NULL) |
| 212 |
|
goto formerr; |
| 213 |
|
*cp++ = '\0'; |
| 214 |
|
if ((pid = atoi(cp)) <= 0) |
| 215 |
|
goto formerr; |
| 216 |
< |
if ((cp = index(cp, '\n')) == NULL) |
| 216 |
> |
if ((cp = strchr(cp, '\n')) == NULL) |
| 217 |
|
goto formerr; |
| 218 |
|
pfin = ++cp; |
| 219 |
< |
if ((cp = index(cp, '\n')) == NULL) |
| 219 |
> |
if ((cp = strchr(cp, '\n')) == NULL) |
| 220 |
|
goto formerr; |
| 221 |
|
*cp++ = '\0'; |
| 222 |
|
pfout = cp; |
| 223 |
< |
if ((cp = index(cp, '\n')) == NULL) |
| 223 |
> |
if ((cp = strchr(cp, '\n')) == NULL) |
| 224 |
|
goto formerr; |
| 225 |
|
*cp++ = '\0'; |
| 226 |
|
pferr = cp; |
| 227 |
< |
if ((cp = index(cp, '\n')) == NULL) |
| 227 |
> |
if ((cp = strchr(cp, '\n')) == NULL) |
| 228 |
|
goto formerr; |
| 229 |
|
*cp++ = '\0'; |
| 230 |
|
if (cp-buf != nr) |
| 297 |
|
if (!strncmp(cp, progname, n) && |
| 298 |
|
cp[n++] == ':' && |
| 299 |
|
cp[n++] == ' ') { |
| 300 |
< |
register struct erract *ep; |
| 300 |
> |
struct erract *ep; |
| 301 |
|
for (ep = erract; ep < erract+NERRS; |
| 302 |
|
ep++) |
| 303 |
|
if (ep->pre[0] && |
| 332 |
|
} while ((nr -= n) > 0); |
| 333 |
|
} |
| 334 |
|
} |
| 335 |
< |
wait(0); /* wait for feeder process */ |
| 335 |
> |
kill(pid, SIGTERM); /* no more process to feed, so... */ |
| 336 |
> |
waitpid(pid, 0, 0); /* wait for feeder process */ |
| 337 |
|
_exit(status); |
| 338 |
|
formerr: |
| 339 |
|
error(USER, "format error in persist file"); |
| 345 |
|
|
| 346 |
|
#else |
| 347 |
|
|
| 348 |
< |
void pfclean() {} |
| 348 |
> |
void pfclean(void) {} |
| 349 |
|
|
| 350 |
|
#endif |