changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: merge

changeset 7112: 15f5de9bb073
parent 7111: 4b62f6d0fd19
parent 7110: 3e16debe80e9
child 7114: 5502ebdaef11
author: Alex Musolino <alex@musolino.id.au>
date: Mon, 01 Apr 2019 23:14:14 +1030
files:
description: merge
     1.1--- a/rc/bin/cpurc
     1.2+++ b/rc/bin/cpurc
     1.3@@ -65,7 +65,7 @@ if(test -r /net/ipselftab){
     1.4 					# try /lib/ndb first, then do dhcp/slaac
     1.5 					ip/ipconfig -6 ether $ether
     1.6 					ip/ipconfig -N ether $ether >[2]/dev/null || @{
     1.7-						ip/ipconfig ether $ether ra6 recvra 1 &
     1.8+						test -e /env/nora6 || ip/ipconfig ether $ether ra6 recvra 1 &
     1.9 						ip/ipconfig -h $sysname ether $ether &
    1.10 						wait
    1.11 					}
     2.1--- a/rc/bin/inst/startether
     2.2+++ b/rc/bin/inst/startether
     2.3@@ -21,7 +21,7 @@ case go
     2.4 		ip/ipconfig -g $gwaddr ether $netdev $ipaddr $ipmask >>[2]/srv/log
     2.5 	case automatic
     2.6 		>>[2]/srv/log @{
     2.7-			ip/ipconfig ra6 recvra 1 &
     2.8+			test -e /env/nora6 || ip/ipconfig ra6 recvra 1 &
     2.9 			ip/ipconfig &
    2.10 			wait
    2.11 		}
     3.1--- a/rc/bin/termrc
     3.2+++ b/rc/bin/termrc
     3.3@@ -66,7 +66,7 @@ if(test -r /net/ipselftab){
     3.4 					# try /lib/ndb first, then do dhcp/slaac
     3.5 					ip/ipconfig -6 ether $ether
     3.6 					ip/ipconfig -N ether $ether >[2]/dev/null || @{
     3.7-						ip/ipconfig ether $ether ra6 recvra 1 &
     3.8+						test -e /env/nora6 || ip/ipconfig ether $ether ra6 recvra 1 &
     3.9 						ip/ipconfig -h $sysname ether $ether &
    3.10 						wait
    3.11 					}
     4.1--- a/sys/include/dtracy.h
     4.2+++ b/sys/include/dtracy.h
     4.3@@ -241,7 +241,7 @@ void dtsync(void);
     4.4 DTProbe *dtpnew(char *, DTProvider *, void *aux);
     4.5 int dtpmatch(char *, DTProbe ***);
     4.6 int dtplist(DTProbe ***);
     4.7-void dtptrigger(DTProbe *, int, DTTrigInfo *);
     4.8+void dtptrigger(DTProbe *, DTTrigInfo *);
     4.9 
    4.10 /* expression functions */
    4.11 int dteverify(DTExpr *);
    4.12@@ -285,7 +285,7 @@ uvlong dttime(void); /* return current t
    4.13 void *dtrealloc(void *, ulong);
    4.14 void dtfree(void *);
    4.15 void *dtmalloc(ulong);
    4.16-void dtmachlock(int); /* lock the per-cpu lock */
    4.17+int dtmachlock(int); /* lock the per-cpu lock */
    4.18 void dtmachunlock(int); /* unlock the per-cpu lock */
    4.19 void dtcoherence(void); /* memory barrier */
    4.20 uvlong dtgetvar(int); /* return the value of a variable */
     5.1--- a/sys/lib/dist/mkfile
     5.2+++ b/sys/lib/dist/mkfile
     5.3@@ -146,4 +146,5 @@ binds:V:
     5.4 	bind mail/lib /n/src9/mail/lib
     5.5 	bind ndb /n/src9/lib/ndb
     5.6 	bind -a adm/timezone /n/src9/adm/timezone
     5.7+	aux/stub -d /n/src9/usr
     5.8 	bind usr /n/src9/usr
     6.1new file mode 100644
     6.2--- /dev/null
     6.3+++ b/sys/man/1/walk
     6.4@@ -0,0 +1,122 @@
     6.5+.TH WALK 1
     6.6+.SH NAME
     6.7+walk \- walk a path
     6.8+.SH SYNOPSIS
     6.9+.B walk
    6.10+[
    6.11+.B -dftxu
    6.12+] [
    6.13+.B -n
    6.14+.I mind,maxd
    6.15+] [
    6.16+.B -e
    6.17+.I ststr
    6.18+] [
    6.19+.I name ...
    6.20+]
    6.21+.SH DESCRIPTION
    6.22+.I Walk
    6.23+recursively descends any directory arguments,
    6.24+printing the name of each file on a separate line.
    6.25+When no arguments are given, the current directory
    6.26+is assumed.
    6.27+Non-directory arguments are checked for existence,
    6.28+then printed, if so.
    6.29+.PP
    6.30+Options are:
    6.31+.TP
    6.32+.B -d
    6.33+Print only directories.
    6.34+.TP
    6.35+.B -f
    6.36+Print only non-directories.
    6.37+.TP
    6.38+.B -t
    6.39+Print a file only if it has the temporary flag set.
    6.40+.TP
    6.41+.B -x
    6.42+Print a file only if it has any executable bits set.
    6.43+.TP
    6.44+.B -u
    6.45+Unbuffered output.
    6.46+.TP
    6.47+.B -n min,max
    6.48+Set the inclusive range of depths for filtering in results.
    6.49+Both
    6.50+.I min
    6.51+and
    6.52+.I max
    6.53+are optional.
    6.54+.TP
    6.55+.B -e statfmt
    6.56+Setting the statfmt string allows specifying the data
    6.57+.B walk
    6.58+should print.
    6.59+It takes a string of characters, each corresponding
    6.60+to some piece of information about the file being
    6.61+traversed, and prints them separated by spaces.
    6.62+.PP
    6.63+The statfmt characters are as follows:
    6.64+.TF .
    6.65+.TP
    6.66+.B U
    6.67+owner name (uid)
    6.68+.TP
    6.69+.B G
    6.70+group name (gid)
    6.71+.TP
    6.72+.B M
    6.73+name of last user to modify (muid)
    6.74+.TP
    6.75+.B a
    6.76+last access time (atime)
    6.77+.TP
    6.78+.B m
    6.79+last modification time (mtime)
    6.80+.TP
    6.81+.B n
    6.82+final path element (name)
    6.83+.TP
    6.84+.B p
    6.85+path
    6.86+.TP
    6.87+.B q
    6.88+qid path.version.type (see
    6.89+.IR stat (2))
    6.90+.TP
    6.91+.B s
    6.92+size in bytes
    6.93+.TP
    6.94+.B x
    6.95+permissions
    6.96+.PD
    6.97+.PP
    6.98+The default statfmt is simply,
    6.99+.IR p .
   6.100+.SH EXAMPLES
   6.101+List files in a directory, sorted by modification time.
   6.102+.IP
   6.103+.EX
   6.104+walk -femp catpics | sort -n | sed 's/^[^ ]+ //'
   6.105+.EE
   6.106+.PP
   6.107+Print the size and path of files (excluding dirs)
   6.108+in the working directory.
   6.109+.IP
   6.110+.EX
   6.111+walk -fn1 -esp
   6.112+.EE
   6.113+.PD
   6.114+.SH SOURCE
   6.115+.B /sys/src/cmd/walk.c
   6.116+.SH SEE ALSO
   6.117+.IR ls (1),
   6.118+.IR du (1)
   6.119+.SH BUGS
   6.120+Statfmt character `x' displays permissions as an integer.
   6.121+.PP
   6.122+Manipulating ifs is a nuisance.
   6.123+.PP
   6.124+File names are assumed to not contain newlines.
   6.125+.PP
   6.126+Correct invocation requires too much thought.
     7.1--- a/sys/man/8/plan9.ini
     7.2+++ b/sys/man/8/plan9.ini
     7.3@@ -443,6 +443,8 @@ to be present on attach in
     7.4 or
     7.5 .B /boot. 
     7.6 See iwl section above for configuration details.
     7.7+.SS \fLnora6=
     7.8+Disable automatic IPv6 configuration from incoming router advertisements.
     7.9 .SS DISKS, TAPES
    7.10 (S)ATA controllers are autodetected.
    7.11 .SS \fL*nodma=\fP
    7.12@@ -865,6 +867,18 @@ The main feature of the interface is the
    7.13 battery life (see
    7.14 .IR stats (8)).
    7.15 It is not on by default because it causes problems on some laptops.
    7.16+.SS USB
    7.17+.SS \fL*nousbprobe=\fP
    7.18+Disable USB host controller detection.
    7.19+.SS \fL*nousbohci=\fP
    7.20+.SS \fL*nousbuhci=\fP
    7.21+.SS \fL*nousbehci=\fP
    7.22+.SS \fL*nousbxhci=\fP
    7.23+Disable specific USB host controller types.
    7.24+.SS \fLnousbrc=\fP
    7.25+Disable
    7.26+.IR nusbrc (8)
    7.27+startup at boot time.
    7.28 .SS \fLnousbhname=\fP
    7.29 When defined,
    7.30 .IR nusbrc (8)
     8.1--- a/sys/src/9/boot/net.rc
     8.2+++ b/sys/src/9/boot/net.rc
     8.3@@ -15,9 +15,9 @@ fn confignet{
     8.4 		}
     8.5 	}
     8.6 
     8.7-	if(~ $1 ether && ~ $#* 2) @{
     8.8+	if(~ $1 ether gbe && ~ $#* 2) @{
     8.9 		ip/ipconfig -6 $*
    8.10-		ip/ipconfig $* ra6 recvra 1 &
    8.11+		test -e /env/nora6 || ip/ipconfig $* ra6 recvra 1 &
    8.12 		ip/ipconfig -p $* &
    8.13 		wait
    8.14 	}
     9.1--- a/sys/src/9/port/devdtracy.c
     9.2+++ b/sys/src/9/port/devdtracy.c
     9.3@@ -512,10 +512,18 @@ dtrealloc(void *v, ulong n)
     9.4 	return v;
     9.5 }
     9.6 
     9.7-void
     9.8+int
     9.9 dtmachlock(int i)
    9.10 {
    9.11+	while(i < 0) {
    9.12+		i = dtmachlock(m->machno);
    9.13+		if(i == m->machno)
    9.14+			return i;
    9.15+		dtmachunlock(i);
    9.16+		i = -1;
    9.17+	}
    9.18 	ilock(&machlocks[i]);
    9.19+	return i;
    9.20 }
    9.21 
    9.22 void
    10.1--- a/sys/src/9/port/dtracysys.c
    10.2+++ b/sys/src/9/port/dtracysys.c
    10.3@@ -20,10 +20,10 @@ extern Syscall *systab[];
    10.4 	uintptr rc;\
    10.5 	DTTrigInfo info;\
    10.6 	memset(&info, 0, sizeof(info));\
    10.7-	dtptrigger(dtpsysentry[y], m->machno, &info);\
    10.8+	dtptrigger(dtpsysentry[y], &info);\
    10.9 	rc = z(va);\
   10.10 	info.arg[9] = (uvlong) rc;\
   10.11-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.12+	dtptrigger(dtpsysreturn[y], &info);\
   10.13 	return rc;\
   10.14 }
   10.15 #define WRAP1(x,y,z,type0)\
   10.16@@ -33,10 +33,10 @@ extern Syscall *systab[];
   10.17 	DTTrigInfo info;\
   10.18 	memset(&info, 0, sizeof(info));\
   10.19 	info.arg[0] = (uvlong) va_arg(vb, type0);\
   10.20-	dtptrigger(dtpsysentry[y], m->machno, &info);\
   10.21+	dtptrigger(dtpsysentry[y], &info);\
   10.22 	rc = z(va);\
   10.23 	info.arg[9] = (uvlong) rc;\
   10.24-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.25+	dtptrigger(dtpsysreturn[y], &info);\
   10.26 	return rc;\
   10.27 }
   10.28 #define WRAP2(x,y,z,type0,type1)\
   10.29@@ -47,10 +47,10 @@ extern Syscall *systab[];
   10.30 	memset(&info, 0, sizeof(info));\
   10.31 	info.arg[0] = (uvlong) va_arg(vb, type0);\
   10.32 	info.arg[1] = (uvlong) va_arg(vb, type1);\
   10.33-	dtptrigger(dtpsysentry[y], m->machno, &info);\
   10.34+	dtptrigger(dtpsysentry[y], &info);\
   10.35 	rc = z(va);\
   10.36 	info.arg[9] = (uvlong) rc;\
   10.37-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.38+	dtptrigger(dtpsysreturn[y], &info);\
   10.39 	return rc;\
   10.40 }
   10.41 #define WRAP3(x,y,z,type0,type1,type2)\
   10.42@@ -62,10 +62,10 @@ extern Syscall *systab[];
   10.43 	info.arg[0] = (uvlong) va_arg(vb, type0);\
   10.44 	info.arg[1] = (uvlong) va_arg(vb, type1);\
   10.45 	info.arg[2] = (uvlong) va_arg(vb, type2);\
   10.46-	dtptrigger(dtpsysentry[y], m->machno, &info);\
   10.47+	dtptrigger(dtpsysentry[y], &info);\
   10.48 	rc = z(va);\
   10.49 	info.arg[9] = (uvlong) rc;\
   10.50-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.51+	dtptrigger(dtpsysreturn[y], &info);\
   10.52 	return rc;\
   10.53 }
   10.54 #define WRAP4(x,y,z,type0,type1,type2,type3)\
   10.55@@ -78,10 +78,10 @@ extern Syscall *systab[];
   10.56 	info.arg[1] = (uvlong) va_arg(vb, type1);\
   10.57 	info.arg[2] = (uvlong) va_arg(vb, type2);\
   10.58 	info.arg[3] = (uvlong) va_arg(vb, type3);\
   10.59-	dtptrigger(dtpsysentry[y], m->machno, &info);\
   10.60+	dtptrigger(dtpsysentry[y], &info);\
   10.61 	rc = z(va);\
   10.62 	info.arg[9] = (uvlong) rc;\
   10.63-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.64+	dtptrigger(dtpsysreturn[y], &info);\
   10.65 	return rc;\
   10.66 }
   10.67 /*TODO*/
   10.68@@ -96,10 +96,10 @@ extern Syscall *systab[];
   10.69 	info.arg[2] = (uvlong) va_arg(vb, type2);\
   10.70 	info.arg[3] = (uvlong) va_arg(vb, type3);\
   10.71 	info.arg[4] = (uvlong) va_arg(vb, type4);\
   10.72-	dtptrigger(dtpsysentry[y], m->machno, &info);\
   10.73+	dtptrigger(dtpsysentry[y], &info);\
   10.74 	rc = z(va);\
   10.75 	info.arg[9] = (uvlong) rc;\
   10.76-	dtptrigger(dtpsysreturn[y], m->machno, &info);\
   10.77+	dtptrigger(dtpsysreturn[y], &info);\
   10.78 	return rc;\
   10.79 }
   10.80 
    11.1--- a/sys/src/9/port/dtracytimer.c
    11.2+++ b/sys/src/9/port/dtracytimer.c
    11.3@@ -17,7 +17,7 @@ dtracytimer(void *)
    11.4 	memset(&info, 0, sizeof(info));
    11.5 	for(;;){
    11.6 		tsleep(&up->sleep, return0, nil, 1000);
    11.7-		dtptrigger(timerprobe, m->machno, &info);
    11.8+		dtptrigger(timerprobe, &info);
    11.9 	}
   11.10 }
   11.11 
    12.1--- a/sys/src/9/port/portmkfile
    12.2+++ b/sys/src/9/port/portmkfile
    12.3@@ -80,6 +80,7 @@ devpipe.$O:	../port/netif.h
    12.4 netif.$O:	../port/netif.h
    12.5 devuart.$O:	../port/netif.h
    12.6 devbridge.$O:	../port/netif.h ../ip/ip.h ../ip/ipv6.h
    12.7+devdtracy.$O dtracysys.$O dtracytimer.$O:	/sys/include/dtracy.h
    12.8 devdraw.$O:	screen.h /sys/include/draw.h /sys/include/memdraw.h /sys/include/memlayer.h /sys/include/cursor.h
    12.9 devmouse.$O:	screen.h /sys/include/draw.h /sys/include/memdraw.h /sys/include/cursor.h
   12.10 swcursor.$O:	screen.h /sys/include/draw.h /sys/include/memdraw.h /sys/include/cursor.h
    13.1--- a/sys/src/cmd/5c/peep.c
    13.2+++ b/sys/src/cmd/5c/peep.c
    13.3@@ -337,7 +337,7 @@ subprop(Reg *r0)
    13.4 			break;
    13.5 
    13.6 		case AMOVM:
    13.7-			t = 1<<v2->reg;
    13.8+			t = (1<<v1->reg) | (1<<v2->reg);
    13.9 			if((p->from.type == D_CONST && (p->from.offset&t)) ||
   13.10 			   (p->to.type == D_CONST && (p->to.offset&t)))
   13.11 				return 0;
    14.1--- a/sys/src/cmd/upas/fs/mbox.c
    14.2+++ b/sys/src/cmd/upas/fs/mbox.c
    14.3@@ -76,8 +76,10 @@ syncmbox(Mailbox *mb, int doplumb)
    14.4 	a = mb->root->subname;
    14.5 	if(rdidxfile(mb) == -2)
    14.6 		wridxfile(mb);
    14.7-	if(s = mb->sync(mb))
    14.8+	if(s = mb->sync(mb)){
    14.9+		mb->syncing = 0;
   14.10 		return s;
   14.11+	}
   14.12 	n = 0;
   14.13 	d = 0;
   14.14 	y = 0;
    15.1new file mode 100644
    15.2--- /dev/null
    15.3+++ b/sys/src/cmd/walk.c
    15.4@@ -0,0 +1,321 @@
    15.5+#include <u.h>
    15.6+#include <libc.h>
    15.7+#include <bio.h>
    15.8+#include <String.h>
    15.9+
   15.10+int Cflag = 0;
   15.11+int uflag = 0;
   15.12+String *stfmt;
   15.13+
   15.14+/* should turn these flags into a mask */
   15.15+int dflag = 1;
   15.16+int fflag = 1;
   15.17+int tflag = 0;
   15.18+int xflag = 0;
   15.19+long maxdepth = ~(1<<31);
   15.20+long mindepth = 0;
   15.21+
   15.22+char *dotpath = ".";
   15.23+Dir *dotdir = nil;
   15.24+
   15.25+Biobuf *bout;
   15.26+
   15.27+int seen(Dir*);
   15.28+
   15.29+void
   15.30+warn(char *fmt, ...)
   15.31+{
   15.32+	va_list arg;
   15.33+	char buf[1024];	/* arbitrary */
   15.34+	int n;
   15.35+
   15.36+	if((n = snprint(buf, sizeof(buf), "%s: ", argv0)) < 0)
   15.37+		sysfatal("snprint: %r");
   15.38+	va_start(arg, fmt);
   15.39+	vseprint(buf+n, buf+sizeof(buf), fmt, arg);
   15.40+	va_end(arg);
   15.41+
   15.42+	Bflush(bout);
   15.43+	fprint(2, "%s\n", buf);
   15.44+}
   15.45+
   15.46+void
   15.47+dofile(char *path, Dir *f, int pathonly)
   15.48+{
   15.49+	char *p;
   15.50+
   15.51+	if(
   15.52+		(f == dotdir)
   15.53+		|| (tflag && ! (f->qid.type & QTTMP))
   15.54+		|| (xflag && ! (f->mode & DMEXEC))
   15.55+	)
   15.56+		return;
   15.57+
   15.58+	for(p = s_to_c(stfmt); *p != '\0'; p++){
   15.59+		switch(*p){
   15.60+		case 'U': Bwrite(bout, f->uid, strlen(f->uid)); break;
   15.61+		case 'G': Bwrite(bout, f->gid, strlen(f->gid)); break;
   15.62+		case 'M': Bwrite(bout, f->muid, strlen(f->muid)); break;
   15.63+		case 'a': Bprint(bout, "%uld", f->atime); break;
   15.64+		case 'm': Bprint(bout, "%uld", f->mtime); break;
   15.65+		case 'n': Bwrite(bout, f->name, strlen(f->name)); break;
   15.66+		case 'p':
   15.67+			if(path != dotpath)
   15.68+				Bwrite(bout, path, strlen(path));
   15.69+			if(! (f->qid.type & QTDIR) && !pathonly){
   15.70+				if(path != dotpath)
   15.71+					Bputc(bout, '/');
   15.72+				Bwrite(bout, f->name, strlen(f->name));
   15.73+			}
   15.74+			break;
   15.75+		case 'q': Bprint(bout, "%ullx.%uld.%.2uhhx", f->qid.path, f->qid.vers, f->qid.type); break;
   15.76+		case 's': Bprint(bout, "%lld", f->length); break;
   15.77+		case 'x': Bprint(bout, "%ulo", f->mode); break;
   15.78+		default:
   15.79+			abort();
   15.80+		}
   15.81+
   15.82+		if(*(p+1) != '\0')
   15.83+			Bputc(bout, ' ');
   15.84+	}
   15.85+
   15.86+	Bputc(bout, '\n');
   15.87+
   15.88+	if(uflag)
   15.89+		Bflush(bout);
   15.90+}
   15.91+
   15.92+void
   15.93+walk(char *path, Dir *cf, long depth)
   15.94+{
   15.95+	String *file;
   15.96+	Dir *dirs, *f, *fe;
   15.97+	int fd;
   15.98+	long n;
   15.99+
  15.100+	if(cf == nil){
  15.101+		warn("path: %s: %r", path);
  15.102+		return;
  15.103+	}
  15.104+
  15.105+	if(depth >= maxdepth)
  15.106+		goto nodescend;
  15.107+
  15.108+	if((fd = open(path, OREAD)) < 0){
  15.109+		warn("couldn't open %s: %r", path);
  15.110+		return;
  15.111+	}
  15.112+
  15.113+	while((n = dirread(fd, &dirs)) > 0){
  15.114+		fe = dirs+n;
  15.115+		for(f = dirs; f < fe; f++){
  15.116+			if(seen(f))
  15.117+				continue;
  15.118+			if(! (f->qid.type & QTDIR)){
  15.119+				if(fflag && depth >= mindepth)
  15.120+					dofile(path, f, 0);
  15.121+			} else if(strcmp(f->name, ".") == 0 || strcmp(f->name, "..") == 0){
  15.122+				warn(". or .. named file: %s/%s", path, f->name);
  15.123+			} else{
  15.124+				if(depth+1 > maxdepth){
  15.125+					dofile(path, f, 0);
  15.126+					continue;
  15.127+				} else if(path == dotpath){
  15.128+					if((file = s_new()) == nil)
  15.129+						sysfatal("s_new: %r");
  15.130+				} else{
  15.131+					if((file = s_copy(path)) == nil)
  15.132+						sysfatal("s_copy: %r");
  15.133+					if(s_len(file) != 1 || *s_to_c(file) != '/')
  15.134+						s_putc(file, '/');
  15.135+				}
  15.136+				s_append(file, f->name);
  15.137+
  15.138+				walk(s_to_c(file), f, depth+1);	
  15.139+				s_free(file);
  15.140+			}
  15.141+		}
  15.142+		free(dirs);
  15.143+	}
  15.144+	close(fd);
  15.145+	if(n < 0)
  15.146+		warn("%s: %r", path);
  15.147+
  15.148+nodescend:
  15.149+	depth--;
  15.150+	if(dflag && depth >= mindepth)
  15.151+		dofile(path, cf, 0);
  15.152+}
  15.153+
  15.154+char*
  15.155+slashslash(char *s)
  15.156+{
  15.157+	char *p, *q;
  15.158+
  15.159+	for(p=q=s; *q; q++){
  15.160+		if(q>s && *q=='/' && *(q-1)=='/')
  15.161+			continue;
  15.162+		if(p != q)
  15.163+			*p = *q;
  15.164+		p++;
  15.165+	}
  15.166+	do{
  15.167+		*p-- = '\0';
  15.168+	} while(p>s && *p=='/');
  15.169+
  15.170+	return s;
  15.171+}
  15.172+
  15.173+long
  15.174+estrtol(char *as, char **aas, int base)
  15.175+{
  15.176+	long n;
  15.177+	char *p;
  15.178+
  15.179+	n = strtol(as, &p, base);
  15.180+	if(p == as || *p != '\0')
  15.181+		sysfatal("estrtol: bad input '%s'", as);
  15.182+	else if(aas != nil)
  15.183+		*aas = p;
  15.184+
  15.185+	return n;
  15.186+}
  15.187+
  15.188+void
  15.189+elimdepth(char *p){
  15.190+	char *q;
  15.191+
  15.192+	if(strlen(p) == 0)
  15.193+		sysfatal("empty depth argument");
  15.194+
  15.195+	if(q = strchr(p, ',')){
  15.196+		*q = '\0';
  15.197+		if(p != q)
  15.198+			mindepth = estrtol(p, nil, 0);
  15.199+		p = q+1;
  15.200+		if(*p == '\0')
  15.201+			return;
  15.202+	}
  15.203+
  15.204+	maxdepth = estrtol(p, nil, 0);
  15.205+}
  15.206+
  15.207+void
  15.208+usage(void)
  15.209+{
  15.210+	fprint(2, "usage: %s [-udftx] [-n mind,maxd] [-e statfmt] [file ...]\n", argv0);
  15.211+	exits("usage");
  15.212+}
  15.213+
  15.214+/*
  15.215+	Last I checked (commit 3dd6a31881535615389c24ab9a139af2798c462c),
  15.216+	libString calls sysfatal when things go wrong; in my local
  15.217+	copy of libString, failed calls return nil and errstr is set.
  15.218+
  15.219+	There are various nil checks in this code when calling libString
  15.220+	functions, but since they are a no-op and libString needs
  15.221+	a rework, I left them in - BurnZeZ
  15.222+*/
  15.223+
  15.224+void
  15.225+main(int argc, char **argv)
  15.226+{
  15.227+	long i;
  15.228+	Dir *d;
  15.229+
  15.230+	stfmt = nil;
  15.231+	ARGBEGIN{
  15.232+	case 'C': Cflag++; break; /* undocumented; do not cleanname() the args */
  15.233+	case 'u': uflag++; break; /* unbuffered output */
  15.234+
  15.235+	case 'd': dflag++; fflag = 0; break; /* only dirs */
  15.236+	case 'f': fflag++; dflag = 0; break; /* only non-dirs */
  15.237+	case 't': tflag++; break; /* only tmp files */
  15.238+	case 'x': xflag++; break; /* only executable permission */
  15.239+
  15.240+	case 'n': elimdepth(EARGF(usage())); break;
  15.241+	case 'e':
  15.242+		if((stfmt = s_reset(stfmt)) == nil)
  15.243+			sysfatal("s_reset: %r");
  15.244+		s_append(stfmt, EARGF(usage()));
  15.245+		i = strspn(s_to_c(stfmt), "UGMamnpqsx");
  15.246+		if(i != s_len(stfmt))
  15.247+			sysfatal("bad stfmt: %s\n", s_to_c(stfmt));
  15.248+		break;
  15.249+	default:
  15.250+		usage();
  15.251+	}ARGEND;
  15.252+
  15.253+	if((bout = Bfdopen(1, OWRITE)) == nil)
  15.254+		sysfatal("Bfdopen: %r");
  15.255+	Blethal(bout, nil);
  15.256+	if(stfmt == nil){
  15.257+		if((stfmt = s_new()) == nil)
  15.258+			sysfatal("s_new: %r");
  15.259+		s_putc(stfmt, 'p');
  15.260+		s_terminate(stfmt);
  15.261+	}
  15.262+	if(maxdepth != ~(1<<31))
  15.263+		maxdepth++;
  15.264+	if(argc == 0){
  15.265+		dotdir = dirstat(".");
  15.266+		walk(dotpath, dotdir, 1);
  15.267+	} else for(i=0; i<argc; i++){
  15.268+		if(strncmp(argv[i], "#/", 2) == 0)
  15.269+			slashslash(argv[i]+2);
  15.270+		else{
  15.271+			if(!Cflag)
  15.272+				cleanname(argv[i]);
  15.273+			slashslash(argv[i]);
  15.274+		}
  15.275+		if((d = dirstat(argv[i])) != nil && ! (d->qid.type & QTDIR)){
  15.276+			if(fflag && !seen(d) && mindepth < 1)
  15.277+				dofile(argv[i], d, 1);
  15.278+		} else
  15.279+			walk(argv[i], d, 1);
  15.280+		free(d);
  15.281+	}
  15.282+	Bterm(bout);
  15.283+
  15.284+	exits(nil);
  15.285+}
  15.286+
  15.287+/* below pilfered from /sys/src/cmd/du.c
  15.288+ * NOTE: I did not check for bugs */
  15.289+
  15.290+#define	NCACHE	256	/* must be power of two */
  15.291+
  15.292+typedef struct
  15.293+{
  15.294+	Dir*	cache;
  15.295+	int	n;
  15.296+	int	max;
  15.297+} Cache;
  15.298+Cache cache[NCACHE];
  15.299+
  15.300+int
  15.301+seen(Dir *dir)
  15.302+{
  15.303+	Dir *dp;
  15.304+	int i;
  15.305+	Cache *c;
  15.306+
  15.307+	c = &cache[dir->qid.path&(NCACHE-1)];
  15.308+	dp = c->cache;
  15.309+	for(i=0; i<c->n; i++, dp++)
  15.310+		if(dir->qid.path == dp->qid.path &&
  15.311+		   dir->type == dp->type &&
  15.312+		   dir->dev == dp->dev)
  15.313+			return 1;
  15.314+	if(c->n == c->max){
  15.315+		if (c->max == 0)
  15.316+			c->max = 8;
  15.317+		else
  15.318+			c->max += c->max/2;
  15.319+		c->cache = realloc(c->cache, c->max*sizeof(Dir));
  15.320+		if(c->cache == nil)
  15.321+			sysfatal("realloc: %r");
  15.322+	}
  15.323+	c->cache[c->n++] = *dir;
  15.324+	return 0;
  15.325+}
    16.1--- a/sys/src/cmd/webfs/fns.h
    16.2+++ b/sys/src/cmd/webfs/fns.h
    16.3@@ -15,10 +15,12 @@ char*	unquote(char *s, char **ps);
    16.4 #pragma	varargck type "U" Url*
    16.5 #pragma varargck type "E" Str2
    16.6 #pragma varargck type "N" char*
    16.7+#pragma varargck type "]" char*
    16.8 
    16.9 int	Efmt(Fmt*);
   16.10 int	Nfmt(Fmt*);
   16.11 int	Ufmt(Fmt*);
   16.12+int	Mfmt(Fmt*);
   16.13 char*	Upath(Url *);
   16.14 Url*	url(char *s, Url *b);
   16.15 Url*	saneurl(Url *u);
    17.1--- a/sys/src/cmd/webfs/fs.c
    17.2+++ b/sys/src/cmd/webfs/fs.c
    17.3@@ -766,6 +766,7 @@ main(int argc, char *argv[])
    17.4 	quotefmtinstall();
    17.5 	fmtinstall('U', Ufmt);
    17.6 	fmtinstall('N', Nfmt);
    17.7+	fmtinstall(']', Mfmt);
    17.8 	fmtinstall('E', Efmt);
    17.9 	fmtinstall('[', encodefmt);
   17.10 	fmtinstall('H', encodefmt);
    18.1--- a/sys/src/cmd/webfs/http.c
    18.2+++ b/sys/src/cmd/webfs/http.c
    18.3@@ -637,7 +637,7 @@ http(char *m, Url *u, Key *shdr, Buq *qb
    18.4 			ru.path = Upath(u);
    18.5 			ru.query = u->query;
    18.6 		}
    18.7-		n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %s%s%s\r\n",
    18.8+		n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %]%s%s\r\n",
    18.9 			method, &ru, host, u->port ? ":" : "", u->port ? u->port : "");
   18.10 		if(n >= sizeof(buf)-64){
   18.11 			werrstr("request too large");
   18.12@@ -649,7 +649,7 @@ http(char *m, Url *u, Key *shdr, Buq *qb
   18.13 				break;
   18.14 		}
   18.15 		if(h->tunnel){
   18.16-			n = snprint(buf, sizeof(buf), "CONNECT %s:%s HTTP/1.1\r\nHost: %s:%s\r\n",
   18.17+			n = snprint(buf, sizeof(buf), "CONNECT %]:%s HTTP/1.1\r\nHost: %]:%s\r\n",
   18.18 				host, u->port ? u->port : "443",
   18.19 				host, u->port ? u->port : "443");
   18.20 		}
    19.1--- a/sys/src/cmd/webfs/url.c
    19.2+++ b/sys/src/cmd/webfs/url.c
    19.3@@ -83,6 +83,14 @@ Nfmt(Fmt *f)
    19.4 }
    19.5 
    19.6 int
    19.7+Mfmt(Fmt *f)
    19.8+{
    19.9+	char *s = va_arg(f->args, char*);
   19.10+	fmtprint(f, (*s != '[' && strchr(s, ':') != nil)? "[%s]" : "%s", s);
   19.11+	return 0;
   19.12+}
   19.13+
   19.14+int
   19.15 Ufmt(Fmt *f)
   19.16 {
   19.17 	char *s;
   19.18@@ -101,7 +109,7 @@ Ufmt(Fmt *f)
   19.19 		fmtprint(f, "@");
   19.20 	}
   19.21 	if(u->host){
   19.22-		fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%s", u->host);
   19.23+		fmtprint(f, "%]", u->host);
   19.24 		if(u->port)
   19.25 			fmtprint(f, ":%s", u->port);
   19.26 	}
    20.1--- a/sys/src/libdtracy/prog.c
    20.2+++ b/sys/src/libdtracy/prog.c
    20.3@@ -336,13 +336,12 @@ dtgexec(DTActGr *g, DTTrigInfo *info)
    20.4 }
    20.5 
    20.6 void
    20.7-dtptrigger(DTProbe *p, int machno, DTTrigInfo *info)
    20.8+dtptrigger(DTProbe *p, DTTrigInfo *info)
    20.9 {
   20.10 	DTEnab *e;
   20.11 	
   20.12 	info->ts = dttime();
   20.13-	dtmachlock(machno);
   20.14-	info->machno = machno;
   20.15+	info->machno = dtmachlock(-1);
   20.16 	for(e = p->enablist.probnext; e != &p->enablist; e = e->probnext)
   20.17 		if(e->gr->chan->state == DTCGO){
   20.18 			info->ch = e->gr->chan;
   20.19@@ -350,5 +349,5 @@ dtptrigger(DTProbe *p, int machno, DTTri
   20.20 			if(dtgexec(e->gr, info) < 0)
   20.21 				e->gr->chan->state = DTCFAULT;
   20.22 		}
   20.23-	dtmachunlock(machno);
   20.24+	dtmachunlock(info->machno);
   20.25 }