diff options
author | Ton Voon <ton.voon@opsera.com> | 2010-06-22 11:47:54 +0100 |
---|---|---|
committer | Ton Voon <ton.voon@opsera.com> | 2010-06-22 11:47:54 +0100 |
commit | 9ff89b1a99926ebfeaeba7f415ae74f93eaef0a5 (patch) | |
tree | 19387dc5aa14bf563f7e599b355cc1fb33c947f2 | |
parent | 10364a6004616c2e52852d80b1e1817056aa7119 (diff) | |
download | monitoring-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.c | 11 | ||||
-rw-r--r-- | lib/utils_base.c | 15 | ||||
-rw-r--r-- | 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 4f761a6d..deb592d6 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 4e8d2ef7..6de92cbd 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 | ||
51 | void 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 | |||
51 | void np_cleanup() { | 60 | void 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 2fbdfbe8..0cb371fd 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -99,6 +99,7 @@ state_data *np_state_read(); | |||
99 | void np_state_write_string(time_t, char *); | 99 | void np_state_write_string(time_t, char *); |
100 | 100 | ||
101 | void np_init(char *, int argc, char **argv); | 101 | void np_init(char *, int argc, char **argv); |
102 | void np_set_args(int argc, char **argv); | ||
102 | void np_cleanup(); | 103 | void np_cleanup(); |
103 | 104 | ||
104 | #endif /* _UTILS_BASE_ */ | 105 | #endif /* _UTILS_BASE_ */ |