int runNBodySimulation(const NBodyFlags* nbf) { NBodyCtx* ctx = &_ctx; NBodyState* st = &_st; int rc = 0; real chisq; double ts = 0.0, te = 0.0; nbodySetCtxFromFlags(ctx, nbf); if (setupRun(ctx, st, &ctx->histogramParams, nbf)) { return warn1("Failed to setup run\n"); } if (initOutput(st, nbf)) { return warn1("Failed to open output files\n"); } if (createSharedScene(st, ctx, nbf->inputFile)) { return warn1("Failed to create shared scene\n"); } ts = mwGetTime(); rc = runSystem(ctx, st, nbf); if (rc) return warn1("Error running system\n"); te = mwGetTime(); if (nbf->printTiming) { printf("<run_time> %f </run_time>\n", te - ts); } /* Get the likelihood */ chisq = nbodyChisq(ctx, st, nbf, &ctx->histogramParams); if (isnan(chisq)) { warn("Failed to calculate chisq\n"); rc = 1; } finalOutput(ctx, st, nbf, chisq); destroyNBodyState(st); return rc; }
int main(int argc, char* argv[]) { const char* ip; const char* tmp; if (argc < 2) die1(1, "usage: relay-ctrl-check program [arguments]\n"); log_ips = getenv("RELAY_CTRL_LOG_IPS") != 0; log_env = getenv("RELAY_CTRL_LOG_ENV") != 0; if (getenv("RELAYCLIENT") == 0) { expiry = 0; if ((tmp = getenv("RELAY_CTRL_EXPIRY")) != 0) expiry = atol(tmp); if (expiry <= 0) expiry = 900; if ((rc = getenv("RELAY_CTRL_RELAYCLIENT")) == 0) rc = ""; if ((ip = getenv("TCPREMOTEIP")) == 0) warn1("$TCPREMOTEIP not set, not checking IP"); else if (do_chdir(0)) stat_ip(ip); } else { if (log_ips) msg1("$RELAYCLIENT already set, not checking IP"); } execvp(argv[1], argv+1); die1(111, "execution of program failed!\n"); return 111; argc = 0; }
static int runSystem(const NBodyCtx* ctx, NBodyState* st, const NBodyFlags* nbf) { const real tstop = ctx->timeEvolve - ctx->timestep / 1024.0; if (nbf->visualizer) { launchVisualizer(st, nbf->visArgs); } while (st->tnow < tstop) { updateDisplayedBodies(st); if (stepSystem(ctx, st)) /* advance N-body system */ return 1; nbodyCheckpoint(ctx, st); } if (BOINC_APPLICATION || ctx->checkpointT >= 0) { mw_report("Making final checkpoint\n"); if (writeCheckpoint(ctx, st)) return warn1("Failed to write final checkpoint\n"); } return 0; }
void casewarn(void) { if (skip(0)) warn = WARN_W; else while (!warn1() && !skip(0)); }
backup(char *fname, char *bname) #endif { FILE *b, *f; static char couldnt[] = "Couldn't open %.80s"; if (!(f = fopen(fname, binread))) { warn1(couldnt, fname); return; } if (!(b = fopen(bname, binwrite))) { warn1(couldnt, bname); return; } ffilecopy(f, b); fclose(f); fclose(b); }
int main(int argc, char* argv[]) { if ((ip = getenv("TCPREMOTEIP")) == 0 || (ip = validate_ip(ip)) == 0) die1(111, "Must be run from tcp-env or tcpserver."); if ((dir = getenv("RELAY_CTRL_DIR")) == 0) warn1("$RELAY_CTRL_DIR is not set."); else if (is_authenticated()) make_file(ip, argc > 1); if (argc > 1) { execvp(argv[1], argv+1); return 111; } return 0; }
LOCAL void docomleng(Void) { register Extsym *p; for(p = extsymtab ; p < nextext ; ++p) if(p->extstg == STGCOMMON) { if(p->maxleng!=0 && p->extleng!=0 && p->maxleng!=p->extleng && strcmp(Blank, p->cextname) ) warn1("incompatible lengths for common block %.60s", p->fextname); if(p->maxleng < p->extleng) p->maxleng = p->extleng; p->extleng = 0; } }
LOCAL void dobss(Void) { register struct Hashentry *p; register Namep q; int qstg, qclass, qtype; Extsym *e; for(p = hashtab ; p<lasthash ; ++p) if(q = p->varp) { qstg = q->vstg; qtype = q->vtype; qclass = q->vclass; if( (qclass==CLUNKNOWN && qstg!=STGARG) || (qclass==CLVAR && qstg==STGUNKNOWN) ) { if (!(q->vis_assigned | q->vimpldovar)) warn1("local variable %s never used", q->fvarname); } else if(qclass==CLVAR && qstg==STGBSS) { ; } /* Give external procedures the proper storage class */ else if(qclass==CLPROC && q->vprocclass==PEXTERNAL && qstg!=STGARG) { e = mkext(q->fvarname,addunder(q->cvarname)); e->extstg = STGEXT; q->vardesc.varno = e - extsymtab; if (e->extype != qtype) changedtype(q); } if(qclass==CLVAR) { if (qstg != STGARG && q->vdim) dim_check(q); } /* if qclass == CLVAR */ } }
execlab(ftnint stateno) #endif { register struct Labelblock *lp; if(lp = mklabel(stateno)) { if(lp->labinacc) warn1("illegal branch to inner block, statement label %s", convic(stateno) ); else if(lp->labdefined == NO) lp->blklevel = blklevel; if(lp->labtype == LABFORMAT) err("may not branch to a format"); else lp->labtype = LABEXEC; } else execerr("illegal label %s", convic(stateno)); return(lp); }
static void load_env(int fd) { static char buf[8192]; int rd; char* ptr; char* end; int len; if ((rd = read(fd, buf, sizeof buf)) == -1) warn1sys("Could not read from opened IP file?!?"); else if (rd > 0) { for (ptr = buf; rd > 0; ptr += len, rd -= len) { if ((end = memchr(ptr, 0, rd)) == 0) break; len = end - ptr + 1; if (memchr(ptr, '=', len) != 0) { if (log_env) msg2("Setting ", ptr); if (putenv(ptr) == -1) warn1("Could not set environment string"); } } } }
setdata(register Addrp varp, register Constp valp, ftnint elen) #endif { struct Constblock con; register int type; int i, k, valtype; ftnint offset; char *varname; static Addrp badvar; register unsigned char *s; static int last_lineno; static char *last_varname; if (varp->vstg == STGCOMMON) { if (!(dfile = blkdfile)) dfile = blkdfile = opf(blkdfname, textwrite); } else { if (procclass == CLBLOCK) { if (varp != badvar) { badvar = varp; warn1("%s is not in a COMMON block", varp->uname_tag == UNAM_NAME ? varp->user.name->fvarname : "???"); } return; } if (!(dfile = initfile)) dfile = initfile = opf(initfname, textwrite); } varname = dataname(varp->vstg, varp->memno); offset = varp->memoffset->constblock.Const.ci; type = varp->vtype; valtype = valp->vtype; if(type!=TYCHAR && valtype==TYCHAR) { if(! ftn66flag && (last_varname != cur_varname || last_lineno != lineno)) { /* prevent multiple warnings */ last_lineno = lineno; warn1( "non-character datum %.42s initialized with character string", last_varname = cur_varname); } varp->vleng = ICON(typesize[type]); varp->vtype = type = TYCHAR; } else if( (type==TYCHAR && valtype!=TYCHAR) || (cktype(OPASSIGN,type,valtype) == TYERROR) ) { err("incompatible types in initialization"); return; } if(type == TYADDR) con.Const.ci = valp->Const.ci; else if(type != TYCHAR) { if(valtype == TYUNKNOWN) con.Const.ci = valp->Const.ci; else consconv(type, &con, valp); } k = 1; switch(type) { case TYLOGICAL: case TYINT1: case TYLOGICAL1: case TYLOGICAL2: case TYSHORT: case TYLONG: #ifdef TYQUAD case TYQUAD: #endif dataline(varname, offset, type); prconi(dfile, con.Const.ci); break; case TYADDR: dataline(varname, offset, type); prcona(dfile, con.Const.ci); break; case TYCOMPLEX: case TYDCOMPLEX: k = 2; case TYREAL: case TYDREAL: dataline(varname, offset, type); prconr(dfile, &con, k); break; case TYCHAR: k = valp -> vleng -> constblock.Const.ci; if (elen < k) k = elen; s = (unsigned char *)valp->Const.ccp; for(i = 0 ; i < k ; ++i) { dataline(varname, offset++, TYCHAR); fprintf(dfile, "\t%d\n", *s++); } k = elen - valp->vleng->constblock.Const.ci; if(k > 0) { dataline(varname, offset, TYBLANK); fprintf(dfile, "\t%d\n", k); } break; default: badtype("setdata", type); } }
intrcall(Namep np, struct Listblock *argsp, int nargs) #endif { int i, rettype; Addrp ap; register struct Specblock *sp; register struct Chain *cp; expptr q, ep; int mtype; int op; int f1field, f2field, f3field; packed.ijunk = np->vardesc.varno; f1field = packed.bits.f1; f2field = packed.bits.f2; f3field = packed.bits.f3; if(nargs == 0) goto badnargs; mtype = 0; for(cp = argsp->listp ; cp ; cp = cp->nextp) { ep = (expptr)cp->datap; if( ISCONST(ep) && ep->headblock.vtype==TYSHORT ) cp->datap = (char *) mkconv(tyint, ep); mtype = maxtype(mtype, ep->headblock.vtype); } switch(f1field) { case INTRBOOL: op = f3field; if( ! ONEOF(mtype, MSKINT|MSKLOGICAL) ) goto badtype; if(op == OPBITNOT) { if(nargs != 1) goto badnargs; q = mkexpr(OPBITNOT, (expptr)argsp->listp->datap, ENULL); } else { if(nargs != 2) goto badnargs; q = mkexpr(op, (expptr)argsp->listp->datap, (expptr)argsp->listp->nextp->datap); } frchain( &(argsp->listp) ); free( (charptr) argsp); return(q); case INTRCONV: rettype = f2field; switch(rettype) { case TYLONG: rettype = tyint; break; case TYLOGICAL: rettype = tylog; } if( ISCOMPLEX(rettype) && nargs==2) { expptr qr, qi; qr = (expptr) argsp->listp->datap; qi = (expptr) argsp->listp->nextp->datap; if(ISCONST(qr) && ISCONST(qi)) q = mkcxcon(qr,qi); else q = mkexpr(OPCONV,mkconv(rettype-2,qr), mkconv(rettype-2,qi)); } else if(nargs == 1) { if (f3field && ((Exprp)argsp->listp->datap)->vtype == TYDCOMPLEX) rettype = TYDREAL; q = mkconv(rettype+100, (expptr)argsp->listp->datap); if (q->tag == TADDR) q->addrblock.parenused = 1; } else goto badnargs; q->headblock.vtype = rettype; frchain(&(argsp->listp)); free( (charptr) argsp); return(q); #if 0 case INTRCNST: /* Machine-dependent f77 stuff that f2c omits: intcon contains radix for short int radix for long int radix for single precision radix for double precision precision for short int precision for long int precision for single precision precision for double precision emin for single precision emin for double precision emax for single precision emax for double prcision largest short int largest long int realcon contains tiny for single precision tiny for double precision huge for single precision huge for double precision mrsp (epsilon) for single precision mrsp (epsilon) for double precision */ { register struct Incstblock *cstp; extern ftnint intcon[14]; extern double realcon[6]; cstp = consttab + f3field; for(i=0 ; i<f2field ; ++i) if(cstp->atype == mtype) goto foundconst; else ++cstp; goto badtype; foundconst: switch(cstp->rtype) { case TYLONG: return(mkintcon(intcon[cstp->constno])); case TYREAL: case TYDREAL: return(mkrealcon(cstp->rtype, realcon[cstp->constno]) ); default: Fatal("impossible intrinsic constant"); } } #endif case INTRGEN: sp = spectab + f3field; if(no66flag) if(sp->atype == mtype) goto specfunct; else err66("generic function"); for(i=0; i<f2field ; ++i) if(sp->atype == mtype) goto specfunct; else ++sp; warn1 ("bad argument type to intrinsic %s", np->fvarname); /* Made this a warning rather than an error so things like "log (5) ==> log (5.0)" can be accommodated. When none of these cases matches, the argument is cast up to the first type in the spectab list; this first type is assumed to be the "smallest" type, e.g. REAL before DREAL before COMPLEX, before DCOMPLEX */ sp = spectab + f3field; mtype = sp -> atype; goto specfunct; case INTRSPEC: sp = spectab + f3field; specfunct: if(tyint==TYLONG && ONEOF(sp->rtype,M(TYSHORT)|M(TYLOGICAL)) && (sp+1)->atype==sp->atype) ++sp; if(nargs != sp->nargs) goto badnargs; if(mtype != sp->atype) goto badtype; /* NOTE!! I moved fixargs (YES) into the ELSE branch so that constants in the inline expression wouldn't get put into the constant table */ fixargs (NO, argsp); cast_args (mtype, argsp -> listp); if(q = Inline((int)(sp-spectab), mtype, argsp->listp)) { frchain( &(argsp->listp) ); free( (charptr) argsp); } else { if(sp->othername) { /* C library routines that return double... */ /* sp->rtype might be TYREAL */ ap = builtin(sp->rtype, callbyvalue[sp->othername], 1); q = fixexpr((Exprp) mkexpr(OPCCALL, (expptr)ap, (expptr)argsp) ); } else { fixargs(YES, argsp); ap = builtin(sp->rtype, sp->spxname, 0); q = fixexpr((Exprp) mkexpr(OPCALL, (expptr)ap, (expptr)argsp) ); } /* else */ } /* else */ return(q); case INTRMIN: case INTRMAX: if(nargs < 2) goto badnargs; if( ! ONEOF(mtype, MSKINT|MSKREAL) ) goto badtype; argsp->vtype = mtype; q = mkexpr( (f1field==INTRMIN ? OPMIN : OPMAX), (expptr)argsp, ENULL); q->headblock.vtype = mtype; rettype = f2field; if(rettype == TYLONG) rettype = tyint; else if(rettype == TYUNKNOWN) rettype = mtype; return( mkconv(rettype, q) ); default: fatali("intrcall: bad intrgroup %d", f1field); } badnargs: errstr("bad number of arguments to intrinsic %s", np->fvarname); goto bad; badtype: errstr("bad argument type to intrinsic %s", np->fvarname); bad: return( errnode() ); }
static const response* message_end(int fd) { const char* hostname; const char* tmp; ipv4port cmdport; ipv4addr ips[MAX_IPS]; int ip_count; int i; int offset; int result; struct timeval tv; int sock; unsigned long timeout; unsigned long connect_timeout; unsigned long send_timeout; unsigned long maxsize; ibuf netin; obuf netout; struct stat st; if ((hostname = session_getenv("CLAMAV_HOST")) != 0 || (hostname = session_getenv("CLAMD_HOST")) != 0) { if (fstat(fd, &st) != 0) return &resp_internal; /* For simplicity, this plugin just sends a single chunk, but each * chunk is limited to 2^32 bytes by the protocol. */ if (st.st_size > 0xffffffffLL) { warn1("ClamAV scanning skipped: message larger than chunk size"); return 0; } if ((tmp = session_getenv("CLAMAV_MAXSIZE")) != 0 && (maxsize = strtoul(tmp, (char**)&tmp, 10)) != 0 && *tmp == 0) { if (st.st_size > (ssize_t)maxsize){ warn1("ClamAV scanning skipped: message larger than maximum"); return 0; } } if (((tmp = session_getenv("CLAMAV_PORT")) == 0 && (tmp = session_getenv("CLAMD_PORT")) == 0) || (cmdport = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) cmdport = 3310; if (((tmp = session_getenv("CLAMAV_TIMEOUT")) == 0 && (tmp = session_getenv("CLAMD_TIMEOUT")) == 0) || (timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) timeout = 5000; if ((tmp = session_getenv("CLAMAV_CONNECT_TIMEOUT")) == 0 || (connect_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) connect_timeout = timeout; if ((tmp = session_getenv("CLAMAV_SEND_TIMEOUT")) == 0 || (send_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) send_timeout = timeout; if ((ip_count = resolve_ipv4name_n(hostname, ips, MAX_IPS)) <= 0) return &resp_no_hostname; gettimeofday(&tv, 0); offset = (tv.tv_sec ^ tv.tv_usec) % ip_count; for (i = 0; i < ip_count; ++i) { const ipv4addr* addr = &ips[(i + offset) % ip_count]; if (lseek(fd, 0, SEEK_SET) != 0) return &resp_internal; if ((sock = try_connect(addr, cmdport, connect_timeout)) < 0) continue; if (obuf_init(&netout, sock, 0, 0, 0)) { netout.io.timeout = send_timeout; result = obuf_puts(&netout, "nINSTREAM\n") && copystream(fd, st.st_size, &netout) && obuf_close(&netout); obuf_close(&netout); if (result) { if (ibuf_init(&netin, sock, 0, IOBUF_NEEDSCLOSE, 0)) { netin.io.timeout = timeout; result = ibuf_getstr(&netin, &line, LF); ibuf_close(&netin); sock = -1; if (result) { if (memcmp(line.s, "stream: ", 8) == 0) { str_lcut(&line, 8); str_rstrip(&line); if (str_diffs(&line, "OK") == 0) return 0; str_splices(&line, 0, 0, "5.7.0 Virus scan failed: "); resp_virus.message = line.s; return &resp_virus; } } } } } if (sock >= 0) close(sock); } } return &resp_no_scan; }