aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/fusermount.c54
1 files changed, 14 insertions, 40 deletions
diff --git a/util/fusermount.c b/util/fusermount.c
index da6d5f2..68fa31e 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -41,6 +41,7 @@
#endif
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
+#define FUSE_KERN_DEVICE_ENV "FUSE_KERN_DEVICE"
#define FUSE_DEV "/dev/fuse"
@@ -1163,56 +1164,30 @@ static int check_perm(const char **mntp, struct stat *stbuf, int *mountpoint_fd)
return -1;
}
-static int try_open(const char *dev, char **devp, int silent)
-{
- int fd = open(dev, O_RDWR);
- if (fd != -1) {
- *devp = strdup(dev);
- if (*devp == NULL) {
- fprintf(stderr, "%s: failed to allocate memory\n",
- progname);
- close(fd);
- fd = -1;
- }
- } else if (errno == ENODEV ||
- errno == ENOENT)/* check for ENOENT too, for the udev case */
- return -2;
- else if (!silent) {
- fprintf(stderr, "%s: failed to open %s: %s\n", progname, dev,
- strerror(errno));
- }
- return fd;
-}
-
-static int try_open_fuse_device(char **devp)
+static int open_fuse_device(const char *dev)
{
int fd;
drop_privs();
- fd = try_open(FUSE_DEV, devp, 0);
+ fd = open(dev, O_RDWR);
+ if (fd == -1) {
+ if (errno == ENODEV || errno == ENOENT)/* check for ENOENT too, for the udev case */
+ fprintf(stderr,
+ "%s: fuse device %s not found. Kernel module not loaded?\n",
+ progname, dev);
+ else
+ fprintf(stderr,
+ "%s: failed to open %s: %s\n", progname, dev, strerror(errno));
+ }
restore_privs();
return fd;
}
-static int open_fuse_device(char **devp)
-{
- int fd = try_open_fuse_device(devp);
- if (fd >= -1)
- return fd;
-
- fprintf(stderr,
- "%s: fuse device not found, try 'modprobe fuse' first\n",
- progname);
-
- return -1;
-}
-
-
static int mount_fuse(const char *mnt, const char *opts, const char **type)
{
int res;
int fd;
- char *dev;
+ const char *dev = getenv(FUSE_KERN_DEVICE_ENV) ?: FUSE_DEV;
struct stat stbuf;
char *source = NULL;
char *mnt_opts = NULL;
@@ -1221,7 +1196,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
char *do_mount_opts = NULL;
char *x_opts = NULL;
- fd = open_fuse_device(&dev);
+ fd = open_fuse_device(dev);
if (fd == -1)
return -1;
@@ -1292,7 +1267,6 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
out_free:
free(source);
free(mnt_opts);
- free(dev);
free(x_opts);
free(do_mount_opts);