Commit Diff


commit - 4f48d1d4f72b1986ba6df3ccd9db62cfa1ef3df9
commit + 2e965b3324b32be00a2193bf304dcb936f02824b
blob - 9fcd9b58196d4a672337cee8c6ed52206acbf258
blob + d4787e78703dbb6e5d973e5e6b7d4645706ccce2
--- acid/thread
+++ acid/thread
@@ -60,11 +60,6 @@ defn altfmt(A){
 defn alt(A){
 	print(altfmt(A), "\n");
 }
-
-threadignsrc = {
-	"plan9/src/libc",
-	"plan9/src/libthread",
-};
 
 defn fnname(a){
 	local sym, s;
@@ -100,7 +95,7 @@ defn threadstkline(T){
 		pc = frame[2];
 		pc0 = frame[0];
 		file = pcfile(pc);
-		if !regexp("plan9/src/libc/", file)
+		if !regexp("plan9/src/lib9/", file)
 		&& !regexp("plan9/src/libthread/", file) 
 		&& match(file, stkignore)==-1 then
 			stop = 1;
@@ -234,7 +229,8 @@ defn lproc(P){
 
 threadstkignore = {
 	"plan9/src/libthread/",
-	"plan9/src/libc/(386|arm|alpha|sparc|power|mips)/"
+	"plan9/src/lib9/",
+	"plan9/src/lib9/(fmt|utf)/",
 };
 defn threadstks(P){
 	complex Proc P;
blob - 2c286e1593cbde409556f0e0f8d0bfc0e71d99e4
blob + 66996345b51bb3593f4138c398ca65dc4a9c41f0
--- src/cmd/acid/proc.c
+++ src/cmd/acid/proc.c
@@ -30,7 +30,7 @@ sproc(int xpid)
 	correg = nil;
 
 	if(mapproc(xpid, cormap, &correg) < 0)
-		error("setproc %d: %r", pid);
+		error("setproc %d: %r", xpid);
 
 	/* XXX check text file here? */
 
@@ -165,6 +165,17 @@ install(int pid)
 	s->v->set = 1;
 }
 
+static int
+installed(int pid)
+{
+	int i;
+
+	for(i=0; i<Maxproc; i++)
+		if(ptab[i].pid == pid)
+			return 1;
+	return 0;
+}
+
 void
 deinstall(int pid)
 {
blob - b47a8c23910ef86a369d6a85bf3dff6f280b89f1
blob + c492ae15275b7c7963b3fcaa7bd225340b02b3e5
--- src/lib9/_p9proc.c
+++ src/lib9/_p9proc.c
@@ -54,7 +54,7 @@ _p9uproc(int inhandler)
 	while((up = mallocz(sizeof(Uproc), 1)) == nil)
 		sleep(1000);
 
-//fprint(2, "alloc uproc for pid %d\n", pid);
+	/* fprint(2, "alloc uproc for pid %d\n", pid); */
 	up->pid = pid;
 	lock(&uproclock);
 	h = pid%PIDHASH;
@@ -82,7 +82,7 @@ _p9uprocdie(void)
 	int pid, i, h;
 
 	pid = getpid();
-fprint(2, "reap uproc for pid %d\n", pid);
+	/* fprint(2, "reap uproc for pid %d\n", pid); */
 	h = pid%PIDHASH;
 	for(i=0; i<PIDHASH; i++){
 		up = alluproc[h];
blob - 5983345e39b1b5fb8e3fe8d2677b485f502df60d
blob + 0677cc8f306fb438da6256c602e6658559e46d82
--- src/libhttpd/gethead.c
+++ src/libhttpd/gethead.c
@@ -15,15 +15,11 @@ hgethead(HConnect *c, int many)
 	int n;
 
 	hin = &c->hin;
-fprint(2, "hgethead top %p - %p\n", hin->pos, hin->stop);
 	for(;;){
 		s = (char*)hin->pos;
 		pp = s;
-fprint(2, "hgethead %p - %p\n", pp, hin->stop);
 		while(p = memchr(pp, '\n', (char*)hin->stop - pp)){
-fprint(2, "hgethead %p - %p newline at %p %d\n", pp, hin->stop, p, *pp);
 			if(!many || p == pp || (p == pp + 1 && *pp == '\r')){
-fprint(2, "breaking\n");
 				pp = p + 1;
 				break;
 			}
@@ -32,14 +28,13 @@ fprint(2, "breaking\n");
 		hin->pos = (uchar*)pp;
 		n = pp - s;
 		if(c->hstop + n > &c->header[HBufSize])
-			return 0;
+			return -1;
 		memmove(c->hstop, s, n);
 		c->hstop += n;
 		*c->hstop = '\0';
-fprint(2, "p %p\n", p);
 		if(p != nil)
-			return 1;
-		if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
 			return 0;
+		if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
+			return -1;
 	}
 }
blob - 34d3a3a2c5f5c957d6b75e7dfc74c9459da34f20
blob + 3561b68168def8e8cf3de8cbb0e9eb5653e22a13
--- src/libhttpd/hio.c
+++ src/libhttpd/hio.c
@@ -281,7 +281,7 @@ hload(Hio *h, char *buf)
 
 	s = strchr(hstates, buf[0]);
 	if(s == nil)
-		return 0;
+		return -1;
 	h->state = s - hstates;
 
 	s = strchr(hxfers, buf[1]);
@@ -300,13 +300,13 @@ hload(Hio *h, char *buf)
 		}
 		*t++ = c;
 		if(t >= stop)
-			return 0;
+			return -1;
 	}
 	*t = '\0';
 	h->pos = h->start;
 	h->stop = t;
 	h->seek = 0;
-	return 1;
+	return 0;
 }
 
 void
blob - 5fd4092a388fb914bb8d2987581216ece1ee715c
blob + 8e8364b0572dadd966b56fb449797e670b2516b8
--- src/libhttpd/parse.c
+++ src/libhttpd/parse.c
@@ -198,7 +198,7 @@ hparseheaders(HConnect *c, int timeout)
 	memset(&h, 0, sizeof(h));
 	h.c = c;
 	alarm(timeout);
-	if(!hgethead(c, 1))
+	if(hgethead(c, 1) < 0)
 		return -1;
 	alarm(0);
 	h.hstart = c->hpos;
blob - 7ef634139a9e9c3e5632cb3ed78bedea458ac5b3
blob + 9423798849bcdb1251ee05697a43a4fe8717d337
--- src/libhttpd/parsereq.c
+++ src/libhttpd/parsereq.c
@@ -41,8 +41,8 @@ hparsereq(HConnect *c, int timeout)
 	 * only works for http/1.1 or later.
 	 */
 	alarm(timeout);
-	if(!hgethead(c, 0))
-		return 0;
+	if(hgethead(c, 0) < 0)
+		return -1;
 	alarm(0);
 	c->reqtime = time(nil);
 	c->req.meth = getword(c);
blob - 62796adbce1b346fede9efadda2ff75cd642010b
blob + 12b0f9b8001beaab242e039df8d44cd04621f0fa
--- src/libmach/Linux.c
+++ src/libmach/Linux.c
@@ -37,6 +37,9 @@ struct PtraceRegs
 static int ptracerw(Map*, Seg*, ulong, void*, uint, int);
 static int ptraceregrw(Regs*, char*, ulong*, int);
 
+static int attachedpids[1000];
+static int nattached;
+
 void
 unmapproc(Map *map)
 {
@@ -55,21 +58,36 @@ unmapproc(Map *map)
 int
 mapproc(int pid, Map *map, Regs **rp)
 {
+	int i;
 	Seg s;
 	PtraceRegs *r;
 
-	if(ptrace(PTRACE_ATTACH, pid, 0, 0) < 0)
-	if(ptrace(PTRACE_PEEKUSER, pid, 0, 0) < 0)
+	if(nattached==1 && attachedpids[0] == pid)
+		goto already;
+	if(nattached)
+		detachproc(attachedpids[0]);
+
+	for(i=0; i<nattached; i++)
+		if(attachedpids[i]==pid)
+			goto already;
+	if(nattached == nelem(attachedpids)){
+		werrstr("attached to too many processes");
+		return -1;
+	}
+
 	if(ptrace(PTRACE_ATTACH, pid, 0, 0) < 0){
 		werrstr("ptrace attach %d: %r", pid);
 		return -1;
 	}
-
+	
 	if(ctlproc(pid, "waitstop") < 0){
+		fprint(2, "waitstop: %r");
 		ptrace(PTRACE_DETACH, pid, 0, 0);
 		return -1;
 	}
+	attachedpids[nattached++] = pid;
 
+already:
 	memset(&s, 0, sizeof s);
 	s.base = 0;
 	s.size = 0xFFFFFFFF;
@@ -78,11 +96,15 @@ mapproc(int pid, Map *map, Regs **rp)
 	s.file = nil;
 	s.rw = ptracerw;
 	s.pid = pid;
-	if(addseg(map, s) < 0)
+	if(addseg(map, s) < 0){
+		fprint(2, "addseg: %r\n");
 		return -1;
+	}
 
-	if((r = mallocz(sizeof(PtraceRegs), 1)) == nil)
+	if((r = mallocz(sizeof(PtraceRegs), 1)) == nil){
+		fprint(2, "mallocz: %r\n");
 		return -1;
+	}
 	r->r.rw = ptraceregrw;
 	r->pid = pid;
 	*rp = (Regs*)r;
@@ -92,6 +114,14 @@ mapproc(int pid, Map *map, Regs **rp)
 int
 detachproc(int pid)
 {
+	int i;
+
+	for(i=0; i<nattached; i++){
+		if(attachedpids[i] == pid){
+			attachedpids[i] = attachedpids[--nattached];
+			break;
+		}
+	}
 	return ptrace(PTRACE_DETACH, pid, 0, 0);
 }
 
@@ -367,9 +397,14 @@ ctlproc(int pid, char *msg)
 		if(isstopped(pid))
 			return 0;
 		for(;;){
-			p = waitpid(pid, &status, WUNTRACED);
-			if(p <= 0)
+			p = waitpid(pid, &status, WUNTRACED|__WALL);
+			if(p <= 0){
+				if(errno == ECHILD){
+					if(isstopped(pid))
+						return 0;
+				}
 				return -1;
+			}
 			if(WIFEXITED(status) || WIFSTOPPED(status))
 				return 0;
 		}
blob - 144b7042ccaa1947172b0536930120a3ef8cc67f
blob + 2745dd4c845a52f2c5ad043b288f4e289fcbbaa0
--- src/libmach/map.c
+++ src/libmach/map.c
@@ -174,7 +174,7 @@ get8(Map *map, ulong addr, u64int *u)
 {
 	u64int v;
 
-	if(mrw(map, addr, &v, 4, 1) < 0)
+	if(mrw(map, addr, &v, 8, 1) < 0)
 		return -1;
 	*u = mach->swap8(v);
 	return 8;
blob - de92d48dc612b050d6f3279beecdc7efa46b3527
blob + 55170c756919421ce45abf2d4a3d94ad6035a2fc
--- src/libthread/note.c
+++ src/libthread/note.c
@@ -65,6 +65,7 @@ delayednotes(Proc *p, void *v)
 			}
 			if(i==NFN){
 				_threaddebug(DBGNOTE, "Unhandled note %s, proc %p\n", n->s, p);
+				fprint(2, "unhandled note %s, pid %d\n", n->s, p->pid);
 				if(v != nil)
 					noted(NDFLT);
 				else if(strncmp(n->s, "sys:", 4)==0)
blob - 915a0243870063758e2e580a2fab04a08db85f8f
blob + c6119e451f1d2ba068663a9b23f672be73dc8388
--- src/libventi/rpc.c
+++ src/libventi/rpc.c
@@ -75,6 +75,7 @@ vtrpc(VtConn *z, Packet *p)
 		while(!r->done){
 			qunlock(&z->lk);
 			if((p = vtrecv(z)) == nil){
+				werrstr("unexpected eof on venti connection");
 				z->muxer = 0;
 				return nil;
 			}
blob - 20aedbee1ceca3de3652cb8d2cfca07a70c39aa1
blob + 029f57bfed987949907650e59a50376c3d294dba
--- src/libventi/srvhello.c
+++ src/libventi/srvhello.c
@@ -8,29 +8,31 @@ vtsrvhello(VtConn *z)
 	VtFcall tx, rx;
 	Packet *p;
 
-	if((p = vtrecv(z)) == nil)
-		return 0;
+	if((p = vtrecv(z)) == nil){
+		werrstr("unexpected eof on venti connection");
+		return -1;
+	}
 
 	if(vtfcallunpack(&tx, p) < 0){
 		packetfree(p);
-		return 0;
+		return -1;
 	}
 	packetfree(p);
 
 	if(tx.type != VtThello){
 		vtfcallclear(&tx);
 		werrstr("bad packet type %d; want Thello %d", tx.type, VtThello);
-		return 0;
+		return -1;
 	}
 	if(tx.tag != 0){
 		vtfcallclear(&tx);
 		werrstr("bad tag in hello");
-		return 0;
+		return -1;
 	}
 	if(strcmp(tx.version, z->version) != 0){
 		vtfcallclear(&tx);
 		werrstr("bad version in hello");
-		return 0;
+		return -1;
 	}
 	vtfree(z->uid);
 	z->uid = tx.uid;
@@ -42,9 +44,9 @@ vtsrvhello(VtConn *z)
 	rx.tag = tx.tag;
 	rx.sid = "anonymous";
 	if((p = vtfcallpack(&rx)) == nil)
-		return 0;
+		return -1;
 	if(vtsend(z, p) < 0)
-		return 0;
+		return -1;
 
-	return 1;
+	return 0;
 }