autofs-5.1.8 - dont immediately call function when waiting

From: Ian Kent <raven@themaw.net>

When autofs needs to wait for a sss connection the connection function
is immediately called a second time without first waiting. Adjust the
calling so that there's a wait before the next call.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG            |    1 +
 modules/lookup_sss.c |   24 ++++++++++++------------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c79f7cb8..772a7645 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -54,6 +54,7 @@
 - include addtional log info for mounts.
 - fail on empty replicated host name.
 - improve handling of ENOENT in sss setautomntent().
+- don't immediately call function when waiting.
 
 19/10/2021 autofs-5.1.8
 - add xdr_exports().
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
index 73832dc9..43545b0c 100644
--- a/modules/lookup_sss.c
+++ b/modules/lookup_sss.c
@@ -338,10 +338,13 @@ static int setautomntent_wait(unsigned int logopt,
 	     "can't connect to sssd, retry for %d seconds",
 	     retries);
 
-	while (++retry <= retries) {
+	while (++retry < retries) {
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
 		struct timespec r;
 
+		while (nanosleep(&t, &r) == -1 && errno == EINTR)
+			memcpy(&t, &r, sizeof(struct timespec));
+
 		ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
 		if (proto_version(ctxt) == 0) {
 			if (ret != ENOENT)
@@ -355,9 +358,6 @@ static int setautomntent_wait(unsigned int logopt,
 			free(*sss_ctxt);
 			*sss_ctxt = NULL;
 		}
-
-		while (nanosleep(&t, &r) == -1 && errno == EINTR)
-			memcpy(&t, &r, sizeof(struct timespec));
 	}
 
 	if (!ret)
@@ -475,10 +475,13 @@ static int getautomntent_wait(unsigned int logopt,
 	 "can't contact sssd to to get map entry, retry for %d seconds",
 	 retries);
 
-	while (++retry <= retries) {
+	while (++retry < retries) {
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
 		struct timespec r;
 
+		while (nanosleep(&t, &r) == -1 && errno == EINTR)
+			memcpy(&t, &r, sizeof(struct timespec));
+
 		ret = ctxt->getautomntent_r(key, value, sss_ctxt);
 		if (proto_version(ctxt) == 0) {
 			if (ret != ENOENT)
@@ -487,9 +490,6 @@ static int getautomntent_wait(unsigned int logopt,
 			if (ret != EHOSTDOWN)
 				break;
 		}
-
-		while (nanosleep(&t, &r) == -1 && errno == EINTR)
-			memcpy(&t, &r, sizeof(struct timespec));
 	}
 
 	if (!ret)
@@ -600,10 +600,13 @@ static int getautomntbyname_wait(unsigned int logopt,
 	"can't contact sssd to to lookup key value, retry for %d seconds",
 	retries);
 
-	while (++retry <= retries) {
+	while (++retry < retries) {
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
 		struct timespec r;
 
+		while (nanosleep(&t, &r) == -1 && errno == EINTR)
+			memcpy(&t, &r, sizeof(struct timespec));
+
 		ret = ctxt->getautomntbyname_r(key, value, sss_ctxt);
 		if (proto_version(ctxt) == 0) {
 			if (ret != ENOENT)
@@ -612,9 +615,6 @@ static int getautomntbyname_wait(unsigned int logopt,
 			if (ret != EHOSTDOWN)
 				break;
 		}
-
-		while (nanosleep(&t, &r) == -1 && errno == EINTR)
-			memcpy(&t, &r, sizeof(struct timespec));
 	}
 
 	if (!ret)