|
|
306fa1 |
autofs-5.1.1 - implement reinit in file lookup module
|
|
|
306fa1 |
|
|
|
306fa1 |
From: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
|
|
|
306fa1 |
Refactor the file 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_file.c | 85 +++++++++++++++++++++++++++++++++++++------------
|
|
|
306fa1 |
1 file changed, 65 insertions(+), 20 deletions(-)
|
|
|
306fa1 |
|
|
|
306fa1 |
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
|
|
|
306fa1 |
index c32a4cd..aed3cba 100644
|
|
|
306fa1 |
--- a/modules/lookup_file.c
|
|
|
306fa1 |
+++ b/modules/lookup_file.c
|
|
|
306fa1 |
@@ -50,23 +50,13 @@ struct lookup_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 |
- free(ctxt);
|
|
|
306fa1 |
logerr(MODPREFIX "No map name");
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
@@ -74,14 +64,12 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
ctxt->mapname = argv[0];
|
|
|
306fa1 |
|
|
|
306fa1 |
if (ctxt->mapname[0] != '/') {
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
logmsg(MODPREFIX
|
|
|
306fa1 |
"file map %s is not an absolute pathname", argv[0]);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
if (access(ctxt->mapname, R_OK)) {
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
warn(LOGOPT_NONE, MODPREFIX
|
|
|
306fa1 |
"file map %s missing or not readable", argv[0]);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
@@ -95,19 +83,51 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
|
|
|
306fa1 |
ctxt->opts_argv = copy_argv(argc, (const char **) argv);
|
|
|
306fa1 |
if (ctxt->opts_argv == NULL) {
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
warn(LOGOPT_NONE, MODPREFIX "failed to duplicate options");
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ctxt->opts_argc = argc;
|
|
|
306fa1 |
|
|
|
306fa1 |
- ctxt->parse = open_parse(mapfmt, MODPREFIX, argc, argv);
|
|
|
306fa1 |
- if (!ctxt->parse) {
|
|
|
306fa1 |
+ if (reinit) {
|
|
|
306fa1 |
+ ret = reinit_parse(ctxt->parse, mapfmt, MODPREFIX, argc, argv);
|
|
|
306fa1 |
+ if (ret)
|
|
|
306fa1 |
+ logmsg(MODPREFIX "failed to reinit parse context");
|
|
|
306fa1 |
+ } else {
|
|
|
306fa1 |
+ ctxt->parse = open_parse(mapfmt, MODPREFIX, argc, argv);
|
|
|
306fa1 |
+ if (!ctxt->parse) {
|
|
|
306fa1 |
+ logmsg(MODPREFIX "failed to open parse context");
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ if (ret)
|
|
|
306fa1 |
free_argv(ctxt->opts_argc, ctxt->opts_argv);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ return ret;
|
|
|
306fa1 |
+}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
+ int argc, const char *const *argv,
|
|
|
306fa1 |
+ 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 |
@@ -116,6 +136,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_argv(ctxt->opts_argc, ctxt->opts_argv);
|
|
|
306fa1 |
+ free(ctxt);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|