}
rv = 0;
+
+ set_hooks(); /* set hooks from libs */
+
if (c.homecluster == NULL && (c.nodes > 0)) {
c.homecluster = conf_get_homecluster();
if (c.homecluster == NULL)
/* --scan implied --brief unless -vv */
c.brief = 1;
- set_dlm_hooks(); /* get dlm funcs from libdlm_lt.so.3 */
-
switch(mode) {
case MANAGE:
/* readonly, add/remove, readwrite, runstop */
#define srandom srand
#endif
+#ifdef NO_COROSYNC
+#define CS_OK 1
+typedef uint64_t cmap_handle_t;
+#else
+#include <corosync/cmap.h>
+#endif
+
#ifndef NO_DLM
#include <libdlm.h>
#include <errno.h>
extern int in_initrd(void);
+struct cmap_hooks {
+ void *cmap_handle; /* corosync lib related */
+
+ int (*initialize)(cmap_handle_t *handle);
+ int (*get_string)(cmap_handle_t handle,
+ const char *string,
+ char **name);
+ int (*finalize)(cmap_handle_t handle);
+};
+
+extern void set_cmap_hooks(void);
+extern void set_hooks(void);
+
struct dlm_hooks {
void *dlm_handle; /* dlm lib related */
#include <dirent.h>
#include <signal.h>
#include <dlfcn.h>
-#include <stdint.h>
-#ifdef NO_COROSYNC
- typedef uint64_t cmap_handle_t;
- #define CS_OK 1
-#else
- #include <corosync/cmap.h>
-#endif
/*
if (fd >= 0 && fd != mdfd)
dup2(fd, mdfd);
}
-#ifndef MDASSEMBLE
-int get_cluster_name(char **cluster_name)
-{
- void *lib_handle = NULL;
- int rv = -1;
- cmap_handle_t handle;
- static int (*initialize)(cmap_handle_t *handle);
- static int (*get_string)(cmap_handle_t handle,
- const char *string,
- char **name);
- static int (*finalize)(cmap_handle_t handle);
+static struct cmap_hooks *cmap_hooks = NULL;
+static int is_cmap_hooks_ready = 0;
+#ifndef MDASSEMBLE
+void set_cmap_hooks(void)
+{
+ cmap_hooks = xmalloc(sizeof(struct cmap_hooks));
+ cmap_hooks->cmap_handle = dlopen("libcmap.so.4", RTLD_NOW | RTLD_LOCAL);
+ if (!cmap_hooks->cmap_handle)
+ return;
- lib_handle = dlopen("libcmap.so.4", RTLD_NOW | RTLD_LOCAL);
- if (!lib_handle)
- return rv;
+ cmap_hooks->initialize = dlsym(cmap_hooks->cmap_handle, "cmap_initialize");
+ cmap_hooks->get_string = dlsym(cmap_hooks->cmap_handle, "cmap_get_string");
+ cmap_hooks->finalize = dlsym(cmap_hooks->cmap_handle, "cmap_finalize");
- initialize = dlsym(lib_handle, "cmap_initialize");
- if (!initialize)
- goto out;
+ if (!cmap_hooks->initialize || !cmap_hooks->get_string ||
+ !cmap_hooks->finalize)
+ dlclose(cmap_hooks->cmap_handle);
+ else
+ is_cmap_hooks_ready = 1;
+}
- get_string = dlsym(lib_handle, "cmap_get_string");
- if (!get_string)
- goto out;
+int get_cluster_name(char **cluster_name)
+{
+ int rv = -1;
+ cmap_handle_t handle;
- finalize = dlsym(lib_handle, "cmap_finalize");
- if (!finalize)
- goto out;
+ if (!is_cmap_hooks_ready)
+ return rv;
- rv = initialize(&handle);
+ rv = cmap_hooks->initialize(&handle);
if (rv != CS_OK)
goto out;
- rv = get_string(handle, "totem.cluster_name", cluster_name);
+ rv = cmap_hooks->get_string(handle, "totem.cluster_name", cluster_name);
if (rv != CS_OK) {
free(*cluster_name);
rv = -1;
rv = 0;
name_err:
- finalize(handle);
+ cmap_hooks->finalize(handle);
out:
- dlclose(lib_handle);
return rv;
}
else
is_dlm_hooks_ready = 1;
}
+
+void set_hooks(void)
+{
+ set_dlm_hooks();
+ set_cmap_hooks();
+}
#endif