[nagiosplug] Added np_set_args, to set arguments after ...
Ton Voon
tonvoon at users.sourceforge.net
Tue Jun 22 12:50:55 CEST 2010
Module: nagiosplug
Branch: ton/state
Commit: 9ff89b1a99926ebfeaeba7f415ae74f93eaef0a5
Author: Ton Voon <ton.voon at opsera.com>
Date: Tue Jun 22 11:47:54 2010 +0100
URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=9ff89b1
Added np_set_args, to set arguments after np_extra_opts has been run
---
lib/tests/test_utils.c | 11 ++++++++++-
lib/utils_base.c | 15 +++++++++++++--
lib/utils_base.h | 1 +
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 4f761a6..deb592d 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -40,7 +40,7 @@ main (int argc, char **argv)
char *temp_filename;
FILE *temp_fp;
- plan_tests(137);
+ plan_tests(141);
ok( this_nagios_plugin==NULL, "nagios_plugin not initialised");
@@ -49,6 +49,15 @@ main (int argc, char **argv)
ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised");
ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" );
+ ok( this_nagios_plugin->argc==argc, "Argc set" );
+ ok( this_nagios_plugin->argv==argv, "Argv set" );
+
+ np_set_args(0,0);
+
+ ok( this_nagios_plugin->argc==0, "argc changed" );
+ ok( this_nagios_plugin->argv==0, "argv changed" );
+
+ np_set_args(argc, argv);
range = parse_range_string("6");
ok( range != NULL, "'6' is valid range");
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 4e8d2ef..6de92cb 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -48,11 +48,22 @@ void np_init( char *plugin_name, int argc, char **argv ) {
}
}
+void np_set_args( int argc, char **argv ) {
+ if (this_nagios_plugin==NULL)
+ die(STATE_UNKNOWN, _("This requires np_init to be called"));
+
+ this_nagios_plugin->argc = argc;
+ this_nagios_plugin->argv = argv;
+}
+
+
void np_cleanup() {
if (this_nagios_plugin!=NULL) {
if(this_nagios_plugin->state!=NULL) {
- np_free(this_nagios_plugin->state->state_data->data);
- np_free(this_nagios_plugin->state->state_data);
+ if(this_nagios_plugin->state->state_data) {
+ np_free(this_nagios_plugin->state->state_data->data);
+ np_free(this_nagios_plugin->state->state_data);
+ }
np_free(this_nagios_plugin->state->name);
np_free(this_nagios_plugin->state);
}
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 2fbdfbe..0cb371f 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -99,6 +99,7 @@ state_data *np_state_read();
void np_state_write_string(time_t, char *);
void np_init(char *, int argc, char **argv);
+void np_set_args(int argc, char **argv);
void np_cleanup();
#endif /* _UTILS_BASE_ */
More information about the Commits
mailing list