[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:49 UTC 2011
The following commit has been merged in the upstream branch:
commit 6173202a8a30eb2b65933af703832ce353a86a6f
Author: Sven Nierlein <sven at nierlein.de>
Date: Sun Jul 17 23:15:18 2011 +0200
code cleanup
diff --git a/common/utils.c b/common/utils.c
index 15a2452..1c74cc6 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1135,6 +1135,7 @@ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * identifier)
int return_code;
int pclose_result;
char *plugin_output;
+ char *bufdup;
char buffer[GM_BUFFERSIZE];
sigset_t mask;
struct timeval start_time,end_time;
@@ -1194,10 +1195,12 @@ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * identifier)
}
return_code = real_exit_code(pclose_result);
+ free(plugin_output);
exit(return_code);
}
else {
snprintf( buffer, sizeof( buffer )-1, "%s", plugin_output );
+ free(plugin_output);
}
}
@@ -1230,15 +1233,19 @@ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * identifier)
/* signaled */
else if(return_code >= 128 && return_code < 144) {
char * signame = nr2signal((int)(return_code-128));
- snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. Plugin exited by signal %s. (worker: %s)\n%s", (int)(return_code), signame, identifier, buffer);
+ bufdup = strdup(buffer);
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. Plugin exited by signal %s. (worker: %s)\n%s\n", (int)(return_code), signame, identifier, bufdup);
return_code = STATE_CRITICAL;
+ free(bufdup);
free(signame);
}
/* other error codes > 3 */
else if(return_code > 3) {
gm_log( GM_LOG_INFO, "check exited with exit code > 3. Exit: %d\n", (int)(return_code));
gm_log( GM_LOG_INFO, "stdout: %s\n", buffer);
- snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. (worker: %s)\n%s\n", (int)(return_code), identifier, buffer);
+ bufdup = strdup(buffer);
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. (worker: %s)\n%s\n", (int)(return_code), identifier, bufdup);
+ free(bufdup);
return_code = STATE_CRITICAL;
}
@@ -1261,9 +1268,10 @@ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * identifier)
exec_job->return_code = 2;
exec_job->early_timeout = 1;
if ( !strcmp( exec_job->type, "service" ) )
- snprintf( buffer, sizeof( buffer ) -1, "(Service Check Timed Out On Worker: %s)", identifier);
+ snprintf( buffer, sizeof( buffer ) -1, "(Service Check Timed Out On Worker: %s)\n", identifier);
if ( !strcmp( exec_job->type, "host" ) )
- snprintf( buffer, sizeof( buffer ) -1, "(Host Check Timed Out On Worker: %s)", identifier);
+ snprintf( buffer, sizeof( buffer ) -1, "(Host Check Timed Out On Worker: %s)\n", identifier);
+ free(exec_job->output);
exec_job->output = strdup( buffer );
}
diff --git a/t/02-full.c b/t/02-full.c
index 354f8e1..cc96c32 100644
--- a/t/02-full.c
+++ b/t/02-full.c
@@ -34,11 +34,11 @@ void *start_gearmand(void*data) {
snprintf(port, 30, "--port=%d", GEARMAND_TEST_PORT);
/* for newer gearman versions */
if(atof(gearman_version()) > 0.14) {
- diag("having gearmand > 0.14");
+ //diag("having gearmand > 0.14");
execlp("gearmand", "gearmand", "--threads=10", "--job-retries=0", port, "--verbose=999", "--log-file=/tmp/gearmand.log" , (char *)NULL);
} else {
/* for gearman 0.14 */
- diag("having gearmand <= 0.14");
+ //diag("having gearmand <= 0.14");
execlp("gearmand", "gearmand", "-t 10", "-j 0", port, (char *)NULL);
}
perror("gearmand");
@@ -301,6 +301,7 @@ int main(void) {
rrc = real_exit_code(run_check(cmd, &result));
cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc);
like(result, "^\\s*$", "output from ./send_gearman");
+ free(result);
/*****************************************
* send_gearman
diff --git a/t/03-exec_checks.c b/t/03-exec_checks.c
index 715f258..db8b9ea 100644
--- a/t/03-exec_checks.c
+++ b/t/03-exec_checks.c
@@ -50,6 +50,7 @@ int main(void) {
rrc = real_exit_code(run_check(cmd, &result));
diag(result);
cmp_ok(rrc, "==", 1, "cmd '%s' returned rc %d", cmd, rrc);
+ free(result);
/*****************************************
* send_gearman
@@ -58,6 +59,7 @@ int main(void) {
rrc = real_exit_code(run_check(cmd, &result));
diag(result);
cmp_ok(rrc, "==", 1, "cmd '%s' returned rc %d", cmd, rrc);
+ free(result);
/*****************************************
* simple test command 1
@@ -67,6 +69,7 @@ int main(void) {
cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc);
rrc = real_exit_code(rc);
cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc);
+ free(result);
/*****************************************
* simple test command 2
@@ -76,6 +79,7 @@ int main(void) {
cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc);
rrc = real_exit_code(rc);
cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc);
+ free(result);
/*****************************************
* simple test command 3
@@ -85,6 +89,7 @@ int main(void) {
cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc);
rrc = real_exit_code(rc);
cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc);
+ free(result);
/*****************************************
* simple test command 4
@@ -94,6 +99,7 @@ int main(void) {
rrc = real_exit_code(rc);
cmp_ok(rrc, "==", 2, "cmd '%s' returned rc %d", cmd, rrc);
like(result, "test", "returned result string");
+ free(result);
gm_job_t * exec_job;
exec_job = ( gm_job_t * )malloc( sizeof *exec_job );
@@ -112,105 +118,130 @@ int main(void) {
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. \\(worker:", "returned result string");
+ free(exec_job->output);
fork_on_exec = 1;
lives_ok({execute_safe_command(exec_job, fork_on_exec, hostname);}, "executing command using fork on exec");
+ free(exec_job->output);
/* non existing command 2 */
+ free(exec_job->command_line);
exec_job->command_line = strdup("/bin/doesntexist 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. \\(worker:", "returned result string");
+ free(exec_job->output);
/*****************************************
* non executable command 1
*/
+ free(exec_job->command_line);
exec_job->command_line = strdup("./THANKS");
fork_on_exec = 0;
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 126 is out of bounds. Make sure the plugin you're trying to run is executable. \\(worker:", "returned result string");
+ free(exec_job->output);
/* non existing command 2 */
fork_on_exec = 1;
+ free(exec_job->command_line);
exec_job->command_line = strdup("./THANKS 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 126 is out of bounds. Make sure the plugin you're trying to run is executable. \\(worker:", "returned result string");
+ free(exec_job->output);
/*****************************************
* unknown exit code 1
*/
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/rc 5");
- fork_on_exec = 1;
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
- like(exec_job->output, "CRITICAL: Return code of 5 is out of bounds. \\(worker:", "returned result string");
+ like(exec_job->output, "CRITICAL: Return code of 5 is out of bounds. \\(worker:.*exiting with exit code 5", "returned result string");
+ free(exec_job->output);
+
/* unknown exit code 2 */
fork_on_exec = 0;
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/rc 5 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
- like(exec_job->output, "CRITICAL: Return code of 5 is out of bounds. \\(worker:", "returned result string");
+ like(exec_job->output, "CRITICAL: Return code of 5 is out of bounds. \\(worker:.*exiting with exit code 5", "returned result string");
+ free(exec_job->output);
/* unknown exit code 3 */
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/rc 128 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 128 is out of bounds. Plugin exited by signal signal 0. \\(worker:", "returned result string");
+ free(exec_job->output);
/* unknown exit code 4 */
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/rc 137 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 137 is out of bounds. Plugin exited by signal SIGKILL. \\(worker:", "returned result string");
+ free(exec_job->output);
/* unknown exit code 5 */
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/rc 255 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 255 is out of bounds. \\(worker:", "returned result string");
+ free(exec_job->output);
/*****************************************
* signaled exit code SIGINT
*/
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/killer INT");
fork_on_exec = 1;
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 130 is out of bounds. Plugin exited by signal SIGINT. \\(worker:", "returned result string");
+ free(exec_job->output);
/* signaled exit code SIGINT 2 */
fork_on_exec = 0;
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/killer INT 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "CRITICAL: Return code of 130 is out of bounds. Plugin exited by signal SIGINT. \\(worker:", "returned result string");
+ free(exec_job->output);
/*****************************************
* timed out check
*/
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/sleep 30");
- exec_job->timeout = 2;
+ exec_job->timeout = 1;
fork_on_exec = 1;
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
like(exec_job->output, "\\(Service Check Timed Out On Worker: ", "returned result string");
+ free(exec_job->output);
/* timed out check 2 */
fork_on_exec = 0;
+ free(exec_job->command_line);
exec_job->command_line = strdup("./t/sleep 30 2>&1");
execute_safe_command(exec_job, fork_on_exec, hostname);
cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line);
@@ -222,7 +253,7 @@ int main(void) {
/* clean up */
free_job(exec_job);
-
+ mod_gm_free_opt(mod_gm_opt);
return exit_status();
}
diff --git a/t/test_all.pl b/t/test_all.pl
new file mode 100755
index 0000000..4d578a2
--- /dev/null
+++ b/t/test_all.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Test::More;
+
+`type valgrind >/dev/null 2>&1`;
+if($? != 0) {
+ plan skip_all => 'valgrind required';
+}
+plan(tests => 13);
+
+`make`;
+is($?, 0, "build rc is $?");
+
+my $vallog = '/tmp/valgrind.log';
+for my $test (qw(01_utils 02_full 03_exec 04_log)) {
+ `make $test`;
+ 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 >/dev/null`;
+ is($?, 0, "$test valgrind exit code is $?");
+
+ is(qx(grep "ERROR SUMMARY: " $vallog | grep -v "ERROR SUMMARY: 0 errors"), "", "valgrind Error Summary")
+ or BAIL_OUT("check memory $test in $vallog");
+}
+
+unlink($vallog);
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list