summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2011-08-22 16:18:06 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2011-08-22 16:18:06 +0000
commit2f42046dbefbf66f3bc6d12d2e562b0bd7eca718 (patch)
tree36ab9c3413d778bf2eb8081db0d83eddf244108e /app
parent96de74950e104fa00d83f682970d61ae325559ea (diff)
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@
Diffstat (limited to 'app')
-rw-r--r--app/cwm/conf.c24
-rw-r--r--app/cwm/parse.y4
2 files changed, 16 insertions, 12 deletions
diff --git a/app/cwm/conf.c b/app/cwm/conf.c
index 5af2f925d..1d8b5ea65 100644
--- a/app/cwm/conf.c
+++ b/app/cwm/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.89 2011/07/26 08:51:24 okan Exp $
+ * $OpenBSD: conf.c,v 1.90 2011/08/22 16:18:05 okan Exp $
*/
#include <sys/param.h>
@@ -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/app/cwm/parse.y b/app/cwm/parse.y
index 94dc862aa..5421b126f 100644
--- a/app/cwm/parse.y
+++ b/app/cwm/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.29 2011/07/25 15:10:24 okan Exp $ */
+/* $OpenBSD: parse.y,v 1.30 2011/08/22 16:18:05 okan Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -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);