+2013-06-20 Miklos Szeredi <miklos@szeredi.hu>
+
+ * libfuse: fix multiple close of device fd. Reported by Dan
+ Greenfield
+
2013-03-19 Miklos Szeredi <miklos@szeredi.hu>
* libfuse: fix thread cancel race. Exiting a worker my race with
size_t op_size, void *userdata);
void fuse_kern_unmount_compat22(const char *mountpoint);
+int fuse_chan_clearfd(struct fuse_chan *ch);
+
void fuse_kern_unmount(const char *mountpoint, int fd);
int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
return ch->fd;
}
+int fuse_chan_clearfd(struct fuse_chan *ch)
+{
+ int fd = ch->fd;
+ ch->fd = -1;
+ return fd;
+}
+
size_t fuse_chan_bufsize(struct fuse_chan *ch)
{
return ch->bufsize;
static void fuse_unmount_common(const char *mountpoint, struct fuse_chan *ch)
{
- int fd = ch ? fuse_chan_fd(ch) : -1;
- fuse_kern_unmount(mountpoint, fd);
- if (ch)
- fuse_chan_destroy(ch);
+ if (mountpoint) {
+ int fd = ch ? fuse_chan_clearfd(ch) : -1;
+ fuse_kern_unmount(mountpoint, fd);
+ if (ch)
+ fuse_chan_destroy(ch);
+ }
}
void fuse_unmount(const char *mountpoint, struct fuse_chan *ch)
pfd.fd = fd;
pfd.events = 0;
res = poll(&pfd, 1, 0);
+
+ /* Need to close file descriptor, otherwise synchronous umount
+ would recurse into filesystem, and deadlock.
+
+ Caller expects fuse_kern_unmount to close the fd, so close it
+ anyway. */
+ close(fd);
+
/* If file poll returns POLLERR on the device file descriptor,
then the filesystem is already unmounted */
if (res == 1 && (pfd.revents & POLLERR))
return;
-
- /* Need to close file descriptor, otherwise synchronous umount
- would recurse into filesystem, and deadlock */
- close(fd);
}
if (geteuid() == 0) {
(void)mountpoint;
if (fstat(fd, &sbuf) == -1)
- return;
+ goto out;
devname_r(sbuf.st_rdev, S_IFCHR, dev, 128);
if (strncmp(dev, "fuse", 4))
- return;
+ goto out;
strtol(dev + 4, &ep, 10);
if (*ep != '\0')
- return;
+ goto out;
do_unmount(dev, fd);
+
+out:
+ close(fd);
}
/* Check if kernel is doing init in background */