#!/bin/rc # # command: /bin/boddle /n/juke/plan_9/sys/src/cmd/ndb /tmp/ndb # srcdir: /n/juke/plan_9/sys/src/cmd/ndb # version: 811708952 # date: Thu Sep 21 14:42:32 EDT 1995 # myname=$0 doextract=no fn usage{ echo $myname: usage: $myname '[-X] [src-directory]' >[1=2] exit usage } fn sigint{ rm -rf 811708952 exit interrupt } while(~ $1 -*){ switch($1){ case -X doextract=yes case -* usage } shift } switch($#*){ case 0 srcdir=/sys/src/cmd/ndb case 1 srcdir=$1 case * usage } if(! ~ $doextract yes){ echo This shell file contains a bundle of diffs representing changes echo to original source files in the Plan 9 distribution. It will run echo against the files in echo ' ' $srcdir echo '(unless overridden by the optional source directory argument)' echo and create a directory 811708952 containing the updated files. echo It will NOT automatically update the original files. echo echo Invoke with argument -X to perform the actual extraction. exit 0 } rm -rf 811708952 mkdir 811708952 target=811708952/dblookup.c echo -n '811708952/dblookup.c: ' if(! test -f $srcdir/dblookup.c || ! test -r $srcdir/dblookup.c){ echo $srcdir/dblookup.c unreadable exit unreadable } sum=`{sum < $srcdir/dblookup.c} if(! ~ 03e754046349 $sum(1)^$sum(2)){ echo $srcdir/dblookup.c is not the original distribution file exit original } cp $srcdir/dblookup.c 811708952/dblookup.c ed 811708952/dblookup.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dblookup.c' 339c goto out; . 315c goto out; . wq //GO.SYSIN DD VADIM dblookup.c sum=`{sum < 811708952/dblookup.c} if(~ 653800336349 $sum(1)^$sum(2)) echo if not{ echo 811708952/dblookup.c checksum error creating updated file exit checksum } target=811708952/dn.c echo -n '811708952/dn.c: ' if(! test -f $srcdir/dn.c || ! test -r $srcdir/dn.c){ echo $srcdir/dn.c unreadable exit unreadable } sum=`{sum < $srcdir/dn.c} if(! ~ 90f84ece7753 $sum(1)^$sum(2)){ echo $srcdir/dn.c is not the original distribution file exit original } cp $srcdir/dn.c 811708952/dn.c ed 811708952/dn.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dn.c' 270a rp->pc = ((ulong*)&type)[-1]; /* works on the 386 */ . 179a * periodicly sweep for old records and remove unreferenced domain names */ void dnageall(void) { DN *dp, **l; int i; RR *rp; static ulong nextage; if(dnvars.names < 2000 && now < nextage){ dnvars.oldest = Week; return; } /* * do nothing if another process is working on a * request since we can't mark its local variables. */ lock(&dnvars); if(dnvars.active > 0){ unlock(&dnvars); return; } lock(&dnlock); if(dnvars.names > 2000) dnvars.oldest /= 2; nextage = now + 1*Hour; /* time out all old entries (and set refs to 0) */ for(i = 0; i < HTLEN; i++) for(dp = ht[i]; dp; dp = dp->next){ dp->refs = 0; dnage(dp); } /* mark all referenced domain names */ for(i = 0; i < HTLEN; i++) for(dp = ht[i]; dp; dp = dp->next) for(rp = dp->rr; rp; rp = rp->next){ REF(rp->owner); switch(rp->type){ case Thinfo: REF(rp->cpu); REF(rp->os); break; case Tcname: case Tmb: case Tmd: case Tmf: case Tns: REF(rp->host); break; case Tmg: case Tmr: REF(rp->mb); break; case Tminfo: REF(rp->rmb); REF(rp->mb); break; case Tmx: REF(rp->host); break; case Ta: REF(rp->ip); break; case Tptr: REF(rp->ptr); break; case Tsoa: REF(rp->host); REF(rp->rmb); break; } } /* sweep and remove unreferenced domain names */ for(i = 0; i < HTLEN; i++){ l = &ht[i]; for(dp = *l; dp; dp = *l){ if(dp->rr == 0 && dp->refs == 0){ *l = dp->next; if(dp->name) free(dp->name); dnvars.names--; free(dp); continue; } l = &dp->next; } } unlock(&dnlock); unlock(&dnvars); } /* * keep track of other processes to know if we can * garbage collect */ void getactivity(void) { lock(&dnvars); dnvars.active++; unlock(&dnvars); } void putactivity(void) { lock(&dnvars); dnvars.active--; if(dnvars.active < 0) fatal("dnvars.active %d", dnvars.active); unlock(&dnvars); } /* . 178a #define REF(x) if(x) x->refs++ . 170c if(!rp->db) if(rp->ttl < now || diff > dnvars.oldest){ . 166c diff = now - dp->referenced; if(diff < Reserved) return; . 164a ulong diff; . 158c * check the age of resource records, free any that have timed out * * ptr records timeout faster than others since they're usually not * critical. This is a local hack to get around space explosions when * people run through logs reversing ip numbers. . 125a dp->referenced = now; . 112a dnvars.names++; . 101,103c dp->referenced = now; . 97d 69a dnvars.oldest = 1*Week; dnvars.names = 0; . 16a static struct { Lock; ulong names; /* names allocated */ ulong oldest; /* longest we'll leave a name around */ int active; } dnvars; . 14,15d wq //GO.SYSIN DD VADIM dn.c sum=`{sum < 811708952/dn.c} if(~ 1d2a770b10244 $sum(1)^$sum(2)) echo if not{ echo 811708952/dn.c checksum error creating updated file exit checksum } target=811708952/dnresolve.c echo -n '811708952/dnresolve.c: ' if(! test -f $srcdir/dnresolve.c || ! test -r $srcdir/dnresolve.c){ echo $srcdir/dnresolve.c unreadable exit unreadable } sum=`{sum < $srcdir/dnresolve.c} if(! ~ 444904fa7346 $sum(1)^$sum(2)){ echo $srcdir/dnresolve.c is not the original distribution file exit original } cp $srcdir/dnresolve.c 811708952/dnresolve.c ed 811708952/dnresolve.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dnresolve.c' 371d 369d 365d 362d 352d 346a /* dump the question */ if(m.qd) rrfreelist(m.qd); . 345a if(m.ns) rrattach(m.ns, 0); . 326d 302d 287a if(rp && rp->db) rrfreelist(rp); . 283c parseip(l->a, tp->ip->name); . 280c for(tp = rp; tp && tp->type == Ta; tp = tp->next){ . 264c RR *rp, *tp; . 250,258d 200a alarm(0); . 199c notify(ding); for( ; ; freeanswers(mp)){ alarm(1000); . 189a /* for alarms in readreq */ static void ding(void *x, char *msg) { USED(x); if(strcmp(msg, "alarm") == 0) noted(NCONT); else noted(NDFLT); } static void freeanswers(DNSmsg *mp) { if(mp->qd) rrfreelist(mp->qd); if(mp->an) rrfreelist(mp->an); if(mp->ns) rrfreelist(mp->ns); if(mp->ar) rrfreelist(mp->ar); } . 186a rrfree(m.qd); . 151c snprint(ds, sizeof(ds), "%s/udp!0.0.0.0!0", mntpt); fd = dial(ds, 0, 0, &ctl); . 148a char ds[64]; . 113a if(nsrp->db) /* free database rr's */ rrfreelist(nsrp); . 42,48c for(loops=0; loops < 32; loops++){ rp = dnresolve1(name, class, Tcname, req); if(rp == 0) break; if(rp && cn && loops==0) *cn = rp; name = rp->host->name; rp = dnresolve1(name, class, type, req); if(rp) break; } return rp; . 34c int loops; . wq //GO.SYSIN DD VADIM dnresolve.c sum=`{sum < 811708952/dnresolve.c} if(~ 5af235f57881 $sum(1)^$sum(2)) echo if not{ echo 811708952/dnresolve.c checksum error creating updated file exit checksum } target=811708952/dns.c echo -n '811708952/dns.c: ' if(! test -f $srcdir/dns.c || ! test -r $srcdir/dns.c){ echo $srcdir/dns.c unreadable exit unreadable } sum=`{sum < $srcdir/dns.c} if(! ~ b03c809710425 $sum(1)^$sum(2)){ echo $srcdir/dns.c is not the original distribution file exit original } cp $srcdir/dns.c 811708952/dns.c ed 811708952/dns.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dns.c' 677a getactivity(); . 550,555d 538,541d 535a } else { /* format data to be read later */ n = 0; mf->nrr = 0; for(tp = rp; mf->nrr < Maxrrr-1 && n < Maxreply && tp && tsame(mf->type, tp->type); tp = tp->next){ mf->rr[mf->nrr++] = n; n += snprint(mf->reply+n, Maxreply-n, "%R", tp); } mf->rr[mf->nrr] = n; /* free database resource records */ if(rp->db) rrfreelist(rp); . 533,534c rp = dnresolve(rhp->data, Cin, mf->type, req, 0); if(rp == 0){ . 517a * kill previous reply */ mf->nrr = 0; mf->rr[0] = 0; /* . 514a } else if(strncmp(rhp->data, "age", 3)==0){ dnageall(); goto send; . 492a RR *rp, *tp; . 490a long n; . 478,480c if(i > mf->nrr) goto send; if(off + cnt > mf->rr[i]) n = mf->rr[i] - off; else n = cnt; thp->data = mf->reply + off; . 466,476c for(i = 1; i <= mf->nrr; i++) if(mf->rr[i] > off) . 459,460c dir.atime = now; dir.mtime = now; . 449d 438d 433,434c int i, n, cnt; long off; . 303,313c USED(tag); . 299a /* ignore flushes since the operation will time out */ . 281a } . 280c if(req.isslave){ putactivity(); . 215a /* * clean out old entries periodicly */ now = time(0); dnageall(); . 158c if(mount(p[1], mntpt, MAFTER, "") < 0) . 127c mountinit(char *service, char *mntpt) . 114a snprint(servefile, sizeof(servefile), "#s/dns%s", ext); snprint(mntpt, sizeof(mntpt), "/net%s", ext); unmount(servefile, mntpt); remove(servefile); mountinit(servefile, mntpt); . 111,113c lockinit(); . 103a case 'x': ext = ARGF(); break; . 93d 91a char *ext = ""; char servefile[Maxpath]; . 83,84c char *logfile = "dns"; char *dbfile; char mntpt[Maxpath]; . 59c void mountinit(char*, char*); . 40a ulong now; . 31a char reply[Maxreply]; ushort rr[Maxrrr]; /* offset of rr's */ ushort nrr; /* number of rr's */ . 30d 12a Maxpath= 128, Maxreply= 512, Maxrrr= 16, . 6a #include . wq //GO.SYSIN DD VADIM dns.c sum=`{sum < 811708952/dns.c} if(~ 8557180b10953 $sum(1)^$sum(2)) echo if not{ echo 811708952/dns.c checksum error creating updated file exit checksum } target=811708952/dns.h echo -n '811708952/dns.h: ' if(! test -f $srcdir/dns.h || ! test -r $srcdir/dns.h){ echo $srcdir/dns.h unreadable exit unreadable } sum=`{sum < $srcdir/dns.h} if(! ~ b9435a564617 $sum(1)^$sum(2)){ echo $srcdir/dns.h is not the original distribution file exit original } cp $srcdir/dns.h 811708952/dns.h ed 811708952/dns.h >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dns.h' 199a extern char mntpt[]; /* time base */ extern ulong now; . 176a extern void getactivity(void); extern void putactivity(void); . 164a extern void dnageall(void); extern void dnget(void); extern void dnput(void); . 104a ulong pc; . 96,97c ulong referenced; /* time last referenced */ ushort class; /* RR class */ char refs; /* for mark and sweep */ . 68a /* reserved time (can't be timed out earlier) */ Reserved= 5*Min, . 63c /* time to live values (in seconds) */ . wq //GO.SYSIN DD VADIM dns.h sum=`{sum < 811708952/dns.h} if(~ 8aeb7bf84925 $sum(1)^$sum(2)) echo if not{ echo 811708952/dns.h checksum error creating updated file exit checksum } target=811708952/dnserver.c echo -n '811708952/dnserver.c: ' if(! test -f $srcdir/dnserver.c || ! test -r $srcdir/dnserver.c){ echo $srcdir/dnserver.c unreadable exit unreadable } sum=`{sum < $srcdir/dnserver.c} if(! ~ aef206af5767 $sum(1)^$sum(2)){ echo $srcdir/dnserver.c is not the original distribution file exit original } cp $srcdir/dnserver.c 811708952/dnserver.c ed 811708952/dnserver.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dnserver.c' 112a } . 111c if(req.isslave){ putactivity(); . 48a getactivity(); . 46c for(;; putactivity()){ . wq //GO.SYSIN DD VADIM dnserver.c sum=`{sum < 811708952/dnserver.c} if(~ 4a28f8075821 $sum(1)^$sum(2)) echo if not{ echo 811708952/dnserver.c checksum error creating updated file exit checksum } target=811708952/dnsquery.c echo -n '811708952/dnsquery.c: ' if(! test -f $srcdir/dnsquery.c || ! test -r $srcdir/dnsquery.c){ echo $srcdir/dnsquery.c unreadable exit unreadable } sum=`{sum < $srcdir/dnsquery.c} if(! ~ e9b669691365 $sum(1)^$sum(2)){ echo $srcdir/dnsquery.c is not the original distribution file exit original } cp $srcdir/dnsquery.c 811708952/dnsquery.c ed 811708952/dnsquery.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dnsquery.c' 60c strcpy(line, buf); . 37c /* default to an "ip" request if alpha, "ptr" if numeric */ if (strchr(line, ' ')==0) { if (line[0]>='0' && line[0]<='9') { strcat(line, " ptr"); n += 4; } else { strcat(line, " ip"); n += 3; } } . 35a strncpy(line, lp, n); . 34c while(lp = Brdline(&in, '\n')){ . 17c if(domount == 0){ fprint(2, "can't open %s: %r\n", mtpt); exits(0); } fd = open(mtpt, ORDWR); . 15c ARGBEGIN { default: fprint(2, "usage: %s [dns-mount-point]\n", argv0); exits("usage"); } ARGEND; if(argc == 1){ domount = 0; mtpt = argv[0]; } else { domount = 1; mtpt = "/net/dns"; } fd = open(mtpt, ORDWR); . 12c char line[1024], *lp, *p, *np, *mtpt; . 10c int fd, n, len, domount; . 8c main(int argc, char *argv[]) . wq //GO.SYSIN DD VADIM dnsquery.c sum=`{sum < 811708952/dnsquery.c} if(~ a08d445a1936 $sum(1)^$sum(2)) echo if not{ echo 811708952/dnsquery.c checksum error creating updated file exit checksum } target=811708952/malloc.c echo -n '811708952/malloc.c: ' if(! test -f $srcdir/malloc.c || ! test -r $srcdir/malloc.c){ echo $srcdir/malloc.c unreadable exit unreadable } sum=`{sum < $srcdir/malloc.c} if(! ~ e95bd8121672 $sum(1)^$sum(2)){ echo $srcdir/malloc.c is not the original distribution file exit original } cp $srcdir/malloc.c 811708952/malloc.c ed 811708952/malloc.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM malloc.c' 93a bp->fpc = getcallerpc(&ptr); . 92d 90d 87a lock(&mlock); . 73a memset(bp->data, 0, 1<pc = getcallerpc(&size); . 62c memset(bp->data, 0, 1<pc = getcallerpc(&size); . 35a ulong getcallerpc(void*); . 19a ulong pc; /* allocating pc */ ulong fpc; /* freeing pc */ . wq //GO.SYSIN DD VADIM malloc.c sum=`{sum < 811708952/malloc.c} if(~ fd7245091882 $sum(1)^$sum(2)) echo if not{ echo 811708952/malloc.c checksum error creating updated file exit checksum } target=811708952/mkfile echo -n '811708952/mkfile: ' if(! test -f $srcdir/mkfile || ! test -r $srcdir/mkfile){ echo $srcdir/mkfile unreadable exit unreadable } sum=`{sum < $srcdir/mkfile} if(! ~ a338f372314 $sum(1)^$sum(2)){ echo $srcdir/mkfile is not the original distribution file exit original } cp $srcdir/mkfile 811708952/mkfile ed 811708952/mkfile >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM mkfile' 21c $O.cs: cs.$O malloc.$O $objtype.$O . 14a . 13c convM2DNS.$O convDNS2M.$O malloc.$O $objtype.$O . wq //GO.SYSIN DD VADIM mkfile sum=`{sum < 811708952/mkfile} if(~ 27ab3c64339 $sum(1)^$sum(2)) echo if not{ echo 811708952/mkfile checksum error creating updated file exit checksum } target=811708952/386.c echo -n '811708952/386.c (new): ' cat > 811708952/386.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /tmp/ndb' #include ulong getcallerpc(void *a) { return (((ulong*)a)[-1]); } //GO.SYSIN DD VADIM /tmp/ndb sum=`{sum < 811708952/386.c} if(~ 380b58d574 $sum(1)^$sum(2)) echo if not{ echo 811708952/386.c checksum error extracting new file exit checksum } target=811708952/68020.c echo -n '811708952/68020.c (new): ' cat > 811708952/68020.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /tmp/ndb' #include ulong getcallerpc(void *a) { return (((ulong*)a)[-1]); } //GO.SYSIN DD VADIM /tmp/ndb sum=`{sum < 811708952/68020.c} if(~ 380b58d574 $sum(1)^$sum(2)) echo if not{ echo 811708952/68020.c checksum error extracting new file exit checksum } target=811708952/mips.s echo -n '811708952/mips.s (new): ' cat > 811708952/mips.s >[2]/dev/null <<'//GO.SYSIN DD VADIM /tmp/ndb' TEXT getcallerpc(SB), $0 MOVW 0(SP), R1 RET //GO.SYSIN DD VADIM /tmp/ndb sum=`{sum < 811708952/mips.s} if(~ 6b88a1cf48 $sum(1)^$sum(2)) echo if not{ echo 811708952/mips.s checksum error extracting new file exit checksum } target=811708952/mkhosts.c echo -n '811708952/mkhosts.c (new): ' cat > 811708952/mkhosts.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /tmp/ndb' #include #include #include #include #include typedef struct x { Ndbtuple *t; Ndbtuple *it; Ndbtuple *nt; } X; X x[4096]; int nx; char* upper(char *x) { char *p; int c; for(p = x; c = *p; p++) *p = toupper(c); return x; } void printentry(int fd, X *p) { Ndbtuple *nt; if(p->nt) return; fprint(fd, "%s ", p->it->val); for(nt = p->t; nt; nt = nt->entry) if(strcmp(nt->attr, "dom") == 0) fprint(fd, " %s", nt->val); for(nt = p->t; nt; nt = nt->entry) if(strcmp(nt->attr, "sys") == 0) fprint(fd, " %s", nt->val); fprint(fd, "\n"); } void printsys(int fd, X *p) { Ndbtuple *nt; for(nt = p->t; nt; nt = nt->entry) if(strcmp(nt->attr, "sys") == 0 || strcmp(nt->attr, "dom") == 0) fprint(fd, "%s\n", nt->val); } void printtxt(int fd, X *p) { int i; Ndbtuple *nt; if(p->nt){ for(;;){ i = strlen(p->it->val); if(strcmp(p->it->val+i-2, ".0") == 0) p->it->val[i-2] = 0; else break; } fprint(fd, "\nNET : %s : %s\n", p->it->val, upper(p->nt->val)); return; } fprint(fd, "HOST : %s :", p->it->val); i = 0; for(nt = p->t; nt; nt = nt->entry) if(strcmp(nt->attr, "dom") == 0){ if(i++ == 0) fprint(fd, " %s", upper(nt->val)); else fprint(fd, ", %s", upper(nt->val)); } fprint(fd, "\n"); } void parse(char *file) { int i; Ndb *db; Ndbtuple *t, *nt, *tt; char *p; db = ndbopen(file); if(db == 0) exits("no database"); while(t = ndbparse(db)){ for(nt = t; nt; nt = nt->entry){ if(strcmp(nt->attr, "ip") == 0) break; if(strcmp(nt->attr, "flavor") == 0 && strcmp(nt->val, "console") == 0) return; } if(nt == 0){ ndbfree(t); continue; } /* dump anything not on our nets */ for(tt = t; tt; tt = tt->entry){ if(strcmp(tt->attr, "ipnet") == 0){ x[nx].nt = tt; break; } if(strcmp(tt->attr, "dom") == 0){ i = strlen(tt->val); p = tt->val+i-(sizeof("research.att.com")-1); if(p >= tt->val && strcmp(p, "research.att.com") == 0) break; } } if(tt == 0){ ndbfree(t); continue; } x[nx].it = nt; x[nx++].t = t; } } void main(void) { int i, fd; parse("/lib/ndb/local"); fd = create("/lib/ndb/hosts.1127", OWRITE, 0664); if(fd < 0){ fprint(2, "can't create /lib/ndb/hosts.1127: %r\n"); exits("boom"); } for(i = 0; i < nx; i++) printentry(fd, &x[i]); close(fd); fd = create("/lib/ndb/hosts.equiv", OWRITE, 0664); if(fd < 0){ fprint(2, "can't create /lib/ndb/hosts.equiv: %r\n"); exits("boom"); } for(i = 0; i < nx; i++) printsys(fd, &x[i]); close(fd); fd = create("/lib/ndb/astro.txt", OWRITE, 0664); if(fd < 0){ fprint(2, "can't create /lib/ndb/astro.txt: %r\n"); exits("boom"); } for(i = 0; i < nx; i++) printtxt(fd, &x[i]); close(fd); exits(0); } //GO.SYSIN DD VADIM /tmp/ndb sum=`{sum < 811708952/mkhosts.c} if(~ 75bd794b2789 $sum(1)^$sum(2)) echo if not{ echo 811708952/mkhosts.c checksum error extracting new file exit checksum } target=811708952/sparc.c echo -n '811708952/sparc.c (new): ' cat > 811708952/sparc.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /tmp/ndb' #include ulong getcallerpc(void *a) { return (((ulong*)a)[-1]); } //GO.SYSIN DD VADIM /tmp/ndb sum=`{sum < 811708952/sparc.c} if(~ 380b58d574 $sum(1)^$sum(2)) echo if not{ echo 811708952/sparc.c checksum error extracting new file exit checksum }