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"; |
15 |
|
#include "view.h" |
16 |
|
#include "vars.h" |
17 |
|
#include "netproc.h" |
18 |
+ |
/* default remote shell */ |
19 |
+ |
#ifdef _AUX_SOURCE |
20 |
+ |
#define REMSH "remsh" |
21 |
+ |
#else |
22 |
+ |
#define REMSH "rsh" |
23 |
+ |
#endif |
24 |
|
/* input variables */ |
25 |
|
#define HOST 0 /* rendering host machine */ |
26 |
|
#define RENDER 1 /* rendering options */ |
44 |
|
#define DISKSPACE 19 /* how much disk space to use */ |
45 |
|
#define RESOLUTION 20 /* desired final resolution */ |
46 |
|
#define EXPOSURE 21 /* how to compute exposure */ |
47 |
+ |
#define RSH 22 /* remote shell script or program */ |
48 |
|
|
49 |
< |
int NVARS = 22; /* total number of variables */ |
49 |
> |
int NVARS = 23; /* total number of variables */ |
50 |
|
|
51 |
|
VARIABLE vv[] = { /* variable-value pairs */ |
52 |
|
{"host", 4, 0, NULL, NULL}, |
71 |
|
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
72 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
73 |
|
{"EXPOSURE", 3, 0, NULL, onevalue}, |
74 |
+ |
{"RSH", 3, 0, NULL, onevalue}, |
75 |
|
}; |
76 |
|
|
77 |
|
#define SFNAME "STATUS" /* status file name */ |
92 |
|
int silent = 0; /* silent mode? */ |
93 |
|
int noaction = 0; /* take no action? */ |
94 |
|
|
95 |
+ |
char *remsh; /* remote shell program/script */ |
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? */ |
100 |
|
|
101 |
+ |
char arcargs[10240]; /* files to archive */ |
102 |
+ |
char *arcfirst, *arcnext; /* pointers to first and next argument */ |
103 |
+ |
|
104 |
|
struct pslot { |
105 |
|
int pid; /* process ID (0 if empty) */ |
106 |
|
int fout; /* output frame number */ |
108 |
|
} *pslot; /* process slots */ |
109 |
|
int npslots; /* number of process slots */ |
110 |
|
|
99 |
– |
int lastpid; /* ID of last completed background process */ |
100 |
– |
PSERVER *lastpserver; /* last process server used */ |
101 |
– |
|
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[]; |
176 |
|
argv[i] = vval(NEXTANIM); /* just change input file */ |
177 |
|
if (!silent) |
178 |
|
printargs(argc, argv, stdout); |
179 |
< |
execvp(progname, argv); /* pass to next */ |
180 |
< |
quit(1); /* shouldn't return */ |
179 |
> |
if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) |
180 |
> |
fprintf(stderr, "%s: command not found\n", progname); |
181 |
> |
else |
182 |
> |
execv(progname, argv); |
183 |
> |
quit(1); |
184 |
|
} |
185 |
|
quit(0); |
186 |
|
userr: |
191 |
|
|
192 |
|
getastat() /* check/set animation status */ |
193 |
|
{ |
194 |
< |
char buf[256]; |
194 |
> |
char sfname[256]; |
195 |
|
FILE *fp; |
196 |
|
|
197 |
< |
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
198 |
< |
if ((fp = fopen(buf, "r")) == NULL) { |
197 |
> |
sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); |
198 |
> |
if ((fp = fopen(sfname, "r")) == NULL) { |
199 |
|
if (errno != ENOENT) { |
200 |
< |
perror(buf); |
200 |
> |
perror(sfname); |
201 |
|
return(-1); |
202 |
|
} |
203 |
|
astat.rnext = astat.fnext = astat.tnext = 0; |
217 |
|
goto fmterr; |
218 |
|
fclose(fp); |
219 |
|
if (astat.pid != 0) { /* thinks it's still running */ |
220 |
< |
gethostname(buf, sizeof(buf)); |
205 |
< |
if (strcmp(buf, astat.host)) { |
220 |
> |
if (strcmp(myhostname(), astat.host)) { |
221 |
|
fprintf(stderr, |
222 |
|
"%s: process %d may still be running on host %s\n", |
223 |
|
progname, astat.pid, astat.host); |
230 |
|
} |
231 |
|
/* assume it is dead */ |
232 |
|
} |
233 |
< |
if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ |
233 |
> |
if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */ |
234 |
|
fprintf(stderr, "%s: unfinished job \"%s\"\n", |
235 |
|
progname, astat.cfname); |
236 |
|
return(-1); |
237 |
|
} |
238 |
+ |
/* check control file mods. */ |
239 |
+ |
if (!nowarn && fdate(cfname) > fdate(sfname)) |
240 |
+ |
fprintf(stderr, |
241 |
+ |
"%s: warning - control file modified since last run\n", |
242 |
+ |
progname); |
243 |
|
setours: /* set our values */ |
244 |
< |
gethostname(astat.host, sizeof(astat.host)); |
244 |
> |
strcpy(astat.host, myhostname()); |
245 |
|
astat.pid = getpid(); |
246 |
|
strcpy(astat.cfname, cfname); |
247 |
|
return(0); |
248 |
|
fmterr: |
249 |
|
fprintf(stderr, "%s: format error in status file \"%s\"\n", |
250 |
< |
progname, buf); |
250 |
> |
progname, sfname); |
251 |
|
fclose(fp); |
252 |
|
return(-1); |
253 |
|
} |
299 |
|
|
300 |
|
setdefaults() /* set default values */ |
301 |
|
{ |
302 |
+ |
extern char *atos(); |
303 |
+ |
int decades; |
304 |
|
char buf[256]; |
305 |
|
|
306 |
|
if (vdef(ANIMATE)) { |
334 |
|
quit(1); |
335 |
|
} |
336 |
|
if (!vdef(BASENAME)) { |
337 |
< |
sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); |
337 |
> |
decades = (int)log10((double)vint(END)) + 1; |
338 |
> |
if (decades < 3) decades = 3; |
339 |
> |
sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); |
340 |
|
vval(BASENAME) = savqstr(buf); |
341 |
|
vdef(BASENAME)++; |
342 |
|
} |
368 |
|
vval(DISKSPACE) = "100"; |
369 |
|
vdef(DISKSPACE)++; |
370 |
|
} |
371 |
+ |
if (!vdef(RSH)) { |
372 |
+ |
vval(RSH) = REMSH; |
373 |
+ |
vdef(RSH)++; |
374 |
+ |
} |
375 |
+ |
/* locate remote shell program */ |
376 |
+ |
atos(buf, sizeof(buf), vval(RSH)); |
377 |
+ |
if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) |
378 |
+ |
remsh = savqstr(remsh); |
379 |
+ |
else |
380 |
+ |
remsh = vval(RSH); /* will generate error if used */ |
381 |
+ |
|
382 |
|
/* append rendering options */ |
383 |
|
if (vdef(RENDER)) |
384 |
|
sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
< |
getradfile(rfname) /* run rad and get needed variables */ |
445 |
< |
char *rfname; |
444 |
> |
getradfile(rfargs) /* run rad and get needed variables */ |
445 |
> |
char *rfargs; |
446 |
|
{ |
447 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
448 |
|
char combuf[256]; |
452 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
453 |
|
sprintf(combuf, |
454 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
455 |
< |
rfname, rendopt+2); |
455 |
> |
rfargs, rendopt+2); |
456 |
|
cp = combuf; |
457 |
|
while (*cp) cp++; /* match unset variables */ |
458 |
|
for (i = 0; mvar[i] >= 0; i++) |
464 |
|
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
465 |
|
cp += 11; /* point to file name */ |
466 |
|
if (system(combuf)) { |
467 |
< |
fprintf(stderr, "%s: bad rad input file \"%s\"\n", |
468 |
< |
progname, rfname); |
467 |
> |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
468 |
> |
progname, combuf); |
469 |
|
quit(1); |
470 |
|
} |
471 |
|
loadvars(cp); /* load variables and remove file */ |
484 |
|
i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); |
485 |
|
mult = vflt(OVERSAMP); |
486 |
|
if (i == 3) { |
487 |
< |
sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres), |
487 |
> |
sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), |
488 |
|
(int)(mult*yres), pa); |
489 |
< |
sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa); |
489 |
> |
sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); |
490 |
|
} else if (i) { |
491 |
|
if (i == 1) yres = xres; |
492 |
|
sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), |
514 |
|
/* figure # frames per batch */ |
515 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
516 |
|
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
517 |
< |
d1 += mult*xres*mult*yres*4; /* space for z-buffer */ |
517 |
> |
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
518 |
|
d2 = xres*yres*4; /* space for final picture */ |
519 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
520 |
|
if (frames_batch < i+2) { |
522 |
|
progname); |
523 |
|
quit(1); |
524 |
|
} |
525 |
+ |
/* initialize archive argument list */ |
526 |
+ |
i = 16; |
527 |
+ |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) |
528 |
+ |
i = strlen(vval(ARCHIVE)); |
529 |
+ |
arcnext = arcfirst = arcargs + i; |
530 |
|
/* initialize status file */ |
531 |
|
if (astat.rnext == 0) |
532 |
|
astat.rnext = astat.fnext = astat.tnext = vint(START); |
621 |
|
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
622 |
|
} |
623 |
|
bwait(0); /* wait for filter processes */ |
624 |
< |
archive(astat.fnext, i-1); /* archive originals */ |
624 |
> |
archive(); /* archive originals */ |
625 |
|
astat.fnext = i; /* update status */ |
626 |
|
putastat(); |
627 |
|
} |
702 |
|
inspoint = combuf + strlen(combuf); |
703 |
|
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
704 |
|
/* run in parallel */ |
705 |
< |
if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) { |
705 |
> |
i = (last-first+1)/(vint(INTERP)+1); |
706 |
> |
if (i < 1) i = 1; |
707 |
> |
if (pruncom(combuf, inspoint, i)) { |
708 |
|
fprintf(stderr, "%s: error rendering frames %d through %d\n", |
709 |
|
progname, first, last); |
710 |
|
quit(1); |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
< |
archive(first, last) /* archive and remove renderings */ |
744 |
< |
int first, last; |
785 |
> |
archive() /* archive and remove renderings */ |
786 |
|
{ |
787 |
|
#define RMCOML (sizeof(rmcom)-1) |
788 |
|
static char rmcom[] = "rm -f"; |
748 |
– |
int offset = RMCOML; |
749 |
– |
char combuf[10240]; |
750 |
– |
struct stat stb; |
751 |
– |
register char *cp; |
789 |
|
register int i; |
790 |
|
|
791 |
< |
if (noaction) |
792 |
< |
return; |
756 |
< |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset) |
757 |
< |
offset = strlen(vval(ARCHIVE)); |
758 |
< |
cp = combuf + offset; |
759 |
< |
*cp++ = ' '; /* make argument list */ |
760 |
< |
for (i = first; i <= last; i++) { |
761 |
< |
sprintf(cp, vval(BASENAME), i); |
762 |
< |
strcat(cp, ".unf"); |
763 |
< |
if (stat(cp, &stb) == 0 && stb.st_size > 0) { /* non-zero? */ |
764 |
< |
while (*cp) cp++; |
765 |
< |
*cp++ = ' '; |
766 |
< |
sprintf(cp, vval(BASENAME), i); |
767 |
< |
strcat(cp, ".zbf"); |
768 |
< |
if (access(cp, F_OK) == 0) { /* exists? */ |
769 |
< |
while (*cp) cp++; |
770 |
< |
*cp++ = ' '; |
771 |
< |
} |
772 |
< |
} |
773 |
< |
} |
774 |
< |
*--cp = '\0'; |
775 |
< |
if (cp <= combuf + offset) /* no files? */ |
776 |
< |
return; |
791 |
> |
if (arcnext == arcfirst) |
792 |
> |
return; /* nothing to do */ |
793 |
|
if (vdef(ARCHIVE)) { /* run archive command */ |
794 |
|
i = strlen(vval(ARCHIVE)); |
795 |
< |
strncpy(combuf+offset-i, vval(ARCHIVE), i); |
796 |
< |
if (runcom(combuf+offset-i)) { |
797 |
< |
fprintf(stderr, |
798 |
< |
"%s: error running archive command on frames %d through %d\n", |
783 |
< |
progname, first, last); |
795 |
> |
strncpy(arcfirst-i, vval(ARCHIVE), i); |
796 |
> |
if (runcom(arcfirst-i)) { |
797 |
> |
fprintf(stderr, "%s: error running archive command\n", |
798 |
> |
progname); |
799 |
|
quit(1); |
800 |
|
} |
801 |
|
} |
802 |
|
/* run remove command */ |
803 |
< |
strncpy(combuf+offset-RMCOML, rmcom, RMCOML); |
804 |
< |
runcom(combuf+offset-RMCOML); |
803 |
> |
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
804 |
> |
runcom(arcfirst-RMCOML); |
805 |
> |
arcnext = arcfirst; /* reset argument list */ |
806 |
|
#undef RMCOML |
807 |
|
} |
808 |
|
|
815 |
|
int rvr; |
816 |
|
{ |
817 |
|
extern int frecover(); |
818 |
+ |
static int iter = 0; |
819 |
|
char fnbefore[128], fnafter[128]; |
820 |
< |
char combuf[1024], fname[128]; |
821 |
< |
int usepinterp, usepfilt; |
820 |
> |
char combuf[1024], fname0[128], fname1[128]; |
821 |
> |
int usepinterp, usepfilt, nora_rgbe; |
822 |
|
int frseq[2]; |
823 |
|
/* check what is needed */ |
824 |
|
usepinterp = atoi(vval(MBLUR)); |
825 |
|
usepfilt = pfiltalways | ep==NULL; |
826 |
+ |
if (ep != NULL && !strcmp(ep, "1")) |
827 |
+ |
ep = "+0"; |
828 |
+ |
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
829 |
+ |
*ep != '+' || *ep != '-' || !isint(ep); |
830 |
|
/* compute rendered views */ |
831 |
|
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
832 |
|
frseq[1] = frseq[0] + vint(INTERP) + 1; |
835 |
|
if (frseq[1] == frame) { /* pfilt only */ |
836 |
|
frseq[0] = frseq[1]; |
837 |
|
usepinterp = 0; /* update what's needed */ |
838 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
839 |
< |
} else if (frseq[0] == frame) { /* no interpolation */ |
840 |
< |
/* update what's needed */ |
841 |
< |
if (!usepinterp) |
842 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
838 |
> |
usepfilt |= nora_rgbe; |
839 |
> |
} else if (frseq[0] == frame) { /* no interpolation needed */ |
840 |
> |
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
841 |
> |
*arcnext++ = ' '; |
842 |
> |
sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); |
843 |
> |
while (*arcnext) arcnext++; |
844 |
> |
strcpy(arcnext, ".unf"); |
845 |
> |
arcnext += 4; |
846 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
847 |
> |
*arcnext++ = ' '; |
848 |
> |
sprintf(arcnext, vval(BASENAME), |
849 |
> |
frame-vint(INTERP)-1); |
850 |
> |
while (*arcnext) arcnext++; |
851 |
> |
strcpy(arcnext, ".zbf"); |
852 |
> |
arcnext += 4; |
853 |
> |
} |
854 |
> |
} |
855 |
> |
if (!usepinterp) /* update what's needed */ |
856 |
> |
usepfilt |= nora_rgbe; |
857 |
|
} else /* interpolation needed */ |
858 |
|
usepinterp++; |
859 |
|
if (frseq[1] >= astat.rnext) /* next batch unavailable */ |
868 |
|
return(1); |
869 |
|
if (atoi(vval(MBLUR))) { |
870 |
|
FILE *fp; /* motion blurring */ |
871 |
< |
sprintf(fname, "%s/vw0", vval(DIRECTORY)); |
872 |
< |
if (access(fname, F_OK) == 0) |
873 |
< |
sleep(10); |
874 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
840 |
< |
perror(fname); quit(1); |
871 |
> |
sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), |
872 |
> |
'a'+(iter%26)); |
873 |
> |
if ((fp = fopen(fname0, "w")) == NULL) { |
874 |
> |
perror(fname0); quit(1); |
875 |
|
} |
876 |
|
fputs(VIEWSTR, fp); |
877 |
|
fprintview(vp, fp); |
882 |
|
progname, frame+1); |
883 |
|
quit(1); |
884 |
|
} |
885 |
< |
sprintf(fname, "%s/vw1", vval(DIRECTORY)); |
886 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
887 |
< |
perror(fname); quit(1); |
885 |
> |
sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), |
886 |
> |
'a'+(iter%26)); |
887 |
> |
if ((fp = fopen(fname1, "w")) == NULL) { |
888 |
> |
perror(fname1); quit(1); |
889 |
|
} |
890 |
|
fputs(VIEWSTR, fp); |
891 |
|
fprintview(vp, fp); |
892 |
|
putc('\n', fp); fclose(fp); |
893 |
|
sprintf(combuf, |
894 |
< |
"(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B", |
894 |
> |
"(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", |
895 |
|
*sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", |
896 |
< |
atoi(vval(MBLUR)), vval(DIRECTORY), |
897 |
< |
vval(DIRECTORY), vval(DIRECTORY), |
898 |
< |
vval(DIRECTORY), vval(DIRECTORY)); |
896 |
> |
atoi(vval(MBLUR)), |
897 |
> |
fname0, fname1, fname0, fname1); |
898 |
> |
iter++; |
899 |
|
} else /* no blurring */ |
900 |
|
strcpy(combuf, "pinterp"); |
901 |
|
strcat(combuf, viewopt(vp)); |
942 |
|
} else { /* else just check it */ |
943 |
|
if (rvr == 2) |
944 |
|
return(1); |
945 |
< |
sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); |
945 |
> |
sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); |
946 |
|
} |
947 |
|
/* output file name */ |
948 |
< |
sprintf(fname, vval(BASENAME), frame); |
949 |
< |
sprintf(combuf+strlen(combuf), " > %s.pic", fname); |
948 |
> |
sprintf(fname0, vval(BASENAME), frame); |
949 |
> |
sprintf(combuf+strlen(combuf), " > %s.pic", fname0); |
950 |
|
if (rvr) /* in recovery */ |
951 |
|
return(runcom(combuf)); |
952 |
|
bruncom(combuf, frame, frecover); /* else run in background */ |
978 |
|
quit(1); |
979 |
|
} |
980 |
|
} else if (n < viewnum) { /* rewind file */ |
981 |
+ |
if (viewnum == 1 && feof(viewfp)) |
982 |
+ |
return(&curview); /* just one view */ |
983 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
984 |
|
perror(vval(VIEWFILE)); |
985 |
|
quit(1); |
989 |
|
} |
990 |
|
while (n > viewnum) { /* scan to desired view */ |
991 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
992 |
< |
return(NULL); |
992 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
993 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
994 |
|
viewnum++; |
995 |
|
} |
1022 |
|
if (n == 0) { /* signal to close file */ |
1023 |
|
if (expfp != NULL) { |
1024 |
|
fclose(expfp); |
1025 |
+ |
free((char *)exppos); |
1026 |
|
expfp = NULL; |
1027 |
|
} |
1028 |
|
return(NULL); |
1029 |
< |
} |
1029 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
1030 |
> |
return(NULL); |
1031 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
1032 |
|
return(NULL); |
1033 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
1065 |
|
} |
1066 |
|
curfrm++; |
1067 |
|
cp = fskip(expval); /* check format */ |
1068 |
< |
if (cp == NULL || *cp != '\n') { |
1068 |
> |
if (cp != NULL) |
1069 |
> |
while (isspace(*cp)) |
1070 |
> |
*cp++ = '\0'; |
1071 |
> |
if (cp == NULL || *cp) { |
1072 |
|
fprintf(stderr, |
1073 |
|
"%s: exposure format error on line %d\n", |
1074 |
|
vval(EXPOSURE), curfrm); |
1075 |
|
quit(1); |
1076 |
|
} |
1035 |
– |
*cp = '\0'; |
1077 |
|
} |
1078 |
|
return(expval); /* return value */ |
1079 |
|
} |
1103 |
|
int status; |
1104 |
|
{ |
1105 |
|
register PROC *pp; |
1106 |
+ |
register struct pslot *psl; |
1107 |
|
|
1108 |
|
pp = ps->proc + pn; |
1109 |
|
if (pp->elen) { /* pass errors */ |
1115 |
|
if (ps->hostname[0]) |
1116 |
|
status = 1; /* because rsh doesn't return status */ |
1117 |
|
} |
1118 |
+ |
lastpserver = NULL; |
1119 |
+ |
psl = findpslot(pp->pid); /* check for bruncom() slot */ |
1120 |
+ |
if (psl->pid) { |
1121 |
+ |
if (status) { |
1122 |
+ |
if (psl->rcvf != NULL) /* attempt recovery */ |
1123 |
+ |
status = (*psl->rcvf)(psl->fout); |
1124 |
+ |
if (status) { |
1125 |
+ |
fprintf(stderr, |
1126 |
+ |
"%s: error rendering frame %d\n", |
1127 |
+ |
progname, psl->fout); |
1128 |
+ |
quit(1); |
1129 |
+ |
} |
1130 |
+ |
lastpserver = ps; |
1131 |
+ |
} |
1132 |
+ |
psl->pid = 0; /* free process slot */ |
1133 |
+ |
} else if (status) |
1134 |
+ |
lastpserver = ps; |
1135 |
|
freestr(pp->com); /* free command string */ |
1077 |
– |
lastpid = pp->pid; /* record PID for bwait() */ |
1078 |
– |
lastpserver = ps; /* record server for serverdown() */ |
1136 |
|
return(status); |
1137 |
|
} |
1138 |
|
|
1140 |
|
int |
1141 |
|
serverdown() /* check status of last process server */ |
1142 |
|
{ |
1143 |
+ |
if (lastpserver == NULL || !lastpserver->hostname[0]) |
1144 |
+ |
return(0); |
1145 |
|
if (pserverOK(lastpserver)) /* server still up? */ |
1146 |
|
return(0); |
1147 |
|
delpserver(lastpserver); /* else delete it */ |
1168 |
|
printf("\t%s\n", com); /* echo command */ |
1169 |
|
return(0); |
1170 |
|
} |
1171 |
< |
/* else start it when we can */ |
1172 |
< |
while ((pid = startjob(NULL, savestr(com), donecom)) == -1) |
1171 |
> |
com = savestr(com); /* else start it when we can */ |
1172 |
> |
while ((pid = startjob(NULL, com, donecom)) == -1) |
1173 |
|
bwait(1); |
1174 |
|
if (!silent) { /* echo command */ |
1175 |
|
PSERVER *ps; |
1191 |
|
int ncoms; |
1192 |
|
{ |
1193 |
|
int status; |
1135 |
– |
register struct pslot *psl; |
1194 |
|
|
1195 |
|
if (noaction) |
1196 |
|
return; |
1197 |
|
while ((status = wait4job(NULL, -1)) != -1) { |
1198 |
< |
psl = findpslot(lastpid); |
1199 |
< |
if (status) { /* attempt recovery */ |
1200 |
< |
serverdown(); /* check server */ |
1143 |
< |
if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { |
1144 |
< |
fprintf(stderr, |
1145 |
< |
"%s: error rendering frame %d\n", |
1146 |
< |
progname, psl->fout); |
1147 |
< |
quit(1); |
1148 |
< |
} |
1149 |
< |
} |
1150 |
< |
psl->pid = 0; /* free process slot */ |
1151 |
< |
if (!--ncoms) |
1152 |
< |
return; /* done enough */ |
1198 |
> |
serverdown(); /* update server status */ |
1199 |
> |
if (--ncoms == 0) |
1200 |
> |
break; /* done enough */ |
1201 |
|
} |
1202 |
|
} |
1203 |
|
|
1209 |
|
{ |
1210 |
|
int retstatus = 0; |
1211 |
|
int hostcopies; |
1212 |
< |
char com1buf[10240], *com1, *endcom1; |
1212 |
> |
char buf[10240], *com1, *s; |
1213 |
|
int status; |
1214 |
+ |
int pfd; |
1215 |
+ |
register int n; |
1216 |
|
register PSERVER *ps; |
1217 |
|
|
1218 |
|
if (!silent) |
1219 |
< |
printf("\t%s &\n", com); /* echo command */ |
1219 |
> |
printf("\t%s\n", com); /* echo command */ |
1220 |
|
if (noaction) |
1221 |
|
return(0); |
1222 |
|
fflush(stdout); |
1224 |
|
for (ps = pslist; ps != NULL; ps = ps->next) { |
1225 |
|
hostcopies = 0; |
1226 |
|
if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { |
1227 |
< |
strcpy(com1=com1buf, com); /* build -PP command */ |
1227 |
> |
strcpy(com1=buf, com); /* build -PP command */ |
1228 |
|
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
1229 |
|
vval(DIRECTORY), phostname(ps)); |
1230 |
|
strcat(com1, ppins); |
1231 |
< |
endcom1 = com1 + strlen(com1); |
1182 |
< |
sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", |
1183 |
< |
vval(DIRECTORY), phostname(ps)); |
1184 |
< |
} else { |
1231 |
> |
} else |
1232 |
|
com1 = com; |
1233 |
< |
endcom1 = NULL; |
1233 |
> |
while (maxcopies > 0) { |
1234 |
> |
s = savestr(com1); |
1235 |
> |
if (startjob(ps, s, donecom) != -1) { |
1236 |
> |
sleep(20); |
1237 |
> |
hostcopies++; |
1238 |
> |
maxcopies--; |
1239 |
> |
} else { |
1240 |
> |
freestr(s); |
1241 |
> |
break; |
1242 |
> |
} |
1243 |
|
} |
1188 |
– |
while (maxcopies > 0 && |
1189 |
– |
startjob(ps, savestr(com1), donecom) != -1) { |
1190 |
– |
sleep(10); |
1191 |
– |
hostcopies++; |
1192 |
– |
maxcopies--; |
1193 |
– |
if (endcom1 != NULL) |
1194 |
– |
*endcom1 = '\0'; |
1195 |
– |
} |
1244 |
|
if (!silent && hostcopies) { |
1245 |
|
if (hostcopies > 1) |
1246 |
|
printf("\t%d duplicate processes", hostcopies); |
1252 |
|
} |
1253 |
|
/* wait for jobs to finish */ |
1254 |
|
while ((status = wait4job(NULL, -1)) != -1) |
1255 |
< |
if (status) |
1256 |
< |
retstatus += !serverdown(); /* check server */ |
1255 |
> |
retstatus += status && !serverdown(); |
1256 |
> |
/* terminate parallel rpict's */ |
1257 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
1258 |
> |
sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); |
1259 |
> |
if ((pfd = open(buf, O_RDONLY)) >= 0) { |
1260 |
> |
n = read(pfd, buf, sizeof(buf)-1); /* get PID */ |
1261 |
> |
buf[n] = '\0'; |
1262 |
> |
close(pfd); |
1263 |
> |
for (n = 0; buf[n] && !isspace(buf[n]); n++) |
1264 |
> |
; |
1265 |
> |
/* terminate */ |
1266 |
> |
sprintf(buf, "kill -ALRM %d", atoi(buf+n)); |
1267 |
> |
wait4job(ps, startjob(ps, buf, NULL)); |
1268 |
> |
} |
1269 |
> |
} |
1270 |
|
return(retstatus); |
1271 |
|
} |
1272 |
|
|