From dbef4d76de92c3388f4e1819a76d6febf90be290 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 16:12:45 +0000 Subject: r12743: Remove the ugly way we had to make a second stage init and introduce a second_stage_init private function for modules that need a second stage init. Simo. (This used to be commit 5e8b365fa2d93801a5de1d9ea76ce9d5546bd248) --- source4/lib/ldb/common/ldb.c | 13 +++++++++++++ source4/lib/ldb/common/ldb_modules.c | 21 +++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/common') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 604f02a1f7..78e6a74425 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -120,6 +120,19 @@ static void ldb_reset_err_string(struct ldb_context *ldb) if (module == NULL) return -1; \ } while (0) +/* + second stage init all modules loaded +*/ +int ldb_second_stage_init(struct ldb_context *ldb) +{ + struct ldb_module *module; + + FIRST_OP(ldb, second_stage_init); + + return module->ops->second_stage_init(module); +} + + /* start a transaction */ diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 26a397dccc..715112a628 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -201,7 +201,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) int m; for (m=0;well_known_modules[m].name;m++) { if (strcmp(modules[i], well_known_modules[m].name) == 0) { - current = well_known_modules[m].init(ldb, LDB_MODULES_INIT_STAGE_1, options); + current = well_known_modules[m].init(ldb, options); if (current == NULL) { ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]); return -1; @@ -217,14 +217,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) } /* second stage init */ - for (i = 0; modules[i] != NULL; i++) { - int m; - for (m = 0; well_known_modules[m].name; m++) { - if (strcmp(modules[i], well_known_modules[m].name) == 0) { - well_known_modules[m].init(ldb, LDB_MODULES_INIT_STAGE_2, options); - break; - } - } + if (ldb_second_stage_init(ldb) != LDB_SUCCESS) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: Second stage init failed!\n"); + return -1; } talloc_free(modules); @@ -239,7 +234,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) #define FIND_OP(module, op) do { \ module = module->next; \ while (module && module->ops->op == NULL) module = module->next; \ - if (module == NULL) return -1; \ + if (module == NULL) return LDB_ERR_OTHER; \ } while (0) @@ -252,6 +247,12 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request) return module->ops->request(module, request); } +int ldb_next_second_stage_init(struct ldb_module *module) +{ + FIND_OP(module, second_stage_init); + return module->ops->second_stage_init(module); +} + int ldb_next_start_trans(struct ldb_module *module) { FIND_OP(module, start_transaction); -- cgit