1 diff -ru nagios-3.4.4.orig/base/nebmods.c nagios-3.4.4/base/nebmods.c
2 --- nagios-3.4.4.orig/base/nebmods.c 2012-06-21 12:58:41.000000000 +0200
3 +++ nagios-3.4.4/base/nebmods.c 2013-01-27 11:18:35.278430012 +0100
5 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.
9 - * open a temp file for copying the module. We use my_fdcopy() so
10 - * we re-use the destination file descriptor returned by mkstemp(3),
11 - * which we have to close ourselves.
13 - snprintf(output_file, sizeof(output_file) - 1, "%s/nebmodXXXXXX", temp_path);
14 - dest_fd = mkstemp(output_file);
15 - result = my_fdcopy(mod->filename, output_file, dest_fd);
17 - if(result == ERROR) {
18 - logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Failed to safely copy module '%s'. The module will not be loaded\n", mod->filename);
21 + /* OMD: Do not copy broker modules since this does not work with tmpfs mounted by the user. */
23 - /* load the module (use the temp copy we just made) */
24 + /* load the module */
26 - mod->module_handle = lt_dlopen(output_file);
27 + mod->module_handle = lt_dlopen(mod->filename);
29 - mod->module_handle = (void *)dlopen(output_file, RTLD_NOW | RTLD_GLOBAL);
30 + mod->module_handle = (void *)dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
32 if(mod->module_handle == NULL) {
35 /* mark the module as being loaded */
36 mod->is_currently_loaded = TRUE;
38 - /* delete the temp copy of the module we just created and loaded */
39 - /* this will prevent other processes from overwriting the file (using the same inode), which would cause Nagios to crash */
40 - /* the kernel will keep the deleted file in memory until we unload it */
41 - /* NOTE: This *should* be portable to most Unices, but I've only tested it on Linux */
42 - if(unlink(output_file) == -1) {
43 - logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not delete temporary file '%s' used for module '%s'. The module will be unloaded: %s\n", output_file, mod->filename, strerror(errno));
44 - neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION);
49 /* find module API version */
51 module_version_ptr = (int *)lt_dlsym(mod->module_handle, "__neb_api_version");