diff options
author | okan <okan> | 2011-08-22 16:18:05 +0000 |
---|---|---|
committer | okan <okan> | 2011-08-22 16:18:05 +0000 |
commit | 2dc8df110c738f4bcbe300a5ec1dec1f555765e7 (patch) | |
tree | 1479187bbc52445e49d795f95ecfe3f1712cc6d2 | |
parent | 912dd46a7e5aac20c685fcb424a484a44bb9c713 (diff) | |
download | cwm-2dc8df110c738f4bcbe300a5ec1dec1f555765e7.tar.gz cwm-2dc8df110c738f4bcbe300a5ec1dec1f555765e7.tar.xz cwm-2dc8df110c738f4bcbe300a5ec1dec1f555765e7.zip |
revert r1.11 of parse.y and create logic in conf_setup instead to deal
with the various scenarios of when to attempt a parse of the config, load defaults, and when to warn and/or exit. triggered by bogus warning first noticed by sobrado@. ok oga@
-rw-r--r-- | conf.c | 22 | ||||
-rw-r--r-- | parse.y | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/conf.c b/conf.c index ecdc578..8473033 100644 --- a/conf.c +++ b/conf.c @@ -265,26 +265,32 @@ conf_clear(struct conf *c) void conf_setup(struct conf *c, const char *conf_file) { + char *home; struct stat sb; + int parse = 0; - if (conf_file == NULL) { - char *home = getenv("HOME"); + conf_init(c); - if (home == NULL) + if (conf_file == NULL) { + if ((home = getenv("HOME")) == NULL) errx(1, "No HOME directory."); (void)snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home, CONFFILE); - } else + + if (stat(c->conf_path, &sb) == 0 && (sb.st_mode & S_IFREG)) + parse = 1; + } else { if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG)) errx(1, "%s: %s", conf_file, strerror(errno)); - else + else { (void)strlcpy(c->conf_path, conf_file, sizeof(c->conf_path)); + parse = 1; + } + } - conf_init(c); - - if (parse_config(c->conf_path, c) == -1) + if (parse && (parse_config(c->conf_path, c) == -1)) warnx("config file %s has errors, not loading", c->conf_path); } diff --git a/parse.y b/parse.y index a31a6c2..1b55f08 100644 --- a/parse.y +++ b/parse.y @@ -462,8 +462,6 @@ pushfile(const char *name) nfile->name = xstrdup(name); if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { - if (errno != ENOENT) - warn("%s", nfile->name); free(nfile->name); free(nfile); return (NULL); |