From 416feb69643175a286dec9ab509aac40e6fb5cd3 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 23 Aug 2024 11:27:16 +1000 Subject: [PATCH] * source/files : 'missingok' option --- configs/conf-available/05-source-files.conf | 2 ++ src/sources/files.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/configs/conf-available/05-source-files.conf b/configs/conf-available/05-source-files.conf index ca31120..d1c033d 100644 --- a/configs/conf-available/05-source-files.conf +++ b/configs/conf-available/05-source-files.conf @@ -1,2 +1,4 @@ [source:files] load = source_files.so +; allow source start if no files matched? +missingok = no diff --git a/src/sources/files.c b/src/sources/files.c index bdb2ee9..0a572b2 100644 --- a/src/sources/files.c +++ b/src/sources/files.c @@ -31,6 +31,7 @@ struct _config { f2b_file_t *files; f2b_file_t *current; int flags; + bool missingok; char path[256]; }; @@ -147,10 +148,10 @@ config(cfg_t *cfg, const char *key, const char *value) { assert(key != NULL); assert(value != NULL); - /* no options */ - (void)(cfg); /* suppress warning for unused variable 'ip' */ - (void)(key); /* suppress warning for unused variable 'ip' */ - (void)(value); /* suppress warning for unused variable 'ip' */ + if (strcmp(key, "missingok") == 0) { + cfg->missingok = (strcmp(value, "yes") == 0) ? true : false; + return true; + } return false; } @@ -158,11 +159,15 @@ config(cfg_t *cfg, const char *key, const char *value) { bool start(cfg_t *cfg) { f2b_file_t *file = NULL; + int glob_flags = GLOB_MARK | GLOB_NOESCAPE; glob_t globbuf; assert(cfg != NULL); - if (glob(cfg->path, GLOB_MARK | GLOB_NOESCAPE, NULL, &globbuf) != 0) + if (cfg->missingok) + glob_flags |= GLOB_NOCHECK; /* allow no matches */ + + if (glob(cfg->path, glob_flags, NULL, &globbuf) != 0) return NULL; for (size_t i = 0; i < globbuf.gl_pathc; i++) { @@ -172,7 +177,7 @@ start(cfg_t *cfg) { continue; } strlcpy(file->path, globbuf.gl_pathv[i], slen); - if (!file_open(cfg, file)) { + if (!file_open(cfg, file) && !cfg->missingok) { FREE(file); continue; }