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

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