diff options
| -rw-r--r-- | lib/parse_ini.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index f352d78c..2e42df7c 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
| @@ -30,8 +30,6 @@ | |||
| 30 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
| 31 | #include <unistd.h> | 31 | #include <unistd.h> |
| 32 | 32 | ||
| 33 | /* TODO: die like N::P if config file is not found */ | ||
| 34 | |||
| 35 | /* np_ini_info contains the result of parsing a "locator" in the format | 33 | /* np_ini_info contains the result of parsing a "locator" in the format |
| 36 | * [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example) | 34 | * [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example) |
| 37 | */ | 35 | */ |
| @@ -112,20 +110,17 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){ | |||
| 112 | np_ini_info i; | 110 | np_ini_info i; |
| 113 | 111 | ||
| 114 | parse_locator(locator, default_section, &i); | 112 | parse_locator(locator, default_section, &i); |
| 115 | /* if a file was specified or if we're using the default file */ | 113 | if(strcmp(i.file, "-")==0){ |
| 116 | if(i.file != NULL && strlen(i.file) > 0){ | 114 | inifile=stdin; |
| 117 | if(strcmp(i.file, "-")==0){ | 115 | } else { |
| 118 | inifile=stdin; | 116 | inifile=fopen(i.file, "r"); |
| 119 | } else { | ||
| 120 | inifile=fopen(i.file, "r"); | ||
| 121 | } | ||
| 122 | if(inifile==NULL) die(STATE_UNKNOWN, "%s\n", _("Can't read config file")); | ||
| 123 | if(read_defaults(inifile, i.stanza, &defaults)==FALSE) | ||
| 124 | die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file); | ||
| 125 | |||
| 126 | free(i.file); | ||
| 127 | if(inifile!=stdin) fclose(inifile); | ||
| 128 | } | 117 | } |
| 118 | if(inifile==NULL) die(STATE_UNKNOWN, "%s\n", _("Can't read config file")); | ||
| 119 | if(read_defaults(inifile, i.stanza, &defaults)==FALSE) | ||
| 120 | die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file); | ||
| 121 | |||
| 122 | free(i.file); | ||
| 123 | if(inifile!=stdin) fclose(inifile); | ||
| 129 | free(i.stanza); | 124 | free(i.stanza); |
| 130 | return defaults; | 125 | return defaults; |
| 131 | } | 126 | } |
