| 10 |
|
|
| 11 |
|
#include "rholo.h" |
| 12 |
|
#include "paths.h" |
| 13 |
+ |
#include <signal.h> |
| 14 |
|
#include <sys/types.h> |
| 15 |
+ |
#include <sys/stat.h> |
| 16 |
|
|
| 17 |
|
/* the following must be consistent with rholo.h */ |
| 18 |
|
int NVARS = NRHVARS; /* total number of variables */ |
| 40 |
|
int rtargc = 1; /* rtrace command */ |
| 41 |
|
char *rtargv[128] = {"rtrace", NULL}; |
| 42 |
|
|
| 43 |
+ |
int orig_mode = -1; /* original file mode (-1 if unchanged) */ |
| 44 |
+ |
|
| 45 |
|
long nraysdone = 0L; /* number of rays done */ |
| 46 |
|
long npacksdone = 0L; /* number of packets done */ |
| 47 |
|
|
| 48 |
|
PACKET *freepacks; /* available packets */ |
| 49 |
|
|
| 50 |
+ |
char *sigerr[NSIG]; /* signal error messages */ |
| 51 |
+ |
|
| 52 |
|
extern time_t time(); |
| 53 |
|
|
| 54 |
|
|
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
+ |
onsig(signo) /* fatal signal */ |
| 135 |
+ |
int signo; |
| 136 |
+ |
{ |
| 137 |
+ |
static int gotsig = 0; |
| 138 |
+ |
|
| 139 |
+ |
if (gotsig++) /* two signals and we're gone! */ |
| 140 |
+ |
_exit(signo); |
| 141 |
+ |
|
| 142 |
+ |
alarm(30); /* allow 30 seconds to clean up */ |
| 143 |
+ |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 144 |
+ |
eputs("signal - "); |
| 145 |
+ |
eputs(sigerr[signo]); |
| 146 |
+ |
eputs("\n"); |
| 147 |
+ |
quit(3); |
| 148 |
+ |
} |
| 149 |
+ |
|
| 150 |
+ |
|
| 151 |
+ |
sigdie(signo, msg) /* set fatal signal */ |
| 152 |
+ |
int signo; |
| 153 |
+ |
char *msg; |
| 154 |
+ |
{ |
| 155 |
+ |
if (signal(signo, onsig) == SIG_IGN) |
| 156 |
+ |
signal(signo, SIG_IGN); |
| 157 |
+ |
sigerr[signo] = msg; |
| 158 |
+ |
} |
| 159 |
+ |
|
| 160 |
+ |
|
| 161 |
+ |
int |
| 162 |
+ |
resfmode(fd, mod) /* restrict open file access mode */ |
| 163 |
+ |
int fd, mod; |
| 164 |
+ |
{ |
| 165 |
+ |
struct stat stbuf; |
| 166 |
+ |
/* get original mode */ |
| 167 |
+ |
if (fstat(fd, &stbuf) < 0) |
| 168 |
+ |
error(SYSTEM, "cannot stat open holodeck file"); |
| 169 |
+ |
mod &= stbuf.st_mode; /* always more restrictive */ |
| 170 |
+ |
if (mod == stbuf.st_mode) |
| 171 |
+ |
return(-1); /* already set */ |
| 172 |
+ |
/* else change it */ |
| 173 |
+ |
if (fchmod(fd, mod) < 0) { |
| 174 |
+ |
error(WARNING, "cannot change holodeck file access mode"); |
| 175 |
+ |
return(-1); |
| 176 |
+ |
} |
| 177 |
+ |
return(stbuf.st_mode); /* return original mode */ |
| 178 |
+ |
} |
| 179 |
+ |
|
| 180 |
+ |
|
| 181 |
|
initrholo() /* get our holodeck running */ |
| 182 |
|
{ |
| 183 |
|
extern int global_packet(); |
| 237 |
|
freepacks[i].next = &freepacks[i+1]; |
| 238 |
|
} |
| 239 |
|
} |
| 240 |
+ |
/* set up signal handling */ |
| 241 |
+ |
sigdie(SIGINT, "Interrupt"); |
| 242 |
+ |
sigdie(SIGHUP, "Hangup"); |
| 243 |
+ |
sigdie(SIGTERM, "Terminate"); |
| 244 |
+ |
sigdie(SIGPIPE, "Broken pipe"); |
| 245 |
+ |
sigdie(SIGALRM, "Alarm clock"); |
| 246 |
+ |
#ifdef SIGXCPU |
| 247 |
+ |
sigdie(SIGXCPU, "CPU limit exceeded"); |
| 248 |
+ |
sigdie(SIGXFSZ, "File size exceeded"); |
| 249 |
+ |
#endif |
| 250 |
+ |
/* protect holodeck file */ |
| 251 |
+ |
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
| 252 |
|
return; |
| 253 |
|
memerr: |
| 254 |
|
error(SYSTEM, "out of memory in initrholo"); |
| 382 |
|
creatholo(gp) /* create a holodeck output file */ |
| 383 |
|
HDGRID *gp; |
| 384 |
|
{ |
| 385 |
+ |
extern char VersionID[]; |
| 386 |
|
long endloc = 0; |
| 387 |
|
int fd; |
| 388 |
|
FILE *fp; |
| 393 |
|
} |
| 394 |
|
/* write information header */ |
| 395 |
|
newheader("RADIANCE", fp); |
| 396 |
+ |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 397 |
|
printvars(fp); |
| 398 |
|
fputformat(HOLOFMT, fp); |
| 399 |
|
fputc('\n', fp); |
| 610 |
|
} else |
| 611 |
|
hdflush(NULL); |
| 612 |
|
} |
| 613 |
+ |
if (orig_mode >= 0) /* reset holodeck access mode */ |
| 614 |
+ |
fchmod(hdlist[0]->fd, orig_mode); |
| 615 |
|
if (outdev != NULL) /* close display */ |
| 616 |
|
disp_close(); |
| 617 |
|
exit(ec ? ec : status); /* exit */ |