Skip to content

Commit bb13a48

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 bb13a48

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/config.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#ifdef __linux__
4040
#include <sys/sysinfo.h>
4141
#endif
42+
#include <glob.h>
4243

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

0 commit comments

Comments
 (0)