| 13 |
|
#include <signal.h> |
| 14 |
|
#include <sys/stat.h> |
| 15 |
|
|
| 16 |
+ |
#include "platform.h" |
| 17 |
|
#include "rtprocess.h" /* getpid() */ |
| 18 |
|
#include "standard.h" |
| 18 |
– |
#include "platform.h" |
| 19 |
|
#include "random.h" |
| 20 |
+ |
#include "ray.h" |
| 21 |
|
|
| 22 |
|
#ifdef F_SETLKW |
| 23 |
|
#include "paths.h" |
| 27 |
|
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
| 28 |
|
#endif |
| 29 |
|
|
| 29 |
– |
extern void io_process(); |
| 30 |
– |
|
| 30 |
|
extern int headismine; /* boolean true if header belongs to me */ |
| 32 |
– |
|
| 31 |
|
extern char *progname; /* global program name */ |
| 34 |
– |
|
| 32 |
|
extern char *errfile; /* global error file name */ |
| 36 |
– |
|
| 33 |
|
static char *persistfname = NULL; /* persist file name */ |
| 34 |
|
static int persistfd = -1; /* persist file descriptor */ |
| 39 |
– |
|
| 35 |
|
static char inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1]; |
| 36 |
|
|
| 37 |
+ |
typedef void (sighandler_t)(int); |
| 38 |
+ |
static sighandler_t sig_io; |
| 39 |
+ |
static sighandler_t sig_alrm; |
| 40 |
|
|
| 41 |
< |
void |
| 42 |
< |
pfdetach() /* release persist (and header) resources */ |
| 41 |
> |
|
| 42 |
> |
extern void |
| 43 |
> |
pfdetach(void) /* release persist (and header) resources */ |
| 44 |
|
{ |
| 45 |
|
if (persistfd >= 0) |
| 46 |
|
close(persistfd); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
|
| 56 |
< |
void |
| 57 |
< |
pfclean() /* clean up persist files */ |
| 56 |
> |
extern void |
| 57 |
> |
pfclean(void) /* clean up persist files */ |
| 58 |
|
{ |
| 59 |
|
if (persistfd >= 0) |
| 60 |
|
close(persistfd); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
< |
void |
| 73 |
< |
pflock(lf) /* place or release exclusive lock on file */ |
| 74 |
< |
int lf; |
| 72 |
> |
extern void |
| 73 |
> |
pflock( /* place or release exclusive lock on file */ |
| 74 |
> |
int lf |
| 75 |
> |
) |
| 76 |
|
{ |
| 77 |
|
struct flock fls; |
| 78 |
|
|
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
|
| 88 |
< |
void |
| 89 |
< |
persistfile(pfn) /* open persist file and lock it */ |
| 90 |
< |
char *pfn; |
| 88 |
> |
extern void |
| 89 |
> |
persistfile( /* open persist file and lock it */ |
| 90 |
> |
char *pfn |
| 91 |
> |
) |
| 92 |
|
{ |
| 93 |
|
persistfd = open(pfn, O_WRONLY|O_CREAT|O_EXCL, 0644); |
| 94 |
|
if (persistfd >= 0) { |
| 109 |
|
|
| 110 |
|
static int got_io; |
| 111 |
|
|
| 112 |
< |
static void sig_io() { got_io++; } |
| 112 |
> |
static void sig_io(int i) { got_io++; } |
| 113 |
|
|
| 114 |
< |
static void sig_alrm() { quit(0); } |
| 114 |
> |
static void sig_alrm(int i) { quit(0); } |
| 115 |
|
|
| 116 |
|
|
| 117 |
< |
void |
| 118 |
< |
pfhold() /* holding pattern for idle rendering process */ |
| 117 |
> |
extern void |
| 118 |
> |
pfhold(void) /* holding pattern for idle rendering process */ |
| 119 |
|
{ |
| 120 |
< |
void (*oldalrm)(); |
| 120 |
> |
sighandler_t *oldalrm; |
| 121 |
|
char buf[512]; |
| 122 |
|
register int n; |
| 123 |
|
/* close input and output descriptors */ |
| 124 |
< |
close(fileno(stdin)); |
| 125 |
< |
close(fileno(stdout)); |
| 124 |
> |
close(0); |
| 125 |
> |
close(1); |
| 126 |
|
if (errfile == NULL) |
| 127 |
< |
close(fileno(stderr)); |
| 127 |
> |
close(2); |
| 128 |
|
/* create named pipes for input and output */ |
| 129 |
|
if (mkfifo(mktemp(strcpy(inpname,TEMPLATE)), 0600) < 0) |
| 130 |
|
goto createrr; |
| 142 |
|
/* wait TIMELIM for someone to signal us */ |
| 143 |
|
got_io = 0; |
| 144 |
|
signal(SIGIO, sig_io); |
| 145 |
< |
oldalrm = (void (*)())signal(SIGALRM, sig_alrm); |
| 145 |
> |
oldalrm = signal(SIGALRM, sig_alrm); |
| 146 |
|
alarm(TIMELIM); |
| 147 |
|
pflock(0); /* unlock persist file for attach */ |
| 148 |
|
while (!got_io) |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
< |
void |
| 189 |
< |
io_process() /* just act as go-between for actual process */ |
| 188 |
> |
extern void |
| 189 |
> |
io_process(void) /* just act as go-between for actual process */ |
| 190 |
|
{ |
| 191 |
|
register char *cp; |
| 192 |
|
register int nr, n; |
| 335 |
|
} while ((nr -= n) > 0); |
| 336 |
|
} |
| 337 |
|
} |
| 338 |
< |
wait(0); /* wait for feeder process */ |
| 338 |
> |
kill(pid, SIGTERM); /* no more process to feed, so... */ |
| 339 |
> |
waitpid(pid, 0, 0); /* wait for feeder process */ |
| 340 |
|
_exit(status); |
| 341 |
|
formerr: |
| 342 |
|
error(USER, "format error in persist file"); |
| 348 |
|
|
| 349 |
|
#else |
| 350 |
|
|
| 351 |
< |
void pfclean() {} |
| 351 |
> |
extern void pfclean(void) {} |
| 352 |
|
|
| 353 |
|
#endif |