Skip to content

Commit 989e913

Browse files
keydb.conf: support globbing in include directive
The existing example keydb.conf indicates that wildcard pattern matching is supported for the include directive, i.e. it implies that: - include /etc/keydb.conf - include /etc/keydb.d/server-specific.conf - include /etc/keydb.d/*.conf should all be supported. However, glob-style matching support is not enabled by the configuration parser. This commit treats the arguments to the include directive as glob patterns via the POSIX standard glob.h library, and calls the loadServerConfig function as many times as necessary. Signed-off-by: Blake Alexander <[email protected]>
1 parent 603ebb2 commit 989e913

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/config.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#ifdef __linux__
4040
#include <sys/sysinfo.h>
4141
#endif
42+
#if defined(__linux__) || defined(__APPLE__)
43+
#include <glob.h>
44+
#endif
4245

4346
const char *KEYDB_SET_VERSION = KEYDB_REAL_VERSION;
4447
size_t g_semiOrderedSetTargetBucketSize = 0; // Its a header only class so nowhere else for this to go
@@ -593,7 +596,22 @@ void loadServerConfigFromString(char *config) {
593596
fclose(logfp);
594597
}
595598
} else if (!strcasecmp(argv[0],"include") && argc == 2) {
596-
loadServerConfig(argv[1], 0, NULL);
599+
glob_t globbuf;
600+
int ret;
601+
ret = glob(argv[1], GLOB_ERR, NULL, &globbuf);
602+
if (ret != EXIT_SUCCESS && ret != GLOB_NOMATCH) {
603+
strerror(errno);
604+
err = sdscatprintf(sdsempty(),
605+
"Error handling include directive: %s", strerror(errno));
606+
globfree(&globbuf);
607+
goto loaderr;
608+
}
609+
610+
for (size_t i = 0; i < globbuf.gl_pathc; i++) {
611+
loadServerConfig(globbuf.gl_pathv[i], 0, NULL);
612+
}
613+
614+
globfree(&globbuf);
597615
} else if ((!strcasecmp(argv[0],"slaveof") ||
598616
!strcasecmp(argv[0],"replicaof")) && argc == 3) {
599617
slaveof_linenum = linenum;

0 commit comments

Comments
 (0)