Allow rawon/rawoff during reads. [rsc] --rw-rw-r-- M 118305 rsc sys 6806 Nov 12 08:22 sys/src/cmd/vnc/devcons.c /n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:230,236 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:230,236 qunlock(&kbd); break; case Qsnarf: - if(c->mode == OWRITE || c->mode == ORDWR) + if((c->mode&3) == OWRITE || (c->mode&3) == ORDWR) c->aux = smalloc(sizeof(Snarf)); break; } /n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:289,296 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:289,297 static long consread(Chan *c, void *buf, long n, vlong off) { - char *cbuf; - int i, ch, eol; + char *cbuf, ch; + int i, eol; + int send; if(n <= 0) return n; /n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:315,362 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:316,355 qunlock(&kbd); nexterror(); } - if(kbd.raw){ - cbuf = buf; - if(qcanread(lineq)) - n = qread(lineq, buf, n); - else { - /* read as much as possible */ - do { - i = qread(kbdq, cbuf, n); - cbuf += i; - n -= i; - } while (n>0 && qcanread(kbdq)); - n = cbuf - (char*)buf; - } - } else { - while(!qcanread(lineq)){ - qread(kbdq, &kbd.line[kbd.x], 1); - ch = kbd.line[kbd.x]; - eol = 0; + while(!qcanread(lineq)){ + qread(kbdq, &ch, 1); + send = 0; + if(ch == 0){ + /* flush output on rawoff -> rawon */ + if(kbd.x > 0) + send = !qcanread(kbdq); + }else if(kbd.raw){ + kbd.line[kbd.x++] = ch; + send = !qcanread(kbdq); + }else{ switch(ch){ case '\b': - if(kbd.x) + if(kbd.x > 0) kbd.x--; break; - case 0x15: + case 0x15: /* ^U */ kbd.x = 0; break; case '\n': - case 0x04: - eol = 1; + case 0x04: /* ^D */ + send = 1; default: - kbd.line[kbd.x++] = ch; + if(ch != 0x04) + kbd.line[kbd.x++] = ch; break; } - if(kbd.x == sizeof(kbd.line) || eol){ - if(ch == 0x04) - kbd.x--; - qwrite(lineq, kbd.line, kbd.x); - kbd.x = 0; - } } - n = qread(lineq, buf, n); + if(send || kbd.x == sizeof kbd.line){ + qwrite(lineq, kbd.line, kbd.x); + kbd.x = 0; + } } + n = qread(lineq, buf, n); qunlock(&kbd); poperror(); return n; /n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:373,378 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:366,372 { Snarf *t; char buf[256], *a; + char ch; switch((ulong)c->qid.path){ case Qcons: /n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:386,403 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:380,391 buf[n] = 0; for(a = buf; a;){ if(strncmp(a, "rawon", 5) == 0){ - qlock(&kbd); - if(kbd.x){ - qwrite(kbdq, kbd.line, kbd.x); - kbd.x = 0; - } kbd.raw = 1; - qunlock(&kbd); + /* clumsy hack - wake up reader */ + ch = 0; + qwrite(kbdq, &ch, 1); } else if(strncmp(a, "rawoff", 6) == 0){ - qlock(&kbd); kbd.raw = 0; - kbd.x = 0; - qunlock(&kbd); } if(a = strchr(a, ' ')) a++; Fix a few races. [rsc] --rw-rw-r-- M 118305 glenda sys 5708 Nov 12 08:42 sys/src/cmd/ip/ping.c /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:81,86 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:81,88 USED(a); if(strstr(msg, "alarm")) noted(NCONT); + else if(strstr(msg, "die")) + exits("errors"); else noted(NDFLT); } /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:94,100 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:96,102 for(l = &first; *l; ){ r = *l; - if(r->seq == seq){ + if(ip && r->seq == seq){ r->rtt = now-r->time; r->ttl = ip->ttl; reply(r, ip); /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:103,109 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:105,112 if(now-r->time > MINUTE){ *l = r->next; r->rtt = now-r->time; - r->ttl = ip->ttl; + if(ip) + r->ttl = ip->ttl; if(r->replied == 0) lost(r, ip); free(r); /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:177,190 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:180,194 ip = (Icmp*)buf; sum = 0; - while(!done || first != nil){ + while(lostmsgs+rcvdmsgs < nmsg){ alarm((nmsg-lostmsgs-rcvdmsgs)*interval+5000); n = read(fd, buf, sizeof(buf)); alarm(0); now = nsec(); - if(n <= 0){ - print("read: %r\n"); - break; + if(n <= 0){ /* read interrupted - time to go */ + fprint(2, "clean\n"); + clean(0, now+MINUTE, nil); + continue; } if(n < msglen){ print("bad len %d/%d\n", n, msglen); /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:213,219 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:217,222 if(lostmsgs) print("%d out of %d messages lost\n", lostmsgs, lostmsgs+rcvdmsgs); - postnote(PNPROC, senderpid, "die"); } void /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:229,234 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:232,238 int fd; int msglen, interval, nmsg; int pid; + char err[ERRMAX]; nsec(); /* make sure time file is already open */ /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:299,307 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:303,312 void reply(Req *r, Icmp *ip) { - rcvdmsgs++; r->rtt /= 1000LL; sum += r->rtt; + if(!r->replied) + rcvdmsgs++; if(!quiet && !lostonly){ if(addresses) print("%ud: %V->%V rtt %lld µs, avg rtt %lld µs, ttl = %d\n", /n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:321,334 - /n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:326,336 { if(!quiet){ if(addresses) - print("lost %ud: %V->%V avg rtt %lld µs\n", - r->seq-firstseq, - ip->src, ip->dst, - sum/rcvdmsgs); + print("lost %ud: %V->%V\n", r->seq-firstseq, + ip->src, ip->dst); else - print("lost %ud: avg rtt %lld µs\n", - r->seq-firstseq, - sum/rcvdmsgs); + print("lost %ud\n", r->seq-firstseq); } lostmsgs++; } +