diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index aaba03e060b3551e83f6191b516b07badeec85ee..57321753c5b0bff692d4b621d82de2eee7336ae4 100644 (file)
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
#include <sys/stat.h>
#include <unistd.h>
-/* FIXME: N::P dies if section is not found */
-/* FIXME: N::P dies if config file 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
* [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example)
@@ -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);
if(isspace(c)) continue;
switch(c){
/* globble up coment lines */
+ case ';':
case '#':
GOBBLE_TO(f, c, '\n');
break;
if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n"));
/* continue from '=' to start of value or EOL */
for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++);
- /* continue to the end of value (FIXME: watching for trailing comments) */
- for(valend=valptr; valend<lineend; valend++)
- /* FIXME: N::P doesn't allow comments here. Remove next line and parse_ini won't either */
- if(*valend=='#') break;
+ /* continue to the end of value */
+ for(valend=valptr; valend<lineend; valend++);
--valend;
/* Finally trim off trailing spaces */
for(valend; isspace(*valend); valend--);
size_t len;
if((np_env=getenv("NAGIOS_CONFIG_PATH"))!=NULL) {
- /* skip ant starting colon... */
+ /* skip any starting colon... */
while(*np_env==':') np_env++;
/* Look for NP_DEFAULT_INI_FILENAME1 and NP_DEFAULT_INI_FILENAME2 in
* every PATHs defined (colon-separated).
default_file=strdup(temp_file);
}
- /* Return default_file or empty string (should return NULL if we want to
- * die there...
+ /* Return default_file or empty string (should return NULL if we want plugins
+ * to die there)...
*/
if(default_file)
return default_file;
static int test_file(const char* env, int len, const char* file, char* temp_file){
struct stat sb;
- /* test for len + filelen + '/' + '\0' */
+ /* test if len + filelen + '/' + '\0' fits in temp_file */
if((len+strlen(file)+2)>MAX_INPUT_BUFFER) return -1;
strncpy(temp_file,env,len);