9 |
|
#include <ctype.h> |
10 |
|
|
11 |
|
#include "platform.h" |
12 |
– |
#include "rtprocess.h" |
12 |
|
#include "mkillum.h" |
13 |
|
#include "random.h" |
14 |
|
|
60 |
|
|
61 |
|
int warnings = 1; /* print warnings? */ |
62 |
|
|
63 |
+ |
int done_rprocs(struct rtproc *rtp); |
64 |
|
void init(int np); |
65 |
|
void filter(register FILE *infp, char *name); |
66 |
|
void xoptions(char *s, char *nm); |
170 |
|
fclose(fp); |
171 |
|
} |
172 |
|
|
173 |
+ |
int |
174 |
+ |
done_rprocs(struct rtproc *rtp) |
175 |
+ |
{ |
176 |
+ |
int st0, st1 = 0; |
177 |
+ |
|
178 |
+ |
if (rtp->next != NULL) { /* close last opened first! */ |
179 |
+ |
st1 = done_rprocs(rtp->next); |
180 |
+ |
free((void *)rtp->next); |
181 |
+ |
rtp->next = NULL; |
182 |
+ |
} |
183 |
+ |
st0 = close_process(&rtp->pd); |
184 |
+ |
if (st0 < 0) |
185 |
+ |
error(WARNING, "unknown return status from rtrace process"); |
186 |
+ |
else if (st0 > 0) |
187 |
+ |
return(st0); |
188 |
+ |
return(st1); |
189 |
+ |
} |
190 |
+ |
|
191 |
|
void |
192 |
|
quit(int status) /* exit with status */ |
193 |
|
{ |
176 |
– |
struct rtproc *rtp; |
194 |
|
int rtstat; |
195 |
|
|
196 |
|
if (rt0.next != NULL) /* terminate persistent rtrace */ |
197 |
|
killpersist(); |
198 |
|
/* clean up rtrace process(es) */ |
199 |
< |
for (rtp = &rt0; rtp != NULL; rtp = rtp->next) { |
200 |
< |
rtstat = close_process(&rtp->pd); |
201 |
< |
if (status == 0) { |
185 |
< |
if (rtstat < 0) |
186 |
< |
error(WARNING, |
187 |
< |
"unknown return status from rtrace process"); |
188 |
< |
else |
189 |
< |
status = rtstat; |
190 |
< |
} |
191 |
< |
} |
199 |
> |
rtstat = done_rprocs(&rt0); |
200 |
> |
if (status == 0) |
201 |
> |
status = rtstat; |
202 |
|
exit(status); |
203 |
|
} |
204 |
|
|
213 |
|
ofun[OBJ_SPHERE].funp = o_sphere; |
214 |
|
ofun[OBJ_RING].funp = o_ring; |
215 |
|
/* set up signal handling */ |
216 |
< |
#ifdef SIGPIPE /* not present on Windows */ |
216 |
> |
signal(SIGINT, quit); |
217 |
> |
#ifdef SIGHUP |
218 |
> |
signal(SIGHUP, quit); |
219 |
> |
#endif |
220 |
> |
#ifdef SIGTERM |
221 |
> |
signal(SIGTERM, quit); |
222 |
> |
#endif |
223 |
> |
#ifdef SIGPIPE |
224 |
|
signal(SIGPIPE, quit); |
225 |
|
#endif |
226 |
|
rtp = &rt0; /* start rtrace process(es) */ |
234 |
|
} |
235 |
|
if (maxbytes < 0) |
236 |
|
error(SYSTEM, "cannot start rtrace process"); |
220 |
– |
if (!i && np > 1) |
221 |
– |
sleep(2); /* wait for persist file */ |
237 |
|
rtp->bsiz = maxbytes/(6*sizeof(float)); |
238 |
|
rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--); |
239 |
|
rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *)); |
242 |
|
rtp->nrays = 0; |
243 |
|
if (i == np) /* last process? */ |
244 |
|
break; |
245 |
+ |
if (np > 1) |
246 |
+ |
sleep(2); /* wait for persist file */ |
247 |
|
rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc)); |
248 |
|
if (rtp->next == NULL) |
249 |
|
error(SYSTEM, "out of memory in init"); |