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

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