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); |
157 |
|
quit(0); |
158 |
|
} |
159 |
|
|
160 |
+ |
|
161 |
+ |
#ifndef SIGALRM |
162 |
+ |
#define SIGALRM SIGTERM |
163 |
+ |
#endif |
164 |
|
static void |
165 |
|
killpersist(void) /* kill persistent rtrace process */ |
166 |
|
{ |
174 |
|
fclose(fp); |
175 |
|
} |
176 |
|
|
177 |
+ |
|
178 |
+ |
int |
179 |
+ |
done_rprocs(struct rtproc *rtp) |
180 |
+ |
{ |
181 |
+ |
int st0, st1 = 0; |
182 |
+ |
|
183 |
+ |
if (rtp->next != NULL) { /* close last opened first! */ |
184 |
+ |
st1 = done_rprocs(rtp->next); |
185 |
+ |
free((void *)rtp->next); |
186 |
+ |
rtp->next = NULL; |
187 |
+ |
} |
188 |
+ |
st0 = close_process(&rtp->pd); |
189 |
+ |
if (st0 < 0) |
190 |
+ |
error(WARNING, "unknown return status from rtrace process"); |
191 |
+ |
else if (st0 > 0) |
192 |
+ |
return(st0); |
193 |
+ |
return(st1); |
194 |
+ |
} |
195 |
+ |
|
196 |
|
void |
197 |
|
quit(int status) /* exit with status */ |
198 |
|
{ |
175 |
– |
struct rtproc *rtp; |
199 |
|
int rtstat; |
200 |
|
|
201 |
|
if (rt0.next != NULL) /* terminate persistent rtrace */ |
202 |
|
killpersist(); |
203 |
|
/* clean up rtrace process(es) */ |
204 |
< |
for (rtp = &rt0; rtp != NULL; rtp = rtp->next) { |
205 |
< |
rtstat = close_process(&rtp->pd); |
206 |
< |
if (status == 0) { |
184 |
< |
if (rtstat < 0) |
185 |
< |
error(WARNING, |
186 |
< |
"unknown return status from rtrace process"); |
187 |
< |
else |
188 |
< |
status = rtstat; |
189 |
< |
} |
190 |
< |
} |
204 |
> |
rtstat = done_rprocs(&rt0); |
205 |
> |
if (status == 0) |
206 |
> |
status = rtstat; |
207 |
|
exit(status); |
208 |
|
} |
209 |
|
|
218 |
|
ofun[OBJ_SPHERE].funp = o_sphere; |
219 |
|
ofun[OBJ_RING].funp = o_ring; |
220 |
|
/* set up signal handling */ |
221 |
< |
#ifdef SIGPIPE /* not present on Windows */ |
221 |
> |
signal(SIGINT, quit); |
222 |
> |
#ifdef SIGHUP |
223 |
> |
signal(SIGHUP, quit); |
224 |
> |
#endif |
225 |
> |
#ifdef SIGTERM |
226 |
> |
signal(SIGTERM, quit); |
227 |
> |
#endif |
228 |
> |
#ifdef SIGPIPE |
229 |
|
signal(SIGPIPE, quit); |
230 |
|
#endif |
231 |
|
rtp = &rt0; /* start rtrace process(es) */ |
239 |
|
} |
240 |
|
if (maxbytes < 0) |
241 |
|
error(SYSTEM, "cannot start rtrace process"); |
219 |
– |
if (!i && np > 1) |
220 |
– |
sleep(2); /* wait for persist file */ |
242 |
|
rtp->bsiz = maxbytes/(6*sizeof(float)); |
243 |
|
rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--); |
244 |
|
rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *)); |
247 |
|
rtp->nrays = 0; |
248 |
|
if (i == np) /* last process? */ |
249 |
|
break; |
250 |
+ |
if (np > 1) |
251 |
+ |
sleep(2); /* wait for persist file */ |
252 |
|
rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc)); |
253 |
|
if (rtp->next == NULL) |
254 |
|
error(SYSTEM, "out of memory in init"); |