Skip to content

Commit

Permalink
keydb.conf: support globbing in include directive
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
blakejalexander committed Dec 10, 2024
1 parent 603ebb2 commit 989e913
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#ifdef __linux__
#include <sys/sysinfo.h>
#endif
#if defined(__linux__) || defined(__APPLE__)
#include <glob.h>
#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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 989e913

Please sign in to comment.