summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 815fbd8)
raw | patch | inline | side by side (parent: 815fbd8)
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Fri, 4 Apr 2008 10:11:22 +0000 (10:11 +0000) | ||
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Fri, 4 Apr 2008 10:11:22 +0000 (10:11 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1976 f882894a-f735-0410-b71e-b25c423dba1c
lib/extra_opts.c | patch | blob | history | |
lib/parse_ini.c | patch | blob | history | |
lib/tests/test_ini.c | patch | blob | history | |
lib/tests/test_opts.c | patch | blob | history |
diff --git a/lib/extra_opts.c b/lib/extra_opts.c
index 8c17fa4ae37eb07f187f671d1c37f27e47ffdb59..b555417a834a4bf9cd1eb5e94042f4a846447899 100644 (file)
--- a/lib/extra_opts.c
+++ b/lib/extra_opts.c
is_option2 (char *str)
{
if (!str)
- return 0;
+ return FALSE;
else if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
- return 1;
+ return TRUE;
else
- return 0;
+ return FALSE;
}
/* this is the externally visible function used by plugins */
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index d5661c9e70755146e212d75ee7eb97a5638c242e..96551cfe881a459daf196ce34ce45c9fe8655577 100644 (file)
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
#include <sys/stat.h>
#include <unistd.h>
-/* TODO: die like N::P if section is not found */
/* TODO: die like N::P if config file is not found */
/* np_ini_info contains the result of parsing a "locator" in the format
@@ -104,11 +103,8 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
inifile=fopen(i.file, "r");
}
if(inifile==NULL) die(STATE_UNKNOWN, _("Can't read config file"));
- if(read_defaults(inifile, i.stanza, &defaults)==FALSE && strcmp(i.stanza, default_section) && inifile!=stdin) {
- /* We got nothing, try the default section */
- rewind(inifile);
- read_defaults(inifile, default_section, &defaults);
- }
+ if(read_defaults(inifile, i.stanza, &defaults)==FALSE)
+ die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
free(i.file);
if(inifile!=stdin) fclose(inifile);
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c
index 80396caa5a222359e46fa8f8da702ab836403e40..1ab1e5d3a97e927a15a784db4abad2c052f5ddfe 100644 (file)
--- a/lib/tests/test_ini.c
+++ b/lib/tests/test_ini.c
{
char *optstr=NULL;
- plan_tests(12);
+ plan_tests(11);
optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
my_free(optstr);
- optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
- ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name over specified one");
- my_free(optstr);
+ /*
+ * This check is expected to die - It's commented so we can eventually put
+ * it in a separate file for testing the return value
+ */
+ /* optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
+ ok( 0, "die if section isn't found");
+ my_free(optstr); */
optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
diff --git a/lib/tests/test_opts.c b/lib/tests/test_opts.c
index 61370a9c03ddbc26187685365ad9001b141e3143..e878abd8dadb650979094a69fd8dea3ac3e6cd09 100644 (file)
--- a/lib/tests/test_opts.c
+++ b/lib/tests/test_opts.c
char **argv_test=NULL, **argv_known=NULL;
int i, argc_test;
- plan_tests(12);
+ plan_tests(9);
argv_test=(char **)malloc(2*sizeof(char **));
argv_test[0] = "prog_name";
ok(array_diff(argc_test, argv_test, 7, argv_known), "twice extra opts using two sections");
my_free(&argc_test,argv_test);
- /* Next three checks should die according to N::P - for now they're useful
- * to test code is working properly (i.e. no srash or unexpected behavior)
+ /* Next three checks dre expected to die. They are commented out as they
+ * could possibly go in a sepatare test checked for return value.
*/
- argv_test=(char **)malloc(6*sizeof(char **));
+ /* argv_test=(char **)malloc(6*sizeof(char **));
argv_test[0] = "prog_name";
argv_test[1] = "arg1";
argv_test[2] = "--extra-opts=missing@./config-opts.ini";
argv_known[4] = NULL;
argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 1");
- my_free(&argc_test,argv_test);
+ my_free(&argc_test,argv_test); */
- argv_test=(char **)malloc(7*sizeof(char **));
+ /* argv_test=(char **)malloc(7*sizeof(char **));
argv_test[0] = "prog_name";
argv_test[1] = "arg1";
argv_test[2] = "--extra-opts";
argv_known[4] = NULL;
argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 2");
- my_free(&argc_test,argv_test);
+ my_free(&argc_test,argv_test); */
- argv_test=(char **)malloc(6*sizeof(char **));
+ /* argv_test=(char **)malloc(6*sizeof(char **));
argv_test[0] = "prog_name";
argv_test[1] = "arg1";
argv_test[2] = "--extra-opts";
argv_known[4] = NULL;
argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3");
- my_free(&argc_test,argv_test);
+ my_free(&argc_test,argv_test); */
setenv("NAGIOS_CONFIG_PATH", ".", 1);
argv_test=(char **)malloc(6*sizeof(char **));
argv_test=(char **)malloc(6*sizeof(char **));
argv_test[0] = "prog_name";
argv_test[1] = "arg1";
- argv_test[2] = "--extra-opts=section2";
- argv_test[3] = "--arg3";
+ argv_test[2] = "--extra-opts";
+ argv_test[3] = "-arg3";
argv_test[4] = "val2";
argv_test[5] = NULL;
argc_test=5;
argv_known[0] = "prog_name";
argv_known[1] = "--foo=bar";
argv_known[2] = "arg1";
- argv_known[3] = "--arg3";
+ argv_known[3] = "-arg3";
argv_known[4] = "val2";
argv_known[5] = NULL;
argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
- ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
+ ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
my_free(&argc_test,argv_test);
return exit_status();