diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-10-07 23:18:37 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-10-07 23:18:37 +0200 |
commit | ad1111cb3e40371de141af7d5e72467b7d0afec7 (patch) | |
tree | 53f58b1282241187104bb794d29b13e23ba68e34 /sys/src/cmd/exportfs | |
parent | 6197758ec15bbd4104f1f340cce07f59f5c7a4ad (diff) |
exportfs: fix more filedescriptor leaks
just closing the pipe isnt enough, we have to
close all remaining file descriptors except sfd
before executing sub exportfs.
Diffstat (limited to 'sys/src/cmd/exportfs')
-rw-r--r-- | sys/src/cmd/exportfs/exportsrv.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sys/src/cmd/exportfs/exportsrv.c b/sys/src/cmd/exportfs/exportsrv.c index ea2d77ab8..058e84193 100644 --- a/sys/src/cmd/exportfs/exportsrv.c +++ b/sys/src/cmd/exportfs/exportsrv.c @@ -578,8 +578,9 @@ flushme: int openmount(int sfd) { - int p[2]; + int p[2], fd, i, n; char *arg[10], fdbuf[20], mbuf[20]; + Dir *dir; if(pipe(p) < 0) return -1; @@ -601,8 +602,19 @@ openmount(int sfd) dup(p[0], 0); dup(p[0], 1); - close(p[0]); - close(p[1]); + + /* close all remaining file descriptors except sfd */ + if((fd = open("/fd", OREAD)) < 0) + _exits("open /fd failed"); + n = dirreadall(fd, &dir); + for(i=0; i<n; i++){ + if(strstr(dir[i].name, "ctl")) + continue; + fd = atoi(dir[i].name); + if(fd > 2 && fd != sfd) + close(fd); + } + free(dir); arg[0] = "exportfs"; snprint(fdbuf, sizeof fdbuf, "-S/fd/%d", sfd); |