Blame SOURCES/autofs-5.1.1-implement-reinit-in-yp-lookup-module.patch

306fa1
autofs-5.1.1 - implement reinit in yp lookup module
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Refactor the yp lookup module to add an implementation for the newly
306fa1
added reinit entry point.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 modules/lookup_yp.c |   93 +++++++++++++++++++++++++++++++++++++++------------
306fa1
 1 file changed, 71 insertions(+), 22 deletions(-)
306fa1
306fa1
diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
306fa1
index 1e5a7ed..e31c2cf 100644
306fa1
--- a/modules/lookup_yp.c
306fa1
+++ b/modules/lookup_yp.c
306fa1
@@ -103,27 +103,18 @@ static unsigned int get_map_order(const char *domain, const char *map)
306fa1
 	return (unsigned int) last_changed;
306fa1
 }
306fa1
 
306fa1
-int lookup_init(const char *mapfmt,
306fa1
-		int argc, const char *const *argv, void **context)
306fa1
+static int do_init(const char *mapfmt,
306fa1
+		   int argc, const char *const *argv,
306fa1
+		   struct lookup_context *ctxt, unsigned int reinit)
306fa1
 {
306fa1
-	struct lookup_context *ctxt;
306fa1
 	char buf[MAX_ERR_BUF];
306fa1
 	int err;
306fa1
-
306fa1
-	*context = NULL;
306fa1
-
306fa1
-	ctxt = malloc(sizeof(struct lookup_context));
306fa1
-	if (!ctxt) {
306fa1
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
-		logerr(MODPREFIX "malloc: %s", estr);
306fa1
-		return 1;
306fa1
-	}
306fa1
-	memset(ctxt, 0, sizeof(struct lookup_context));
306fa1
+	int ret = 0;
306fa1
 
306fa1
 	if (argc < 1) {
306fa1
-		free(ctxt);
306fa1
 		logerr(MODPREFIX "no map name");
306fa1
-		return 1;
306fa1
+		ret = 1;
306fa1
+		goto out;
306fa1
 	}
306fa1
 	ctxt->mapname = argv[0];
306fa1
 	ctxt->check_defaults = 1;
306fa1
@@ -138,15 +129,15 @@ int lookup_init(const char *mapfmt,
306fa1
 		if (err) {
306fa1
 			logerr(MODPREFIX
306fa1
 			      "map %s: %s", ctxt->mapname, yperr_string(err));
306fa1
-			free(ctxt);
306fa1
-			return 1;
306fa1
+			ret = 1;
306fa1
+			goto out;
306fa1
 		}
306fa1
 		ctxt->domainname = strdup(domainname);
306fa1
 		if (!ctxt->domainname) {
306fa1
 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
 			logerr(MODPREFIX "strdup: %s", estr);
306fa1
-			free(ctxt);
306fa1
-			return 1;
306fa1
+			ret = 1;
306fa1
+			goto out;
306fa1
 		}
306fa1
 	}
306fa1
 
306fa1
@@ -155,12 +146,45 @@ int lookup_init(const char *mapfmt,
306fa1
 	if (!mapfmt)
306fa1
 		mapfmt = MAPFMT_DEFAULT;
306fa1
 
306fa1
-	ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
306fa1
-	if (!ctxt->parse) {
306fa1
+	if (reinit) {
306fa1
+		ret = reinit_parse(ctxt->parse, mapfmt, MODPREFIX, argc - 1, argv + 1);
306fa1
+		if (ret)
306fa1
+			logmsg(MODPREFIX "failed to reinit parse context");
306fa1
+	} else {
306fa1
+		ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
306fa1
+		if (!ctxt->parse) {
306fa1
+			logmsg(MODPREFIX "failed to open parse context");
306fa1
+			ret = 1;
306fa1
+		}
306fa1
+	}
306fa1
+out:
306fa1
+	if (ret && ctxt->domainname)
306fa1
+		free(ctxt->domainname);
306fa1
+
306fa1
+	return ret;
306fa1
+}
306fa1
+
306fa1
+int lookup_init(const char *mapfmt,
306fa1
+		int argc, const char *const *argv, void **context)
306fa1
+{
306fa1
+	struct lookup_context *ctxt;
306fa1
+	char buf[MAX_ERR_BUF];
306fa1
+
306fa1
+	*context = NULL;
306fa1
+
306fa1
+	ctxt = malloc(sizeof(struct lookup_context));
306fa1
+	if (!ctxt) {
306fa1
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
+		logerr(MODPREFIX "malloc: %s", estr);
306fa1
+		return 1;
306fa1
+	}
306fa1
+	memset(ctxt, 0, sizeof(struct lookup_context));
306fa1
+
306fa1
+	if (do_init(mapfmt, argc, argv, ctxt, 0)) {
306fa1
 		free(ctxt);
306fa1
-		logmsg(MODPREFIX "failed to open parse context");
306fa1
 		return 1;
306fa1
 	}
306fa1
+
306fa1
 	*context = ctxt;
306fa1
 
306fa1
 	return 0;
306fa1
@@ -169,6 +193,31 @@ int lookup_init(const char *mapfmt,
306fa1
 int lookup_reinit(const char *mapfmt,
306fa1
 		  int argc, const char *const *argv, void **context)
306fa1
 {
306fa1
+	struct lookup_context *ctxt = (struct lookup_context *) *context;
306fa1
+	struct lookup_context *new;
306fa1
+	char buf[MAX_ERR_BUF];
306fa1
+	int ret;
306fa1
+
306fa1
+	new = malloc(sizeof(struct lookup_context));
306fa1
+	if (!new) {
306fa1
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
+		logerr(MODPREFIX "malloc: %s", estr);
306fa1
+		return 1;
306fa1
+	}
306fa1
+	memset(new, 0, sizeof(struct lookup_context));
306fa1
+
306fa1
+	new->parse = ctxt->parse;
306fa1
+	ret = do_init(mapfmt, argc, argv, new, 1);
306fa1
+	if (ret) {
306fa1
+		free(new);
306fa1
+		return 1;
306fa1
+	}
306fa1
+
306fa1
+	*context = new;
306fa1
+
306fa1
+	free(ctxt->domainname);
306fa1
+	free(ctxt);
306fa1
+
306fa1
 	return 0;
306fa1
 }
306fa1