Blame SOURCES/autofs-5.1.6-refactor-sss-setautomntent.patch

1b50e3
autofs-5.1.6 - refactor sss setautomntent()
1b50e3
1b50e3
From: Ian Kent <raven@themaw.net>
1b50e3
1b50e3
Refactor the sss setautomntent() to consolidate the error handling in
1b50e3
one location.
1b50e3
1b50e3
Also move the number of retries calculation into the wait function
1b50e3
as it's a much more sensible place for it.
1b50e3
1b50e3
Signed-off-by: Ian Kent <raven@themaw.net>
1b50e3
---
1b50e3
 CHANGELOG            |    1 
1b50e3
 modules/lookup_sss.c |  106 +++++++++++++++++++++++---------------------------
1b50e3
 2 files changed, 49 insertions(+), 58 deletions(-)
1b50e3
1b50e3
diff --git a/CHANGELOG b/CHANGELOG
1b50e3
index b3ffbb6..141658d 100644
1b50e3
--- a/CHANGELOG
1b50e3
+++ b/CHANGELOG
1b50e3
@@ -98,6 +98,7 @@ xx/xx/2018 autofs-5.1.5
1b50e3
 - use mapname in sss context for setautomntent().
1b50e3
 - add support for new sss autofs proto version call.
1b50e3
 - fix retries check in setautomntent_wait().
1b50e3
+- refactor sss setautomntent().
1b50e3
 
1b50e3
 19/12/2017 autofs-5.1.4
1b50e3
 - fix spec file url.
1b50e3
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
1b50e3
index d65e71c..011b232 100644
1b50e3
--- a/modules/lookup_sss.c
1b50e3
+++ b/modules/lookup_sss.c
1b50e3
@@ -232,20 +232,6 @@ int lookup_reinit(const char *mapfmt,
1b50e3
 	return 0;
1b50e3
 }
1b50e3
 
