| 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" |
| 18 |
– |
#include "platform.h" |
| 24 |
|
#include "random.h" |
| 25 |
+ |
#include "ray.h" |
| 26 |
|
|
| 27 |
|
#ifdef F_SETLKW |
| 28 |
|
#include "paths.h" |
| 32 |
|
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
| 33 |
|
#endif |
| 34 |
|
|
| 29 |
– |
extern void io_process(); |
| 30 |
– |
|
| 35 |
|
extern int headismine; /* boolean true if header belongs to me */ |
| 32 |
– |
|
| 36 |
|
extern char *progname; /* global program name */ |
| 34 |
– |
|
| 37 |
|
extern char *errfile; /* global error file name */ |
| 36 |
– |
|
| 38 |
|
static char *persistfname = NULL; /* persist file name */ |
| 39 |
|
static int persistfd = -1; /* persist file descriptor */ |
| 39 |
– |
|
| 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 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
void |
| 94 |
< |
persistfile(pfn) /* open persist file and lock it */ |
| 95 |
< |
char *pfn; |
| 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; |
| 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 */ |
| 154 |
– |
/* |
| 155 |
– |
if (freopen(inpname, "r", stdin) == NULL) |
| 156 |
– |
goto openerr; |
| 157 |
– |
if (freopen(outpname, "w", stdout) == NULL) |
| 158 |
– |
goto openerr; |
| 159 |
– |
*/ |
| 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"); |
| 182 |
– |
openerr: |
| 183 |
– |
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"); |
| 208 |
– |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
| 206 |
|
ftruncate(persistfd, (off_t)0L); /* truncate persist file */ |
| 210 |
– |
#endif |
| 207 |
|
pfdetach(); /* close & release persist file */ |
| 208 |
|
buf[nr] = '\0'; /* parse what we got */ |
| 209 |
|
if ((cp = strchr(buf, ' ')) == NULL) |
| 295 |
|
if (!strncmp(cp, progname, n) && |
| 296 |
|
cp[n++] == ':' && |
| 297 |
|
cp[n++] == ' ') { |
| 298 |
< |
register struct erract *ep; |
| 298 |
> |
struct erract *ep; |
| 299 |
|
for (ep = erract; ep < erract+NERRS; |
| 300 |
|
ep++) |
| 301 |
|
if (ep->pre[0] && |
| 330 |
|
} while ((nr -= n) > 0); |
| 331 |
|
} |
| 332 |
|
} |
| 333 |
< |
wait(0); /* wait for feeder process */ |
| 333 |
> |
kill(pid, SIGTERM); /* no more process to feed, so... */ |
| 334 |
> |
waitpid(pid, 0, 0); /* wait for feeder process */ |
| 335 |
|
_exit(status); |
| 336 |
|
formerr: |
| 337 |
|
error(USER, "format error in persist file"); |
| 343 |
|
|
| 344 |
|
#else |
| 345 |
|
|
| 346 |
< |
void pfclean() {} |
| 346 |
> |
void pfclean(void) {} |
| 347 |
|
|
| 348 |
|
#endif |