hv: hypervvssd: call endmntent before call setmntent again
authorVaughan Cao <vaughan.cao@oracle.com>
Wed, 18 Mar 2015 19:29:28 +0000 (12:29 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Mar 2015 10:53:54 +0000 (11:53 +0100)
If freeze fails, vss_operate will re-enter itself to thaw. But it forgets
to call endmntent() before it recalls setmntent() again.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/hv/hv_vss_daemon.c

index 5e63f70bd956e56f9506ef306e11ff2206c23b52..506dd01488286f8033f3ceaf3915fd06742f33de 100644 (file)
@@ -81,6 +81,7 @@ static int vss_operate(int operation)
        char match[] = "/dev/";
        FILE *mounts;
        struct mntent *ent;
+       char errdir[1024] = {0};
        unsigned int cmd;
        int error = 0, root_seen = 0, save_errno = 0;
 
@@ -115,6 +116,8 @@ static int vss_operate(int operation)
                        goto err;
        }
 
+       endmntent(mounts);
+
        if (root_seen) {
                error |= vss_do_freeze("/", cmd);
                if (error && operation == VSS_OP_FREEZE)
@@ -124,16 +127,19 @@ static int vss_operate(int operation)
        goto out;
 err:
        save_errno = errno;
+       if (ent) {
+               strncpy(errdir, ent->mnt_dir, sizeof(errdir)-1);
+               endmntent(mounts);
+       }
        vss_operate(VSS_OP_THAW);
        /* Call syslog after we thaw all filesystems */
        if (ent)
                syslog(LOG_ERR, "FREEZE of %s failed; error:%d %s",
-                      ent->mnt_dir, save_errno, strerror(save_errno));
+                      errdir, save_errno, strerror(save_errno));
        else
                syslog(LOG_ERR, "FREEZE of / failed; error:%d %s", save_errno,
                       strerror(save_errno));
 out:
-       endmntent(mounts);
        return error;
 }