aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-05-05 04:22:16 +0000
committerrsc <devnull@localhost>2004-05-05 04:22:16 +0000
commit2e965b3324b32be00a2193bf304dcb936f02824b (patch)
treec183e68a04ee42308f493face299cb4cc4c559ec
parent4f48d1d4f72b1986ba6df3ccd9db62cfa1ef3df9 (diff)
downloadplan9port-2e965b3324b32be00a2193bf304dcb936f02824b.tar.gz
plan9port-2e965b3324b32be00a2193bf304dcb936f02824b.tar.bz2
plan9port-2e965b3324b32be00a2193bf304dcb936f02824b.zip
various bug fixes
-rw-r--r--acid/thread10
-rw-r--r--src/cmd/acid/proc.c13
-rw-r--r--src/lib9/_p9proc.c4
-rw-r--r--src/libhttpd/gethead.c11
-rw-r--r--src/libhttpd/hio.c6
-rw-r--r--src/libhttpd/parse.c2
-rw-r--r--src/libhttpd/parsereq.c4
-rw-r--r--src/libmach/Linux.c49
-rw-r--r--src/libmach/map.c2
-rw-r--r--src/libthread/note.c1
-rw-r--r--src/libventi/rpc.c1
-rw-r--r--src/libventi/srvhello.c20
12 files changed, 82 insertions, 41 deletions
diff --git a/acid/thread b/acid/thread
index 9fcd9b58..d4787e78 100644
--- a/acid/thread
+++ b/acid/thread
@@ -61,11 +61,6 @@ 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;
diff --git a/src/cmd/acid/proc.c b/src/cmd/acid/proc.c
index 2c286e15..66996345 100644
--- a/src/cmd/acid/proc.c
+++ b/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)
{
diff --git a/src/lib9/_p9proc.c b/src/lib9/_p9proc.c
index b47a8c23..c492ae15 100644
--- a/src/lib9/_p9proc.c
+++ b/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];
diff --git a/src/libhttpd/gethead.c b/src/libhttpd/gethead.c
index 5983345e..0677cc8f 100644
--- a/src/libhttpd/gethead.c
+++ b/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;
}
}
diff --git a/src/libhttpd/hio.c b/src/libhttpd/hio.c
index 34d3a3a2..3561b681 100644
--- a/src/libhttpd/hio.c
+++ b/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
diff --git a/src/libhttpd/parse.c b/src/libhttpd/parse.c
index 5fd4092a..8e8364b0 100644
--- a/src/libhttpd/parse.c
+++ b/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;
diff --git a/src/libhttpd/parsereq.c b/src/libhttpd/parsereq.c
index 7ef63413..94237988 100644
--- a/src/libhttpd/parsereq.c
+++ b/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);
diff --git a/src/libmach/Linux.c b/src/libmach/Linux.c
index 62796adb..12b0f9b8 100644
--- a/src/libmach/Linux.c
+++ b/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;
}
diff --git a/src/libmach/map.c b/src/libmach/map.c
index 144b7042..2745dd4c 100644
--- a/src/libmach/map.c
+++ b/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;
diff --git a/src/libthread/note.c b/src/libthread/note.c
index de92d48d..55170c75 100644
--- a/src/libthread/note.c
+++ b/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)
diff --git a/src/libventi/rpc.c b/src/libventi/rpc.c
index 915a0243..c6119e45 100644
--- a/src/libventi/rpc.c
+++ b/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;
}
diff --git a/src/libventi/srvhello.c b/src/libventi/srvhello.c
index 20aedbee..029f57bf 100644
--- a/src/libventi/srvhello.c
+++ b/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;
}