2 Unix SMB/CIFS implementation.
4 Copyright (C) Jelmer Vernooij 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * @brief Module initialization function handling
27 #include "system/dir.h"
29 static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name)
35 path = talloc_asprintf(mem_ctx, "%s/%s", dir, name);
37 handle = dlopen(path, RTLD_NOW);
39 DEBUG(0, ("Unable to open %s: %s\n", path, dlerror()));
44 init_fn = dlsym(handle, "init_module");
46 if (init_fn == NULL) {
47 DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror()));
48 DEBUG(1, ("Loading module '%s' failed\n", path));
59 init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
64 init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2);
74 while((entry = readdir(dir))) {
75 if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
78 ret[success] = load_module(mem_ctx, path, entry->d_name);
80 ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
91 BOOL run_init_functions(NTSTATUS (**fns) (void))
99 for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); }