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

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