Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 216

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.1 - 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 file changed, 14 insertions(+), 1 deletion(-)


--- autofs-5.0.1.orig/lib/master.c
+++ autofs-5.0.1/lib/master.c
@@ -543,13 +543,26 @@ void send_map_update_request(struct auto
 
 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;
 }