Blame SOURCES/autofs-5.0.7-syncronize-handle_mounts-shutdown.patch

304803
autofs-5.0.7 - syncronize handle_mounts() shutdown
304803
304803
From: Ian Kent <ikent@redhat.com>
304803
304803
When re-reading the master map the signal handler thread receives
304803
a SIGTERM signal from handle_mounts_cleanup() for map entries that
304803
have been removed. This is done to allow joining with handle_mounts()
304803
threads before shutting down to ensure clean up has been completed
304803
before the thread terminates.
304803
304803
But, if more than one map entry is removed, multiple threads may be
304803
cleaned up during the handling of a single signal so there can be no
304803
work to do when a subsequent signal is received. In this case the
304803
signal handler thread interprets the additional SIGTERM signal as a
304803
request to shutdown and exits.
304803
---
304803
 CHANGELOG          |    1 +
304803
 daemon/automount.c |    9 +++++++--
304803
 2 files changed, 8 insertions(+), 2 deletions(-)
304803
304803
diff --git a/CHANGELOG b/CHANGELOG
304803
index 488ad1e..f1ec1e5 100644
304803
--- a/CHANGELOG
304803
+++ b/CHANGELOG
304803
@@ -38,6 +38,7 @@
304803
 - fix systemd unidir in spec file.
304803
 - document browse option in man page.
304803
 - fix some automount(8) typos.
304803
+- syncronize handle_mounts() shutdown.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
diff --git a/daemon/automount.c b/daemon/automount.c
304803
index 4c651cf..3f9337f 100644
304803
--- a/daemon/automount.c
304803
+++ b/daemon/automount.c
304803
@@ -1285,7 +1285,8 @@ static int do_hup_signal(struct master *master, time_t age)
304803
 	nfs_mount_uses_string_options = check_nfs_mount_version(&vers, &check);
304803
 
304803
 	master_mutex_lock();
304803
-	if (master->reading) {
304803
+	/* Already doing a map read or shutdown or no mounts */
304803
+	if (master->reading || list_empty(&master->mounts)) {
304803
 		status = pthread_mutex_unlock(&mrc.mutex);
304803
 		if (status)
304803
 			fatal(status);
304803
@@ -1449,6 +1450,7 @@ static void handle_mounts_cleanup(void *arg)
304803
 	char path[PATH_MAX + 1];
304803
 	char buf[MAX_ERR_BUF];
304803
 	unsigned int clean = 0, submount, logopt;
304803
+	unsigned int pending = 0;
304803
 
304803
 	ap = (struct autofs_point *) arg;
304803
 
304803
@@ -1466,6 +1468,9 @@ static void handle_mounts_cleanup(void *arg)
304803
 		list_del_init(&ap->mounts);
304803
 	}
304803
 
304803
+	/* Don't signal the handler if we have already done so */
304803
+	if (!list_empty(&master_list->completed))
304803
+		pending = 1;
304803
 	master_remove_mapent(ap->entry);
304803
 	master_source_unlock(ap->entry);
304803
 
304803
@@ -1498,7 +1503,7 @@ static void handle_mounts_cleanup(void *arg)
304803
 	 * so it can join with any completed handle_mounts() threads and
304803
 	 * perform final cleanup.
304803
 	 */
304803
-	if (!submount)
304803
+	if (!submount && !pending)
304803
 		pthread_kill(state_mach_thid, SIGTERM);
304803
 
304803
 	master_mutex_unlock();