ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
(Generate patch)

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.11 by gregl, Wed Nov 19 17:56:47 1997 UTC vs.
Revision 3.14 by gregl, Mon Dec 1 16:34:21 1997 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ SGI";
9   */
10  
11   #include "rholo.h"
12 + #include "random.h"
13   #include "paths.h"
14 + #include <signal.h>
15   #include <sys/types.h>
16 + #include <sys/stat.h>
17  
18                          /* the following must be consistent with rholo.h */
19   int     NVARS = NRHVARS;                /* total number of variables */
# Line 38 | Line 41 | long   maxdisk;                /* maximum file space (bytes) */
41   int     rtargc = 1;             /* rtrace command */
42   char    *rtargv[128] = {"rtrace", NULL};
43  
44 + int     orig_mode = -1;         /* original file mode (-1 if unchanged) */
45 +
46   long    nraysdone = 0L;         /* number of rays done */
47   long    npacksdone = 0L;        /* number of packets done */
48  
49   PACKET  *freepacks;             /* available packets */
50  
51 + char  *sigerr[NSIG];            /* signal error messages */
52 +
53   extern time_t   time();
54  
55  
# Line 55 | Line 62 | char   *argv[];
62          int     force = 0;
63                                                  /* mark start time */
64          starttime = time(NULL);
65 +        initurand(10240);                       /* initialize urand */
66          progname = argv[0];                     /* get arguments */
67          for (i = 1; i < argc && argv[i][0] == '-'; i++)
68                  switch (argv[i][1]) {
# Line 125 | Line 133 | userr:
133   }
134  
135  
136 + onsig(signo)                            /* fatal signal */
137 + int  signo;
138 + {
139 +        static int  gotsig = 0;
140 +
141 +        if (gotsig++)                   /* two signals and we're gone! */
142 +                _exit(signo);
143 +
144 +        alarm(30);                      /* allow 30 seconds to clean up */
145 +        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
146 +        eputs("signal - ");
147 +        eputs(sigerr[signo]);
148 +        eputs("\n");
149 +        quit(3);
150 + }
151 +
152 +
153 + sigdie(signo, msg)                      /* set fatal signal */
154 + int  signo;
155 + char  *msg;
156 + {
157 +        if (signal(signo, onsig) == SIG_IGN)
158 +                signal(signo, SIG_IGN);
159 +        sigerr[signo] = msg;
160 + }
161 +
162 +
163 + int
164 + resfmode(fd, mod)               /* restrict open file access mode */
165 + int     fd, mod;
166 + {
167 +        struct stat     stbuf;
168 +                                        /* get original mode */
169 +        if (fstat(fd, &stbuf) < 0)
170 +                error(SYSTEM, "cannot stat open holodeck file");
171 +        mod &= stbuf.st_mode;           /* always more restrictive */
172 +        if (mod == stbuf.st_mode)
173 +                return(-1);             /* already set */
174 +                                        /* else change it */
175 +        if (fchmod(fd, mod) < 0) {
176 +                error(WARNING, "cannot change holodeck file access mode");
177 +                return(-1);
178 +        }
179 +        return(stbuf.st_mode);          /* return original mode */
180 + }
181 +
182 +
183   initrholo()                     /* get our holodeck running */
184   {
185          extern int      global_packet();
# Line 184 | Line 239 | initrholo()                    /* get our holodeck running */
239                          freepacks[i].next = &freepacks[i+1];
240                  }
241          }
242 +                                        /* set up signal handling */
243 +        sigdie(SIGINT, "Interrupt");
244 +        sigdie(SIGHUP, "Hangup");
245 +        sigdie(SIGTERM, "Terminate");
246 +        sigdie(SIGPIPE, "Broken pipe");
247 +        sigdie(SIGALRM, "Alarm clock");
248 + #ifdef  SIGXCPU
249 +        sigdie(SIGXCPU, "CPU limit exceeded");
250 +        sigdie(SIGXFSZ, "File size exceeded");
251 + #endif
252 +                                                /* protect holodeck file */
253 +        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
254          return;
255   memerr:
256          error(SYSTEM, "out of memory in initrholo");
# Line 304 | Line 371 | register HDGRID        *gp;
371                  vval(OBSTRUCTIONS) = "T";
372                  vdef(OBSTRUCTIONS)++;
373          }
374 +        if (!vdef(VDIST)) {
375 +                vval(VDIST) = "F";
376 +                vdef(VDIST)++;
377 +        }
378          if (!vdef(OCCUPANCY)) {
379                  vval(OCCUPANCY) = "U";
380                  vdef(OCCUPANCY)++;
# Line 317 | Line 388 | register HDGRID        *gp;
388   creatholo(gp)                   /* create a holodeck output file */
389   HDGRID  *gp;
390   {
391 +        extern char     VersionID[];
392          long    endloc = 0;
393          int     fd;
394          FILE    *fp;
# Line 327 | Line 399 | HDGRID *gp;
399          }
400                                          /* write information header */
401          newheader("RADIANCE", fp);
402 +        fprintf(fp, "SOFTWARE= %s\n", VersionID);
403          printvars(fp);
404          fputformat(HOLOFMT, fp);
405          fputc('\n', fp);
# Line 396 | Line 469 | loadholo()                     /* start loading a holodeck from fname */
469   done_packets(pl)                /* handle finished packets */
470   PACKET  *pl;
471   {
472 <        static int      nunflushed = 0;
472 >        static int      n2flush = 0;
473          register PACKET *p;
474  
475          while (pl != NULL) {
# Line 407 | Line 480 | PACKET *pl;
480                                  p->nr*sizeof(RAYVAL));
481                          if (outdev != NULL)     /* display it */
482                                  disp_packet((PACKHEAD *)p);
483 <                        else
484 <                                nunflushed += p->nr;
483 >                        if (hdcachesize <= 0)   /* manual flushing */
484 >                                n2flush += p->nr;
485                          nraysdone += p->nr;
486                          npacksdone++;
487                  }
# Line 416 | Line 489 | PACKET *pl;
489                  p->next = freepacks;
490                  freepacks = p;
491          }
492 <        if (nunflushed >= 256*RPACKSIZ) {
492 >        if (n2flush > 512*RPACKSIZ*ncprocs) {
493                  hdflush(NULL);                  /* flush holodeck buffers */
494 <                nunflushed = 0;
494 >                n2flush = 0;
495          }
496   }
497  
# Line 543 | Line 616 | int    ec;
616                  } else
617                          hdflush(NULL);
618          }
619 +        if (orig_mode >= 0)             /* reset holodeck access mode */
620 +                fchmod(hdlist[0]->fd, orig_mode);
621          if (outdev != NULL)             /* close display */
622                  disp_close();
623          exit(ec ? ec : status);         /* exit */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines