1 From 80bf922a80ae0e3fd090a691e63903da899a85b3 Mon Sep 17 00:00:00 2001
2 From: Michael Friedrich <michael.friedrich@netways.de>
3 Date: Thu, 5 Jun 2014 14:23:31 +0200
4 Subject: [PATCH] Revert "nebmods: fix multiple modules sharing same symbols
5 not receiving callback data"
7 This reverts commit 524838659e715f1edc57f0ef96d8ab02544347ef.
12 base/nebmods.c | 52 +++++++++++-----------------------------------------
13 include/nebmodules.h | 1 -
14 2 files changed, 11 insertions(+), 42 deletions(-)
16 diff --git a/base/nebmods.c b/base/nebmods.c
17 index 4e4371d..635207c 100644
20 @@ -37,7 +37,6 @@ nebmodule *neb_module_list = NULL;
21 nebcallback **neb_callback_list = NULL;
23 extern char *temp_path;
24 -extern int daemon_dumps_core;
27 /* compat stuff for USE_LTDL */
28 @@ -173,8 +172,8 @@ int neb_load_all_modules(void) {
29 int neb_load_module(nebmodule *mod) {
30 int (*initfunc)(int, char *, void *);
31 int *module_version_ptr = NULL;
32 - int dest_fd, result = OK;
33 - char output_file[PATH_MAX];
37 if (mod == NULL || mod->filename == NULL)
39 @@ -201,24 +200,14 @@ int neb_load_module(nebmodule *mod) {
40 So... the trick is to (1) copy the module to a temp file, (2) dlopen() the temp file, and (3) immediately delete the temp file.
44 - * create a temp copy with a different name,
45 - * not sharing the global symbol space with
46 - * other neb modules of the same binary.
47 - * check https://dev.icinga.org/issues/4199
49 - snprintf(output_file, sizeof(output_file)-1, "%s/icinganebmodXXXXXX", temp_path);
50 - dest_fd = mkstemp(output_file);
51 - result = my_fdcopy(mod->filename, output_file, dest_fd);
54 - if (result == ERROR) {
55 - logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Failed to safely copy module '%s' to '%s'. The module will not be loaded\n", mod->filename, output_file);
58 + /* 2010-01-05 MF: Patch taken from OMD into Icinga Core
59 + OMD: Do not make a copy of the module, but directly load it. This prevents problems with a tmpfs which
60 + is mounted as user. OMD users surely have no problems with modules overwritten by 'cp in runtime. Anyway,
61 + the usual way to install files is 'install', which removes and recreates the file (just as tar, rpm and
62 + many other installation-tools do). */
64 /* load the module (use the temp copy we just made) */
65 - mod->module_handle = dlopen(output_file, RTLD_NOW | RTLD_GLOBAL);
66 + mod->module_handle = dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
68 if (mod->module_handle == NULL) {
70 @@ -227,25 +216,12 @@ int neb_load_module(nebmodule *mod) {
74 - /* mark the module as being loaded */
75 - mod->is_currently_loaded = TRUE;
77 - /* delete the temp copy of the module just loaded */
78 - if (unlink(output_file) == -1) {
79 - logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Could not delete temporary file '%s' used for module '%s'. The module will be unloaded: %s", output_file, mod->filename, strerror(errno));
80 - neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION);
83 - /* if we're debugging, create a copy for debuggers finding the correct symbols */
84 - if (daemon_dumps_core == TRUE) {
85 - dest_fd = open(output_file, O_CREAT | O_WRONLY, S_IRWXU | S_IRGRP | S_IROTH);
86 - result = my_fdcopy(mod->filename, output_file, dest_fd);
87 - mod->dl_file = strdup(output_file);
90 /* find module API version */
91 module_version_ptr = (int *)dlsym(mod->module_handle, "__neb_api_version");
93 + /* mark the module as being loaded */
94 + mod->is_currently_loaded = TRUE;
96 /* check the module API version */
97 if (module_version_ptr == NULL || ((*module_version_ptr) != CURRENT_NEB_API_VERSION)) {
99 @@ -346,12 +322,6 @@ int neb_unload_module(nebmodule *mod, int flags, int reason) {
101 log_debug_info(DEBUGL_EVENTBROKER, 0, "Attempting to unload module '%s': flags=%d, reason=%d\n", mod->filename, flags, reason);
103 - /* if we're debugging, remove the copied file */
104 - if (daemon_dumps_core == TRUE && mod->dl_file) {
105 - result = unlink(mod->dl_file);
106 - my_free(mod->dl_file);
109 /* call the de-initialization function if available (and the module was initialized) */
110 if (mod->deinit_func && reason != NEBMODULE_ERROR_BAD_INIT) {
112 diff --git a/include/nebmodules.h b/include/nebmodules.h
113 index a46a2a4..0d62d37 100644
114 --- a/include/nebmodules.h
115 +++ b/include/nebmodules.h
116 @@ -90,7 +90,6 @@ typedef struct nebmodule_struct{
119 struct nebmodule_struct *next;