--- ray/src/gen/mkillum.c 2004/09/17 21:43:50 2.20 +++ ray/src/gen/mkillum.c 2006/06/07 17:52:04 2.27 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mkillum.c,v 2.20 2004/09/17 21:43:50 greg Exp $"; +static const char RCSid[] = "$Id: mkillum.c,v 2.27 2006/06/07 17:52:04 schorsch 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); @@ -154,10 +155,15 @@ main( /* compute illum distributions using rtrace */ else filter(stdin, "standard input"); quit(0); + return 0; /* pro forma return */ } + +#ifndef SIGALRM +#define SIGALRM SIGTERM +#endif static void -killpersist(void) /* kill persistent process */ +killpersist(void) /* kill persistent rtrace process */ { FILE *fp = fopen(persistfn, "r"); int pid; @@ -169,25 +175,36 @@ killpersist(void) /* kill persistent 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 +219,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 +240,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 +248,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");