mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
lib/: set O_CLOEXEC on all fds
As found by
git grep -E '(open|setmntent|pipe2?)\(' |
grep -vE '((zfs|zpool)_|fd|dl|lzc_re|pidfile_|g_)open\('
FreeBSD's pidfile_open() says nothing about the flags of the files it
opens, but we can't do anything about it anyway; the implementation does
open all files with O_CLOEXEC
Consider this output with zpool.d/media appended with
"pid=$$; (ls -l /proc/$pid/fd > /dev/tty)":
$ /sbin/zpool iostat -vc media
lrwx------ 0 -> /dev/pts/0
l-wx------ 1 -> 'pipe:[3278500]'
l-wx------ 2 -> /dev/null
lrwx------ 3 -> /dev/zfs
lr-x------ 4 -> /proc/31895/mounts
lrwx------ 5 -> /dev/zfs
lr-x------ 10 -> /usr/lib/zfs-linux/zpool.d/media
vs
$ ./zpool iostat -vc vendor,upath,iostat,media
lrwx------ 0 -> /dev/pts/0
l-wx------ 1 -> 'pipe:[3279887]'
l-wx------ 2 -> /dev/null
lr-x------ 10 -> /usr/lib/zfs-linux/zpool.d/media
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #11866
This commit is contained in:
@@ -66,7 +66,7 @@ static int
|
||||
nfs_exports_lock(void)
|
||||
{
|
||||
nfs_lock_fd = open(ZFS_EXPORTS_LOCK,
|
||||
O_RDWR | O_CREAT, 0600);
|
||||
O_RDWR | O_CREAT | O_CLOEXEC, 0600);
|
||||
if (nfs_lock_fd == -1) {
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
@@ -228,8 +228,8 @@ nfs_copy_entries(char *filename, const char *mountpoint)
|
||||
int error = SA_OK;
|
||||
char *line;
|
||||
|
||||
FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "r");
|
||||
FILE *newfp = fopen(filename, "w+");
|
||||
FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "re");
|
||||
FILE *newfp = fopen(filename, "w+e");
|
||||
if (newfp == NULL) {
|
||||
fprintf(stderr, "failed to open %s file: %s", filename,
|
||||
strerror(errno));
|
||||
@@ -291,7 +291,7 @@ nfs_enable_share(sa_share_impl_t impl_share)
|
||||
return (error);
|
||||
}
|
||||
|
||||
FILE *fp = fopen(filename, "a+");
|
||||
FILE *fp = fopen(filename, "a+e");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "failed to open %s file: %s", filename,
|
||||
strerror(errno));
|
||||
@@ -368,7 +368,7 @@ nfs_is_shared(sa_share_impl_t impl_share)
|
||||
char *mntpoint = impl_share->sa_mountpoint;
|
||||
size_t mntlen = strlen(mntpoint);
|
||||
|
||||
FILE *fp = fopen(ZFS_EXPORTS_FILE, "r");
|
||||
FILE *fp = fopen(ZFS_EXPORTS_FILE, "re");
|
||||
if (fp == NULL)
|
||||
return (B_FALSE);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ static int
|
||||
nfs_exports_lock(void)
|
||||
{
|
||||
nfs_lock_fd = open(ZFS_EXPORTS_LOCK,
|
||||
O_RDWR | O_CREAT, 0600);
|
||||
O_RDWR | O_CREAT | O_CLOEXEC, 0600);
|
||||
if (nfs_lock_fd == -1) {
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
@@ -453,7 +453,7 @@ nfs_add_entry(const char *filename, const char *sharepath,
|
||||
if (linux_opts == NULL)
|
||||
linux_opts = "";
|
||||
|
||||
FILE *fp = fopen(filename, "a+");
|
||||
FILE *fp = fopen(filename, "a+e");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "failed to open %s file: %s", filename,
|
||||
strerror(errno));
|
||||
@@ -489,8 +489,8 @@ nfs_copy_entries(char *filename, const char *mountpoint)
|
||||
size_t buflen = 0;
|
||||
int error = SA_OK;
|
||||
|
||||
FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "r");
|
||||
FILE *newfp = fopen(filename, "w+");
|
||||
FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "re");
|
||||
FILE *newfp = fopen(filename, "w+e");
|
||||
if (newfp == NULL) {
|
||||
fprintf(stderr, "failed to open %s file: %s", filename,
|
||||
strerror(errno));
|
||||
@@ -632,7 +632,7 @@ nfs_is_shared(sa_share_impl_t impl_share)
|
||||
size_t buflen = 0;
|
||||
char *buf = NULL;
|
||||
|
||||
FILE *fp = fopen(ZFS_EXPORTS_FILE, "r");
|
||||
FILE *fp = fopen(ZFS_EXPORTS_FILE, "re");
|
||||
if (fp == NULL) {
|
||||
return (B_FALSE);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ smb_retrieve_shares(void)
|
||||
if (!S_ISREG(eStat.st_mode))
|
||||
continue;
|
||||
|
||||
if ((share_file_fp = fopen(file_path, "r")) == NULL) {
|
||||
if ((share_file_fp = fopen(file_path, "re")) == NULL) {
|
||||
rc = SA_SYSTEM_ERR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user