| 1 | – | /* Copyright (c) 1997 Silicon Graphics, Inc. */ | 
| 2 | – |  | 
| 1 |  | #ifndef lint | 
| 2 | < | static char SCCSid[] = "$SunId$ SGI"; | 
| 2 | > | static const char       RCSid[] = "$Id$"; | 
| 3 |  | #endif | 
| 6 | – |  | 
| 4 |  | /* | 
| 5 |  | * Routines for local rtrace execution | 
| 6 |  | */ | 
| 13 |  | #include <sys/time.h> | 
| 14 |  |  | 
| 15 |  | #ifndef MAXPROC | 
| 16 | < | #define MAXPROC         16 | 
| 16 | > | #define MAXPROC         64 | 
| 17 |  | #endif | 
| 18 |  |  | 
| 19 | + | int     nprocs = 0;                             /* running process count */ | 
| 20 | + |  | 
| 21 |  | static char     pfile[] = TEMPLATE;             /* persist file name */ | 
| 22 |  |  | 
| 23 |  | static int      rtpd[MAXPROC][3];               /* process descriptors */ | 
| 24 |  | static float    *rtbuf = NULL;                  /* allocated i/o buffer */ | 
| 25 |  | static int      maxqlen = 0;                    /* maximum packets per queue */ | 
| 27 | – | static int      nprocs = 0;                     /* number of processes */ | 
| 26 |  |  | 
| 27 |  | static PACKET   *pqueue[MAXPROC];               /* packet queues */ | 
| 28 |  | static int      pqlen[MAXPROC];                 /* packet queue lengths */ | 
| 33 |  | { | 
| 34 |  | static char     buf1[8]; | 
| 35 |  | int     rmaxpack = 0; | 
| 36 | < | int     psiz, npt, n; | 
| 36 | > | int     psiz, n; | 
| 37 |  | /* get number of processes */ | 
| 38 | < | if ((npt = ncprocs) <= 0) | 
| 38 | > | if (ncprocs <= 0 || nprocs > 0) | 
| 39 |  | return(0); | 
| 40 | < | if (npt > MAXPROC) { | 
| 40 | > | if (ncprocs > MAXPROC) { | 
| 41 |  | sprintf(errmsg, | 
| 42 |  | "number of rtrace processes reduced from %d to %d", | 
| 43 | < | npt, MAXPROC); | 
| 43 | > | ncprocs, MAXPROC); | 
| 44 |  | error(WARNING, errmsg); | 
| 45 | < | npt = MAXPROC; | 
| 45 | > | ncprocs = MAXPROC; | 
| 46 |  | } | 
| 47 | < | /* add compulsory options */ | 
| 48 | < | rtargv[rtargc++] = "-i-"; | 
| 49 | < | rtargv[rtargc++] = "-I-"; | 
| 50 | < | rtargv[rtargc++] = "-h-"; | 
| 51 | < | rtargv[rtargc++] = "-ld-"; | 
| 52 | < | sprintf(buf1, "%d", RPACKSIZ); | 
| 53 | < | rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; | 
| 54 | < | rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; | 
| 55 | < | rtargv[rtargc++] = "-fff"; | 
| 56 | < | rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; | 
| 57 | < | rtargv[rtargc++] = nowarn ? "-w-" : "-w+"; | 
| 58 | < | if (npt > 1) { | 
| 59 | < | mktemp(pfile); | 
| 60 | < | rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; | 
| 47 | > | if (rtargv[rtargc-1] != vval(OCTREE)) { | 
| 48 | > | /* add compulsory options */ | 
| 49 | > | rtargv[rtargc++] = "-i-"; | 
| 50 | > | rtargv[rtargc++] = "-I-"; | 
| 51 | > | rtargv[rtargc++] = "-h-"; | 
| 52 | > | rtargv[rtargc++] = "-ld-"; | 
| 53 | > | sprintf(buf1, "%d", RPACKSIZ); | 
| 54 | > | rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; | 
| 55 | > | rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; | 
| 56 | > | rtargv[rtargc++] = "-fff"; | 
| 57 | > | rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; | 
| 58 | > | if (nowarn) | 
| 59 | > | rtargv[rtargc++] = "-w-"; | 
| 60 | > | if (ncprocs > 1) { | 
| 61 | > | mktemp(pfile); | 
| 62 | > | rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; | 
| 63 | > | } | 
| 64 | > | rtargv[rtargc++] = vval(OCTREE); | 
| 65 | > | rtargv[rtargc] = NULL; | 
| 66 |  | } | 
| 64 | – | rtargv[rtargc++] = vval(OCTREE); | 
| 65 | – | rtargv[rtargc] = NULL; | 
| 67 |  | maxqlen = 0; | 
| 68 | < | for (nprocs = 0; nprocs < npt; nprocs++) {      /* spawn children */ | 
| 68 | > | for (nprocs = 0; nprocs < ncprocs; nprocs++) {  /* spawn children */ | 
| 69 |  | psiz = open_process(rtpd[nprocs], rtargv); | 
| 70 |  | if (psiz <= 0) | 
| 71 |  | error(SYSTEM, "cannot start rtrace process"); | 
| 74 |  | if (!(maxqlen = n)) | 
| 75 |  | error(INTERNAL, | 
| 76 |  | "bad pipe buffer size assumption"); | 
| 77 | + | sleep(2); | 
| 78 |  | } else if (n != maxqlen) | 
| 79 |  | error(INTERNAL, "varying pipe buffer size!"); | 
| 80 |  | rmaxpack += n; | 
| 315 |  | if (rv > 0) | 
| 316 |  | status = rv; | 
| 317 |  | } | 
| 318 | < | free((char *)rtbuf); | 
| 318 | > | free((void *)rtbuf); | 
| 319 |  | rtbuf = NULL; | 
| 320 |  | maxqlen = 0; | 
| 321 |  | return(status); |