|
|
306fa1 |
autofs-5.1.1 - implement reinit in program lookup module
|
|
|
306fa1 |
|
|
|
306fa1 |
From: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
|
|
|
306fa1 |
Refactor the program 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_program.c | 98 ++++++++++++++++++++++++++++++++++++----------
|
|
|
306fa1 |
1 file changed, 76 insertions(+), 22 deletions(-)
|
|
|
306fa1 |
|
|
|
306fa1 |
diff --git a/modules/lookup_program.c b/modules/lookup_program.c
|
|
|
306fa1 |
index fa4f54d..3e9c448 100644
|
|
|
306fa1 |
--- a/modules/lookup_program.c
|
|
|
306fa1 |
+++ b/modules/lookup_program.c
|
|
|
306fa1 |
@@ -49,53 +49,82 @@ struct parse_context {
|
|
|
306fa1 |
|
|
|
306fa1 |
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
|
|
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 |
-
|
|
|
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 |
+ int ret = 0;
|
|
|
306fa1 |
|
|
|
306fa1 |
if (argc < 1) {
|
|
|
306fa1 |
logmsg(MODPREFIX "No map name");
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
- return 1;
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ goto out;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ctxt->mapname = argv[0];
|
|
|
306fa1 |
|
|
|
306fa1 |
if (ctxt->mapname[0] != '/') {
|
|
|
306fa1 |
logmsg(MODPREFIX "program map %s is not an absolute pathname",
|
|
|
306fa1 |
ctxt->mapname);
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
- return 1;
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ goto out;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
if (access(ctxt->mapname, X_OK)) {
|
|
|
306fa1 |
logmsg(MODPREFIX "program map %s missing or not executable",
|
|
|
306fa1 |
ctxt->mapname);
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
- return 1;
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ goto out;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
if (!mapfmt)
|
|
|
306fa1 |
mapfmt = MAPFMT_DEFAULT;
|
|
|
306fa1 |
|
|
|
306fa1 |
ctxt->mapfmt = strdup(mapfmt);
|
|
|
306fa1 |
+ if (!ctxt->mapfmt) {
|
|
|
306fa1 |
+ logmsg(MODPREFIX "failed to allocate storage for map format");
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ goto out;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
|
|
|
306fa1 |
- ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
- if (!ctxt->parse) {
|
|
|
306fa1 |
- logmsg(MODPREFIX "failed to open parse context");
|
|
|
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->mapfmt)
|
|
|
306fa1 |
+ free(ctxt->mapfmt);
|
|
|
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 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
*context = ctxt;
|
|
|
306fa1 |
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
@@ -104,6 +133,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->mapfmt);
|
|
|
306fa1 |
+ free(ctxt);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|