Browse Source

Plan 9 from Bell Labs 2008-02-02

David du Colombier 16 years ago
parent
commit
11fe92b0ff

+ 5 - 1
dist/replica/_plan9.db

@@ -7581,7 +7581,7 @@ sys/man/2/genrandom - 664 sys sys 1196638940 876
 sys/man/2/getcallerpc - 664 sys sys 1196638940 666
 sys/man/2/getenv - 664 sys sys 1196638937 685
 sys/man/2/getfcr - 664 sys sys 1196638940 2713
-sys/man/2/getfields - 664 sys sys 1196638937 1605
+sys/man/2/getfields - 664 sys sys 1201889839 1749
 sys/man/2/getpid - 664 sys sys 1196638937 657
 sys/man/2/getuser - 664 sys sys 1196638937 641
 sys/man/2/getwd - 664 sys sys 1196638937 701
@@ -15856,3 +15856,7 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+sys/src/cmd/ndb/dblookup.c - 664 sys sys 1201927753 25262
+sys/src/cmd/ndb/dn.c - 664 sys sys 1201927830 37758
+sys/src/cmd/ndb/dns.c - 664 sys sys 1201927800 17679
+sys/src/cmd/ndb/dns.h - 664 sys sys 1201927786 11915

+ 0 - 0
dist/replica/nplan9.db


+ 1 - 1
dist/replica/plan9.db

@@ -7581,7 +7581,7 @@ sys/man/2/genrandom - 664 sys sys 1196638940 876
 sys/man/2/getcallerpc - 664 sys sys 1196638940 666
 sys/man/2/getenv - 664 sys sys 1196638937 685
 sys/man/2/getfcr - 664 sys sys 1196638940 2713
-sys/man/2/getfields - 664 sys sys 1196638937 1605
+sys/man/2/getfields - 664 sys sys 1201889839 1749
 sys/man/2/getpid - 664 sys sys 1196638937 657
 sys/man/2/getuser - 664 sys sys 1196638937 641
 sys/man/2/getwd - 664 sys sys 1196638937 701

+ 5 - 0
dist/replica/plan9.log

@@ -18395,3 +18395,8 @@
 1201806004 0 c sys/man/8/aquarela - 664 sys sys 1201804560 3612
 1201822204 0 c sys/src/9/pc/etherigbe.c - 664 sys sys 1201822310 45935
 1201822204 1 c sys/src/boot/pc/etherigbe.c - 664 sys sys 1201822335 41718
+1201890604 0 c sys/man/2/getfields - 664 sys sys 1201889839 1749
+1201926609 0 c sys/src/cmd/ndb/dblookup.c - 664 sys sys 1201927753 25262
+1201926609 1 c sys/src/cmd/ndb/dn.c - 664 sys sys 1201927830 37758
+1201926609 2 c sys/src/cmd/ndb/dns.c - 664 sys sys 1201927800 17679
+1201926609 3 c sys/src/cmd/ndb/dns.h - 664 sys sys 1201927786 11915

+ 6 - 2
sys/man/2/getfields

@@ -76,16 +76,20 @@ non-zero,
 except that fields may be quoted using single quotes, in the manner
 of
 .IR rc (1).
+Any such quotes remain in the resulting
+.IR args .
 See
 .IR quote (2)
 for related quote-handling software.
 .PP
 .I Tokenize
-is
+is similar to
 .I gettokens
 with 
 .I delims
-set to \f5"\et\er\en "\fP.
+set to \f5"\et\er\en\ "\fP,
+except that quotes are interpreted but do not appear in the resulting
+.IR args .
 .SH SOURCE
 .B /sys/src/libc/port/tokenize.c
 .SH SEE ALSO

+ 8 - 12
sys/src/cmd/ndb/dblookup.c

@@ -70,13 +70,11 @@ opendatabase(void)
 		return 0;
 
 	xdb = ndbopen(dbfile);		/* /lib/ndb */
-	if(xdb)
-		xdb->nohash = 1;	/* seems odd */
 
 	snprint(netdbnm, sizeof netdbnm, "%s/ndb", mntpt);
 	netdb = ndbopen(netdbnm);	/* /net/ndb */
