autofs-5.0.5 - wait for master source mutex

From: Ian Kent <raven@themaw.net>

Occasionally we might not be able to get the master source write
lock when a read lock is held. We can wait a little while to see
if it gets released without causing a problem.
---

 lib/master.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)


diff --git a/lib/master.c b/lib/master.c
index 5846f72..53dfa27 100644
--- a/lib/master.c
+++ b/lib/master.c
@@ -536,13 +536,26 @@ void send_map_update_request(struct autofs_point *ap)
 
 void master_source_writelock(struct master_mapent *entry)
 {
+	int retries = 5; /* 1 second maximum */
 	int status;
 
-	status = pthread_rwlock_wrlock(&entry->source_lock);
+	while (retries--) {
+		status = pthread_rwlock_wrlock(&entry->source_lock);
+		if (status != EAGAIN)
+			break;
+		else {
+                	struct timespec t = { 0, 200000000 };
+	                struct timespec r;
+                	while (nanosleep(&t, &r) == -1 && errno == EINTR)
+                        	memcpy(&t, &r, sizeof(struct timespec));
+		}
+	}
+
 	if (status) {
 		logmsg("master_mapent source write lock failed");
 		fatal(status);
 	}
+
 	return;
 }