1b50e3
-static int setautomntent(unsigned int logopt,
1b50e3
-			 struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
-{
1b50e3
-	int ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
1b50e3
-	if (ret) {
1b50e3
-		char buf[MAX_ERR_BUF];
1b50e3
-		char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-		error(logopt, MODPREFIX "setautomntent: %s", estr);
1b50e3
-		if (*sss_ctxt)
1b50e3
-			free(*sss_ctxt);
1b50e3
-	}
1b50e3
-	return ret;
1b50e3
-}
1b50e3
-
1b50e3
 static unsigned int proto_version(struct lookup_context *ctxt)
1b50e3
 {
1b50e3
 	unsigned int proto_version = 0;
1b50e3
@@ -264,14 +250,18 @@ static unsigned int proto_version(struct lookup_context *ctxt)
1b50e3
 }
1b50e3
 
1b50e3
 static int setautomntent_wait(unsigned int logopt,
1b50e3
-			      struct lookup_context *ctxt,
1b50e3
-			      void **sss_ctxt, unsigned int retries)
1b50e3
+			      struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
 {
1b50e3
+	unsigned int retries;
1b50e3
 	unsigned int retry = 0;
1b50e3
 	int ret = 0;
1b50e3
 
1b50e3
 	*sss_ctxt = NULL;
1b50e3
 
1b50e3
+	retries = defaults_get_sss_master_map_wait();
1b50e3
+	if (retries <= 0)
1b50e3
+		return ENOENT;
1b50e3
+
1b50e3
 	while (++retry <= retries) {
1b50e3
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
1b50e3
 		struct timespec r;
1b50e3
@@ -291,9 +281,6 @@ static int setautomntent_wait(unsigned int logopt,
1b50e3
 
1b50e3
 
1b50e3
 	if (ret) {
1b50e3
-		char buf[MAX_ERR_BUF];
1b50e3
-		char *estr;
1b50e3
-
1b50e3
 		if (*sss_ctxt) {
1b50e3
 			free(*sss_ctxt);
1b50e3
 			*sss_ctxt = NULL;
1b50e3
@@ -301,14 +288,47 @@ static int setautomntent_wait(unsigned int logopt,
1b50e3
 
1b50e3
 		if (retry > retries)
1b50e3
 			ret = ETIMEDOUT;
1b50e3
-
1b50e3
-		estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-		error(logopt, MODPREFIX "setautomntent: %s", estr);
1b50e3
 	}
1b50e3
 
1b50e3
 	return ret;
1b50e3
 }
1b50e3
 
1b50e3
+static int setautomntent(unsigned int logopt,
1b50e3
+			 struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
+{
1b50e3
+	char buf[MAX_ERR_BUF];
1b50e3
+	char *estr;
1b50e3
+	int ret;
1b50e3
+
1b50e3
+	ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
1b50e3
+	if (ret) {
1b50e3
+		if (ret == ECONNREFUSED)
1b50e3
+			return NSS_STATUS_UNKNOWN;
1b50e3
+
1b50e3
+		if (ret != ENOENT)
1b50e3
+			goto error;
1b50e3
+
1b50e3
+		ret = setautomntent_wait(logopt, ctxt, sss_ctxt);
1b50e3
+		if (ret) {
1b50e3
+			if (ret == ECONNREFUSED)
1b50e3
+				return NSS_STATUS_UNKNOWN;
1b50e3
+			if (ret == ENOENT)
1b50e3
+				return NSS_STATUS_NOTFOUND;
1b50e3
+			goto error;
1b50e3
+		}
1b50e3
+	}
1b50e3
+	return ret;
1b50e3
+
1b50e3
+error:
1b50e3
+	estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
+	error(logopt, MODPREFIX "setautomntent: %s", estr);
1b50e3
+	if (*sss_ctxt) {
1b50e3
+		free(*sss_ctxt);
1b50e3
+		*sss_ctxt = NULL;
1b50e3
+	}
1b50e3
+	return NSS_STATUS_UNAVAIL;
1b50e3
+}
1b50e3
+
1b50e3
 static int endautomntent(unsigned int logopt,
1b50e3
 			 struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
 {
1b50e3
@@ -336,28 +356,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
1b50e3
 	int count, ret;
1b50e3
 
1b50e3
 	ret = setautomntent(logopt, ctxt, &sss_ctxt);
1b50e3
-	if (ret) {
1b50e3
-		unsigned int retries;
1b50e3
-
1b50e3
-		if (ret == ECONNREFUSED)
1b50e3
-			return NSS_STATUS_UNKNOWN;
1b50e3
-
1b50e3
-		if (ret != ENOENT)
1b50e3
-			return NSS_STATUS_UNAVAIL;
1b50e3
-
1b50e3
-		retries = defaults_get_sss_master_map_wait();
1b50e3
-		if (retries <= 0)
1b50e3
-			return NSS_STATUS_NOTFOUND;
1b50e3
-
1b50e3
-		ret = setautomntent_wait(logopt, ctxt, &sss_ctxt, retries);
1b50e3
-		if (ret) {
1b50e3
-			if (ret == ECONNREFUSED)
1b50e3
-				return NSS_STATUS_UNKNOWN;
1b50e3
-			if (ret == ENOENT)
1b50e3
-				return NSS_STATUS_NOTFOUND;
1b50e3
-			return NSS_STATUS_UNAVAIL;
1b50e3
-		}
1b50e3
-	}
1b50e3
+	if (ret)
1b50e3
+		return ret;
1b50e3
 
1b50e3
 	count = 0;
1b50e3
 	while (1) {
1b50e3
@@ -459,13 +459,8 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
1b50e3
 	}
1b50e3
 
1b50e3
 	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
-	if (ret) {
1b50e3
-		if (ret == ECONNREFUSED)
1b50e3
-			return NSS_STATUS_UNKNOWN;
1b50e3
-		if (ret == ENOENT)
1b50e3
-			return NSS_STATUS_NOTFOUND;
1b50e3
-		return NSS_STATUS_UNAVAIL;
1b50e3
-	}
1b50e3
+	if (ret)
1b50e3
+		return ret;
1b50e3
 
1b50e3
 	count = 0;
1b50e3
 	while (1) {
1b50e3
@@ -571,13 +566,8 @@ static int lookup_one(struct autofs_point *ap,
1b50e3
 	mc = source->mc;
1b50e3
 
1b50e3
 	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
-	if (ret) {
1b50e3
-		if (ret == ECONNREFUSED)
1b50e3
-			return NSS_STATUS_UNKNOWN;
1b50e3
-		if (ret == ENOENT)
1b50e3
-			return NSS_STATUS_NOTFOUND;
1b50e3
-		return NSS_STATUS_UNAVAIL;
1b50e3
-	}
1b50e3
+	if (ret)
1b50e3
+		return ret;
1b50e3
 
1b50e3
 	ret = ctxt->getautomntbyname_r(qKey, &value, sss_ctxt);
1b50e3
 	if (ret && ret != ENOENT) {