Blame SOURCES/autofs-5.1.1-implement-reinit-in-parse-modules.patch

304803
autofs-5.1.1 - implement reinit in parse modules
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Refactor the parse modules to add an implementation for the newly added
304803
reinit entry point.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 modules/parse_hesiod.c |    1 +
304803
 modules/parse_sun.c    |   70 ++++++++++++++++++++++++++++++++++++------------
304803
 2 files changed, 54 insertions(+), 17 deletions(-)
304803
304803
diff --git a/modules/parse_hesiod.c b/modules/parse_hesiod.c
304803
index 0b2b57f..a02da82 100644
304803
--- a/modules/parse_hesiod.c
304803
+++ b/modules/parse_hesiod.c
304803
@@ -258,6 +258,7 @@ static int parse_generic(struct autofs_point *ap,
304803
 
304803
 int parse_init(int argc, const char *const *argv, void **context)
304803
 {
304803
+	*context = NULL;
304803
 	return 0;
304803
 }
304803
 
304803
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
304803
index 35d6da5..a164fba 100644
304803
--- a/modules/parse_sun.c
304803
+++ b/modules/parse_sun.c
304803
@@ -232,27 +232,15 @@ int expandsunent(const char *src, char *dst, const char *key,
304803
 	return len;
304803
 }
304803
 
304803
-int parse_init(int argc, const char *const *argv, void **context)
304803
+static int do_init(int argc, const char *const *argv, struct parse_context *ctxt)
304803
 {
304803
-	struct parse_context *ctxt;
304803
-	char buf[MAX_ERR_BUF];
304803
 	char *noptstr, *def, *val, *macros, *gbl_options;
304803
-	const char *xopt;
304803
+	char buf[MAX_ERR_BUF];
304803
 	int optlen, len, offset;
304803
+	const char *xopt;
304803
 	int i, bval;
304803
 	unsigned int append_options;
304803
 
304803
-	/* Set up context and escape chain */
304803
-
304803
-	if (!(ctxt = (struct parse_context *) malloc(sizeof(struct parse_context)))) {
304803
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
-		logerr(MODPREFIX "malloc: %s", estr);
304803
-		*context = NULL;
304803
-		return 1;
304803
-	}
304803
-	*context = (void *) ctxt;
304803
-
304803
-	*ctxt = default_context;
304803
 	optlen = 0;
304803
 
304803
 	/* Look for options and capture, and create new defines if we need to */
304803
@@ -359,7 +347,6 @@ int parse_init(int argc, const char *const *argv, void **context)
304803
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
 				kill_context(ctxt);
304803
 				logerr(MODPREFIX "%s", estr);
304803
-				*context = NULL;
304803
 				return 1;
304803
 			}
304803
 			ctxt->optstr = noptstr;
304803
@@ -391,9 +378,36 @@ int parse_init(int argc, const char *const *argv, void **context)
304803
 		}
304803
 	}
304803
 options_done:
304803
+
304803
 	debug(LOGOPT_NONE,
304803
 	      MODPREFIX "init gathered global options: %s", ctxt->optstr);
304803
 
304803
+	return 0;
304803
+}
304803
+
304803
+int parse_init(int argc, const char *const *argv, void **context)
304803
+{
304803
+	struct parse_context *ctxt;
304803
+	char buf[MAX_ERR_BUF];
304803
+
304803
+	*context = NULL;
304803
+
304803
+	/* Set up context and escape chain */
304803
+
304803
+	ctxt = (struct parse_context *) malloc(sizeof(struct parse_context));
304803
+	if (!ctxt) {
304803
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
+		logerr(MODPREFIX "malloc: %s", estr);
304803
+		return 1;
304803
+	}
304803
+
304803
+	*ctxt = default_context;
304803
+
304803
+	if (do_init(argc, argv, ctxt)) {
304803
+		free(ctxt);
304803
+		return 1;
304803
+	}
304803
+
304803
 	/* We only need this once.  NFS mounts are so common that we cache
304803
 	   this module. */
304803
 	instance_mutex_lock();
304803
@@ -404,17 +418,39 @@ options_done:
304803
 			init_ctr++;
304803
 		} else {
304803
 			kill_context(ctxt);
304803
-			*context = NULL;
304803
 			instance_mutex_unlock();
304803
 			return 1;
304803
 		}
304803
 	}
304803
 	instance_mutex_unlock();
304803
+
304803
+	*context = (void *) ctxt;
304803
+
304803
 	return 0;
304803
 }
304803
 
304803
 int parse_reinit(int argc, const char *const *argv, void **context)
304803
 {
304803
+	struct parse_context *ctxt = (struct parse_context *) *context;
304803
+	struct parse_context *new;
304803
+	char buf[MAX_ERR_BUF];
304803
+
304803
+	new = (struct parse_context *) malloc(sizeof(struct parse_context));
304803
+	if (!new) {
304803
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
+		logerr(MODPREFIX "malloc: %s", estr);
304803
+		return 1;
304803
+	}
304803
+
304803
+	*new = default_context;
304803
+
304803
+	if (do_init(argc, argv, new))
304803
+		return 1;
304803
+
304803
+	kill_context(ctxt);
304803
+
304803
+	*context = (void *) new;
304803
+
304803
 	return 0;
304803
 }
304803