ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
Revision: 3.49
Committed: Wed Feb 10 16:24:07 1999 UTC (25 years, 2 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.48: +11 -19 lines
Log Message:
simplified flushing with RTFLUSH macro

File Contents

# User Rev Content
1 gwlarson 3.46 /* Copyright (c) 1999 Silicon Graphics, Inc. */
2 gregl 3.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Radiance holodeck generation controller
9     */
10    
11     #include "rholo.h"
12 gregl 3.14 #include "random.h"
13 gregl 3.12 #include <signal.h>
14 gregl 3.1 #include <sys/types.h>
15 gregl 3.12 #include <sys/stat.h>
16 gregl 3.1
17 gwlarson 3.44 #ifndef FRAGWARN
18     #define FRAGWARN 20 /* fragmentation for warning (%) */
19     #endif
20 gregl 3.33 #ifndef MAXQTIME
21     #define MAXQTIME 5 /* target maximum seconds in queue */
22     #endif
23 gwlarson 3.49 /* manual cache flushing frequency */
24     #ifndef RTFLUSH
25     #if MAXQTIME
26     #define RTFLUSH (300/MAXQTIME*totqlen) /* <= 5 minutes */
27     #else
28     #define RTFLUSH (50*totqlen) /* just guess */
29     #endif
30     #endif
31 gregl 3.1 /* the following must be consistent with rholo.h */
32     int NVARS = NRHVARS; /* total number of variables */
33    
34     VARIABLE vv[] = RHVINIT; /* variable-value pairs */
35    
36     char *progname; /* our program name */
37     char *hdkfile; /* holodeck file name */
38 gregl 3.22 char froot[256]; /* root file name */
39 gregl 3.1
40     int ncprocs = 0; /* desired number of compute processes */
41    
42     char *outdev = NULL; /* output device name */
43    
44 gregl 3.17 int readinp = 0; /* read commands from stdin */
45    
46 gregl 3.20 int force = 0; /* allow overwrite of holodeck */
47    
48 gregl 3.1 time_t starttime; /* time we got started */
49     time_t endtime; /* time we should end by */
50     time_t reporttime; /* time for next report */
51    
52 gregl 3.8 long maxdisk; /* maximum file space (bytes) */
53    
54 gregl 3.1 int rtargc = 1; /* rtrace command */
55     char *rtargv[128] = {"rtrace", NULL};
56    
57 gregl 3.12 int orig_mode = -1; /* original file mode (-1 if unchanged) */
58    
59 gregl 3.1 long nraysdone = 0L; /* number of rays done */
60     long npacksdone = 0L; /* number of packets done */
61    
62     PACKET *freepacks; /* available packets */
63 gwlarson 3.49 int totqlen; /* maximum queue length (number of packets) */
64 gregl 3.1
65 gregl 3.12 char *sigerr[NSIG]; /* signal error messages */
66    
67 gwlarson 3.40 extern int nowarn; /* turn warnings off? */
68    
69 gregl 3.1 extern time_t time();
70    
71    
72     main(argc, argv)
73     int argc;
74     char *argv[];
75     {
76     int i;
77 gregl 3.33
78 gregl 3.18 initurand(16384); /* initialize urand */
79 gregl 3.1 progname = argv[0]; /* get arguments */
80     for (i = 1; i < argc && argv[i][0] == '-'; i++)
81     switch (argv[i][1]) {
82     case 'w': /* turn off warnings */
83     nowarn++;
84     break;
85     case 'f': /* force overwrite */
86     force++;
87     break;
88 gregl 3.17 case 'i': /* read input from stdin */
89     readinp++;
90     break;
91 gregl 3.1 case 'n': /* compute processes */
92     if (i >= argc-2)
93     goto userr;
94     ncprocs = atoi(argv[++i]);
95     break;
96     case 'o': /* output display */
97     if (i >= argc-2)
98     goto userr;
99     outdev = argv[++i];
100     break;
101     default:
102     goto userr;
103     }
104     /* get root file name */
105 gregl 3.32 if (i >= argc)
106     goto userr;
107 gregl 3.1 rootname(froot, hdkfile=argv[i++]);
108 gregl 3.27 /* load variables? */
109     if (i < argc)
110     if (argv[i][0] != '-' && argv[i][0] != '+')
111     loadvars(argv[i]); /* load variables from file */
112    
113     if (i >= argc || argv[i][0] == '+')
114     loadholo(); /* load existing holodeck */
115    
116     while (++i < argc) /* get command line settings */
117     if (setvariable(argv[i], matchvar) < 0) {
118     sprintf(errmsg, "unknown variable: %s", argv[i]);
119     error(USER, errmsg);
120     }
121     /* check settings */
122     checkvalues();
123 gregl 3.36 /* load rad input file */
124     getradfile();
125 gregl 3.27
126 gregl 3.28 if (hdlist[0] == NULL) { /* create new holodeck */
127 gregl 3.29 HDGRID hdg[HDMAX];
128 gregl 3.1 /* set defaults */
129 gregl 3.29 setdefaults(hdg);
130 gregl 3.1 /* holodeck exists? */
131     if (!force && access(hdkfile, R_OK|W_OK) == 0)
132     error(USER,
133     "holodeck file exists -- use -f to overwrite");
134     /* create holodeck */
135 gregl 3.29 creatholo(hdg);
136 gregl 3.27 } else /* else just set defaults */
137 gregl 3.15 setdefaults(NULL);
138 gregl 3.1 /* initialize */
139     initrholo();
140 gregl 3.15 /* main loop */
141 gregl 3.1 while (rholo())
142     ;
143     /* done */
144     quit(0);
145     userr:
146     fprintf(stderr,
147 gregl 3.27 "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
148 gregl 3.1 progname);
149     quit(1);
150     }
151    
152    
153 gregl 3.12 onsig(signo) /* fatal signal */
154     int signo;
155     {
156     static int gotsig = 0;
157    
158 gwlarson 3.47 if (gotsig > 1) /* we're going as fast as we can! */
159     return;
160     if (gotsig++) { /* two signals and we split */
161     hdsync(NULL, 0); /* don't leave w/o saying goodbye */
162 gregl 3.12 _exit(signo);
163 gwlarson 3.47 }
164     alarm(300); /* allow 5 minutes to clean up */
165 gregl 3.12 eputs("signal - ");
166     eputs(sigerr[signo]);
167     eputs("\n");
168     quit(3);
169     }
170    
171    
172     sigdie(signo, msg) /* set fatal signal */
173     int signo;
174     char *msg;
175     {
176     if (signal(signo, onsig) == SIG_IGN)
177     signal(signo, SIG_IGN);
178     sigerr[signo] = msg;
179     }
180    
181    
182     int
183     resfmode(fd, mod) /* restrict open file access mode */
184     int fd, mod;
185     {
186     struct stat stbuf;
187     /* get original mode */
188     if (fstat(fd, &stbuf) < 0)
189     error(SYSTEM, "cannot stat open holodeck file");
190     mod &= stbuf.st_mode; /* always more restrictive */
191 gregl 3.35 if (mod == (stbuf.st_mode & 0777))
192 gregl 3.12 return(-1); /* already set */
193     /* else change it */
194     if (fchmod(fd, mod) < 0) {
195     error(WARNING, "cannot change holodeck file access mode");
196     return(-1);
197     }
198     return(stbuf.st_mode); /* return original mode */
199     }
200    
201    
202 gregl 3.1 initrholo() /* get our holodeck running */
203     {
204     extern int global_packet();
205     register int i;
206 gregl 3.17 /* close holodeck on exec() */
207     fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC);
208 gregl 3.4
209     if (outdev != NULL) /* open output device */
210     disp_open(outdev);
211 gregl 3.1 else if (ncprocs > 0) /* else use global ray feed */
212     init_global();
213 gregl 3.8 /* record disk space limit */
214     if (!vdef(DISKSPACE))
215     maxdisk = 0;
216     else
217 gregl 3.9 maxdisk = 1024.*1024.*vflt(DISKSPACE);
218 gregl 3.1 /* set up memory cache */
219 gregl 3.5 if (outdev == NULL)
220     hdcachesize = 0; /* manual flushing */
221     else if (vdef(CACHE))
222     hdcachesize = 1024.*1024.*vflt(CACHE);
223 gregl 3.1 /* open report file */
224     if (vdef(REPORT)) {
225     register char *s = sskip2(vval(REPORT), 1);
226     if (*s && freopen(s, "a", stderr) == NULL)
227     quit(2);
228     }
229 gregl 3.33 /* mark the starting time */
230     starttime = time(NULL);
231     /* compute end time */
232     if (!vdef(TIME) || vflt(TIME) <= FTINY)
233     endtime = 0;
234     else
235     endtime = starttime + vflt(TIME)*3600. + .5;
236 gregl 3.1 /* start rtrace */
237     if (ncprocs > 0) {
238 gwlarson 3.38 totqlen = i = start_rtrace();
239 gregl 3.1 if (i < 1)
240 gregl 3.20 error(USER, "cannot start rtrace process(es)");
241 gregl 3.1 if (vdef(REPORT)) { /* make first report */
242     printargs(rtargc, rtargv, stderr);
243     report(0);
244     }
245     /* allocate packets */
246     freepacks = (PACKET *)bmalloc(i*sizeof(PACKET));
247     if (freepacks == NULL)
248     goto memerr;
249     freepacks[--i].nr = 0;
250     freepacks[i].next = NULL;
251 gregl 3.25 if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
252 gregl 3.1 freepacks[i].offset = (float *)bmalloc(
253     RPACKSIZ*sizeof(float)*(i+1) );
254     if (freepacks[i].offset == NULL)
255     goto memerr;
256     } else
257     freepacks[i].offset = NULL;
258     while (i--) {
259     freepacks[i].nr = 0;
260     freepacks[i].offset = freepacks[i+1].offset == NULL ?
261     NULL : freepacks[i+1].offset+RPACKSIZ ;
262     freepacks[i].next = &freepacks[i+1];
263     }
264     }
265 gregl 3.12 /* set up signal handling */
266     sigdie(SIGINT, "Interrupt");
267     sigdie(SIGHUP, "Hangup");
268     sigdie(SIGTERM, "Terminate");
269     sigdie(SIGPIPE, "Broken pipe");
270     sigdie(SIGALRM, "Alarm clock");
271     #ifdef SIGXCPU
272     sigdie(SIGXCPU, "CPU limit exceeded");
273     sigdie(SIGXFSZ, "File size exceeded");
274     #endif
275     /* protect holodeck file */
276     orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
277 gregl 3.1 return;
278     memerr:
279     error(SYSTEM, "out of memory in initrholo");
280     }
281    
282    
283     rholo() /* holodeck main loop */
284     {
285 gwlarson 3.44 static long nextfragwarn = 100*(1L<<20);
286 gregl 3.30 static int idle = 0;
287 gregl 3.1 PACKET *pl = NULL, *plend;
288 gwlarson 3.44 long fsiz;
289 gregl 3.33 int pksiz;
290 gregl 3.1 register PACKET *p;
291     time_t t;
292 gregl 3.30 /* check display */
293     if (nprocs <= 0)
294     idle = 1;
295     if (outdev != NULL) {
296 gregl 3.4 if (!disp_check(idle))
297 gregl 3.30 return(0); /* quit request */
298     if (nprocs <= 0)
299     return(1);
300     } else if (idle)
301     return(0); /* all done */
302 gwlarson 3.44 fsiz = hdfilen(hdlist[0]->fd); /* check file size */
303     if (maxdisk > 0 && fsiz >= maxdisk) {
304 gregl 3.8 error(WARNING, "file limit exceeded");
305 gregl 3.21 done_rtrace();
306     return(1); /* comes back */
307 gregl 3.8 }
308 gwlarson 3.44 #if FRAGWARN
309     if (fsiz >= nextfragwarn &&
310     (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
311     sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
312     100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
313     error(WARNING, errmsg);
314     nextfragwarn = fsiz + (fsiz>>2); /* decent interval */
315     }
316     #endif
317 gregl 3.33 t = time(NULL); /* check time */
318 gregl 3.8 if (endtime > 0 && t >= endtime) {
319     error(WARNING, "time limit exceeded");
320 gregl 3.21 done_rtrace();
321     return(1); /* comes back */
322 gregl 3.8 }
323 gregl 3.3 if (reporttime > 0 && t >= reporttime)
324 gregl 3.1 report(t);
325 gregl 3.33 /* figure out good packet size */
326 gwlarson 3.48 pksiz = RPACKSIZ;
327 gregl 3.33 #if MAXQTIME
328 gwlarson 3.48 if (!chunkycmp) {
329     pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
330     if (pksiz < 1) pksiz = 1;
331     else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
332     }
333 gregl 3.33 #endif
334 gregl 3.28 idle = 0; /* get packets to process */
335 gregl 3.1 while (freepacks != NULL) {
336     p = freepacks; freepacks = p->next; p->next = NULL;
337 gregl 3.33 if (!next_packet(p, pksiz)) {
338 gregl 3.1 p->next = freepacks; freepacks = p;
339 gregl 3.21 idle = 1;
340 gregl 3.1 break;
341     }
342     if (pl == NULL) pl = p;
343     else plend->next = p;
344     plend = p;
345     }
346 gregl 3.21 /* process packets */
347 gregl 3.1 done_packets(do_packets(pl));
348     return(1); /* and continue */
349     }
350    
351    
352     setdefaults(gp) /* set default values */
353     register HDGRID *gp;
354     {
355     extern char *atos();
356     register int i;
357 gregl 3.29 int n;
358 gregl 3.37 double len[3], d;
359 gregl 3.1 char buf[64];
360    
361     if (!vdef(SECTION)) {
362     sprintf(errmsg, "%s must be defined", vnam(SECTION));
363     error(USER, errmsg);
364     }
365     if (!vdef(OCTREE)) {
366     if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
367     error(SYSTEM, "out of memory");
368     sprintf(vval(OCTREE), "%s.oct", froot);
369     vdef(OCTREE)++;
370 gregl 3.14 }
371     if (!vdef(VDIST)) {
372     vval(VDIST) = "F";
373     vdef(VDIST)++;
374 gregl 3.1 }
375     /* append rendering options */
376     if (vdef(RENDER))
377     rtargc += wordstring(rtargv+rtargc, vval(RENDER));
378 gregl 3.15
379     if (gp == NULL) /* already initialized? */
380     return;
381     /* set grid parameters */
382 gregl 3.29 for (n = 0; n < vdef(SECTION); n++, gp++) {
383     gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
384     if (sscanf(nvalue(SECTION, n),
385 gregl 3.16 "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
386 gregl 3.29 &gp->orig[0], &gp->orig[1], &gp->orig[2],
387     &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
388     &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
389     &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
390     &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
391     badvalue(SECTION);
392     for (i = 0; i < 3; i++)
393 gregl 3.37 len[i] = VLEN(gp->xv[i]);
394     if (!vdef(GRID)) {
395 gwlarson 3.43 d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
396 gregl 3.37 len[2]*len[2] + 4*len[1]*len[2])
397     + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
398     + 4*len[0]*len[1]*len[2]*len[2] );
399     d = sqrt(sqrt(d));
400     } else if ((d = vflt(GRID)) <= FTINY)
401 gregl 3.29 badvalue(GRID);
402     for (i = 0; i < 3; i++)
403     if (gp->grid[i] <= 0)
404     gp->grid[i] = len[i]/d + (1.-FTINY);
405 gregl 3.15 }
406 gregl 3.1 }
407    
408    
409     creatholo(gp) /* create a holodeck output file */
410     HDGRID *gp;
411     {
412 gregl 3.12 extern char VersionID[];
413 gregl 3.29 int4 lastloc, nextloc;
414     int n;
415 gregl 3.10 int fd;
416 gregl 3.1 FILE *fp;
417     /* open & truncate file */
418     if ((fp = fopen(hdkfile, "w+")) == NULL) {
419     sprintf(errmsg, "cannot open \"%s\" for writing", hdkfile);
420     error(SYSTEM, errmsg);
421     }
422     /* write information header */
423     newheader("RADIANCE", fp);
424 gregl 3.12 fprintf(fp, "SOFTWARE= %s\n", VersionID);
425 gregl 3.1 printvars(fp);
426     fputformat(HOLOFMT, fp);
427     fputc('\n', fp);
428 gregl 3.29 putw(HOLOMAGIC, fp); /* put magic number */
429 gregl 3.10 fd = dup(fileno(fp));
430     fclose(fp); /* flush and close stdio stream */
431 gregl 3.29 lastloc = lseek(fd, 0L, 2);
432     for (n = vdef(SECTION); n--; gp++) { /* initialize each section */
433     nextloc = 0L;
434     write(fd, (char *)&nextloc, sizeof(nextloc));
435     hdinit(fd, gp); /* writes beam index */
436     if (!n)
437     break;
438     nextloc = hdfilen(fd); /* write section pointer */
439     if (lseek(fd, (long)lastloc, 0) < 0)
440     error(SYSTEM,
441     "cannot seek on holodeck file in creatholo");
442     write(fd, (char *)&nextloc, sizeof(nextloc));
443     lseek(fd, (long)(lastloc=nextloc), 0);
444     }
445 gregl 3.1 }
446    
447    
448 gwlarson 3.42 int
449 gregl 3.1 headline(s) /* process information header line */
450     char *s;
451     {
452     extern char FMTSTR[];
453     register char *cp;
454     char fmt[32];
455    
456 gregl 3.2 if (formatval(fmt, s)) {
457 gregl 3.1 if (strcmp(fmt, HOLOFMT)) {
458     sprintf(errmsg, "%s file \"%s\" has %s%s",
459     HOLOFMT, hdkfile, FMTSTR, fmt);
460     error(USER, errmsg);
461     }
462 gwlarson 3.42 return(0);
463 gregl 3.1 }
464     for (cp = s; *cp; cp++) /* take off any comments */
465     if (*cp == '#') {
466     *cp = '\0';
467     break;
468     }
469     setvariable(s, matchvar); /* don't flag errors */
470 gwlarson 3.42 return(0);
471 gregl 3.1 }
472    
473    
474     loadholo() /* start loading a holodeck from fname */
475     {
476 gregl 3.10 extern long ftell();
477 gregl 3.1 FILE *fp;
478 gregl 3.10 int fd;
479 gregl 3.29 int n;
480     int4 nextloc;
481 gregl 3.4 /* open holodeck file */
482     if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
483 gwlarson 3.39 sprintf(errmsg, "cannot %s \"%s\"",
484     ncprocs>0 ? "append" : "read", hdkfile);
485 gregl 3.1 error(SYSTEM, errmsg);
486     }
487     /* load variables from header */
488     getheader(fp, headline, NULL);
489     /* check magic number */
490     if (getw(fp) != HOLOMAGIC) {
491     sprintf(errmsg, "bad magic number in holodeck file \"%s\"",
492     hdkfile);
493     error(USER, errmsg);
494     }
495 gregl 3.29 nextloc = ftell(fp); /* get stdio position */
496 gregl 3.10 fd = dup(fileno(fp));
497     fclose(fp); /* done with stdio */
498 gregl 3.29 for (n = 0; nextloc > 0L; n++) { /* initialize each section */
499     lseek(fd, (long)nextloc, 0);
500     read(fd, (char *)&nextloc, sizeof(nextloc));
501     hdinit(fd, NULL);
502     }
503     if (n != vdef(SECTION)) {
504     sprintf(errmsg, "number of sections does not match %s setting",
505     vnam(SECTION));
506     error(WARNING, errmsg);
507     }
508 gregl 3.1 }
509    
510    
511     done_packets(pl) /* handle finished packets */
512     PACKET *pl;
513     {
514 gregl 3.13 static int n2flush = 0;
515 gregl 3.1 register PACKET *p;
516    
517     while (pl != NULL) {
518     p = pl; pl = p->next; p->next = NULL;
519     if (p->nr > 0) { /* add to holodeck */
520     bcopy((char *)p->ra,
521     (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
522     p->nr*sizeof(RAYVAL));
523     if (outdev != NULL) /* display it */
524 gregl 3.7 disp_packet((PACKHEAD *)p);
525 gwlarson 3.49 if (hdcachesize <= 0)
526 gregl 3.33 n2flush++;
527 gregl 3.6 nraysdone += p->nr;
528     npacksdone++;
529 gregl 3.33 p->nr = 0;
530 gregl 3.1 }
531 gregl 3.33 p->next = freepacks; /* push onto free list */
532 gregl 3.1 freepacks = p;
533 gregl 3.5 }
534 gwlarson 3.49 if (n2flush > RTFLUSH) {
535 gwlarson 3.46 if (outdev != NULL)
536     hdsync(NULL, 1);
537 gwlarson 3.41 else
538 gwlarson 3.46 hdflush(NULL);
539 gregl 3.13 n2flush = 0;
540 gregl 3.1 }
541     }
542    
543    
544     rootname(rn, fn) /* remove tail from end of fn */
545     register char *rn, *fn;
546     {
547     char *tp, *dp;
548    
549     for (tp = NULL, dp = rn; *rn = *fn++; rn++)
550 gregl 3.22 if (*rn == '/')
551 gregl 3.1 dp = rn;
552     else if (*rn == '.')
553     tp = rn;
554     if (tp != NULL && tp > dp)
555     *tp = '\0';
556     }
557    
558    
559     badvalue(vc) /* report bad variable value and exit */
560     int vc;
561     {
562     sprintf(errmsg, "bad value for variable '%s'", vnam(vc));
563     error(USER, errmsg);
564     }
565    
566    
567     eputs(s) /* put error message to stderr */
568     register char *s;
569     {
570     static int midline = 0;
571    
572     if (!*s)
573     return;
574     if (!midline++) { /* prepend line with program name */
575     fputs(progname, stderr);
576     fputs(": ", stderr);
577     }
578     fputs(s, stderr);
579     if (s[strlen(s)-1] == '\n') {
580     fflush(stderr);
581     midline = 0;
582     }
583     }
584    
585    
586     quit(ec) /* exit program gracefully */
587     int ec;
588     {
589     int status = 0;
590    
591 gregl 3.24 if (hdlist[0] != NULL) { /* close holodeck */
592 gregl 3.21 if (nprocs > 0)
593 gregl 3.24 status = done_rtrace(); /* calls hdsync() */
594 gregl 3.19 if (ncprocs > 0 && vdef(REPORT)) {
595     long fsiz, fuse;
596     fsiz = hdfilen(hdlist[0]->fd);
597     fuse = hdfiluse(hdlist[0]->fd, 1);
598     fprintf(stderr,
599 gregl 3.3 "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
600 gregl 3.19 hdkfile, fsiz/(1024.*1024.),
601     100.*(fsiz-fuse)/fsiz);
602     }
603 gregl 3.1 }
604 gregl 3.12 if (orig_mode >= 0) /* reset holodeck access mode */
605     fchmod(hdlist[0]->fd, orig_mode);
606 gregl 3.11 if (outdev != NULL) /* close display */
607     disp_close();
608 gregl 3.1 exit(ec ? ec : status); /* exit */
609     }