Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/in_blob/win32_glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static void globfree(glob_t *context)
flb_free(context->gl_pathv);
context->gl_pathv = NULL;
}
context->gl_pathc = 0;

flb_file_glob_clean(&context->inner_context);
}
Expand All @@ -127,7 +128,7 @@ static int glob(const char *path,

(void) unused;

result = flb_file_glob_start(context, path, flags);
result = flb_file_glob_start(&context->inner_context, path, flags);

if (result == FLB_FILE_GLOB_ERROR_SUCCESS) {
entries = cfl_list_size(&context->inner_context.inner_context->results);
Expand All @@ -150,14 +151,15 @@ static int glob(const char *path,
return result;
}
}
context->gl_pathc = entries;
}

return result;
Comment thread
cosmo0920 marked this conversation as resolved.
Resolved
}

static int is_directory(char *path, struct stat *fs_entry_metadata)
{
return (fs_entry_metadata->st_mode & S_IFDIR != 0);
return (fs_entry_metadata->st_mode & S_IFMT) == S_IFDIR;
}

static void reset_errno()
Expand Down Expand Up @@ -604,4 +606,4 @@ int flb_file_glob_fetch(struct flb_file_glob_context *context,
return FLB_FILE_GLOB_ERROR_SUCCESS;
}

#endif
#endif
72 changes: 59 additions & 13 deletions src/config_format/flb_cf_fluentbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,28 @@ static int read_glob(struct flb_cf *cf, struct local_ctx *ctx, const char *path,
char *star, *p0, *p1;
char pattern[MAX_PATH];
char buf[MAX_PATH];
char full_path[MAX_PATH];
int ret;
struct stat st;
HANDLE h;
WIN32_FIND_DATA data;

if (ctx->root_path && path[0] != '/' && path[0] != '\\' &&
!(path[0] != '\0' && path[1] == ':')) {
ret = snprintf(buf, sizeof(buf), "%s\\%s", ctx->root_path, path);
Comment thread
cosmo0920 marked this conversation as resolved.
Resolved
if (ret < 0 || ret >= sizeof(buf)) {
return -1;
}
path = buf;
}

/* Resolve relative includes against the config directory and normalize
* forward slashes before splitting the Windows wildcard components. */
if (_fullpath(full_path, path, sizeof(full_path)) == NULL) {
return -1;
}
path = full_path;

if (strlen(path) > MAX_PATH - 1) {
return -1;
}
Expand Down Expand Up @@ -351,7 +368,11 @@ static int is_file_included(struct local_ctx *ctx, const char *path)

mk_list_foreach(head, &ctx->includes) {
file = mk_list_entry(head, struct local_file, _head);
#ifdef _WIN32
if (strcasecmp(file->path, path) == 0) {
#else
if (strcmp(file->path, path) == 0) {
#endif
return FLB_TRUE;
}
}
Expand Down Expand Up @@ -416,14 +437,15 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
int key_len;
char *val = NULL;
int val_len;
char *buf;
char *buf = NULL;
char *fgets_ptr;
size_t bufsize = FLB_DEFAULT_CF_BUF_SIZE;
char tmp[PATH_MAX];
char *full_path = NULL;
flb_sds_t section = NULL;
flb_sds_t indent = NULL;
struct stat st;
struct local_file *file;
struct local_file *file = NULL;
struct flb_cf_meta *meta;
struct flb_cf_section *current_section = NULL;
struct flb_cf_group *current_group = NULL;
Expand Down Expand Up @@ -473,22 +495,46 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
}
#endif

/* Check this file have not been included before */
#if defined(_WIN32) && !defined(FLB_HAVE_STATIC_CONF)
full_path = realpath(cfg_file, NULL);
if (full_path == NULL) {
return -1;
}
cfg_file = full_path;
#endif

/* Check both active and previously parsed files. */
ret = is_file_included(ctx, cfg_file);
if (ret) {
flb_error("[config] file already included %s", cfg_file);
flb_free(full_path);
return -1;
}
ctx->level++;

#ifndef FLB_HAVE_STATIC_CONF
/* Open configuration file */
if ((f = fopen(cfg_file, "rb")) == NULL) {
flb_warn("[config] I cannot open %s file", cfg_file);
flb_free(full_path);
return -1;
}
#endif

ctx->level++;
file = flb_malloc(sizeof(struct local_file));
if (!file) {
flb_errno();
goto error;
}
file->path = flb_sds_create(cfg_file);
if (!file->path) {
flb_free(file);
file = NULL;
goto error;
}
/* Register before parsing so recursive includes cannot re-enter this file. */
mk_list_add(&file->_head, &ctx->includes);

/* Allocate temporal buffer to read file content */
buf = flb_malloc(bufsize);
if (!buf) {
Expand Down Expand Up @@ -744,20 +790,20 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
}
flb_free(buf);

/* Append this file to the list */
file = flb_malloc(sizeof(struct local_file));
if (!file) {
flb_errno();
ctx->level--;
goto error;
}
file->path = flb_sds_create(cfg_file);
mk_list_add(&file->_head, &ctx->includes);
/* Keep successful files registered to reject later duplicates. */
flb_free(full_path);
ctx->level--;

return 0;

error:
flb_free(full_path);
if (file) {
mk_list_del(&file->_head);
flb_sds_destroy(file->path);
flb_free(file);
}
ctx->level--;
if (f) {
fclose(f);
}
Expand Down
39 changes: 39 additions & 0 deletions src/config_format/flb_cf_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@ static int is_file_included(struct local_ctx *ctx, const char *path)
mk_list_foreach(head, &ctx->includes) {
entry = mk_list_entry(head, struct flb_slist_entry, _head);

#ifdef _WIN32
if (strcasecmp(entry->str, path) == 0) {
#else
if (strcmp(entry->str, path) == 0) {
#endif
return FLB_TRUE;
}
}
Expand Down Expand Up @@ -574,11 +578,28 @@ static int read_glob(struct flb_cf *conf, struct local_ctx *ctx,
char *star, *p0, *p1;
char pattern[MAX_PATH];
char buf[MAX_PATH];
char full_path[MAX_PATH];
int ret;
struct stat st;
HANDLE hnd;
WIN32_FIND_DATA data;

if (state->file->path && path[0] != '/' && path[0] != '\\' &&
!(path[0] != '\0' && path[1] == ':')) {
ret = snprintf(buf, sizeof(buf), "%s\\%s", state->file->path, path);
if (ret < 0 || ret >= sizeof(buf)) {
return -1;
}
path = buf;
}

/* Resolve relative includes against the config directory and normalize
* forward slashes before splitting the Windows wildcard components. */
if (_fullpath(full_path, path, sizeof(full_path)) == NULL) {
Comment thread
cosmo0920 marked this conversation as resolved.
Resolved
return -1;
}
path = full_path;

if (strlen(path) > MAX_PATH - 1) {
return -1;
}
Expand Down Expand Up @@ -3131,6 +3152,9 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx,
yaml_event_t event;
FILE *fh;
struct file_state fstate;
#ifdef _WIN32
char *full_path;
#endif

path_is_absolute = cfg_file[0] == '/';
#ifdef _WIN32
Expand Down Expand Up @@ -3180,6 +3204,21 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx,
}
}

#ifdef _WIN32
/* Use the same absolute identity for direct and wildcard includes. */
full_path = realpath(include_dir, NULL);
if (full_path == NULL) {
flb_sds_destroy(include_dir);
return -1;
}
flb_sds_destroy(include_dir);
include_dir = flb_sds_create(full_path);
flb_free(full_path);
if (include_dir == NULL) {
return -1;
}
#endif

include_file = flb_sds_create(include_dir);

if (include_file == NULL) {
Expand Down
27 changes: 21 additions & 6 deletions src/flb_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ void flb_env_destroy(struct flb_env *env)
flb_free(env);
}

static const char *env_file_path(const char *uri)
{
const char *path = uri;

if (strncmp(path, "file://", 7) == 0) {
path += 7;
}
#ifdef FLB_SYSTEM_WINDOWS
/* A local drive URI uses file:///C:/path; the filesystem needs C:/path. */
if (path[0] == '/' &&
((path[1] >= 'A' && path[1] <= 'Z') || (path[1] >= 'a' && path[1] <= 'z')) &&
path[2] == ':' && (path[3] == '/' || path[3] == '\\')) {
path++;
}
#endif

return path;
}

int flb_env_set_extended(struct flb_env *env, const char *key, const char *val,
const char *uri, int refresh_interval)
{
Expand Down Expand Up @@ -146,8 +165,7 @@ int flb_env_set_extended(struct flb_env *env, const char *key, const char *val,
/* Check if the variable is a reference to a file */
if (vlen > 7 && strncmp(value, "file://", 7) == 0) {
orig_uri = value;
vlen -= 7;
value += 7;
value = env_file_path(value);

if (access(value, R_OK) == -1) {
flb_error("[env] file %s not found", value);
Expand Down Expand Up @@ -247,10 +265,7 @@ const char *flb_env_get(struct flb_env *env, const char *key)
now = time(NULL);
if (var->last_refresh == 0 ||
now - var->last_refresh >= var->refresh_interval) {
file = var->uri;
if (strncmp(file, "file://", 7) == 0) {
file += 7;
}
file = env_file_path(var->uri);

if (access(file, R_OK) == -1) {
flb_error("[env] file %s not found", file);
Expand Down
18 changes: 3 additions & 15 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,9 @@
from utils.fluent_bit_manager import fluent_bit_binary_version
from utils.test_service import stop_active_services

# Configure logging
def configure_logging():
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

if not logger.handlers:
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

return logger

logger = configure_logging()
# Let pytest manage handlers so none retain a closed capture stream at shutdown.
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

def load_global_config():
config_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'config.yaml'))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Deprecated==1.2.14
Flask==3.0.3
google==3.0.0
googleapis-common-protos==1.63.2
grpcio==1.64.1
grpcio==1.85.0
h2==4.1.0
idna==3.7
importlib_metadata==7.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_hot_reload_watch_yaml_config_change():
service.stop()


@pytest.mark.skipif(os.name == "nt", reason="SIGHUP reload requires POSIX; Windows uses HTTP reload")
def test_hot_reload_sighup_yaml_config_change():
service = Service("fluent-bit-manual-before.yaml", "fluent-bit-manual-after.yaml")

Expand Down
Loading
Loading