aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-03-10 00:00:43 +0100
committerBrian Behlendorf <[email protected]>2021-04-11 15:45:31 -0700
commit92ffd87aafd2cf35f82acec01513e16e9ed4edd6 (patch)
tree1fc69e009d960911d1ea45fb44b5190449d3f3ad /lib
parent0fc401a7ef630857c9e17bb3424b039c5492cb38 (diff)
libzfs{,_core}: set O_CLOEXEC on persistent (ZFS_DEV and MNTTAB) fds
These were fd 3, 4, and 5 by the time zfs change-key hit execute_key_fob() glibc appends "e" to setmntent() mode, but musl's just returns fopen() Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11866
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_dataset.c4
-rw-r--r--lib/libzfs/libzfs_mount.c2
-rw-r--r--lib/libzfs/libzfs_util.c6
-rw-r--r--lib/libzfs_core/libzfs_core.c2
4 files changed, 7 insertions, 7 deletions
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
index e57bc49ba..f469f3a4b 100644
--- a/lib/libzfs/libzfs_dataset.c
+++ b/lib/libzfs/libzfs_dataset.c
@@ -811,7 +811,7 @@ libzfs_mnttab_update(libzfs_handle_t *hdl)
struct mnttab entry;
/* Reopen MNTTAB to prevent reading stale data from open file */
- if (freopen(MNTTAB, "r", hdl->libzfs_mnttab) == NULL)
+ if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
return (ENOENT);
while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
@@ -882,7 +882,7 @@ libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
libzfs_mnttab_fini(hdl);
/* Reopen MNTTAB to prevent reading stale data from open file */
- if (freopen(MNTTAB, "r", hdl->libzfs_mnttab) == NULL)
+ if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
return (ENOENT);
srch.mnt_special = (char *)fsname;
diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c
index 2a543daac..45dccccd4 100644
--- a/lib/libzfs/libzfs_mount.c
+++ b/lib/libzfs/libzfs_mount.c
@@ -1517,7 +1517,7 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
namelen = strlen(zhp->zpool_name);
/* Reopen MNTTAB to prevent reading stale data from open file */
- if (freopen(MNTTAB, "r", hdl->libzfs_mnttab) == NULL)
+ if (freopen(MNTTAB, "re", hdl->libzfs_mnttab) == NULL)
return (ENOENT);
used = alloc = 0;
diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c
index 95cb32957..7c2f84c7a 100644
--- a/lib/libzfs/libzfs_util.c
+++ b/lib/libzfs/libzfs_util.c
@@ -1024,15 +1024,15 @@ libzfs_init(void)
return (NULL);
}
- if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR|O_EXCL)) < 0) {
+ if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR|O_EXCL|O_CLOEXEC)) < 0) {
free(hdl);
return (NULL);
}
#ifdef HAVE_SETMNTENT
- if ((hdl->libzfs_mnttab = setmntent(MNTTAB, "r")) == NULL) {
+ if ((hdl->libzfs_mnttab = setmntent(MNTTAB, "re")) == NULL) {
#else
- if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) {
+ if ((hdl->libzfs_mnttab = fopen(MNTTAB, "re")) == NULL) {
#endif
(void) close(hdl->libzfs_fd);
free(hdl);
diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c
index a3ba3b284..1e6bbcd56 100644
--- a/lib/libzfs_core/libzfs_core.c
+++ b/lib/libzfs_core/libzfs_core.c
@@ -137,7 +137,7 @@ libzfs_core_init(void)
{
(void) pthread_mutex_lock(&g_lock);
if (g_refcount == 0) {
- g_fd = open(ZFS_DEV, O_RDWR);
+ g_fd = open(ZFS_DEV, O_RDWR|O_CLOEXEC);
if (g_fd < 0) {
(void) pthread_mutex_unlock(&g_lock);
return (errno);