diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-10-06 04:42:46 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-10-06 04:42:46 +0200 |
commit | 6197758ec15bbd4104f1f340cce07f59f5c7a4ad (patch) | |
tree | c9730a38e2be03ddb77864e9ee535829fc4b2275 /sys | |
parent | cb8eac54ed990ae351b4d670b83e17316809e0f0 (diff) |
exportfs: fix openmount() rfork flags and filedescriptor leak, silence of on initstr error
fork child exportfs with new rendezvous group.
fix missing close of pipe filedescriptors on error.
fix missing close of other end of pipe in child.
dont bark when we get eof on the first init string read.
this condition can happen when unmount opens and
immidiately closes a exported srv file.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/cmd/exportfs/exportfs.c | 11 | ||||
-rw-r--r-- | sys/src/cmd/exportfs/exportsrv.c | 11 |
2 files changed, 13 insertions, 9 deletions
diff --git a/sys/src/cmd/exportfs/exportfs.c b/sys/src/cmd/exportfs/exportfs.c index b618369b4..0ac79edd0 100644 --- a/sys/src/cmd/exportfs/exportfs.c +++ b/sys/src/cmd/exportfs/exportfs.c @@ -288,7 +288,10 @@ main(int argc, char **argv) fatal("open ack write"); ini = initial; - if (readn(netfd, initial, sizeof(initial)) < sizeof(initial)) + n = readn(netfd, initial, sizeof(initial)); + if (n == 0) + fatal(nil); /* port scan or spurious open/close on exported /srv file (unmount) */ + if (n < sizeof(initial)) fatal("can't read initial string: %r"); if (memcmp(ini, "impo", 4) == 0) { @@ -844,10 +847,10 @@ fatal(char *s, ...) for(m = Proclist; m; m = m->next) postnote(PNPROC, m->pid, "kill"); - DEBUG(DFD, "%s\n", buf); - if (s) + if (s) { + DEBUG(DFD, "%s\n", buf); sysfatal("%s", buf); /* caution: buf could contain '%' */ - else + } else exits(nil); } diff --git a/sys/src/cmd/exportfs/exportsrv.c b/sys/src/cmd/exportfs/exportsrv.c index 7e8d836ff..ea2d77ab8 100644 --- a/sys/src/cmd/exportfs/exportsrv.c +++ b/sys/src/cmd/exportfs/exportsrv.c @@ -584,8 +584,10 @@ openmount(int sfd) if(pipe(p) < 0) return -1; - switch(rfork(RFPROC|RFMEM|RFNOWAIT|RFNAMEG|RFFDG)){ + switch(rfork(RFPROC|RFMEM|RFNOWAIT|RFNAMEG|RFFDG|RFREND)){ case -1: + close(p[0]); + close(p[1]); return -1; default: @@ -597,6 +599,9 @@ openmount(int sfd) break; } + dup(p[0], 0); + dup(p[0], 1); + close(p[0]); close(p[1]); arg[0] = "exportfs"; @@ -606,10 +611,6 @@ openmount(int sfd) arg[2] = mbuf; arg[3] = nil; - close(0); - close(1); - dup(p[0], 0); - dup(p[0], 1); exec("/bin/exportfs", arg); _exits("whoops: exec failed"); return -1; |