--- ray/src/gen/mkillum.c 2004/09/19 08:42:22 2.21 +++ ray/src/gen/mkillum.c 2005/05/26 14:46:21 2.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mkillum.c,v 2.21 2004/09/19 08:42:22 greg Exp $"; +static const char RCSid[] = "$Id: mkillum.c,v 2.25 2005/05/26 14:46:21 greg Exp $"; #endif /* * Make illum sources for optimizing rendering process @@ -60,6 +60,7 @@ int doneheader = 0; /* printed header yet? */ int warnings = 1; /* print warnings? */ +int done_rprocs(struct rtproc *rtp); void init(int np); void filter(register FILE *infp, char *name); void xoptions(char *s, char *nm); @@ -169,25 +170,35 @@ killpersist(void) /* kill persistent rtrace process fclose(fp); } +int +done_rprocs(struct rtproc *rtp) +{ + int st0, st1 = 0; + + if (rtp->next != NULL) { /* close last opened first! */ + st1 = done_rprocs(rtp->next); + free((void *)rtp->next); + rtp->next = NULL; + } + st0 = close_process(&rtp->pd); + if (st0 < 0) + error(WARNING, "unknown return status from rtrace process"); + else if (st0 > 0) + return(st0); + return(st1); +} + void quit(int status) /* exit with status */ { - struct rtproc *rtp; int rtstat; if (rt0.next != NULL) /* terminate persistent rtrace */ killpersist(); /* clean up rtrace process(es) */ - for (rtp = &rt0; rtp != NULL; rtp = rtp->next) { - rtstat = close_process(&rtp->pd); - if (status == 0) { - if (rtstat < 0) - error(WARNING, - "unknown return status from rtrace process"); - else - status = rtstat; - } - } + rtstat = done_rprocs(&rt0); + if (status == 0) + status = rtstat; exit(status); } @@ -202,7 +213,14 @@ init(int np) /* start rtrace and set up buffers */ ofun[OBJ_SPHERE].funp = o_sphere; ofun[OBJ_RING].funp = o_ring; /* set up signal handling */ -#ifdef SIGPIPE /* not present on Windows */ + signal(SIGINT, quit); +#ifdef SIGHUP + signal(SIGHUP, quit); +#endif +#ifdef SIGTERM + signal(SIGTERM, quit); +#endif +#ifdef SIGPIPE signal(SIGPIPE, quit); #endif rtp = &rt0; /* start rtrace process(es) */ @@ -216,8 +234,6 @@ init(int np) /* start rtrace and set up buffers */ } if (maxbytes < 0) error(SYSTEM, "cannot start rtrace process"); - if (!i && np > 1) - sleep(2); /* wait for persist file */ rtp->bsiz = maxbytes/(6*sizeof(float)); rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--); rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *)); @@ -226,6 +242,8 @@ init(int np) /* start rtrace and set up buffers */ rtp->nrays = 0; if (i == np) /* last process? */ break; + if (np > 1) + sleep(2); /* wait for persist file */ rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc)); if (rtp->next == NULL) error(SYSTEM, "out of memory in init");