From fc3f92f3be911a3c7ddd2dce0c1ceef60e89b079 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 25 Jul 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-07-25 --- gnot/devdk.c | 9 ++-- gnot/devincon.c | 16 +++---- gnot/devmnt.c | 1 - gnot/errno.h | 1 + gnot/proc.c | 11 +++-- gnot/sturp.c | 108 ++++++++++++++++++++++++++++++++++-------------- port/devbit.c | 4 +- port/devmnt.c | 1 - port/devsrv.c | 2 +- port/sturp.c | 53 +++++++++++++++++++++++- 10 files changed, 156 insertions(+), 50 deletions(-) diff --git a/gnot/devdk.c b/gnot/devdk.c index 88599861ed9b0178e491ba31402c32f01b3732c7..dd6c6ed75729bb518c81e1117e8df49b8879a204 100644 --- a/gnot/devdk.c +++ b/gnot/devdk.c @@ -456,6 +456,7 @@ dkmuxconfig(Dk *dp, Block *bp) */ dp->restart = 1; n = getfields((char *)bp->rptr, fields, 4, ' '); + strcpy(dp->name, "dk"); switch(n){ case 4: strncpy(dp->name, fields[3], sizeof(dp->name)); @@ -494,7 +495,7 @@ dkmuxconfig(Dk *dp, Block *bp) /* * start a process to deal with it */ - sprint(buf, "**csckproc%d**", dp->ncsc); + sprint(buf, "csckproc%d", dp->ncsc); kproc(buf, dkcsckproc, dp); poperror(); @@ -503,7 +504,7 @@ dkmuxconfig(Dk *dp, Block *bp) */ if(dktimeron == 0){ dktimeron = 1; - kproc("**dktimer**", dktimer, 0); + kproc("dktimer", dktimer, 0); } } @@ -592,8 +593,10 @@ dkattach(char *spec) Dk *dp; /* - * find a multiplexor with the same name + * find a multiplexor with the same name (default dk) */ + if(*spec == 0) + spec = "dk"; for(dp = dk; dp < &dk[Ndk]; dp++){ qlock(dp); if(dp->wq && strcmp(spec, dp->name)==0) { diff --git a/gnot/devincon.c b/gnot/devincon.c index bbfcf1161015480820a5ecb8beb6233dd9eea3eb..9da2e4a17583408b6a0ad5df3550cce581bd13f1 100644 --- a/gnot/devincon.c +++ b/gnot/devincon.c @@ -89,7 +89,7 @@ Incon incon[Nincon]; enum { Selecting, Selected, - Dead, + Notliving, }; /* @@ -177,7 +177,7 @@ inconpoll(Incon *ip, int station) /* * get us to a known state */ - ip->state = Dead; + ip->state = Notliving; dev->cmd = INCON_STOP; /* @@ -271,7 +271,7 @@ inconreset(void) /* inconset(&incon[0], 3, 15); /**/ for(i=1; icmd = INCON_STOP; incon[i].ri = incon[i].wi = 0; } @@ -400,7 +400,7 @@ inconstopen(Queue *q, Stream *s) char name[32]; ip = &incon[s->dev]; - sprint(name, "**incon%d**", s->dev); + sprint(name, "incon%d", s->dev); q->ptr = q->other->ptr = ip; ip->rq = q; kproc(name, inconkproc, ip); @@ -410,7 +410,7 @@ inconstopen(Queue *q, Stream *s) * kill off the kernel process */ static int -kDead(void *arg) +kNotliving(void *arg) { Incon *ip; @@ -427,7 +427,7 @@ inconstclose(Queue * q) ip->rq = 0; qunlock(ip); wakeup(&ip->kr); - sleep(&ip->r, kDead, ip); + sleep(&ip->r, kNotliving, ip); } /* @@ -500,7 +500,7 @@ inconoput(Queue *q, Block *bp) /* * make sure there's an incon out there */ - if(!(dev->status&INCON_ALIVE) || ip->state==Dead){ + if(!(dev->status&INCON_ALIVE) || ip->state==Notliving){ inconrestart(ip); freemsg(q, bp); qunlock(&ip->xmit); @@ -812,7 +812,7 @@ inconintr(Ureg *ur) ip->dev->cmd = INCON_STOP; break; } - ip->state = Dead; + ip->state = Notliving; } } diff --git a/gnot/devmnt.c b/gnot/devmnt.c index c96f567a91dad05afe95d1d46a88913cf1dd2b3c..239b2b253383fbeb890e71a0eda588606e89c1e2 100644 --- a/gnot/devmnt.c +++ b/gnot/devmnt.c @@ -291,7 +291,6 @@ mntattach(char *spec) mh = mhalloc(); if(waserror()){ mhfree(mh); - mqfree(q); close(c); nexterror(); } diff --git a/gnot/errno.h b/gnot/errno.h index f569775960d22f6307d687a57ff826844e296c87..ee070d757d339a590130a6765dd747ff37150b39 100644 --- a/gnot/errno.h +++ b/gnot/errno.h @@ -50,6 +50,7 @@ enum{ Enobitmap, /* out of bitmap descriptors */ Enobitstore, /* out of bitmap storage */ Ebadbitmap, /* unallocated bitmap */ + Ebadfont, /* unallocated font */ Eshortmsg, /* short message */ Ebadmsg, /* format error or mismatch in message */ Ebadcnt, /* read count greater than requested */ diff --git a/gnot/proc.c b/gnot/proc.c index eed82727919e996223972847a5452ceee822cd95..d86d46c3cbc8c19176619eedb4cdf59faae0ad06 100644 --- a/gnot/proc.c +++ b/gnot/proc.c @@ -575,6 +575,7 @@ kproc(char *name, void (*func)(void *), void *arg) int lastvar; /* used to compute stack address */ User *up; KMap *k; + static Pgrp *kpgrp; /* * Kernel stack @@ -612,12 +613,16 @@ kproc(char *name, void (*func)(void *), void *arg) p->mach = m; m->proc = p; spllo(); - strncpy(p->text, name, sizeof p->text); (*func)(arg); pexit(0, 1); } - p->pgrp = u->p->pgrp; - incref(p->pgrp); + if(kpgrp == 0){ + kpgrp = newpgrp(); + strcpy(kpgrp->user, "bootes"); + } + p->pgrp = kpgrp; + incref(kpgrp); + sprint(p->text, "%s.%.6s", name, u->p->pgrp->user); p->nchild = 0; p->parent = 0; memset(p->time, 0, sizeof(p->time)); diff --git a/gnot/sturp.c b/gnot/sturp.c index a6879dc8ccef1fbff799e5511a68737309705caa..b85c6ebe64003fabaf41f0100f1b06bfa963bf5f 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -11,7 +11,7 @@ enum { Nmask= 0x7, }; -#define DPRINT if(q->flag&QDEBUG)kprint +#define DPRINT /*if(q->flag&QDEBUG)kprint*/ typedef struct Urp Urp; @@ -67,6 +67,12 @@ struct Urp { #define IN(x, f, n) (f<=n ? (x>=f && x=f)) #define NEXT(x) (((x)+1)&Nmask) +/* + * Alarm for urptiming + */ +Alarm *urptiming; +Lock urptlock; + /* * Protocol control bytes */ @@ -116,6 +122,7 @@ static void sendrej(Urp*); static void initoutput(Urp*, int); static void initinput(Urp*, int); static void urpkproc(void *arg); +static void urptimer(Alarm*); static void urpvomit(char*, Urp*); Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" }; @@ -160,10 +167,18 @@ urpopen(Queue *q, Stream *s) /* * start the ack/(re)xmit process */ - if(up->kstarted == 0){ - up->kstarted = 1; - sprint(name, "**urp%d**", up - urp); - kproc(name, urpkproc, up); + sprint(name, "urp%d", up - urp); + kproc(name, urpkproc, up); + + /* + * start the urptimer if it isn't already + */ + if(urptiming==0){ + if(canlock(&urptlock)){ + if(urptiming == 0) + urptiming = alarm(500, urptimer, 0); + unlock(&urptlock); + } } } @@ -171,6 +186,14 @@ urpopen(Queue *q, Stream *s) * Shut down the connection and kill off the kernel process */ static int +isdead(void *a) +{ + Urp *up; + + up = (Urp *)a; + return up->kstarted==0; +} +static int isflushed(void *a) { Urp *up; @@ -199,7 +222,7 @@ urpclose(Queue *q) tsleep(&up->r, isflushed, up, 2*60*1000); /* - * kill off the kernel process + * tell kernel process to die */ up->state |= HUNGUP; wakeup(&up->rq->r); @@ -223,10 +246,13 @@ urpclose(Queue *q) } qunlock(&up->xmit); - if(up->kstarted == 0){ - DPRINT("urpclose %ux\n", up); - up->state = 0; - } + /* + * wait for kernel process to die + */ + while(up->kstarted) + sleep(&up->r, isdead, up); + + up->state = 0; } /* @@ -589,6 +615,17 @@ output(Urp *up) int n; int i; + /* + * start the urptimer if it isn't already + */ + if(urptiming==0){ + if(canlock(&urptlock)){ + if(urptiming == 0) + urptiming = alarm(500, urptimer, 0); + unlock(&urptlock); + } + } + if(!canqlock(&up->xmit)) return; @@ -607,9 +644,7 @@ output(Urp *up) sendctl(up, INIT1); up->timer = now + MSrexmit; } - qunlock(&up->xmit); - poperror(); - return; + goto out; } /* @@ -653,9 +688,7 @@ output(Urp *up) up->timer = NOW + MSrexmit; up->state &= ~REJECTING; sendctl(up, ENQ); - qunlock(&up->xmit); - poperror(); - return; + goto out; } /* @@ -676,6 +709,7 @@ output(Urp *up) up->next = NEXT(up->next); poperror(); } +out: qunlock(&up->xmit); poperror(); } @@ -941,39 +975,53 @@ todo(void *arg) static void urpkproc(void *arg) { - Urp *up; Queue *q; + Urp *up; up = (Urp *)arg; - q = up->wq; + up->kstarted = 1; if(waserror()){ print("urpkproc error %ux\n", up); - up->state = 0; up->kstarted = 0; wakeup(&up->r); return; } for(;;){ - if(up->state & (HUNGUP|CLOSING)){ - if(isflushed(up)) - wakeup(&up->r); - if(up->state & HUNGUP) - break; - } - if(up->state == 0){ - DPRINT("urpkproc: %ux->state == 0\n", up); + if(up->state & HUNGUP) break; - } if(!QFULL(up->rq->next)) sendack(up); output(up); - tsleep(&up->rq->r, todo, up, MSrexmit/2); + sleep(&up->rq->r, todo, up); } - up->state = 0; up->kstarted = 0; + wakeup(&up->r); + poperror(); DPRINT("urpkproc %ux\n", up); } +/* + * timer to wakeup urpkproc's for retransmissions + */ +static void +urptimer(Alarm *a) +{ + Urp *up; + Urp *last; + Queue *q; + + urptiming = 0; + for(up = urp, last = &urp[conf.nurp]; up < last; up++){ + if(up->state==0) + continue; + if(up->unacked!=up->next && NOW>up->timer){ + q = up->rq; + if(q) + wakeup(&q->r); + } + } +} + /* * urp got very confused, complain */ diff --git a/port/devbit.c b/port/devbit.c index bd217e8f98912d5d0bacd94789bc2af8bba17f9e..f324a3567cb318a521a6795a642c35773402a0fe 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -61,7 +61,7 @@ struct{ Cursor arrow = { - {0, 0}, + {1, 1}, {0xFF, 0xE0, 0xFF, 0xE0, 0xFF, 0xC0, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x80, 0xFF, 0xC0, 0xFF, 0xE0, 0xE7, 0xF0, 0xE3, 0xF8, 0xC1, 0xFC, 0x00, 0xFE, @@ -657,7 +657,7 @@ bitwrite(Chan *c, void *va, long n) v = GSHORT(p+1); f = &bit.font[v]; if(v<0 || v>=conf.nfont || f->bits==0) - error(0, Ebadbitmap); + error(0, Ebadfont); f->bits = 0; m -= 3; p += 3; diff --git a/port/devmnt.c b/port/devmnt.c index c96f567a91dad05afe95d1d46a88913cf1dd2b3c..239b2b253383fbeb890e71a0eda588606e89c1e2 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -291,7 +291,6 @@ mntattach(char *spec) mh = mhalloc(); if(waserror()){ mhfree(mh); - mqfree(q); close(c); nexterror(); } diff --git a/port/devsrv.c b/port/devsrv.c index 3a96b82499f77a20dc6b176bd45865f481e86716..c938e198a1d1e6b6a2b2d6d6a8c85730d6d19108 100644 --- a/port/devsrv.c +++ b/port/devsrv.c @@ -83,7 +83,7 @@ srvopen(Chan *c, int omode) f = srv.chan[c->qid]; if(f == 0) error(0, Eshutdown); - if(omode&OTRUNC) + if(omode & OTRUNC) error(0, Eperm); if(omode!=f->mode && f->mode!=ORDWR) error(0, Eperm); diff --git a/port/sturp.c b/port/sturp.c index 72e3d379e3487590ff304db3ace5d8e1d6ab9c0e..51084d8cb87cf0d1b8f407b29a8c5769281c687d 100644 --- a/port/sturp.c +++ b/port/sturp.c @@ -67,6 +67,12 @@ struct Urp { #define IN(x, f, n) (f<=n ? (x>=f && x=f)) #define NEXT(x) (((x)+1)&Nmask) +/* + * Alarm for urptiming + */ +Alarm *urptiming; +Lock urptlock; + /* * Protocol control bytes */ @@ -116,6 +122,7 @@ static void sendrej(Urp*); static void initoutput(Urp*, int); static void initinput(Urp*, int); static void urpkproc(void *arg); +static void urptimer(Alarm*); static void urpvomit(char*, Urp*); Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" }; @@ -165,6 +172,17 @@ urpopen(Queue *q, Stream *s) sprint(name, "urp%d", up - urp); kproc(name, urpkproc, up); } + + /* + * start the urptimer if it isn't already + */ + if(urptiming==0){ + if(canlock(&urptlock)){ + if(urptiming == 0) + urptiming = alarm(500, urptimer, 0); + unlock(&urptlock); + } + } } /* @@ -589,6 +607,17 @@ output(Urp *up) int n; int i; + /* + * start the urptimer if it isn't already + */ + if(urptiming==0){ + if(canlock(&urptlock)){ + if(urptiming == 0) + urptiming = alarm(500, urptimer, 0); + unlock(&urptlock); + } + } + if(!canqlock(&up->xmit)) return; @@ -967,13 +996,35 @@ urpkproc(void *arg) if(!QFULL(up->rq->next)) sendack(up); output(up); - tsleep(&up->rq->r, todo, up, MSrexmit/2); + sleep(&up->rq->r, todo, up); } up->state = 0; up->kstarted = 0; DPRINT("urpkproc %ux\n", up); } +/* + * timer to wakeup urpkproc's for retransmissions + */ +static void +urptimer(Alarm *a) +{ + Urp *up; + Urp *last; + Queue *q; + + urptiming = 0; + for(up = urp, last = &urp[conf.nurp]; up < last; up++){ + if(up->state==0) + continue; + if(up->unacked!=up->next && NOW>up->timer){ + q = up->rq; + if(q) + wakeup(&q->r); + } + } +} + /* * urp got very confused, complain */