* In case of failure to add to /etc/mtab use same mountpoint for
cleanup as for mounting. Reported by Marc Deslauriers
+ * fusermount: chdir to / before performing mount/umount
+
2010-12-16 Miklos Szeredi <miklos@szeredi.hu>
* Highlevel lib: allow hash tables to shrink
return 0;
}
-static int check_perm(const char **mntp, struct stat *stbuf, int *currdir_fd,
+static int check_perm(const char **mntp, struct stat *stbuf,
int *mountpoint_fd, int *isdir)
{
int res;
if (S_ISDIR(stbuf->st_mode)) {
*isdir = 1;
- *currdir_fd = open(".", O_RDONLY);
- if (*currdir_fd == -1) {
- fprintf(stderr,
- "%s: failed to open current directory: %s\n",
- progname, strerror(errno));
- return -1;
- }
*mountpoint_fd = open(mnt, O_RDONLY);
if (*mountpoint_fd == -1) {
fprintf(stderr, "%s: failed to open %s: %s\n",
char *source = NULL;
char *mnt_opts = NULL;
const char *real_mnt = mnt;
- int currdir_fd = -1;
int mountpoint_fd = -1;
int isdir = 0;
res = check_version(dev);
if (res != -1) {
- res = check_perm(&real_mnt, &stbuf, &currdir_fd,
- &mountpoint_fd, &isdir);
+ res = check_perm(&real_mnt, &stbuf, &mountpoint_fd, &isdir);
restore_privs();
if (res != -1)
res = do_mount(real_mnt, &type, stbuf.st_mode & S_IFMT,
} else
restore_privs();
- if (currdir_fd != -1) {
- fchdir(currdir_fd);
- close(currdir_fd);
- }
+ chdir("/");
if (mountpoint_fd != -1)
fcntl(mountpoint_fd, F_SETFD, FD_CLOEXEC);
drop_privs();
mnt = fuse_mnt_resolve_path(progname, origmnt);
+ if (mnt != NULL) {
+ res = chdir("/");
+ if (res == -1) {
+ fprintf(stderr, "%s: failed to chdir to '/'\n", progname);
+ exit(1);
+ }
+ }
restore_privs();
if (mnt == NULL)
exit(1);