| 10 |
|
|
| 11 |
|
#include "rholo.h" |
| 12 |
|
#include "random.h" |
| 13 |
+ |
#include "paths.h" |
| 14 |
+ |
#include "selcall.h" |
| 15 |
|
#include <signal.h> |
| 16 |
|
#include <sys/time.h> |
| 17 |
|
|
| 18 |
|
#ifndef MAXPROC |
| 19 |
< |
#define MAXPROC 16 |
| 19 |
> |
#define MAXPROC 64 |
| 20 |
|
#endif |
| 21 |
|
|
| 22 |
< |
static char PFILE[] = "/usr/tmp/RHpersist"; /* persist file name */ |
| 22 |
> |
int nprocs = 0; /* running process count */ |
| 23 |
|
|
| 24 |
+ |
static char pfile[] = TEMPLATE; /* persist file name */ |
| 25 |
+ |
|
| 26 |
|
static int rtpd[MAXPROC][3]; /* process descriptors */ |
| 27 |
|
static float *rtbuf = NULL; /* allocated i/o buffer */ |
| 28 |
|
static int maxqlen = 0; /* maximum packets per queue */ |
| 25 |
– |
static int nprocs = 0; /* number of processes */ |
| 29 |
|
|
| 30 |
|
static PACKET *pqueue[MAXPROC]; /* packet queues */ |
| 31 |
|
static int pqlen[MAXPROC]; /* packet queue lengths */ |
| 36 |
|
{ |
| 37 |
|
static char buf1[8]; |
| 38 |
|
int rmaxpack = 0; |
| 39 |
< |
int psiz, npt, n; |
| 39 |
> |
int psiz, n; |
| 40 |
|
/* get number of processes */ |
| 41 |
< |
if ((npt = ncprocs) <= 0) |
| 41 |
> |
if (ncprocs <= 0 || nprocs > 0) |
| 42 |
|
return(0); |
| 43 |
< |
if (npt > MAXPROC) { |
| 43 |
> |
if (ncprocs > MAXPROC) { |
| 44 |
|
sprintf(errmsg, |
| 45 |
|
"number of rtrace processes reduced from %d to %d", |
| 46 |
< |
npt, MAXPROC); |
| 46 |
> |
ncprocs, MAXPROC); |
| 47 |
|
error(WARNING, errmsg); |
| 48 |
< |
npt = MAXPROC; |
| 48 |
> |
ncprocs = MAXPROC; |
| 49 |
|
} |
| 50 |
< |
/* add compulsory options */ |
| 51 |
< |
rtargv[rtargc++] = "-i-"; |
| 52 |
< |
rtargv[rtargc++] = "-I-"; |
| 53 |
< |
rtargv[rtargc++] = "-h-"; |
| 54 |
< |
rtargv[rtargc++] = "-ld-"; |
| 55 |
< |
sprintf(buf1, "%d", RPACKSIZ); |
| 56 |
< |
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
| 57 |
< |
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
| 58 |
< |
rtargv[rtargc++] = "-fff"; |
| 59 |
< |
rtargv[rtargc++] = "-ovl"; |
| 60 |
< |
rtargv[rtargc++] = nowarn ? "-w-" : "-w+"; |
| 61 |
< |
if (npt > 1) { |
| 62 |
< |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = PFILE; |
| 50 |
> |
if (rtargv[rtargc-1] != vval(OCTREE)) { |
| 51 |
> |
/* add compulsory options */ |
| 52 |
> |
rtargv[rtargc++] = "-i-"; |
| 53 |
> |
rtargv[rtargc++] = "-I-"; |
| 54 |
> |
rtargv[rtargc++] = "-h-"; |
| 55 |
> |
rtargv[rtargc++] = "-ld-"; |
| 56 |
> |
sprintf(buf1, "%d", RPACKSIZ); |
| 57 |
> |
rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; |
| 58 |
> |
rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; |
| 59 |
> |
rtargv[rtargc++] = "-fff"; |
| 60 |
> |
rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; |
| 61 |
> |
if (nowarn) |
| 62 |
> |
rtargv[rtargc++] = "-w-"; |
| 63 |
> |
if (ncprocs > 1) { |
| 64 |
> |
mktemp(pfile); |
| 65 |
> |
rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; |
| 66 |
> |
} |
| 67 |
> |
rtargv[rtargc++] = vval(OCTREE); |
| 68 |
> |
rtargv[rtargc] = NULL; |
| 69 |
|
} |
| 61 |
– |
rtargv[rtargc++] = vval(OCTREE); |
| 62 |
– |
rtargv[rtargc] = NULL; |
| 70 |
|
maxqlen = 0; |
| 71 |
< |
for (nprocs = 0; nprocs < npt; nprocs++) { /* spawn children */ |
| 71 |
> |
for (nprocs = 0; nprocs < ncprocs; nprocs++) { /* spawn children */ |
| 72 |
|
psiz = open_process(rtpd[nprocs], rtargv); |
| 73 |
|
if (psiz <= 0) |
| 74 |
|
error(SYSTEM, "cannot start rtrace process"); |
| 214 |
|
if (n) /* read past end? */ |
| 215 |
|
error(INTERNAL, "packet sync error in get_packets"); |
| 216 |
|
/* take from queue */ |
| 217 |
< |
if (pldone = NULL) |
| 217 |
> |
if (pldone == NULL) |
| 218 |
|
pldone = plend = pqueue[pn]; |
| 219 |
|
else |
| 220 |
|
plend->next = pqueue[pn]; |
| 225 |
|
} |
| 226 |
|
return(pldone); /* return finished packets */ |
| 227 |
|
eoferr: |
| 228 |
< |
error(USER, "unexpected EOF from rtrace process"); |
| 228 |
> |
error(USER, "rtrace process died"); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 259 |
|
if (pqlen[i]) { |
| 260 |
|
if (rpdone == NULL) { /* tack on queue */ |
| 261 |
|
rpdone = rpl = pqueue[i]; |
| 262 |
< |
n = rpl->nr; |
| 262 |
> |
if ((nr = rpl->nr) < RPACKSIZ) nr++; |
| 263 |
|
} else { |
| 264 |
|
rpl->next = pqueue[i]; |
| 265 |
< |
n = 0; |
| 265 |
> |
nr = 0; |
| 266 |
|
} |
| 267 |
< |
while (rpl->next != NULL) |
| 268 |
< |
n += (rpl = rpl->next)->nr; |
| 267 |
> |
while (rpl->next != NULL) { |
| 268 |
> |
nr += (rpl = rpl->next)->nr; |
| 269 |
> |
if (rpl->nr < RPACKSIZ) |
| 270 |
> |
nr++; /* add flush block */ |
| 271 |
> |
} |
| 272 |
|
n = readbuf(rtpd[i][0], (char *)rtbuf, |
| 273 |
< |
4*sizeof(float)*n); |
| 273 |
> |
4*sizeof(float)*nr); |
| 274 |
|
if (n < 0) |
| 275 |
|
error(SYSTEM, "read failure in flush_queue"); |
| 276 |
|
bp = rtbuf; /* process packets */ |
| 297 |
|
FILE *fp; |
| 298 |
|
int pid; |
| 299 |
|
|
| 300 |
< |
if ((fp = fopen(PFILE, "r")) == NULL) |
| 300 |
> |
if ((fp = fopen(pfile, "r")) == NULL) |
| 301 |
|
return; |
| 302 |
|
if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) |
| 303 |
< |
unlink(PFILE); |
| 303 |
> |
unlink(pfile); |
| 304 |
|
fclose(fp); |
| 305 |
|
} |
| 306 |
|
|