From b139273d483ad58287481cdfd60a131b95405a3f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 21 Jun 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-06-21 --- gnot/dat.h | 2 +- gnot/devpipe.c | 15 +++++----- gnot/stream.c | 74 ++++++++++++++++++++++++-------------------------- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index c33f5f950d4b3cd494303e775b2c10c5fd0e4843..4876d16ad1cc98371a6a032b5eb13cd5d5e0978e 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -327,7 +327,7 @@ struct Proc ulong pc; /* DEBUG only */ }; -#define NERR 10 +#define NERR 15 #define NNOTE 5 #define NFD 100 struct User diff --git a/gnot/devpipe.c b/gnot/devpipe.c index e14f44c0e06dfa5cf93b85171a3c8b9a0c4c3fb1..9df787e1136966acee0ec6085c347c853074a742 100644 --- a/gnot/devpipe.c +++ b/gnot/devpipe.c @@ -70,8 +70,10 @@ pipeclone(Chan *c, Chan *nc) * up the inuse count of each stream to reflect the * pointer from the other stream. */ - streamenter(c->stream); - streamenter(nc->stream); + if(streamenter(c->stream)<0) + panic("pipeattach"); + if(streamenter(nc->stream)<0) + panic("pipeattach"); return nc; } @@ -131,6 +133,7 @@ pipeclose(Chan *c) } streamclose(c); /* close this stream */ streamexit(other, 0); /* release stream for other half of pipe */ + poperror(); } long @@ -206,9 +209,7 @@ pipestclose(Queue *q) * send a hangup */ q = q->other; - if(q->next){ - bp = allocb(0); - bp->type = M_HANGUP; - pipeiput(q->next, bp); - } + bp = allocb(0); + bp->type = M_HANGUP; + PUTNEXT(q, bp); } diff --git a/gnot/stream.c b/gnot/stream.c index c14e4a2e02269df5f9a59119b360e0954d29db3c..16ddce2349703f3d938511bb5ec88292e632f8ea 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -531,8 +531,12 @@ prepend(Block *bp, int n) void nullput(Queue *q, Block *bp) { - freeb(bp); - error(0, Ehungup); + if(bp->type == M_HANGUP) + freeb(bp); + else { + freeb(bp); + error(0, Ehungup); + } } /* @@ -757,21 +761,17 @@ streamexit(Stream *s, int locked) if(!locked) lock(s); - s->inuse--; - if(s->inuse != 0){ - if(!locked) - unlock(s); - return; - } - - /* - * ascend the stream freeing the queues - */ - for(q = s->devq; q; q = nq){ - nq = q->next; - freeq(q); + if(s->inuse == 1){ + /* + * ascend the stream freeing the queues + */ + for(q = s->devq; q; q = nq){ + nq = q->next; + freeq(q); + } + s->id = s->dev = s->type = 0; } - s->id = s->dev = s->type = 0; + s->inuse--; if(!locked) unlock(s); } @@ -797,29 +797,27 @@ streamclose(Chan *c) * decrement the reference count */ lock(s); - if(s->opens != 1){ - s->opens--; - unlock(c->stream); - return; - } - - /* - * descend the stream closing the queues - */ - for(q = s->procq; q; q = q->next){ - if(q->info->close) - (*q->info->close)(q->other); - if(q == s->devq->other) - break; - } - - /* - * ascend the stream flushing the queues - */ - for(q = s->devq; q; q = nq){ - nq = q->next; - flushq(q); + if(s->opens == 1){ + /* + * descend the stream closing the queues + */ + for(q = s->procq; q; q = q->next){ + if(q->info->close) + (*q->info->close)(q->other); + /* this may be 2 streams joined device end to device end */ + if(q == s->devq->other) + break; + } + + /* + * ascend the stream flushing the queues + */ + for(q = s->devq; q; q = nq){ + nq = q->next; + flushq(q); + } } + s->opens--; /* * leave it and free it