mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
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@
This commit is contained in:
parent
912dd46a7e
commit
2dc8df110c
22
conf.c
22
conf.c
@ -265,26 +265,32 @@ conf_clear(struct conf *c)
|
|||||||
void
|
void
|
||||||
conf_setup(struct conf *c, const char *conf_file)
|
conf_setup(struct conf *c, const char *conf_file)
|
||||||
{
|
{
|
||||||
|
char *home;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
int parse = 0;
|
||||||
|
|
||||||
|
conf_init(c);
|
||||||
|
|
||||||
if (conf_file == NULL) {
|
if (conf_file == NULL) {
|
||||||
char *home = getenv("HOME");
|
if ((home = getenv("HOME")) == NULL)
|
||||||
|
|
||||||
if (home == NULL)
|
|
||||||
errx(1, "No HOME directory.");
|
errx(1, "No HOME directory.");
|
||||||
|
|
||||||
(void)snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s",
|
(void)snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s",
|
||||||
home, CONFFILE);
|
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))
|
if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
|
||||||
errx(1, "%s: %s", conf_file, strerror(errno));
|
errx(1, "%s: %s", conf_file, strerror(errno));
|
||||||
else
|
else {
|
||||||
(void)strlcpy(c->conf_path, conf_file,
|
(void)strlcpy(c->conf_path, conf_file,
|
||||||
sizeof(c->conf_path));
|
sizeof(c->conf_path));
|
||||||
|
parse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conf_init(c);
|
if (parse && (parse_config(c->conf_path, c) == -1))
|
||||||
|
|
||||||
if (parse_config(c->conf_path, c) == -1)
|
|
||||||
warnx("config file %s has errors, not loading", c->conf_path);
|
warnx("config file %s has errors, not loading", c->conf_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
parse.y
2
parse.y
@ -462,8 +462,6 @@ pushfile(const char *name)
|
|||||||
nfile->name = xstrdup(name);
|
nfile->name = xstrdup(name);
|
||||||
|
|
||||||
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
|
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
|
||||||
if (errno != ENOENT)
|
|
||||||
warn("%s", nfile->name);
|
|
||||||
free(nfile->name);
|
free(nfile->name);
|
||||||
free(nfile);
|
free(nfile);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user