zfsonlinux/zfs — pull request #2215 by jmlayman (2014-03-26 21:31:21+00:00)
Title: Fix for re-reading /etc/mtab, part 2.

This is a continuation of fb5c53ea65b75c67c23f90ebbbb1134a5bb6c140:

When /etc/mtab is updated on Linux it's done atomically with
rename(2). A new mtab is written, the existing mtab is unlinked,
and the new mtab is renamed to /etc/mtab. This means that we
must close the old file and open the new file to get the updated
contents. Using rewind(3) will just move the file pointer back
to the start of the file, freopen(3) will close and open the file.

In this commit, a few more rewind(3) calls were replaced with freopen(3)
to allow updated mtab entries to be picked up immediately.

Note that technically only libzfs_mount.c & libzfs_util.c need to be modified as they are libraries and so the functions within them can be called multiple times (during which time /etc/mtab could change). Since zfs_main.c is a utility front-end, it probably isn't necessary to modify it but I went ahead & did so anyway. If this is not desired, those changes can be omitted.