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" |
29 |
|
#define TIMELIM (8*3600) /* time limit for holding pattern */ |
30 |
|
#endif |
31 |
|
|
28 |
– |
#ifndef freebsd |
29 |
– |
#define mkfifo(fn,md) mknod(fn, S_IFIFO|(md), 0) |
30 |
– |
#endif |
31 |
– |
|
32 |
– |
extern void io_process(); |
33 |
– |
|
32 |
|
extern int headismine; /* boolean true if header belongs to me */ |
35 |
– |
|
33 |
|
extern char *progname; /* global program name */ |
37 |
– |
|
34 |
|
extern char *errfile; /* global error file name */ |
39 |
– |
|
35 |
|
static char *persistfname = NULL; /* persist file name */ |
36 |
|
static int persistfd = -1; /* persist file descriptor */ |
42 |
– |
|
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); |
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); |
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 |
|
|
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) { |
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; |
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) |
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; |
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"); |
350 |
|
|
351 |
|
#else |
352 |
|
|
353 |
< |
void pfclean() {} |
353 |
> |
extern void pfclean(void) {} |
354 |
|
|
355 |
|
#endif |