Blame SOURCES/autofs-5.1.6-add-force-unlink-mounts-and-exit-option.patch

d702dc
autofs-5.1.6 - add force unlink mounts and exit option
d702dc
d702dc
From: Ian Kent <raven@themaw.net>
d702dc
d702dc
Add a automount program option to force an unlink umount of all
d702dc
existing mounts under configured autofs mount points then exit.
d702dc
d702dc
Signed-off-by: Ian Kent <raven@themaw.net>
d702dc
---
d702dc
 CHANGELOG           |    1 +
d702dc
 daemon/automount.c  |   51 +++++++++++++++++++++++++++++++++------------------
d702dc
 daemon/direct.c     |   12 +++++++++++-
d702dc
 daemon/indirect.c   |   21 ++++++++++++++++-----
d702dc
 include/automount.h |    1 +
d702dc
 lib/master.c        |    6 ++++--
d702dc
 man/automount.8     |    6 ++++++
d702dc
 7 files changed, 72 insertions(+), 26 deletions(-)
d702dc
d702dc
--- autofs-5.1.4.orig/CHANGELOG
d702dc
+++ autofs-5.1.4/CHANGELOG
d702dc
@@ -89,6 +89,7 @@ xx/xx/2018 autofs-5.1.5
d702dc
 - use bit flag for force unlink mounts.
d702dc
 - improve force unlink option description.
d702dc
 - remove command fifo on autofs mount fail.
d702dc
+- add force unlink mounts and exit option.
d702dc
 
d702dc
 19/12/2017 autofs-5.1.4
d702dc
 - fix spec file url.
d702dc
--- autofs-5.1.4.orig/daemon/automount.c
d702dc
+++ autofs-5.1.4/daemon/automount.c
d702dc
@@ -1153,8 +1153,13 @@ static int mount_autofs(struct autofs_po
d702dc
 {
d702dc
 	int status = 0;
d702dc
 
d702dc
-	if (autofs_init_ap(ap) != 0)
d702dc
-		return -1;
d702dc
+	/* No need to create comms fds and command fifo if
d702dc
+	 * unlinking mounts and exiting.
d702dc
+	 */
d702dc
+	if (!(do_force_unlink & UNLINK_AND_EXIT)) {
d702dc
+		if (autofs_init_ap(ap) != 0)
d702dc
+			return -1;
d702dc
+	}
d702dc
 
d702dc
 	if (ap->type == LKP_DIRECT)
d702dc
 		status = mount_autofs_direct(ap);
d702dc
@@ -1859,7 +1864,8 @@ void *handle_mounts(void *arg)
d702dc
 	}
d702dc
 
d702dc
 	if (mount_autofs(ap, root) < 0) {
d702dc
-		crit(ap->logopt, "mount of %s failed!", ap->path);
d702dc
+		if (!(do_force_unlink & UNLINK_AND_EXIT))
d702dc
+			crit(ap->logopt, "mount of %s failed!", ap->path);
d702dc
 		suc->status = 1;
d702dc
 		umount_autofs(ap, root, 1);
d702dc
 		free(root);
d702dc
@@ -1951,6 +1957,7 @@ static void usage(void)
d702dc
 		"	-C --dont-check-daemon\n"
d702dc
 		"			don't check if daemon is already running\n"
d702dc
 		"	-F --force	forceably clean up known automounts at start\n"
d702dc
+		"	-U --force-exit	forceably clean up known automounts and exit\n"
d702dc
 		"	-V --version	print version, build config and exit\n"
d702dc
 		, program);
d702dc
 }
d702dc
@@ -2202,7 +2209,7 @@ int main(int argc, char *argv[])
d702dc
 	time_t timeout;
d702dc
 	time_t age = monotonic_time(NULL);
d702dc
 	struct rlimit rlim;
d702dc
-	const char *options = "+hp:t:vmdD:SfVrO:l:n:CFM";
d702dc
+	const char *options = "+hp:t:vmdD:SfVrO:l:n:CFUM";
d702dc
 	static const struct option long_options[] = {
d702dc
 		{"help", 0, 0, 'h'},
d702dc
 		{"pid-file", 1, 0, 'p'},
d702dc
@@ -2220,6 +2227,7 @@ int main(int argc, char *argv[])
d702dc
 		{"set-log-priority", 1, 0, 'l'},
d702dc
 		{"dont-check-daemon", 0, 0, 'C'},
d702dc
 		{"force", 0, 0, 'F'},
d702dc
+		{"force-exit", 0, 0, 'U'},
d702dc
 		{"master-wait", 1, 0, 'M'},
d702dc
 		{0, 0, 0, 0}
d702dc
 	};
