ref: 8f64e448545a11c1c0e0db8bef34c23d3c0e0ad7
parent: dce28e58e492e5b4448451ddcbe948d9b104d859
author: cinap_lenrek <[email protected]>
date: Sat Mar 7 10:01:29 EST 2020
lib9p: zero out per connection state in Srv template for listensrv() in case listensrv() is called with a previously active Srv, we have to make sure that per connection state is zeroed out (locks and reference conuts). also, dont assume anything about the Ref structure. there might be implementations that have a spinlock in them.
--- a/sys/src/lib9p/listen.c
+++ b/sys/src/lib9p/listen.c
@@ -15,11 +15,26 @@
{
Srv *s;
- if(_forker == nil)
- sysfatal("no forker");
s = emalloc9p(sizeof *s);
*s = *os;
+
s->addr = estrdup9p(addr);
+ s->infd = s->outfd = s->srvfd = -1;
+ s->fpool = nil;
+ s->rpool = nil;
+ s->msize = 0;
+ s->rbuf = nil;
+ s->wbuf = nil;
+ memset(&s->rlock, 0, sizeof(s->rlock));
+ memset(&s->wlock, 0, sizeof(s->wlock));
+ memset(&s->slock, 0, sizeof(s->slock));
+ memset(&s->sref, 0, sizeof(s->sref));
+ memset(&s->rref, 0, sizeof(s->rref));
+ s->spid = 0;
+ s->free = nil;
+
+ if(_forker == nil)
+ sysfatal("no forker");
_forker(listenproc, s, 0);
}
@@ -56,10 +71,6 @@
*s = *os;
s->addr = getremotesys(ndir);
s->infd = s->outfd = data;
- s->fpool = nil;
- s->rpool = nil;
- s->rbuf = nil;
- s->wbuf = nil;
s->free = srvfree;
_forker(srvproc, s, 0);
}
--- a/sys/src/lib9p/srv.c
+++ b/sys/src/lib9p/srv.c
@@ -810,8 +810,8 @@
fmtinstall('F', fcallfmt);
srv->spid = getpid();
- srv->sref.ref = 0;
- srv->rref.ref = 0;
+ memset(&s->sref, 0, sizeof(s->sref));
+ memset(&s->rref, 0, sizeof(s->rref));
if(srv->fpool == nil)
srv->fpool = allocfidpool(srv->destroyfid);