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 |
23 |
– |
#include "paths.h" |
28 |
|
#include "selcall.h" |
29 |
|
|
30 |
|
#ifndef TIMELIM |
38 |
|
static int persistfd = -1; /* persist file descriptor */ |
39 |
|
static char inpname[TEMPLEN+1], outpname[TEMPLEN+1], errname[TEMPLEN+1]; |
40 |
|
|
41 |
< |
typedef void (sighandler_t)(int); |
42 |
< |
static sighandler_t sig_io; |
43 |
< |
static sighandler_t sig_alrm; |
41 |
> |
typedef void (rsighandler_t)(int); |
42 |
> |
static rsighandler_t sig_io; |
43 |
> |
static rsighandler_t sig_alrm; |
44 |
|
|
45 |
|
|
46 |
< |
extern void |
46 |
> |
void |
47 |
|
pfdetach(void) /* release persist (and header) resources */ |
48 |
|
{ |
49 |
|
if (persistfd >= 0) |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
< |
extern void |
60 |
> |
void |
61 |
|
pfclean(void) /* clean up persist files */ |
62 |
|
{ |
63 |
|
if (persistfd >= 0) |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
< |
extern void |
76 |
> |
void |
77 |
|
pflock( /* place or release exclusive lock on file */ |
78 |
|
int lf |
79 |
|
) |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
< |
extern void |
92 |
> |
void |
93 |
|
persistfile( /* open persist file and lock it */ |
94 |
|
char *pfn |
95 |
|
) |
118 |
|
static void sig_alrm(int i) { quit(0); } |
119 |
|
|
120 |
|
|
121 |
< |
extern void |
121 |
> |
void |
122 |
|
pfhold(void) /* holding pattern for idle rendering process */ |
123 |
|
{ |
124 |
< |
sighandler_t *oldalrm; |
124 |
> |
rsighandler_t *oldalrm; |
125 |
|
char buf[512]; |
126 |
< |
register int n; |
126 |
> |
int n; |
127 |
|
/* close input and output descriptors */ |
128 |
< |
close(fileno(stdin)); |
129 |
< |
close(fileno(stdout)); |
128 |
> |
close(0); |
129 |
> |
close(1); |
130 |
|
if (errfile == NULL) |
131 |
< |
close(fileno(stderr)); |
131 |
> |
close(2); |
132 |
|
/* create named pipes for input and output */ |
133 |
|
if (mkfifo(mktemp(strcpy(inpname,TEMPLATE)), 0600) < 0) |
134 |
|
goto createrr; |
156 |
|
signal(SIGIO, SIG_DFL); |
157 |
|
pflock(1); /* grab persist file back */ |
158 |
|
/* someone wants us; reopen stdin and stdout */ |
155 |
– |
/* |
156 |
– |
if (freopen(inpname, "r", stdin) == NULL) |
157 |
– |
goto openerr; |
158 |
– |
if (freopen(outpname, "w", stdout) == NULL) |
159 |
– |
goto openerr; |
160 |
– |
*/ |
159 |
|
close(0); |
160 |
|
if (open(inpname, O_RDONLY) != 0) |
161 |
|
error(INTERNAL, "unexpected stdin file number"); |
178 |
|
return; |
179 |
|
createrr: |
180 |
|
error(SYSTEM, "cannot create named pipes in pfhold"); |
183 |
– |
openerr: |
184 |
– |
error(SYSTEM, "cannot open named pipes in pfhold"); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
< |
extern void |
184 |
> |
void |
185 |
|
io_process(void) /* just act as go-between for actual process */ |
186 |
|
{ |
187 |
< |
register char *cp; |
188 |
< |
register int nr, n; |
187 |
> |
char *cp; |
188 |
> |
int nr, n; |
189 |
|
char buf[BUFSIZ], *pfin, *pfout, *pferr; |
190 |
|
int pid, nfds; |
191 |
|
int fdout, fderr = -1; |
202 |
|
} |
203 |
|
if (nr < 0) |
204 |
|
error(SYSTEM, "error reading persist file"); |
209 |
– |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
205 |
|
ftruncate(persistfd, (off_t)0L); /* truncate persist file */ |
211 |
– |
#endif |
206 |
|
pfdetach(); /* close & release persist file */ |
207 |
|
buf[nr] = '\0'; /* parse what we got */ |
208 |
|
if ((cp = strchr(buf, ' ')) == NULL) |
294 |
|
if (!strncmp(cp, progname, n) && |
295 |
|
cp[n++] == ':' && |
296 |
|
cp[n++] == ' ') { |
297 |
< |
register struct erract *ep; |
297 |
> |
struct erract *ep; |
298 |
|
for (ep = erract; ep < erract+NERRS; |
299 |
|
ep++) |
300 |
|
if (ep->pre[0] && |
342 |
|
|
343 |
|
#else |
344 |
|
|
345 |
< |
extern void pfclean(void) {} |
345 |
> |
void pfclean(void) {} |
346 |
|
|
347 |
|
#endif |