From 989e91397f157ebb79d5284bd31e22f82d0caf78 Mon Sep 17 00:00:00 2001 From: Blake Alexander Date: Tue, 10 Dec 2024 13:34:38 +0100 Subject: [PATCH] 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 --- src/config.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/config.cpp b/src/config.cpp index 0eea60a1c..289dd8a1e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -39,6 +39,9 @@ #ifdef __linux__ #include #endif +#if defined(__linux__) || defined(__APPLE__) +#include +#endif const char *KEYDB_SET_VERSION = KEYDB_REAL_VERSION; 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) { fclose(logfp); } } else if (!strcasecmp(argv[0],"include") && argc == 2) { - loadServerConfig(argv[1], 0, NULL); + glob_t globbuf; + int ret; + ret = glob(argv[1], GLOB_ERR, NULL, &globbuf); + if (ret != EXIT_SUCCESS && ret != GLOB_NOMATCH) { + strerror(errno); + err = sdscatprintf(sdsempty(), + "Error handling include directive: %s", strerror(errno)); + globfree(&globbuf); + goto loaderr; + } + + for (size_t i = 0; i < globbuf.gl_pathc; i++) { + loadServerConfig(globbuf.gl_pathv[i], 0, NULL); + } + + globfree(&globbuf); } else if ((!strcasecmp(argv[0],"slaveof") || !strcasecmp(argv[0],"replicaof")) && argc == 3) { slaveof_linenum = linenum;