From 1828cb75bd4052187e7a3640de9c0060b54b210d Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 14 Jun 2008 21:51:00 +0000 Subject: slightly alter the semantics of config files: - if no config file, continue silently and apply defaults - if config file, parse and move on - if config file specified but not found, error out ok oga@ --- conf.c | 10 ++++++++-- parse.y | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/conf.c b/conf.c index be87f6e..04ebad9 100644 --- a/conf.c +++ b/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. * - * $Id: conf.c,v 1.37 2008/06/14 21:48:54 okan Exp $ + * $Id: conf.c,v 1.38 2008/06/14 21:51:00 okan Exp $ */ #include "headers.h" @@ -168,6 +168,8 @@ conf_init(struct conf *c) void conf_setup(struct conf *c, const char *conf_file) { + struct stat sb; + if (conf_file == NULL) { char *home = getenv("HOME"); @@ -177,7 +179,11 @@ conf_setup(struct conf *c, const char *conf_file) snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home, CONFFILE); } else - snprintf(c->conf_path, sizeof(c->conf_path), "%s", conf_file); + if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG)) + errx(1, "%s: %s", conf_file, strerror(errno)); + else + snprintf(c->conf_path, sizeof(c->conf_path), "%s", + conf_file); conf_init(c); diff --git a/parse.y b/parse.y index dd2a45b..e344e11 100644 --- a/parse.y +++ b/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.10 2008/06/14 21:48:54 okan Exp $ */ +/* $OpenBSD: parse.y,v 1.11 2008/06/14 21:51:00 okan Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -441,7 +441,8 @@ pushfile(const char *name) nfile->name = xstrdup(name); if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { - warn("%s", nfile->name); + if (errno != ENOENT) + warn("%s", nfile->name); free(nfile->name); free(nfile); return (NULL); -- cgit v1.2.3-2-gb3c3