d702dc
@@ -2342,6 +2350,11 @@ int main(int argc, char *argv[])
d702dc
 			do_force_unlink = UNLINK_AND_CONT;
d702dc
 			break;
d702dc
 
d702dc
+		case 'U':
d702dc
+			flags |= DAEMON_FLAGS_FOREGROUND;
d702dc
+			do_force_unlink = UNLINK_AND_EXIT;
d702dc
+			break;
d702dc
+
d702dc
 		case '?':
d702dc
 		case ':':
d702dc
 			printf("%s: Ambiguous or unknown options\n", program);
d702dc
@@ -2657,25 +2670,27 @@ int main(int argc, char *argv[])
d702dc
 		}
d702dc
 	}
d702dc
 
d702dc
-	/*
d702dc
-	 * Mmm ... reset force unlink umount so we don't also do this
d702dc
-	 * in future when we receive a HUP signal.
d702dc
-	 */
d702dc
-	do_force_unlink = 0;
d702dc
+	if (!(do_force_unlink & UNLINK_AND_EXIT)) {
d702dc
+		/*
d702dc
+		 * Mmm ... reset force unlink umount so we don't also do
d702dc
+		 * this in future when we receive a HUP signal.
d702dc
+		 */
d702dc
+		do_force_unlink = 0;
d702dc
 
d702dc
-	if (start_pipefd[1] != -1) {
d702dc
-		st_stat = 0;
d702dc
-		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
d702dc
-		close(start_pipefd[1]);
d702dc
-	}
d702dc
+		if (start_pipefd[1] != -1) {
d702dc
+			st_stat = 0;
d702dc
+			res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
d702dc
+			close(start_pipefd[1]);
d702dc
+		}
d702dc
 
d702dc
 #ifdef WITH_SYSTEMD
d702dc
-	if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE)
d702dc
-		sd_notify(1, "READY=1");
d702dc
+		if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE)
d702dc
+			sd_notify(1, "READY=1");
d702dc
 #endif
d702dc
 
d702dc
-	state_mach_thid = pthread_self();
d702dc
-	statemachine(NULL);
d702dc
+		state_mach_thid = pthread_self();
d702dc
+		statemachine(NULL);
d702dc
+	}
d702dc
 
d702dc
 	master_kill(master_list);
d702dc
 
