diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-31 07:04:07 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-31 07:04:07 (GMT) |
commit | d043862c154070b2c58172289899dd14776e2d03 (patch) | |
tree | 2b660e8f4a73d0237b7dabf7faaad4a17bbe69b6 /lib | |
parent | 20a8bf1a3ffcdf0e715e03ad654a4a08673e870f (diff) | |
download | monitoring-plugins-d043862c154070b2c58172289899dd14776e2d03.tar.gz |
Fix bug with --extra-opts as last argument with no value
Fix problem with duplicate function name (function should eventually move to /lib)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1969 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extra_opts.c | 4 | ||||
-rw-r--r-- | lib/tests/test_opts.c | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index e425121..d46d124 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ | 33 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ |
34 | int | 34 | int |
35 | is_option (char *str) | 35 | is_option2 (char *str) |
36 | { | 36 | { |
37 | if (!str) | 37 | if (!str) |
38 | return 0; | 38 | return 0; |
@@ -67,7 +67,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ | |||
67 | i--; | 67 | i--; |
68 | *argc-=1; | 68 | *argc-=1; |
69 | }else if(strcmp(argv[i], "--extra-opts")==0){ | 69 | }else if(strcmp(argv[i], "--extra-opts")==0){ |
70 | if(!is_option(argv[i+1])){ | 70 | if((i+1<*argc)&&!is_option2(argv[i+1])){ |
71 | /* It is a argument with separate value */ | 71 | /* It is a argument with separate value */ |
72 | argptr=argv[i+1]; | 72 | argptr=argv[i+1]; |
73 | /* Delete the extra-opts argument/value */ | 73 | /* Delete the extra-opts argument/value */ |
diff --git a/lib/tests/test_opts.c b/lib/tests/test_opts.c index 54210fb..61370a9 100644 --- a/lib/tests/test_opts.c +++ b/lib/tests/test_opts.c | |||
@@ -59,7 +59,7 @@ main (int argc, char **argv) | |||
59 | char **argv_test=NULL, **argv_known=NULL; | 59 | char **argv_test=NULL, **argv_known=NULL; |
60 | int i, argc_test; | 60 | int i, argc_test; |
61 | 61 | ||
62 | plan_tests(11); | 62 | plan_tests(12); |
63 | 63 | ||
64 | argv_test=(char **)malloc(2*sizeof(char **)); | 64 | argv_test=(char **)malloc(2*sizeof(char **)); |
65 | argv_test[0] = "prog_name"; | 65 | argv_test[0] = "prog_name"; |
@@ -221,6 +221,18 @@ main (int argc, char **argv) | |||
221 | argv_known[5] = NULL; | 221 | argv_known[5] = NULL; |
222 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | 222 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); |
223 | ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1"); | 223 | ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1"); |
224 | |||
225 | argv_test=(char **)malloc(3*sizeof(char **)); | ||
226 | argv_test[0] = "prog_name"; | ||
227 | argv_test[1] = "--extra-opts"; | ||
228 | argv_test[2] = NULL; | ||
229 | argc_test=2; | ||
230 | argv_known=(char **)realloc(argv_known, 3*sizeof(char **)); | ||
231 | argv_known[0] = "prog_name"; | ||
232 | argv_known[1] = "--foo=bar"; | ||
233 | argv_known[2] = NULL; | ||
234 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
235 | ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2"); | ||
224 | my_free(&argc_test,argv_test); | 236 | my_free(&argc_test,argv_test); |
225 | 237 | ||
226 | argv_test=(char **)malloc(6*sizeof(char **)); | 238 | argv_test=(char **)malloc(6*sizeof(char **)); |
@@ -239,7 +251,7 @@ main (int argc, char **argv) | |||
239 | argv_known[4] = "val2"; | 251 | argv_known[4] = "val2"; |
240 | argv_known[5] = NULL; | 252 | argv_known[5] = NULL; |
241 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | 253 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); |
242 | ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 2"); | 254 | ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3"); |
243 | my_free(&argc_test,argv_test); | 255 | my_free(&argc_test,argv_test); |
244 | 256 | ||
245 | argv_test=(char **)malloc(6*sizeof(char **)); | 257 | argv_test=(char **)malloc(6*sizeof(char **)); |