summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalahal Naineni <malahal@us.ibm.com>2015-11-02 08:35:25 -0500
committerSteve Dickson <steved@redhat.com>2015-11-02 08:55:04 -0500
commit602da10c87ea40f693aa4fc81968bb2a92bb52f9 (patch)
treebc28d8c0413d33f381f513be0110cd8e0967abe1
parent9a92ef6f194926904b1289e0ce1daecb42bd5e8b (diff)
downloadnfs-utils-602da10c87ea40f693aa4fc81968bb2a92bb52f9.tar.gz
nfs-utils-602da10c87ea40f693aa4fc81968bb2a92bb52f9.tar.xz
nfs-utils-602da10c87ea40f693aa4fc81968bb2a92bb52f9.zip
Close etab file's file descriptor on stat error.
Also, fixed erroneously closing file descriptor 0 at init time. Signed-off-by: Malahal Naineni <malahal@us.ibm.com> Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--utils/mountd/auth.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
index 330cab5..894a7a5 100644
--- a/utils/mountd/auth.c
+++ b/utils/mountd/auth.c
@@ -85,7 +85,7 @@ auth_reload()
{
struct stat stb;
static ino_t last_inode;
- static int last_fd;
+ static int last_fd = -1;
static unsigned int counter;
int fd;
@@ -93,11 +93,22 @@ auth_reload()
xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
} else if (fstat(fd, &stb) < 0) {
xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
- } else if (stb.st_ino == last_inode) {
+ close(fd);
+ } else if (last_fd != -1 && stb.st_ino == last_inode) {
+ /* We opened the etab file before, and its inode
+ * number hasn't changed since then.
+ */
close(fd);
return counter;
} else {
- close(last_fd);
+ /* Need to process entries from the etab file. Close
+ * the file descriptor from the previous open (last_fd),
+ * and keep the current file descriptor open to prevent
+ * the file system reusing the current inode number
+ * (last_inode).
+ */
+ if (last_fd != -1)
+ close(last_fd);
last_fd = fd;
last_inode = stb.st_ino;
}