libfuse: use O_CLOEXEC flag when opening /dev/fuse device
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 2 Apr 2012 18:04:02 +0000 (19:04 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Wed, 20 Feb 2013 14:59:08 +0000 (15:59 +0100)
ChangeLog
lib/mount.c

index 508ae467d33315fd8d68f1739abf4f226ef8b090..511c69429ca3ec67e41728d851b168bc8d5bbffb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
        * libfuse: change the type of fuse_ino_t from 'unsigned long' to
        'uint64_t'
 
+       * libfuse: use O_CLOEXEC flag when opening /dev/fuse device.
+       Patch by Richard W.M. Jones
+
 2013-02-19  Miklos Szeredi <miklos@szeredi.hu>
 
        * fuse_daemonize(): chdir to "/" even if not running in the
index 01f64da78c56ce37d5ed2f65e02e0fd7bb702469..4f748417466b438e696b9d7d7bb61a86996bcdbf 100644 (file)
@@ -406,6 +406,10 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo,
        return rv;
 }
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
 static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
                          const char *mnt_opts)
 {
@@ -442,7 +446,7 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
                return -2;
        }
 
-       fd = open(devname, O_RDWR);
+       fd = open(devname, O_RDWR | O_CLOEXEC);
        if (fd == -1) {
                if (errno == ENODEV || errno == ENOENT)
                        fprintf(stderr, "fuse: device not found, try 'modprobe fuse' first\n");
@@ -451,6 +455,8 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
                                devname, strerror(errno));
                return -1;
        }
+       if (!O_CLOEXEC)
+               fcntl(fd, F_SETFD, FD_CLOEXEC);
 
        snprintf(tmp, sizeof(tmp),  "fd=%i,rootmode=%o,user_id=%i,group_id=%i",
                 fd, stbuf.st_mode & S_IFMT, getuid(), getgid());