-//	if(netdb)
-//		netdb->nohash = 1;	/* cs does this; seems right */
+	if(netdb)
+		netdb->nohash = 1;
 
 	db = ndbcat(netdb, xdb);	/* both */
 	return db? 0: -1;
@@ -867,6 +865,7 @@ myaddr(char *addr)
 }
 
 static char *locdns[20];
+static QLock locdnslck;
 
 static void
 addlocaldnsserver(DN *dp, int class, char *ipaddr, int i)
@@ -875,7 +874,6 @@ addlocaldnsserver(DN *dp, int class, char *ipaddr, int i)
 	DN *nsdp;
 	RR *rp;
 	char buf[32];
-	static QLock locdnslck;
 
 	/* reject our own ip addresses so we don't query ourselves via udp */
 	if (myaddr(ipaddr))
@@ -891,7 +889,7 @@ addlocaldnsserver(DN *dp, int class, char *ipaddr, int i)
 		}
 	if (n < nelem(locdns))
 		if (locdns[n] == nil || ++n < nelem(locdns))
-			locdns[n] = strdup(ipaddr); /* remember first few local ns */
+			locdns[n] = strdup(ipaddr); /* remember 1st few local ns */
 	qunlock(&locdnslck);
 
 	/* ns record for name server, make up an impossible name */
