Skip to content
Snippets Groups Projects
Commit e636a3a4 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Support !include wildcard-pattern

This allows auto-inclusion of sub-directories of config files (e.g. !include modopts.d/*.ini). This, along with the next commit to js_file.c, allows module authors (or sysops) to keep their module-specific settings in a module-specific file (rather than always merging-with/managing the monolithic/shared modopts.ini). The [modname] section heading is still required in the included .ini file.

Replaced use of non-thread-safe STRERROR() with safe_strerror().
parent 55271814
Branches
Tags
No related merge requests found
...@@ -2307,6 +2307,7 @@ BOOL iniCloseFile(FILE* fp) ...@@ -2307,6 +2307,7 @@ BOOL iniCloseFile(FILE* fp)
str_list_t iniReadFile(FILE* fp) str_list_t iniReadFile(FILE* fp)
{ {
char str[INI_MAX_LINE_LEN]; char str[INI_MAX_LINE_LEN];
char err[512];
char* p; char* p;
size_t i; size_t i;
size_t inc_len; size_t inc_len;
...@@ -2328,19 +2329,29 @@ str_list_t iniReadFile(FILE* fp) ...@@ -2328,19 +2329,29 @@ str_list_t iniReadFile(FILE* fp)
p=list[i]+inc_len; p=list[i]+inc_len;
SKIP_WHITESPACE(p); SKIP_WHITESPACE(p);
truncsp(p); truncsp(p);
if(inc_counter >= INI_INCLUDE_MAX) glob_t gl;
SAFEPRINTF2(str, ";%s - MAXIMUM INCLUDES REACHED: %u", list[i], INI_INCLUDE_MAX); glob(p, GLOB_MARK, NULL, &gl);
else if((insert_fp=fopen(p,"r"))==NULL) safe_snprintf(str, sizeof(str), "; %s - %lu matches found", list[i], (ulong)gl.gl_pathc);
SAFEPRINTF2(str, ";%s - FAILURE: %s", list[i], STRERROR(errno));
else
SAFEPRINTF(str, ";%s", list[i]);
strListReplace(list, i, str); strListReplace(list, i, str);
if(insert_fp!=NULL) { for(size_t j = 0; j < gl.gl_pathc; j++) {
strListInsertFile(insert_fp, &list, i+1, INI_MAX_LINE_LEN); char* fname = gl.gl_pathv[j];
fclose(insert_fp); if(*lastchar(fname) == '/')
insert_fp=NULL; continue;
inc_counter++; if(inc_counter >= INI_INCLUDE_MAX)
SAFEPRINTF2(str, "; %s - MAXIMUM INCLUDES REACHED: %u", fname, INI_INCLUDE_MAX);
else if((insert_fp=fopen(fname,"r"))==NULL)
SAFEPRINTF2(str, "; %s - FAILURE: %s", fname, safe_strerror(errno, err, sizeof(err)));
else
SAFEPRINTF(str, "; %s", fname);
strListInsert(&list, str, i + 1);
if(insert_fp!=NULL) {
strListInsertFile(insert_fp, &list, i + 2, INI_MAX_LINE_LEN);
fclose(insert_fp);
insert_fp=NULL;
inc_counter++;
}
} }
globfree(&gl);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment