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

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