1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 01UPSTREAM_autofs-5.0.4-force-unlink-umount.dpatch
7
autofs-5.0.4 - force unlink umount at startup
9
From: Ian Kent <raven@themaw.net>
11
Version 5.0.3 autofs would unlink existing mounts at startup. This
12
functioned OK most of the time but caused processes whose working
13
directory was within unlinked automounted directories to not get a
14
correct pwd reported by the system.
16
There can be situations where the unlink umounting is desirable, such
17
as when the daemon is forceably killed and we want to get rid of any
18
existing mounts at startup. This change provides a way to force this
19
old behavior by passing the "--force" option to the daemon. This can
20
also be done by using the "forcestart" and "forcerestart" actions to
23
Note that the old behavior will always be used if the kernel does not
24
include the iotcl re-implementation which provides the ability to
25
re-connect to existing mounts.
29
daemon/automount.c | 14 +++++++++++++-
30
daemon/direct.c | 2 +-
31
daemon/indirect.c | 2 +-
32
include/automount.h | 3 +++
33
man/automount.8 | 13 +++++++++++++
34
redhat/autofs.init.in | 10 +++++++++-
35
samples/rc.autofs.in | 10 +++++++++-
36
8 files changed, 51 insertions(+), 5 deletions(-)
39
diff --git a/CHANGELOG b/CHANGELOG
40
index 7dee674..d4dd70b 100644
44
- fix hosts map use after free.
45
- fix uri list locking (again).
46
- check for stale SASL credentials upon connect fail.
47
+- add "forcestart" and "forcerestart" init script options to allow
48
+ use of 5.0.3 strartup behavior if required.
50
4/11/2008 autofs-5.0.4
51
-----------------------
52
diff --git a/daemon/automount.c b/daemon/automount.c
53
index f04273f..e20e7c9 100644
54
--- a/daemon/automount.c
55
+++ b/daemon/automount.c
56
@@ -57,6 +57,7 @@ static char *pid_file = NULL; /* File in which to keep pid */
57
unsigned int global_random_selection; /* use random policy when selecting
58
* which multi-mount host to mount */
59
long global_negative_timeout = -1;
60
+int do_force_unlink = 0; /* Forceably unlink mount tree at startup */
62
static int start_pipefd[2];
63
static int st_stat = 0;
64
@@ -1798,6 +1799,7 @@ int main(int argc, char *argv[])
65
{"version", 0, 0, 'V'},
66
{"set-log-priority", 1, 0, 'l'},
67
{"dont-check-daemon", 0, 0, 'C'},
68
+ {"force", 0, 0, 'F'},
72
@@ -1819,7 +1821,7 @@ int main(int argc, char *argv[])
76
- while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:C", long_options, NULL)) != EOF) {
77
+ while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
81
@@ -1892,6 +1894,10 @@ int main(int argc, char *argv[])
86
+ do_force_unlink = 1;
91
printf("%s: Ambiguous or unknown options\n", program);
92
@@ -2066,6 +2072,12 @@ int main(int argc, char *argv[])
97
+ * Mmm ... reset force unlink umount so we don't also do this
98
+ * in future when we receive a HUP signal.
100
+ do_force_unlink = 0;
102
res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
103
close(start_pipefd[1]);
105
diff --git a/daemon/direct.c b/daemon/direct.c
106
index d9dda3d..2d979f1 100644
107
--- a/daemon/direct.c
108
+++ b/daemon/direct.c
109
@@ -335,7 +335,7 @@ int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struc
110
/* Calculate the timeouts */
111
ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
113
- if (ops->version) {
114
+ if (ops->version && !do_force_unlink) {
115
ap->flags |= MOUNT_FLAG_REMOUNT;
116
ret = try_remount(ap, me, t_direct);
117
ap->flags &= ~MOUNT_FLAG_REMOUNT;
118
diff --git a/daemon/indirect.c b/daemon/indirect.c
119
index 0721707..2ccbc53 100644
120
--- a/daemon/indirect.c
121
+++ b/daemon/indirect.c
122
@@ -97,7 +97,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)
124
ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
126
- if (ops->version) {
127
+ if (ops->version && !do_force_unlink) {
128
ap->flags |= MOUNT_FLAG_REMOUNT;
129
ret = try_remount(ap, NULL, t_indirect);
130
ap->flags &= ~MOUNT_FLAG_REMOUNT;
131
diff --git a/include/automount.h b/include/automount.h
132
index 46cb6c6..1f14d5b 100644
133
--- a/include/automount.h
134
+++ b/include/automount.h
135
@@ -428,6 +428,9 @@ struct autofs_point {
136
struct list_head submounts; /* List of child submounts */
139
+/* Foreably unlink existing mounts at startup. */
140
+extern int do_force_unlink;
142
/* Standard functions used by daemon or modules */
144
#define MOUNT_OFFSET_OK 0
145
diff --git a/man/automount.8 b/man/automount.8
146
index d9285bf..9fcaaf4 100644
147
--- a/man/automount.8
148
+++ b/man/automount.8
149
@@ -84,6 +84,11 @@ path name as specified in the master map.
151
.I "\-C, \-\-dont-check-daemon"
152
Don't check if the daemon is currently running (see NOTES).
155
+Force an unlink umount of existing mounts under autofs managed mount points
156
+during startup. This can cause problems for processes with working directories
157
+within these mounts (see NOTES).
159
\fBautomount\fP takes one optional argument, the name of the master map to
161
@@ -132,6 +137,14 @@ for certain types of automount maps. The mounts of the seperate daemons
162
might interfere with one another. The implications of running multiple
163
daemon instances needs to be checked and tested before we can say this
166
+If the option to force an unlink of mounts at startup is used then processes
167
+whose working directory is within unlinked automounted directories will not
168
+get the correct pwd from the system. This is because, after the mount is
169
+unlinked from the mount tree, anything that needs to walk back up the mount
170
+tree to construct a path, such as getcwd(2) and the proc filesystem
171
+/proc/<pid>/cwd, cannot work because the point from which the path is
172
+constructed has been detached from the mount tree.
176
diff --git a/redhat/autofs.init.in b/redhat/autofs.init.in
177
index 65c786e..471667e 100644
178
--- a/redhat/autofs.init.in
179
+++ b/redhat/autofs.init.in
180
@@ -137,6 +137,10 @@ case "$1" in
185
+ OPTIONS="$OPTIONS --force"
191
@@ -146,6 +150,10 @@ case "$1" in
196
+ OPTIONS="$OPTIONS --force"
202
@@ -155,7 +163,7 @@ case "$1" in
206
- echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
207
+ echo $"Usage: $0 {start|forcestart|stop|status|restart|orcerestart|reload|condrestart}"
211
diff --git a/samples/rc.autofs.in b/samples/rc.autofs.in
212
index 51f5b02..2877fe2 100644
213
--- a/samples/rc.autofs.in
214
+++ b/samples/rc.autofs.in
215
@@ -117,17 +117,25 @@ case "$1" in
220
+ OPTIONS="$OPTIONS --force"
230
+ OPTIONS="$OPTIONS --force"
237
- echo $"Usage: $0 {start|stop|restart|reload}"
238
+ echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}"