Skip to content

Commit

Permalink
lib: monkey: sync changes for rconf and libco
Browse files Browse the repository at this point in the history
 - f0fc1e07 lib: libco: always build with LIBCO_MP flag (for multithread callers)
 - 86ea4dbb core: rconf: support wild card to include conf files

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Apr 23, 2018
1 parent f3eeb23 commit 34727c2
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions lib/monkey/mk_core/mk_rconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <glob.h>

#include <mk_core/mk_rconf.h>
#include <mk_core/mk_utils.h>
Expand Down Expand Up @@ -163,6 +163,9 @@ static int mk_rconf_meta_add(struct mk_rconf *conf, char *buf, int len)
return 0;
}

/* To call this function from mk_rconf_read */
static int mk_rconf_read_glob(struct mk_rconf *conf, const char * path);

static int mk_rconf_read(struct mk_rconf *conf, const char *path)
{
int i;
Expand Down Expand Up @@ -236,7 +239,12 @@ static int mk_rconf_read(struct mk_rconf *conf, const char *path)
}

if (len > 9 && strncasecmp(buf, "@INCLUDE ", 9) == 0) {
ret = mk_rconf_read(conf, buf + 9);
if ( strchr(buf + 9, '*') != NULL) {
ret = mk_rconf_read_glob(conf, buf + 9);
}
else {
ret = mk_rconf_read(conf, buf + 9);
}
if (ret == -1) {
conf->level--;
fclose(f);
Expand Down Expand Up @@ -375,6 +383,53 @@ static int mk_rconf_read(struct mk_rconf *conf, const char *path)
return 0;
}

static int mk_rconf_read_glob(struct mk_rconf *conf, const char * path)
{
int ret = -1;
glob_t glb;
char tmp[PATH_MAX];

const char *glb_path;
size_t i;
int ret_glb = -1;

if (conf->root_path) {
snprintf(tmp, PATH_MAX, "%s/%s", conf->root_path, path);
glb_path = tmp;
}
else {
glb_path = path;
}

ret_glb = glob(glb_path, GLOB_NOSORT, NULL, &glb);
if (ret_glb != 0) {
switch(ret_glb){
case GLOB_NOSPACE:
mk_warn("[%s] glob: no space", __FUNCTION__);
break;
case GLOB_NOMATCH:
mk_warn("[%s] glob: no match", __FUNCTION__);
break;
case GLOB_ABORTED:
mk_warn("[%s] glob: aborted", __FUNCTION__);
break;
default:
mk_warn("[%s] glob: other error", __FUNCTION__);
}
return ret;
}

for (i = 0; i < glb.gl_pathc; i++) {
ret = mk_rconf_read(conf, glb.gl_pathv[i]);
if (ret < 0) {
break;
}
}

globfree(&glb);
return ret;
}

static int mk_rconf_path_set(struct mk_rconf *conf, char *file)
{
char *p;
Expand Down

0 comments on commit 34727c2

Please sign in to comment.