-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmount.c.diff
More file actions
134 lines (120 loc) · 3.51 KB
/
mount.c.diff
File metadata and controls
134 lines (120 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff -ur a/lib/mount.c b/lib/mount.c
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -46,7 +46,6 @@
#define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0)
#endif
-#define FUSERMOUNT_PROG "fusermount3"
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
#define FUSE_COMMFD2_ENV "_FUSE_COMMFD2"
@@ -121,6 +120,35 @@
FUSE_OPT_END
};
+/**
+ * Returns FUSERMOUNT_PROG path from environment variable.
+ *
+ * If $FUSERMOUNT_PROG is not set, the program exits.
+ *
+ * Call with FUSERMOUNT_PROG_DEBUG=nonzerovalue to make the code print the value before evaluation.
+ */
+static const char *fusermountProg(void)
+{
+ static const char envVar[] = "FUSERMOUNT_PROG";
+ char *fusermountProg = getenv(envVar);
+
+ static const char debugEnvVarSuffix[] = "_DEBUG";
+ char debugEnvVar[sizeof(envVar) + sizeof(debugEnvVarSuffix) + 1];
+ sprintf(debugEnvVar, "%s%s", envVar, debugEnvVarSuffix);
+
+ if (fusermountProg == NULL) {
+ fprintf(stderr, "Error: $%s not set\n", envVar);
+ exit(1);
+ }
+
+ if (getenv(debugEnvVar) != NULL) {
+ fprintf(stderr, "$%s: %s\n", envVar, fusermountProg);
+ }
+
+ return fusermountProg;
+}
+
+
/*
* Running fusermount by calling 'posix_spawn'
*
@@ -129,19 +157,13 @@
static int fusermount_posix_spawn(posix_spawn_file_actions_t *action,
char const * const argv[], pid_t *out_pid)
{
- const char *full_path = FUSERMOUNT_DIR "/" FUSERMOUNT_PROG;
pid_t pid;
/* See man 7 environ for the global environ pointer */
/* first try the install path */
- int status = posix_spawn(&pid, full_path, action, NULL,
+ int status = posix_spawn(&pid, fusermountProg(), action, NULL,
(char * const *) argv, environ);
- if (status != 0) {
- /* if that fails, try a system install */
- status = posix_spawnp(&pid, FUSERMOUNT_PROG, action, NULL,
- (char * const *) argv, environ);
- }
if (status != 0) {
fuse_log(FUSE_LOG_ERR,
@@ -160,12 +182,12 @@
void fuse_mount_version(void)
{
- char const *const argv[] = {FUSERMOUNT_PROG, "--version", NULL};
+ char const *const argv[] = {fusermountProg(), "--version", NULL};
int status = fusermount_posix_spawn(NULL, argv, NULL);
if(status != 0)
fuse_log(FUSE_LOG_ERR, "Running '%s --version' failed",
- FUSERMOUNT_PROG);
+ fusermountProg());
}
struct mount_flags {
@@ -337,12 +359,12 @@
return;
char const * const argv[] =
- { FUSERMOUNT_PROG, "--unmount", "--quiet", "--lazy",
+ { fusermountProg(), "--unmount", "--quiet", "--lazy",
"--", mountpoint, NULL };
int status = fusermount_posix_spawn(NULL, argv, NULL);
if(status != 0) {
fuse_log(FUSE_LOG_ERR, "Spawning %s to unmount failed: %s",
- FUSERMOUNT_PROG, strerror(-status));
+ fusermountProg(), strerror(-status));
return;
}
}
@@ -378,7 +400,7 @@
setenv(FUSE_COMMFD2_ENV, arg_fd_entry, 1);
char const *const argv[] = {
- FUSERMOUNT_PROG,
+ fusermountProg(),
"--auto-unmount",
"--",
mountpoint,
@@ -434,7 +456,7 @@
res = socketpair(PF_UNIX, SOCK_STREAM, 0, fds);
if(res == -1) {
fuse_log(FUSE_LOG_ERR, "Running %s: socketpair() failed: %s\n",
- FUSERMOUNT_PROG, strerror(errno));
+ fusermountProg(), strerror(errno));
return -1;
}
@@ -451,7 +473,7 @@
setenv(FUSE_COMMFD2_ENV, arg_fd_entry, 1);
char const *const argv[] = {
- FUSERMOUNT_PROG,
+ fusermountProg(),
"-o", opts ? opts : "",
"--",
mountpoint,
@@ -476,7 +498,7 @@
close(fds[0]);
close(fds[1]);
fuse_log(FUSE_LOG_ERR, "posix_spawn(p)() for %s failed: %s",
- FUSERMOUNT_PROG, strerror(-status));
+ fusermountProg(), strerror(-status));
return -1;
}