1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
93 |
|
int noaction = 0; /* take no action? */ |
94 |
|
|
95 |
|
char *remsh; /* remote shell program/script */ |
96 |
< |
char rendopt[2048] = ""; /* rendering options */ |
96 |
> |
char rendopt[2048]; /* rendering options */ |
97 |
|
char rresopt[32]; /* rendering resolution options */ |
98 |
|
char fresopt[32]; /* filter resolution options */ |
99 |
|
int pfiltalways; /* always use pfilt? */ |
108 |
|
} *pslot; /* process slots */ |
109 |
|
int npslots; /* number of process slots */ |
110 |
|
|
111 |
– |
int lastpid; /* ID of last completed background process */ |
112 |
– |
PSERVER *lastpserver; /* last process server used */ |
113 |
– |
|
111 |
|
#define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) |
112 |
|
|
113 |
|
struct pslot *findpslot(); |
114 |
|
|
115 |
+ |
PSERVER *lastpserver; /* last process server with error */ |
116 |
+ |
|
117 |
|
VIEW *getview(); |
118 |
|
char *getexp(); |
119 |
|
|
120 |
+ |
extern time_t fdate(), time(); |
121 |
|
|
122 |
+ |
|
123 |
|
main(argc, argv) |
124 |
|
int argc; |
125 |
|
char *argv[]; |
150 |
|
cfname = argv[i]; |
151 |
|
/* load variables */ |
152 |
|
loadvars(cfname); |
153 |
+ |
/* check variables */ |
154 |
+ |
checkvalues(); |
155 |
|
/* did we get DIRECTORY? */ |
156 |
|
checkdir(); |
157 |
|
/* check status */ |
178 |
|
argv[i] = vval(NEXTANIM); /* just change input file */ |
179 |
|
if (!silent) |
180 |
|
printargs(argc, argv, stdout); |
181 |
< |
execvp(progname, argv); /* pass to next */ |
182 |
< |
quit(1); /* shouldn't return */ |
181 |
> |
if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) |
182 |
> |
fprintf(stderr, "%s: command not found\n", progname); |
183 |
> |
else |
184 |
> |
execv(progname, argv); |
185 |
> |
quit(1); |
186 |
|
} |
187 |
|
quit(0); |
188 |
|
userr: |
193 |
|
|
194 |
|
getastat() /* check/set animation status */ |
195 |
|
{ |
196 |
< |
char buf[256]; |
196 |
> |
char sfname[256]; |
197 |
|
FILE *fp; |
198 |
|
|
199 |
< |
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
200 |
< |
if ((fp = fopen(buf, "r")) == NULL) { |
199 |
> |
sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); |
200 |
> |
if ((fp = fopen(sfname, "r")) == NULL) { |
201 |
|
if (errno != ENOENT) { |
202 |
< |
perror(buf); |
202 |
> |
perror(sfname); |
203 |
|
return(-1); |
204 |
|
} |
205 |
|
astat.rnext = astat.fnext = astat.tnext = 0; |
232 |
|
} |
233 |
|
/* assume it is dead */ |
234 |
|
} |
235 |
< |
if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ |
235 |
> |
if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */ |
236 |
|
fprintf(stderr, "%s: unfinished job \"%s\"\n", |
237 |
|
progname, astat.cfname); |
238 |
|
return(-1); |
239 |
|
} |
240 |
+ |
/* check control file mods. */ |
241 |
+ |
if (!nowarn && fdate(cfname) > fdate(sfname)) |
242 |
+ |
fprintf(stderr, |
243 |
+ |
"%s: warning - control file modified since last run\n", |
244 |
+ |
progname); |
245 |
|
setours: /* set our values */ |
246 |
|
strcpy(astat.host, myhostname()); |
247 |
|
astat.pid = getpid(); |
249 |
|
return(0); |
250 |
|
fmterr: |
251 |
|
fprintf(stderr, "%s: format error in status file \"%s\"\n", |
252 |
< |
progname, buf); |
252 |
> |
progname, sfname); |
253 |
|
fclose(fp); |
254 |
|
return(-1); |
255 |
|
} |
302 |
|
setdefaults() /* set default values */ |
303 |
|
{ |
304 |
|
extern char *atos(); |
305 |
+ |
int decades; |
306 |
|
char buf[256]; |
307 |
|
|
308 |
|
if (vdef(ANIMATE)) { |
336 |
|
quit(1); |
337 |
|
} |
338 |
|
if (!vdef(BASENAME)) { |
339 |
< |
sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); |
339 |
> |
decades = (int)log10((double)vint(END)) + 1; |
340 |
> |
if (decades < 3) decades = 3; |
341 |
> |
sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); |
342 |
|
vval(BASENAME) = savqstr(buf); |
343 |
|
vdef(BASENAME)++; |
344 |
|
} |
486 |
|
i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); |
487 |
|
mult = vflt(OVERSAMP); |
488 |
|
if (i == 3) { |
489 |
< |
sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres), |
489 |
> |
sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), |
490 |
|
(int)(mult*yres), pa); |
491 |
< |
sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa); |
491 |
> |
sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); |
492 |
|
} else if (i) { |
493 |
|
if (i == 1) yres = xres; |
494 |
|
sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), |
516 |
|
/* figure # frames per batch */ |
517 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
518 |
|
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
519 |
< |
d1 += mult*xres*mult*yres*4; /* space for z-buffer */ |
519 |
> |
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
520 |
|
d2 = xres*yres*4; /* space for final picture */ |
521 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
522 |
|
if (frames_batch < i+2) { |
845 |
|
while (*arcnext) arcnext++; |
846 |
|
strcpy(arcnext, ".unf"); |
847 |
|
arcnext += 4; |
848 |
< |
if (usepinterp || vint(INTERP)) { /* and z-buf */ |
848 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
849 |
|
*arcnext++ = ' '; |
850 |
|
sprintf(arcnext, vval(BASENAME), |
851 |
|
frame-vint(INTERP)-1); |
903 |
|
strcat(combuf, viewopt(vp)); |
904 |
|
if (vbool(RTRACE)) |
905 |
|
sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", |
906 |
< |
rendopt, vval(OCTREE)); |
906 |
> |
rendopt+1, vval(OCTREE)); |
907 |
|
if (vdef(PINTERP)) |
908 |
|
sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); |
909 |
|
if (usepfilt) |
991 |
|
} |
992 |
|
while (n > viewnum) { /* scan to desired view */ |
993 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
994 |
< |
return(viewnum==1 ? &curview : NULL); |
994 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
995 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
996 |
|
viewnum++; |
997 |
|
} |
1024 |
|
if (n == 0) { /* signal to close file */ |
1025 |
|
if (expfp != NULL) { |
1026 |
|
fclose(expfp); |
1027 |
+ |
free((char *)exppos); |
1028 |
|
expfp = NULL; |
1029 |
|
} |
1030 |
|
return(NULL); |
1031 |
< |
} |
1031 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
1032 |
> |
return(NULL); |
1033 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
1034 |
|
return(NULL); |
1035 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
1067 |
|
} |
1068 |
|
curfrm++; |
1069 |
|
cp = fskip(expval); /* check format */ |
1070 |
< |
if (cp == NULL || *cp != '\n') { |
1070 |
> |
if (cp != NULL) |
1071 |
> |
while (isspace(*cp)) |
1072 |
> |
*cp++ = '\0'; |
1073 |
> |
if (cp == NULL || *cp) { |
1074 |
|
fprintf(stderr, |
1075 |
|
"%s: exposure format error on line %d\n", |
1076 |
|
vval(EXPOSURE), curfrm); |
1077 |
|
quit(1); |
1078 |
|
} |
1060 |
– |
*cp = '\0'; |
1079 |
|
} |
1080 |
|
return(expval); /* return value */ |
1081 |
|
} |
1105 |
|
int status; |
1106 |
|
{ |
1107 |
|
register PROC *pp; |
1108 |
+ |
register struct pslot *psl; |
1109 |
|
|
1110 |
|
pp = ps->proc + pn; |
1111 |
|
if (pp->elen) { /* pass errors */ |
1117 |
|
if (ps->hostname[0]) |
1118 |
|
status = 1; /* because rsh doesn't return status */ |
1119 |
|
} |
1120 |
+ |
lastpserver = NULL; |
1121 |
+ |
psl = findpslot(pp->pid); /* check for bruncom() slot */ |
1122 |
+ |
if (psl->pid) { |
1123 |
+ |
if (status) { |
1124 |
+ |
if (psl->rcvf != NULL) /* attempt recovery */ |
1125 |
+ |
status = (*psl->rcvf)(psl->fout); |
1126 |
+ |
if (status) { |
1127 |
+ |
fprintf(stderr, |
1128 |
+ |
"%s: error rendering frame %d\n", |
1129 |
+ |
progname, psl->fout); |
1130 |
+ |
quit(1); |
1131 |
+ |
} |
1132 |
+ |
lastpserver = ps; |
1133 |
+ |
} |
1134 |
+ |
psl->pid = 0; /* free process slot */ |
1135 |
+ |
} else if (status) |
1136 |
+ |
lastpserver = ps; |
1137 |
|
freestr(pp->com); /* free command string */ |
1102 |
– |
lastpid = pp->pid; /* record PID for bwait() */ |
1103 |
– |
lastpserver = ps; /* record server for serverdown() */ |
1138 |
|
return(status); |
1139 |
|
} |
1140 |
|
|
1142 |
|
int |
1143 |
|
serverdown() /* check status of last process server */ |
1144 |
|
{ |
1145 |
+ |
if (lastpserver == NULL || !lastpserver->hostname[0]) |
1146 |
+ |
return(0); |
1147 |
|
if (pserverOK(lastpserver)) /* server still up? */ |
1148 |
|
return(0); |
1149 |
|
delpserver(lastpserver); /* else delete it */ |
1170 |
|
printf("\t%s\n", com); /* echo command */ |
1171 |
|
return(0); |
1172 |
|
} |
1173 |
< |
/* else start it when we can */ |
1174 |
< |
while ((pid = startjob(NULL, savestr(com), donecom)) == -1) |
1173 |
> |
com = savestr(com); /* else start it when we can */ |
1174 |
> |
while ((pid = startjob(NULL, com, donecom)) == -1) |
1175 |
|
bwait(1); |
1176 |
|
if (!silent) { /* echo command */ |
1177 |
|
PSERVER *ps; |
1193 |
|
int ncoms; |
1194 |
|
{ |
1195 |
|
int status; |
1160 |
– |
register struct pslot *psl; |
1196 |
|
|
1197 |
|
if (noaction) |
1198 |
|
return; |
1199 |
|
while ((status = wait4job(NULL, -1)) != -1) { |
1200 |
< |
psl = findpslot(lastpid); |
1201 |
< |
if (status) { /* attempt recovery */ |
1202 |
< |
serverdown(); /* check server */ |
1168 |
< |
if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { |
1169 |
< |
fprintf(stderr, |
1170 |
< |
"%s: error rendering frame %d\n", |
1171 |
< |
progname, psl->fout); |
1172 |
< |
quit(1); |
1173 |
< |
} |
1174 |
< |
} |
1175 |
< |
psl->pid = 0; /* free process slot */ |
1176 |
< |
if (!--ncoms) |
1177 |
< |
return; /* done enough */ |
1200 |
> |
serverdown(); /* update server status */ |
1201 |
> |
if (--ncoms == 0) |
1202 |
> |
break; /* done enough */ |
1203 |
|
} |
1204 |
|
} |
1205 |
|
|
1211 |
|
{ |
1212 |
|
int retstatus = 0; |
1213 |
|
int hostcopies; |
1214 |
< |
char com1buf[10240], *com1, *endcom1; |
1214 |
> |
char buf[10240], *com1, *s; |
1215 |
|
int status; |
1216 |
+ |
int pfd; |
1217 |
+ |
register int n; |
1218 |
|
register PSERVER *ps; |
1219 |
|
|
1220 |
|
if (!silent) |
1226 |
|
for (ps = pslist; ps != NULL; ps = ps->next) { |
1227 |
|
hostcopies = 0; |
1228 |
|
if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { |
1229 |
< |
strcpy(com1=com1buf, com); /* build -PP command */ |
1229 |
> |
strcpy(com1=buf, com); /* build -PP command */ |
1230 |
|
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
1231 |
|
vval(DIRECTORY), phostname(ps)); |
1232 |
|
strcat(com1, ppins); |
1233 |
< |
endcom1 = com1 + strlen(com1); |
1207 |
< |
sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", |
1208 |
< |
vval(DIRECTORY), phostname(ps)); |
1209 |
< |
} else { |
1233 |
> |
} else |
1234 |
|
com1 = com; |
1235 |
< |
endcom1 = NULL; |
1235 |
> |
while (maxcopies > 0) { |
1236 |
> |
s = savestr(com1); |
1237 |
> |
if (startjob(ps, s, donecom) != -1) { |
1238 |
> |
sleep(20); |
1239 |
> |
hostcopies++; |
1240 |
> |
maxcopies--; |
1241 |
> |
} else { |
1242 |
> |
freestr(s); |
1243 |
> |
break; |
1244 |
> |
} |
1245 |
|
} |
1213 |
– |
while (maxcopies > 0 && |
1214 |
– |
startjob(ps, savestr(com1), donecom) != -1) { |
1215 |
– |
sleep(10); |
1216 |
– |
hostcopies++; |
1217 |
– |
maxcopies--; |
1218 |
– |
if (endcom1 != NULL) |
1219 |
– |
*endcom1 = '\0'; |
1220 |
– |
} |
1246 |
|
if (!silent && hostcopies) { |
1247 |
|
if (hostcopies > 1) |
1248 |
|
printf("\t%d duplicate processes", hostcopies); |
1254 |
|
} |
1255 |
|
/* wait for jobs to finish */ |
1256 |
|
while ((status = wait4job(NULL, -1)) != -1) |
1257 |
< |
if (status) |
1258 |
< |
retstatus += !serverdown(); /* check server */ |
1257 |
> |
retstatus += status && !serverdown(); |
1258 |
> |
/* terminate parallel rpict's */ |
1259 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
1260 |
> |
sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); |
1261 |
> |
if ((pfd = open(buf, O_RDONLY)) >= 0) { |
1262 |
> |
n = read(pfd, buf, sizeof(buf)-1); /* get PID */ |
1263 |
> |
buf[n] = '\0'; |
1264 |
> |
close(pfd); |
1265 |
> |
for (n = 0; buf[n] && !isspace(buf[n]); n++) |
1266 |
> |
; |
1267 |
> |
/* terminate */ |
1268 |
> |
sprintf(buf, "kill -ALRM %d", atoi(buf+n)); |
1269 |
> |
wait4job(ps, startjob(ps, buf, NULL)); |
1270 |
> |
} |
1271 |
> |
} |
1272 |
|
return(retstatus); |
1273 |
|
} |
1274 |
|
|