[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1976] nagiosplug/trunk/lib

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Fri Apr 4 12:11:23 CEST 2008


Revision: 1976
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1976&view=rev
Author:   dermoth
Date:     2008-04-04 03:11:22 -0700 (Fri, 04 Apr 2008)

Log Message:
-----------
make parse_ini die like in N::P if section isn't found

Modified Paths:
--------------
    nagiosplug/trunk/lib/extra_opts.c
    nagiosplug/trunk/lib/parse_ini.c
    nagiosplug/trunk/lib/tests/test_ini.c
    nagiosplug/trunk/lib/tests/test_opts.c

Modified: nagiosplug/trunk/lib/extra_opts.c
===================================================================
--- nagiosplug/trunk/lib/extra_opts.c	2008-04-02 23:05:27 UTC (rev 1975)
+++ nagiosplug/trunk/lib/extra_opts.c	2008-04-04 10:11:22 UTC (rev 1976)
@@ -35,11 +35,11 @@
 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 */

Modified: nagiosplug/trunk/lib/parse_ini.c
===================================================================
--- nagiosplug/trunk/lib/parse_ini.c	2008-04-02 23:05:27 UTC (rev 1975)
+++ nagiosplug/trunk/lib/parse_ini.c	2008-04-04 10:11:22 UTC (rev 1976)
@@ -34,7 +34,6 @@
 #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 @@
 			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);

Modified: nagiosplug/trunk/lib/tests/test_ini.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini.c	2008-04-02 23:05:27 UTC (rev 1975)
+++ nagiosplug/trunk/lib/tests/test_ini.c	2008-04-04 10:11:22 UTC (rev 1976)
@@ -55,7 +55,7 @@
 {
 	char *optstr=NULL;
 
-	plan_tests(12);
+	plan_tests(11);
 
 	optstr=list2str(np_get_defaults("section at ./config-tiny.ini", "check_disk"));
 	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
@@ -65,9 +65,13 @@
 	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 at ./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 at ./config-tiny.ini", "section"));
+	ok( 0, "die if section isn't found");
+	my_free(optstr); */
 
 	optstr=list2str(np_get_defaults("Section Two at ./config-tiny.ini", "check_disk"));
 	ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");

Modified: nagiosplug/trunk/lib/tests/test_opts.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_opts.c	2008-04-02 23:05:27 UTC (rev 1975)
+++ nagiosplug/trunk/lib/tests/test_opts.c	2008-04-04 10:11:22 UTC (rev 1976)
@@ -59,7 +59,7 @@
 	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";
@@ -145,10 +145,10 @@
 	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 at ./config-opts.ini";
@@ -164,9 +164,9 @@
 	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";
@@ -183,9 +183,9 @@
 	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";
@@ -201,7 +201,7 @@
 	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 **));
@@ -257,8 +257,8 @@
 	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;
@@ -266,11 +266,11 @@
 	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();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list