summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <ton.voon@opsera.com>2010-06-22 10:47:54 (GMT)
committerTon Voon <ton.voon@opsera.com>2010-06-22 10:47:54 (GMT)
commit9ff89b1a99926ebfeaeba7f415ae74f93eaef0a5 (patch)
tree19387dc5aa14bf563f7e599b355cc1fb33c947f2
parent10364a6004616c2e52852d80b1e1817056aa7119 (diff)
downloadmonitoring-plugins-9ff89b1a99926ebfeaeba7f415ae74f93eaef0a5.tar.gz
Added np_set_args, to set arguments after np_extra_opts has been run
-rw-r--r--lib/tests/test_utils.c11
-rw-r--r--lib/utils_base.c15
-rw-r--r--lib/utils_base.h1
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)
40 char *temp_filename; 40 char *temp_filename;
41 FILE *temp_fp; 41 FILE *temp_fp;
42 42
43 plan_tests(137); 43 plan_tests(141);
44 44
45 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); 45 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised");
46 46
@@ -49,6 +49,15 @@ main (int argc, char **argv)
49 ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised"); 49 ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised");
50 ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" ); 50 ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" );
51 51
52 ok( this_nagios_plugin->argc==argc, "Argc set" );
53 ok( this_nagios_plugin->argv==argv, "Argv set" );
54
55 np_set_args(0,0);
56
57 ok( this_nagios_plugin->argc==0, "argc changed" );
58 ok( this_nagios_plugin->argv==0, "argv changed" );
59
60 np_set_args(argc, argv);
52 61
53 range = parse_range_string("6"); 62 range = parse_range_string("6");
54 ok( range != NULL, "'6' is valid range"); 63 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 ) {
48 } 48 }
49} 49}
50 50
51void np_set_args( int argc, char **argv ) {
52 if (this_nagios_plugin==NULL)
53 die(STATE_UNKNOWN, _("This requires np_init to be called"));
54
55 this_nagios_plugin->argc = argc;
56 this_nagios_plugin->argv = argv;
57}
58
59
51void np_cleanup() { 60void np_cleanup() {
52 if (this_nagios_plugin!=NULL) { 61 if (this_nagios_plugin!=NULL) {
53 if(this_nagios_plugin->state!=NULL) { 62 if(this_nagios_plugin->state!=NULL) {
54 np_free(this_nagios_plugin->state->state_data->data); 63 if(this_nagios_plugin->state->state_data) {
55 np_free(this_nagios_plugin->state->state_data); 64 np_free(this_nagios_plugin->state->state_data->data);
65 np_free(this_nagios_plugin->state->state_data);
66 }
56 np_free(this_nagios_plugin->state->name); 67 np_free(this_nagios_plugin->state->name);
57 np_free(this_nagios_plugin->state); 68 np_free(this_nagios_plugin->state);
58 } 69 }
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();
99void np_state_write_string(time_t, char *); 99void np_state_write_string(time_t, char *);
100 100
101void np_init(char *, int argc, char **argv); 101void np_init(char *, int argc, char **argv);
102void np_set_args(int argc, char **argv);
102void np_cleanup(); 103void np_cleanup();
103 104
104#endif /* _UTILS_BASE_ */ 105#endif /* _UTILS_BASE_ */