From 2fd1f0db665a1b5737c41b2fb9f5e5e9ddc97a96 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 9 Mar 2008 18:31:16 +0100 Subject: [PATCH] Write our own cfg_awesome_include() function to do check before calling confuse's one --- common/configopts.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/common/configopts.c b/common/configopts.c index 1c32c8eee..e827fd007 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -19,6 +19,12 @@ * */ +#include +#include +#include +#include +#include + #include #include "rules.h" @@ -27,9 +33,35 @@ #define AWESOME_CONFIG_FILE ".awesomerc" #define CFG_AWESOME_END() \ - CFG_FUNC((char *) "include", cfg_include), \ + CFG_FUNC((char *) "include", cfg_awesome_include), \ CFG_END() +/** This is a better writing of cfg_include coming from libconfuse. + * With this one, we do not treat errors as fatal. + */ +static int +cfg_awesome_include(cfg_t *cfg, cfg_opt_t *opt, + int argc, const char **argv) +{ + FILE *fp; + + if(argc != 1 || !a_strlen(argv[0])) + { + cfg_error(cfg, "wrong number of arguments to cfg_awesome_include()"); + return 0; + } + + if(!(fp = fopen(argv[0], "r"))) + { + cfg_error(cfg, "cannot include configuration file %s: %s", argv[0], strerror(errno)); + return 0; + } + + fclose(fp); + + return cfg_include(cfg, opt, argc, argv); +} + cfg_opt_t general_opts[] = { CFG_INT((char *) "border", 1, CFGF_NONE),