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

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.2 by greg, Thu Jan 18 11:25:11 1996 UTC vs.
Revision 2.18 by greg, Mon Jul 8 14:53:17 1996 UTC

# Line 1 | Line 1
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";
# Line 15 | Line 15 | 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 */
# Line 38 | Line 44 | static char SCCSid[] = "$SunId$ LBL";
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},
# Line 57 | Line 64 | VARIABLE       vv[] = {                /* variable-value pairs */
64          {"ANIMATE",     2,      0,      NULL,   onevalue},
65          {"TRANSFER",    2,      0,      NULL,   onevalue},
66          {"ARCHIVE",     2,      0,      NULL,   onevalue},
67 <        {"INTERP",      3,      0,      NULL,   intvalue},
68 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
67 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
69          {"MBLUR",       2,      0,      NULL,   onevalue},
70          {"RTRACE",      2,      0,      NULL,   boolvalue},
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 */
# Line 84 | Line 92 | int    nowarn = 0;             /* turn warnings off? */
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 */
# Line 96 | Line 108 | struct pslot {
108   }       *pslot;                 /* process slots */
109   int     npslots;                /* number of process slots */
110  
111 < int     lastpid;                /* ID of last completed background process */
100 < PSERVER *lastpserver;           /* last process server used */
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[];
# Line 161 | Line 176 | 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:
# Line 173 | Line 191 | 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;
# Line 199 | Line 217 | getastat()                     /* check/set animation status */
217                  goto fmterr;
218          fclose(fp);
219          if (astat.pid != 0) {                   /* thinks it's still running */
220 <                gethostname(buf, sizeof(buf));
203 <                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);
# Line 218 | Line 235 | getastat()                     /* check/set animation status */
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   }
# Line 277 | Line 299 | checkdir()                     /* make sure we have our directory */
299  
300   setdefaults()                   /* set default values */
301   {
302 +        extern char     *atos();
303          char    buf[256];
304  
305          if (vdef(ANIMATE)) {
# Line 300 | Line 323 | setdefaults()                  /* set default values */
323                  vdef(START)++;
324          }
325          if (!vdef(END)) {
326 <                sprintf(buf, "%d", countviews());
326 >                sprintf(buf, "%d", countviews()+vint(START)-1);
327                  vval(END) = savqstr(buf);
328                  vdef(END)++;
329          }
330 +        if (vint(END) < vint(START)) {
331 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
332 +                                progname);
333 +                quit(1);
334 +        }
335          if (!vdef(BASENAME)) {
336                  sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
337                  vval(BASENAME) = savqstr(buf);
# Line 337 | Line 365 | setdefaults()                  /* set default values */
365                  vval(DISKSPACE) = "100";
366                  vdef(DISKSPACE)++;
367          }
368 +        if (!vdef(RSH)) {
369 +                vval(RSH) = REMSH;
370 +                vdef(RSH)++;
371 +        }
372 +                                /* locate remote shell program */
373 +        atos(buf, sizeof(buf), vval(RSH));
374 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
375 +                remsh = savqstr(remsh);
376 +        else
377 +                remsh = vval(RSH);      /* will generate error if used */
378 +
379                                  /* append rendering options */
380          if (vdef(RENDER))
381                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 399 | Line 438 | sethosts()                     /* set up process servers */
438   }
439  
440  
441 < getradfile(rfname)              /* run rad and get needed variables */
442 < char    *rfname;
441 > getradfile(rfargs)              /* run rad and get needed variables */
442 > char    *rfargs;
443   {
444          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
445          char    combuf[256];
# Line 410 | Line 449 | char   *rfname;
449          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
450          sprintf(combuf,
451          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
452 <                        rfname, rendopt+2);
452 >                        rfargs, rendopt+2);
453          cp = combuf;
454          while (*cp) cp++;               /* match unset variables */
455          for (i = 0; mvar[i] >= 0; i++)
# Line 422 | Line 461 | char   *rfname;
461          sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
462          cp += 11;                       /* point to file name */
463          if (system(combuf)) {
464 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
465 <                                progname, rfname);
464 >                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
465 >                                progname, combuf);
466                  quit(1);
467          }
468          loadvars(cp);                   /* load variables and remove file */
# Line 442 | Line 481 | animate()                      /* run animation */
481          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
482          mult = vflt(OVERSAMP);
483          if (i == 3) {
484 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
484 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
485                                  (int)(mult*yres), pa);
486 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
486 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
487          } else if (i) {
488                  if (i == 1) yres = xres;
489                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 472 | Line 511 | animate()                      /* run animation */
511                                          /* figure # frames per batch */
512          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
513          if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
514 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
514 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
515          d2 = xres*yres*4;                       /* space for final picture */
516          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
517          if (frames_batch < i+2) {
# Line 480 | Line 519 | animate()                      /* run animation */
519                                  progname);
520                  quit(1);
521          }
522 +                                        /* initialize archive argument list */
523 +        i = 16;
524 +        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
525 +                i = strlen(vval(ARCHIVE));
526 +        arcnext = arcfirst = arcargs + i;
527                                          /* initialize status file */
528          if (astat.rnext == 0)
529                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 574 | Line 618 | filterframes()                         /* catch up with filtering */
618                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
619          }
620          bwait(0);                       /* wait for filter processes */
621 <        archive(astat.fnext, i-1);      /* archive originals */
621 >        archive();                      /* archive originals */
622          astat.fnext = i;                /* update status */
623          putastat();
624   }
# Line 636 | Line 680 | int    first, last;
680   char    *vfn;
681   {
682          char    combuf[2048];
683 +        char    *inspoint;
684          register int    i;
685  
686          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 646 | Line 691 | char   *vfn;
691                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
692                          }
693                                          /* create command */
694 <        sprintf(combuf, "rpict%s -w0 ", rendopt);
694 >        sprintf(combuf, "rpict%s -w0", rendopt);
695          if (vint(INTERP) || atoi(vval(MBLUR)))
696 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
697 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
698 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
696 >                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
697 >        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
698 >                        vval(BASENAME), rresopt, first);
699 >        inspoint = combuf + strlen(combuf);
700 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
701                                          /* run in parallel */
702 <        if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) {
702 >        i = (last-first+1)/(vint(INTERP)+1);
703 >        if (i < 1) i = 1;
704 >        if (pruncom(combuf, inspoint, i)) {
705                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
706                                  progname, first, last);
707                  quit(1);
# Line 730 | Line 779 | int    frame;
779   }
780  
781  
782 < archive(first, last)                    /* archive and remove renderings */
734 < int     first, last;
782 > archive()                       /* archive and remove renderings */
783   {
784   #define RMCOML  (sizeof(rmcom)-1)
785          static char     rmcom[] = "rm -f";
738        int     offset = RMCOML;
739        char    combuf[10240];
740        struct stat     stb;
741        register char   *cp;
786          register int    i;
787  
788 <        if (noaction)
789 <                return;
746 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
747 <                offset = strlen(vval(ARCHIVE));
748 <        cp = combuf + offset;
749 <        *cp++ = ' ';                            /* make argument list */
750 <        for (i = first; i <= last; i++) {
751 <                sprintf(cp, vval(BASENAME), i);
752 <                strcat(cp, ".unf");
753 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
754 <                        while (*cp) cp++;
755 <                        *cp++ = ' ';
756 <                        sprintf(cp, vval(BASENAME), i);
757 <                        strcat(cp, ".zbf");
758 <                        if (access(cp, F_OK) == 0) {            /* exists? */
759 <                                while (*cp) cp++;
760 <                                *cp++ = ' ';
761 <                        }
762 <                }
763 <        }
764 <        *--cp = '\0';
765 <        if (cp <= combuf + offset)              /* no files? */
766 <                return;
788 >        if (arcnext == arcfirst)
789 >                return;                         /* nothing to do */
790          if (vdef(ARCHIVE)) {                    /* run archive command */
791                  i = strlen(vval(ARCHIVE));
792 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
793 <                if (runcom(combuf+offset-i)) {
794 <                        fprintf(stderr,
795 <                "%s: error running archive command on frames %d through %d\n",
773 <                                        progname, first, last);
792 >                strncpy(arcfirst-i, vval(ARCHIVE), i);
793 >                if (runcom(arcfirst-i)) {
794 >                        fprintf(stderr, "%s: error running archive command\n",
795 >                                        progname);
796                          quit(1);
797                  }
798          }
799                                                  /* run remove command */
800 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
801 <        runcom(combuf+offset-RMCOML);
800 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
801 >        runcom(arcfirst-RMCOML);
802 >        arcnext = arcfirst;                     /* reset argument list */
803   #undef RMCOML
804   }
805  
# Line 789 | Line 812 | char   *ep;
812   int     rvr;
813   {
814          extern int      frecover();
815 +        static int      iter = 0;
816          char    fnbefore[128], fnafter[128];
817 <        char    combuf[1024], fname[128];
818 <        int     usepinterp, usepfilt;
817 >        char    combuf[1024], fname0[128], fname1[128];
818 >        int     usepinterp, usepfilt, nora_rgbe;
819          int     frseq[2];
820                                                  /* check what is needed */
821          usepinterp = atoi(vval(MBLUR));
822          usepfilt = pfiltalways | ep==NULL;
823 +        if (ep != NULL && !strcmp(ep, "1"))
824 +                ep = "+0";
825 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
826 +                        *ep != '+' || *ep != '-' || !isint(ep);
827                                                  /* compute rendered views */
828          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
829          frseq[1] = frseq[0] + vint(INTERP) + 1;
# Line 804 | Line 832 | int    rvr;
832          if (frseq[1] == frame) {                        /* pfilt only */
833                  frseq[0] = frseq[1];
834                  usepinterp = 0;                 /* update what's needed */
835 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
836 <        } else if (frseq[0] == frame) {         /* no interpolation */
837 <                                                /* update what's needed */
838 <                if (!usepinterp)
839 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
835 >                usepfilt |= nora_rgbe;
836 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
837 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
838 >                        *arcnext++ = ' ';
839 >                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
840 >                        while (*arcnext) arcnext++;
841 >                        strcpy(arcnext, ".unf");
842 >                        arcnext += 4;
843 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
844 >                                *arcnext++ = ' ';
845 >                                sprintf(arcnext, vval(BASENAME),
846 >                                                frame-vint(INTERP)-1);
847 >                                while (*arcnext) arcnext++;
848 >                                strcpy(arcnext, ".zbf");
849 >                                arcnext += 4;
850 >                        }
851 >                }
852 >                if (!usepinterp)                /* update what's needed */
853 >                        usepfilt |= nora_rgbe;
854          } else                                  /* interpolation needed */
855                  usepinterp++;
856          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 823 | Line 865 | int    rvr;
865                          return(1);
866                  if (atoi(vval(MBLUR))) {
867                          FILE    *fp;            /* motion blurring */
868 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
869 <                        if ((fp = fopen(fname, "w")) == NULL) {
870 <                                perror(fname); quit(1);
868 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
869 >                                        'a'+(iter%26));
870 >                        if ((fp = fopen(fname0, "w")) == NULL) {
871 >                                perror(fname0); quit(1);
872                          }
873                          fputs(VIEWSTR, fp);
874                          fprintview(vp, fp);
# Line 836 | Line 879 | int    rvr;
879                                                  progname, frame+1);
880                                  quit(1);
881                          }
882 <                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
883 <                        if ((fp = fopen(fname, "w")) == NULL) {
884 <                                perror(fname); quit(1);
882 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
883 >                                        'a'+(iter%26));
884 >                        if ((fp = fopen(fname1, "w")) == NULL) {
885 >                                perror(fname1); quit(1);
886                          }
887                          fputs(VIEWSTR, fp);
888                          fprintview(vp, fp);
889                          putc('\n', fp); fclose(fp);
890                          sprintf(combuf,
891 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
891 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
892                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
893 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
894 <                                        vval(DIRECTORY), vval(DIRECTORY),
895 <                                        vval(DIRECTORY), vval(DIRECTORY));
893 >                                        atoi(vval(MBLUR)),
894 >                                        fname0, fname1, fname0, fname1);
895 >                        iter++;
896                  } else                          /* no blurring */
897                          strcpy(combuf, "pinterp");
898                  strcat(combuf, viewopt(vp));
# Line 895 | Line 939 | int    rvr;
939          } else {                                /* else just check it */
940                  if (rvr == 2)
941                          return(1);
942 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
942 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
943          }
944                                                  /* output file name */
945 <        sprintf(fname, vval(BASENAME), frame);
946 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
945 >        sprintf(fname0, vval(BASENAME), frame);
946 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
947          if (rvr)                                /* in recovery */
948                  return(runcom(combuf));
949          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 931 | Line 975 | int    n;
975                          quit(1);
976                  }
977          } else if (n < viewnum) {       /* rewind file */
978 +                if (viewnum == 1 && feof(viewfp))
979 +                        return(&curview);               /* just one view */
980                  if (fseek(viewfp, 0L, 0) == EOF) {
981                          perror(vval(VIEWFILE));
982                          quit(1);
# Line 940 | Line 986 | int    n;
986          }
987          while (n > viewnum) {           /* scan to desired view */
988                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
989 <                        return(NULL);
989 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
990                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
991                          viewnum++;
992          }
# Line 973 | Line 1019 | int    n;
1019          if (n == 0) {                           /* signal to close file */
1020                  if (expfp != NULL) {
1021                          fclose(expfp);
1022 +                        free((char *)exppos);
1023                          expfp = NULL;
1024                  }
1025                  return(NULL);
1026 <        }
1026 >        } else if (n > vint(END))               /* request past end (error?) */
1027 >                return(NULL);
1028          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1029                  return(NULL);
1030          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1014 | Line 1062 | int    n;
1062                  }
1063                  curfrm++;
1064                  cp = fskip(expval);                     /* check format */
1065 <                if (cp == NULL || *cp != '\n') {
1065 >                if (cp != NULL)
1066 >                        while (isspace(*cp))
1067 >                                *cp++ = '\0';
1068 >                if (cp == NULL || *cp) {
1069                          fprintf(stderr,
1070                                  "%s: exposure format error on line %d\n",
1071                                          vval(EXPOSURE), curfrm);
1072                          quit(1);
1073                  }
1023                *cp = '\0';
1074          }
1075          return(expval);                         /* return value */
1076   }
# Line 1050 | Line 1100 | int    pn;
1100   int     status;
1101   {
1102          register PROC   *pp;
1103 +        register struct pslot   *psl;
1104  
1105          pp = ps->proc + pn;
1055        if (!silent) {                  /* echo command */
1056                if (ps->hostname[0])
1057                        printf("On %s:", ps->hostname);
1058                printf("\t%s\n", pp->com);
1059                fflush(stdout);
1060        }
1106          if (pp->elen) {                 /* pass errors */
1107 +                if (ps->hostname[0])
1108 +                        fprintf(stderr, "%s: ", ps->hostname);
1109 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1110                  fputs(pp->errs, stderr);
1111                  fflush(stderr);
1112                  if (ps->hostname[0])
1113                          status = 1;     /* because rsh doesn't return status */
1114          }
1115 +        lastpserver = NULL;
1116 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1117 +        if (psl->pid) {
1118 +                if (status) {
1119 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1120 +                                status = (*psl->rcvf)(psl->fout);
1121 +                        if (status) {
1122 +                                fprintf(stderr,
1123 +                                        "%s: error rendering frame %d\n",
1124 +                                                progname, psl->fout);
1125 +                                quit(1);
1126 +                        }
1127 +                        lastpserver = ps;
1128 +                }
1129 +                psl->pid = 0;                   /* free process slot */
1130 +        } else if (status)
1131 +                lastpserver = ps;
1132          freestr(pp->com);               /* free command string */
1068        lastpid = pp->pid;              /* record PID for bwait() */
1069        lastpserver = ps;               /* record server for serverdown() */
1133          return(status);
1134   }
1135  
# Line 1074 | Line 1137 | int    status;
1137   int
1138   serverdown()                    /* check status of last process server */
1139   {
1140 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1141 +                return(0);
1142          if (pserverOK(lastpserver))     /* server still up? */
1143                  return(0);
1144          delpserver(lastpserver);        /* else delete it */
# Line 1097 | Line 1162 | int    (*rf)();
1162  
1163          if (noaction) {
1164                  if (!silent)
1165 <                        printf("\t%s\n", com);  /* just echo it */
1165 >                        printf("\t%s\n", com);  /* echo command */
1166                  return(0);
1167          }
1168 <                                        /* else start it when we can */
1169 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1168 >        com = savestr(com);             /* else start it when we can */
1169 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1170                  bwait(1);
1171 +        if (!silent) {                          /* echo command */
1172 +                PSERVER *ps;
1173 +                int     psn = pid;
1174 +                ps = findjob(&psn);
1175 +                printf("\t%s\n", com);
1176 +                printf("\tProcess started on %s\n", phostname(ps));
1177 +                fflush(stdout);
1178 +        }
1179          psl = findpslot(pid);           /* record info. in appropriate slot */
1180          psl->pid = pid;
1181          psl->fout = fout;
# Line 1115 | Line 1188 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1188   int     ncoms;
1189   {
1190          int     status;
1118        register struct pslot   *psl;
1191  
1192          if (noaction)
1193                  return;
1194          while ((status = wait4job(NULL, -1)) != -1) {
1195 <                psl = findpslot(lastpid);
1196 <                if (status) {           /* attempt recovery */
1197 <                        serverdown();   /* check server */
1126 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1127 <                                fprintf(stderr,
1128 <                                        "%s: error rendering frame %d\n",
1129 <                                                progname, psl->fout);
1130 <                                quit(1);
1131 <                        }
1132 <                }
1133 <                psl->pid = 0;           /* free process slot */
1134 <                if (!--ncoms)
1135 <                        return;         /* done enough */
1195 >                serverdown();           /* update server status */
1196 >                if (--ncoms == 0)
1197 >                        break;          /* done enough */
1198          }
1199   }
1200  
1201  
1202   int
1203 < pruncom(com, maxcopies)         /* run a command in parallel over network */
1204 < char    *com;
1203 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1204 > char    *com, *ppins;
1205   int     maxcopies;
1206   {
1207          int     retstatus = 0;
1208 +        int     hostcopies;
1209 +        char    buf[10240], *com1, *s;
1210          int     status;
1211 +        int     pfd;
1212 +        register int    n;
1213          register PSERVER        *ps;
1214  
1215 <        if (noaction) {
1216 <                if (!silent)
1217 <                        printf("\t%s\n", com);  /* just echo */
1215 >        if (!silent)
1216 >                printf("\t%s\n", com);  /* echo command */
1217 >        if (noaction)
1218                  return(0);
1219 <        }
1219 >        fflush(stdout);
1220                                          /* start jobs on each server */
1221 <        for (ps = pslist; ps != NULL; ps = ps->next)
1222 <                while (maxcopies > 0 &&
1223 <                                startjob(ps, savestr(com), donecom) != -1) {
1224 <                        sleep(10);
1225 <                        maxcopies--;
1221 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1222 >                hostcopies = 0;
1223 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1224 >                        strcpy(com1=buf, com);  /* build -PP command */
1225 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1226 >                                        vval(DIRECTORY), phostname(ps));
1227 >                        strcat(com1, ppins);
1228 >                } else
1229 >                        com1 = com;
1230 >                while (maxcopies > 0) {
1231 >                        s = savestr(com1);
1232 >                        if (startjob(ps, s, donecom) != -1) {
1233 >                                sleep(20);
1234 >                                hostcopies++;
1235 >                                maxcopies--;
1236 >                        } else {
1237 >                                freestr(s);
1238 >                                break;
1239 >                        }
1240                  }
1241 +                if (!silent && hostcopies) {
1242 +                        if (hostcopies > 1)
1243 +                                printf("\t%d duplicate processes", hostcopies);
1244 +                        else
1245 +                                printf("\tProcess");
1246 +                        printf(" started on %s\n", phostname(ps));
1247 +                        fflush(stdout);
1248 +                }
1249 +        }
1250                                          /* wait for jobs to finish */
1251          while ((status = wait4job(NULL, -1)) != -1)
1252 <                if (status)
1253 <                        retstatus += !serverdown();     /* check server */
1252 >                retstatus += status && !serverdown();
1253 >                                        /* terminate parallel rpict's */
1254 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1255 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1256 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1257 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1258 >                        buf[n] = '\0';
1259 >                        close(pfd);
1260 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1261 >                                ;
1262 >                                                                /* terminate */
1263 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1264 >                        wait4job(ps, startjob(ps, buf, NULL));
1265 >                }
1266 >        }
1267          return(retstatus);
1268   }
1269  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines