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

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