@@ -927,7 +925,7 @@ RR*
 dnsservers(int class)
 {
 	int i, n;
-	char *p, *buf;
+	char *p;
 	char *args[5];
 	Ndbtuple *t, *nt;
 	RR *nsrp;
@@ -940,11 +938,10 @@ dnsservers(int class)
 
 	p = getenv("DNSSERVER");		/* list of ip addresses */
 	if(p != nil){
-		buf = estrdup(p);
-		n = tokenize(buf, args, nelem(args));
+		n = tokenize(p, args, nelem(args));
 		for(i = 0; i < n; i++)
 			addlocaldnsserver(dp, class, args[i], i);
-		free(buf);
+		free(p);
 	} else {
 		t = lookupinfo("@dns");		/* @dns=ip1 @dns=ip2 ... */
 		if(t == nil)
@@ -1134,7 +1131,7 @@ createv6ptrs(void)
 		buf[sizeof buf-1] = 0;
 		/* buf contains something like 2.0.0.2.ip6.arpa (n==6) */
 		n = getfields(buf, f, nelem(f), 0, ".");
-		pfxnibs = n - 2;
+		pfxnibs = n - 2;		/* 2 for .ip6.arpa */
 		if (pfxnibs < 0 || pfxnibs > V6maxrevdomdepth)
 			continue;
 
@@ -1155,7 +1152,6 @@ createv6ptrs(void)
 		/*
 		 * go through all domain entries looking for RR's
 		 * in this network and create ptrs.
-		 * +2 for .ip6.arpa.
 		 */
 		dnptr(net, mask, dom, Taaaa, V6maxrevdomdepth - pfxnibs, Ptrttl);
 	}

+ 35 - 22
sys/src/cmd/ndb/dn.c

@@ -11,10 +11,10 @@
  *  about 1780 names.
  *
  * aging seems to corrupt the cache, so raise the trigger from 4000 until we
- * figure it out.
+ * figure it out.  trying again with 4000...
  */
 enum {
-	Deftarget = 100000,
+	Deftarget = 4000,
 };
 enum {
 	Minage		= 10*60,
@@ -224,37 +224,25 @@ static int
 rronlist(RR *rp, RR *lp)
 {
 	for(; lp; lp = lp->next)
-		if (rrsame(lp, rp)) {
-			dnslog("adding duplicate %R to list of %R", rp, lp);
+		if (rrsame(lp, rp))
 			return 1;
-		}
 	return 0;
 }
 
-static void
-ckrronlist(RR *rp, RR *lp)
-{
-	if (rronlist(rp, lp)) {
-		dnslog("adding duplicate %R to list of %R", rp, lp);
-		abort();
-	}
-}
-
 /*
- *  dump the cache
+ * dump the stats
  */
 void
-dndump(char *file)
+dnstats(char *file)
 {
-	DN *dp;
 	int i, fd;
-	RR *rp;
 
 	fd = create(file, OWRITE, 0666);
 	if(fd < 0)
 		return;
 
 	qlock(&stats);
+	fprint(fd, "# system %s\n", sysname());
 	fprint(fd, "# slave procs high-water mark\t%lud\n", stats.slavehiwat);
 	fprint(fd, "# queries received by 9p\t%lud\n", stats.qrecvd9p);
 	fprint(fd, "# queries received by udp\t%lud\n", stats.qrecvdudp);
@@ -279,6 +267,25 @@ dndump(char *file)
 
 	lock(&dnlock);
 	fprint(fd, "\n# domain names %lud target %lud\n", dnvars.names, target);
+	unlock(&dnlock);
+	close(fd);
+}
+
+/*
+ *  dump the cache
+ */
+void
+dndump(char *file)
+{
+	int i, fd;
+	DN *dp;
+	RR *rp;
+
+	fd = create(file, OWRITE, 0666);
+	if(fd < 0)
+		return;
+
+	lock(&dnlock);
 	for(i = 0; i < HTLEN; i++)
 		for(dp = ht[i]; dp; dp = dp->next){
 			fprint(fd, "%s\n", dp->name);
@@ -550,7 +557,6 @@ dnagedb(void)
 	DN *dp;
 	int i;
 	RR *rp;
-	static ulong nextage;
 
 	lock(&dnlock);
 
@@ -576,7 +582,6 @@ dnauthdb(void)
 	Area *area;
 	DN *dp;
 	RR *rp;
-	static ulong nextage;
 
 	lock(&dnlock);
 
@@ -756,7 +761,11 @@ rrattach1(RR *new, int auth)
 		l = &rp->next;
 	}
 
-	ckrronlist(new, *l);
+	if (rronlist(new, *l)) {
+		/* should not happen; duplicates were processed above */
+		dnslog("adding duplicate %R to list of %R; aborting", new, *l);
+		abort();
+	}
 	/*
 	 *  add to chain
 	 */
@@ -1478,7 +1487,11 @@ dncheck(void *p, int dolock)
 				assert(rp->cached);
 				assert(rp->owner == dp);
 				/* also check for duplicate rrs */
-				ckrronlist(rp, rp->next);
+				if (dolock && rronlist(rp, rp->next)) {
+					dnslog("%R duplicates its next chain "
+						"(%R); aborting", rp, rp->next);
+					abort();
+				}
 			}
 		}
 	if(dolock)

+ 6 - 3
sys/src/cmd/ndb/dns.c

@@ -713,15 +713,18 @@ rwrite(Job *job, Mfile *mf, Request *req)
 	} else if(strcmp(job->request.data, "dump")==0){
 		dndump("/lib/ndb/dnsdump");
 		goto send;
-	} else if(strcmp(job->request.data, "refresh")==0){
-		needrefresh = 1;
-		goto send;
 	} else if(strcmp(job->request.data, "poolcheck")==0){
 		poolcheck(mainmem);
 		goto send;
+	} else if(strcmp(job->request.data, "refresh")==0){
+		needrefresh = 1;
+		goto send;
 	} else if(strcmp(job->request.data, "restart")==0){
 		stop = 1;
 		goto send;
+	} else if(strcmp(job->request.data, "stats")==0){
+		dnstats("/lib/ndb/dnsstats");
+		goto send;
 	} else if(strncmp(job->request.data, "target", 6)==0){
 		target = atol(job->request.data + 6);
 		dnslog("target set to %ld", target);

+ 1 - 0
sys/src/cmd/ndb/dns.h

@@ -463,6 +463,7 @@ void	dnptr(uchar*, uchar*, char*, int, int, int);
 void	dnpurge(void);
 void	dnput(void);
 void	dnslog(char*, ...);
+void	dnstats(char *file);
 void*	emalloc(int);
 char*	estrdup(char*);
 void	freeanswers(DNSmsg *mp);