From 0f6300f1e6a038f37c406b2362218ea043def55b Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Tue, 13 Nov 2012 09:40:32 +0900 Subject: Silently ignore wildcard includes that match nothing This will avoid an error message when including an empty directory. --- grammar/rainerscript.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 39ff6df3..e54c9060 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -2778,8 +2778,15 @@ cnfDoInclude(char *name) } } /* Use GLOB_MARK to append a trailing slash for directories. */ - result = glob(finalName, GLOB_MARK, NULL, &cfgFiles); - if(result == GLOB_NOSPACE || result == GLOB_ABORTED || cfgFiles.gl_pathc == 0) { + /* Use GLOB_NOMAGIC to detect wildcards that match nothing. */ + result = glob(finalName, GLOB_MARK | GLOB_NOMAGIC, NULL, &cfgFiles); + + /* Silently ignore wildcards that match nothing */ + if(result == GLOB_NOMATCH) { + return 1; + } + + if(result == GLOB_NOSPACE || result == GLOB_ABORTED) { char errStr[1024]; rs_strerror_r(errno, errStr, sizeof(errStr)); parser_errmsg("error accessing config file or directory '%s': %s", @@ -2790,8 +2797,13 @@ cnfDoInclude(char *name) for(i = 0; i < cfgFiles.gl_pathc; i++) { cfgFile = cfgFiles.gl_pathv[i]; - if(stat(cfgFile, &fileInfo) != 0) - continue; /* continue with the next file if we can't stat() the file */ + if(stat(cfgFile, &fileInfo) != 0) + { + char errStr[1024]; + rs_strerror_r(errno, errStr, sizeof(errStr)); + parser_errmsg("error accessing config file or directory '%s': %s", + cfgFile, errStr); + } if(S_ISREG(fileInfo.st_mode)) { /* config file */ dbgprintf("requested to include config file '%s'\n", cfgFile); -- cgit v1.2.3