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

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