Browse Source

* source/files : 'missingok' option

master
Alex 'AdUser' Z 3 months ago
parent
commit
416feb6964
  1. 2
      configs/conf-available/05-source-files.conf
  2. 17
      src/sources/files.c

2
configs/conf-available/05-source-files.conf

@ -1,2 +1,4 @@
[source:files] [source:files]
load = source_files.so load = source_files.so
; allow source start if no files matched?
missingok = no

17
src/sources/files.c

@ -31,6 +31,7 @@ struct _config {
f2b_file_t *files; f2b_file_t *files;
f2b_file_t *current; f2b_file_t *current;
int flags; int flags;
bool missingok;
char path[256]; char path[256];
}; };
@ -147,10 +148,10 @@ config(cfg_t *cfg, const char *key, const char *value) {
assert(key != NULL); assert(key != NULL);
assert(value != NULL); assert(value != NULL);
/* no options */ if (strcmp(key, "missingok") == 0) {
(void)(cfg); /* suppress warning for unused variable 'ip' */ cfg->missingok = (strcmp(value, "yes") == 0) ? true : false;
(void)(key); /* suppress warning for unused variable 'ip' */ return true;
(void)(value); /* suppress warning for unused variable 'ip' */ }
return false; return false;
} }
@ -158,11 +159,15 @@ config(cfg_t *cfg, const char *key, const char *value) {
bool bool
start(cfg_t *cfg) { start(cfg_t *cfg) {
f2b_file_t *file = NULL; f2b_file_t *file = NULL;
int glob_flags = GLOB_MARK | GLOB_NOESCAPE;
glob_t globbuf; glob_t globbuf;
assert(cfg != NULL); 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; return NULL;
for (size_t i = 0; i < globbuf.gl_pathc; i++) { for (size_t i = 0; i < globbuf.gl_pathc; i++) {
@ -172,7 +177,7 @@ start(cfg_t *cfg) {
continue; continue;
} }
strlcpy(file->path, globbuf.gl_pathv[i], slen); strlcpy(file->path, globbuf.gl_pathv[i], slen);
if (!file_open(cfg, file)) { if (!file_open(cfg, file) && !cfg->missingok) {
FREE(file); FREE(file);
continue; continue;
} }

Loading…
Cancel
Save