[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. upstream/1.0.6-34-gd3fb2ec
Sven Nierlein
sven at nierlein.de
Wed Aug 24 09:21:52 UTC 2011
The following commit has been merged in the upstream branch:
commit f4ba66b3b1ae855ed24cb6bb8cc447daa95c4120
Author: Sven Nierlein <sven at nierlein.de>
Date: Mon Jul 18 23:36:05 2011 +0200
fixed memory leak when reloading neb module
diff --git a/.gitignore b/.gitignore
index 49044d9..df41e57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ mod_gearman_worker
02_full
03_exec
04_log
+05_neb
images
send_gearman
send_multi
diff --git a/Changes b/Changes
index 6530a41..1f4f9da 100644
--- a/Changes
+++ b/Changes
@@ -3,7 +3,8 @@ This file documents the revision history for mod_gearman.
1.0.8 Fri Jul 15 20:24:27 CEST 2011
- use identifier for error messages if set
- fixed ld options (fixes debian bug #632431) thanks Ilya Barygin
- - removed memory leak in gearman_top
+ - fixed memory leak in gearman_top
+ - fixed memory leak when reloading neb module
1.0.7 Sun Jul 3 15:18:16 CEST 2011
- show plugin output for exit codes > 3
diff --git a/Makefile.am b/Makefile.am
index ffd94d5..339c5cc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,11 +56,14 @@ gearman_top_SOURCES = $(common_SOURCES) \
gearman_top_LDADD = -lncurses
# tests
-check_PROGRAMS = 01_utils 02_full 03_exec 04_log
+check_PROGRAMS = 01_utils 02_full 03_exec 04_log 05_neb
01_utils_SOURCES = $(common_SOURCES) t/tap.h t/tap.c t/01-utils.c
02_full_SOURCES = $(common_SOURCES) t/tap.h t/tap.c t/02-full.c
03_exec_SOURCES = $(common_SOURCES) t/tap.h t/tap.c t/03-exec_checks.c
04_log_SOURCES = $(common_SOURCES) t/tap.h t/tap.c t/04-log.c
+05_neb_SOURCES = $(common_SOURCES) t/tap.h t/tap.c t/05-neb.c
+05_neb_LDADD = -ldl
+05_neb_LDFLAGS = --export-dynamic -rdynamic
TESTS = $(check_PROGRAMS)
diff --git a/neb_module/mod_gearman.c b/neb_module/mod_gearman.c
index 2bccd9b..bf363c6 100644
--- a/neb_module/mod_gearman.c
+++ b/neb_module/mod_gearman.c
@@ -47,8 +47,7 @@ static pthread_mutex_t mod_gm_result_list_mutex = PTHREAD_MUTEX_INITIALIZER;
void *gearman_module_handle=NULL;
gearman_client_st client;
-int send_now = FALSE;
-int result_threads_running = 0;
+int send_now, result_threads_running;
pthread_t result_thr[GM_LISTSIZE];
char target_queue[GM_BUFFERSIZE];
char temp_buffer[GM_BUFFERSIZE];
@@ -72,6 +71,8 @@ static void move_results_to_core(void);
int nebmodule_init( int flags, char *args, nebmodule *handle ) {
int i;
int broker_option_errors = 0;
+ send_now = FALSE;
+ result_threads_running = 0;
/* save our handle */
gearman_module_handle=handle;
@@ -88,12 +89,14 @@ int nebmodule_init( int flags, char *args, nebmodule *handle ) {
set_default_options(mod_gm_opt);
/* parse arguments */
- read_arguments( args );
gm_log( GM_LOG_INFO, "Version %s\n", GM_VERSION );
gm_log( GM_LOG_TRACE, "args: %s\n", args );
gm_log( GM_LOG_TRACE, "nebmodule_init(%i, %i)\n", flags );
gm_log( GM_LOG_DEBUG, "running on libgearman %s\n", gearman_version() );
+ if( read_arguments( args ) == GM_ERROR )
+ return NEB_ERROR;
+
/* check for minimum eventbroker options */
if(!(event_broker_options & BROKER_PROGRAM_STATE)) {
gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_PROGRAM_STATE (%i) event_broker_options enabled to work\n", BROKER_PROGRAM_STATE );
@@ -235,13 +238,14 @@ int nebmodule_deinit( int flags, int reason ) {
gm_log( GM_LOG_DEBUG, "deregistered callbacks\n" );
/* stop result threads */
- for(x = 0; x < mod_gm_opt->result_workers; x++) {
+ for(x = 0; x < result_threads_running; x++) {
pthread_cancel(result_thr[x]);
pthread_join(result_thr[x], NULL);
}
- /* cleanup client */
+ /* cleanup */
free_client(&client);
+ mod_gm_free_opt(mod_gm_opt);
return NEB_OK;
}
@@ -835,7 +839,7 @@ static void set_target_queue( host *hst, service *svc ) {
/* start our threads */
static void start_threads(void) {
- if ( !result_threads_running ) {
+ if ( result_threads_running < mod_gm_opt->result_workers ) {
/* create result worker */
int x;
for(x = 0; x < mod_gm_opt->result_workers; x++) {
diff --git a/t/05-neb.c b/t/05-neb.c
new file mode 100644
index 0000000..ee350f2
--- /dev/null
+++ b/t/05-neb.c
@@ -0,0 +1,95 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <t/tap.h>
+
+#include "nagios/nagios.h"
+#include "nagios/nebmodules.h"
+#include "nagios/nebstructs.h"
+#include "nagios/nebcallbacks.h"
+#include "nagios/broker.h"
+
+int service_check_timeout;
+int host_check_timeout;
+int currently_running_service_checks;
+int currently_running_host_checks;
+int event_broker_options;
+check_result *check_result_list;
+check_result check_result_info;
+int process_performance_data;
+
+int main(void) {
+ int (*initfunc)(int,char *,void *);
+ int (*deinitfunc)(int,int);
+ int (*callfunc)(int,void *);
+ int *module_version_ptr=NULL;
+ void* neb_handle;
+ lt_ptr init_func;
+ lt_ptr deinit_func;
+ lt_ptr call_func;
+ char * nebargs = "encryption=no server=localhost";
+
+ plan(7);
+
+ /* set some external variables */
+ service_check_timeout = 30;
+ host_check_timeout = 30;
+ currently_running_service_checks = 0;
+ currently_running_host_checks = 0;
+ event_broker_options = 1048575; /* BROKER_EVERYTHING */
+ check_result_list = NULL;
+ check_result_info.check_options = 1; /* CHECK_OPTION_FORCE_EXECUTION */
+ process_performance_data = 1;
+
+ /* load neb module */
+ neb_handle=(void *)dlopen("./mod_gearman.o",RTLD_LAZY|RTLD_GLOBAL);
+ ok(neb_handle != NULL, "neb module loaded") || BAIL_OUT("cannot load module: %s\n", dlerror());
+ module_version_ptr=(int *)dlsym(neb_handle,"__neb_api_version");
+ ok((*module_version_ptr) == CURRENT_NEB_API_VERSION, "got module api version %i", CURRENT_NEB_API_VERSION);
+
+ /* init neb module */
+ init_func=(void *)dlsym(neb_handle,"nebmodule_init");
+ ok(init_func != NULL, "located nebmodule_init()") || BAIL_OUT("cannot locate nebmodule_init() %s\n", dlerror());
+ initfunc = init_func;
+ int result=(*initfunc)(NEBMODULE_NORMAL_LOAD, nebargs, neb_handle);
+ ok(result == 0, "run nebmodule_init() -> %d", result) || BAIL_OUT("cannot run nebmodule_init(), got %d\n", result);
+
+ /* callback */
+ //call_func=(void *)dlsym(neb_handle,"handle_process_events");
+/*
+ call_func=(void *)dlsym(neb_handle,"handle_eventhandler");
+ ok(call_func != NULL, "located handle_process_events()") || BAIL_OUT("cannot locate handle_process_events() %s\n", dlerror());
+ callfunc=call_func;
+ nebstruct_process_data ps;
+ ps.type = NEBTYPE_PROCESS_EVENTLOOPSTART;
+ result=(*callfunc)(NEBCALLBACK_PROCESS_DATA,(void *)&ps);
+ ok(result == 0, "run handle_process_events() -> %d", result) || BAIL_OUT("cannot run handle_process_events(), got %d\n", result);
+*/
+
+ /* deinit neb module */
+ deinit_func=(void *)dlsym(neb_handle,"nebmodule_deinit");
+ ok(deinit_func != NULL, "located nebmodule_deinit()") || BAIL_OUT("cannot locate nebmodule_deinit() %s\n", dlerror());
+ deinitfunc=deinit_func;
+ result=(*deinitfunc)(NEBMODULE_FORCE_UNLOAD,NEBMODULE_NEB_SHUTDOWN);
+ ok(result == 0, "run nebmodule_deinit() -> %d", result) || BAIL_OUT("cannot run nebmodule_deinit(), got %d\n", result);
+
+
+ result=dlclose(neb_handle);
+ ok(result == 0, "dlclose() -> %d", result);
+
+ return exit_status();
+}
+
+/* core log wrapper */
+void write_core_log(char *data);
+void write_core_log(char *data) {
+ printf("logger: %s", data);
+ return;
+}
+
+/* fake some core functions */
+int neb_set_module_info(void *handle, int type, char *data) { return 0; }
+int neb_register_callback(int callback_type, void *mod_handle, int priority, int (*callback_func)(int,void *)) { return 0; }
+int neb_deregister_callback(int callback_type, int (*callback_func)(int,void *)) { return 0; }
\ No newline at end of file
diff --git a/t/test_all.pl b/t/test_all.pl
index 6c8db1b..e954750 100755
--- a/t/test_all.pl
+++ b/t/test_all.pl
@@ -8,18 +8,18 @@ use Test::More;
if($? != 0) {
plan skip_all => 'valgrind required';
}
-plan(tests => 13);
+plan(tests => 16);
-`make`;
+`make clean && make`;
is($?, 0, "build rc is $?");
my $vallog = '/tmp/valgrind.log';
my $testlog = '/tmp/mod_gearman_test.log';
-for my $test (qw(01_utils 02_full 03_exec 04_log)) {
- `make $test`;
+for my $test (qw(01_utils 02_full 03_exec 04_log 05_neb)) {
+ `make $test 2>/dev/null`;
is($?, 0, "$test build rc is $?");
- `valgrind --tool=memcheck --leak-check=yes --leak-check=full --show-reachable=yes --track-origins=yes --log-file=/tmp/valgrind.log ./$test >$testlog 2>&1`;
+ `valgrind --tool=memcheck --leak-check=yes --leak-check=full --show-reachable=yes --track-origins=yes --log-file=$vallog ./$test >$testlog 2>&1`;
is($?, 0, "$test valgrind exit code is $?") or diag(`cat $testlog`);
is(qx(grep "ERROR SUMMARY: " $vallog | grep -v "ERROR SUMMARY: 0 errors"), "", "valgrind Error Summary")
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list