d702dc
--- autofs-5.1.4.orig/daemon/direct.c
d702dc
+++ autofs-5.1.4/daemon/direct.c
d702dc
@@ -286,7 +286,14 @@ int do_mount_autofs_direct(struct autofs
d702dc
 		if (ret == 0)
d702dc
 			return -1;
d702dc
 	} else {
d702dc
-		if (ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
d702dc
+		/* I don't remember why this is here for the force
d702dc
+		 * unlink case. I don't think it should be but I may
d702dc
+		 * have done it for a reason so keep it for the unlink
d702dc
+		 * and continue case but not for the unlink and exit
d702dc
+		 * case.
d702dc
+		 */
d702dc
+		if (!(do_force_unlink & UNLINK_AND_EXIT) &&
d702dc
+		    ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
d702dc
 			time_t tout = get_exp_timeout(ap, me->source);
d702dc
 			int save_ioctlfd, ioctlfd;
d702dc
 
d702dc
@@ -319,6 +326,9 @@ int do_mount_autofs_direct(struct autofs
d702dc
 			goto out_err;
d702dc
 		}
d702dc
 
d702dc
+		if (do_force_unlink & UNLINK_AND_EXIT)
d702dc
+			return -1;
d702dc
+
d702dc
 		if (me->ioctlfd != -1) {
d702dc
 			error(ap->logopt, "active direct mount %s", me->key);
d702dc
 			return -1;
d702dc
--- autofs-5.1.4.orig/daemon/indirect.c
d702dc
+++ autofs-5.1.4/daemon/indirect.c
d702dc
@@ -76,6 +76,9 @@ static int do_mount_autofs_indirect(stru
d702dc
 			      "or failed to unlink entry in tree");
d702dc
 			goto out_err;
d702dc
 		}
d702dc
+
d702dc
+		if (do_force_unlink & UNLINK_AND_EXIT)
d702dc
+			return -1;
d702dc
 	}
d702dc
 
d702dc
 	options = make_options_string(ap->path,
d702dc
@@ -163,12 +166,20 @@ int mount_autofs_indirect(struct autofs_
d702dc
 	int status;
d702dc
 	int map;
d702dc
 
d702dc
+	/* Don't read the map if the unlink and exit option has been
d702dc
+	 * given. do_mount_autofs_indirect() will return -1 if this
d702dc
+	 * option has been given so there's no need to do anything
d702dc
+	 * else.
d702dc
+	 */
d702dc
+
d702dc
 	/* TODO: read map, determine map type is OK */
d702dc
-	if (lookup_nss_read_map(ap, NULL, now))
d702dc
-		lookup_prune_cache(ap, now);
d702dc
-	else {
d702dc
-		error(ap->logopt, "failed to read map for %s", ap->path);
d702dc
-		return -1;
d702dc
+	if (!(do_force_unlink & UNLINK_AND_EXIT)) {
d702dc
+		if (lookup_nss_read_map(ap, NULL, now))
d702dc
+			lookup_prune_cache(ap, now);
d702dc
+		else {
d702dc
+			error(ap->logopt, "failed to read map for %s", ap->path);
d702dc
+			return -1;
d702dc
+		}
d702dc
 	}
d702dc
 
d702dc
 	status = do_mount_autofs_indirect(ap, root);
d702dc
--- autofs-5.1.4.orig/include/automount.h
d702dc
+++ autofs-5.1.4/include/automount.h
d702dc
@@ -591,6 +591,7 @@ struct autofs_point {
d702dc
 };
d702dc
 
d702dc
 #define UNLINK_AND_CONT		0x01
d702dc
+#define UNLINK_AND_EXIT		0x02
d702dc
 
d702dc
 /* Foreably unlink existing mounts at startup. */
d702dc
 extern int do_force_unlink;
d702dc
--- autofs-5.1.4.orig/lib/master.c
d702dc
+++ autofs-5.1.4/lib/master.c
d702dc
@@ -1358,7 +1358,8 @@ static int master_do_mount(struct master
d702dc
 	suc.done = 0;
d702dc
 	suc.status = 0;
d702dc
 
d702dc
-	debug(ap->logopt, "mounting %s", entry->path);
d702dc
+	if (!(do_force_unlink & UNLINK_AND_EXIT))
d702dc
+		debug(ap->logopt, "mounting %s", entry->path);
d702dc
 
d702dc
 	status = pthread_create(&thid, &th_attr, handle_mounts, &suc);
d702dc
 	if (status) {
d702dc
@@ -1376,7 +1377,8 @@ static int master_do_mount(struct master
d702dc
 	}
d702dc
 
d702dc
 	if (suc.status) {
d702dc
-		error(ap->logopt, "failed to startup mount");
d702dc
+		if (!(do_force_unlink & UNLINK_AND_EXIT))
d702dc
+			error(ap->logopt, "failed to startup mount");
d702dc
 		handle_mounts_startup_cond_destroy(&suc);
d702dc
 		return 0;
d702dc
 	}
d702dc
--- autofs-5.1.4.orig/man/automount.8
d702dc
+++ autofs-5.1.4/man/automount.8
d702dc
@@ -121,6 +121,12 @@ Don't check if the daemon is currently r
d702dc
 Force an unlink umount of existing mounts under configured autofs managed
d702dc
 mount points during startup. This can cause problems for processes with
d702dc
 working directories within these mounts (see NOTES).
d702dc
+.TP
d702dc
+.I "\-U, \-\-force-exit"
d702dc
+Force an unlink umount of existing mounts under configured autofs managed
d702dc
+mount points and exit rather than continuing the startup. This can cause
d702dc
+problems for processes with working directories within these mounts (see
d702dc
+NOTES).
d702dc
 .SH ARGUMENTS
d702dc
 \fBautomount\fP takes one optional argument, the name of the master map to
d702dc
 use.