From 0a05f222752f0325ff55417745d47d4672c2387e Mon Sep 17 00:00:00 2001 From: zackwine Date: Thu, 30 Apr 2020 20:37:27 -0400 Subject: [PATCH] in_tail: fix symlink log rotation for stat(2) backend on Linux (#2052) When compiled with FLB_HAVE_INOTIFY=no for linux records were continuously resent if the files in PATH are symlinks. This patch ensures the fs_stat file monitoring correctly handles symlinks when checking for file rotations. The issue was found when running fluentbit as a daemonset in kubernetes where all files in /var/log/containers/* are symlinks. This patch was tested by forwarding 1M records of 1K size when compiled with both FLB_HAVE_INOTIFY=no/yes and verifying the output metrics reported exactly 1M records. The test was executed by running a container logging to stdout in a kubernetes cluster where symlinks are the target input. Further docker was configured to rotate logs at 10M to ensure multiple file rotations occurred. Signed-off-by: Zack Wine --- plugins/in_tail/tail_file.c | 4 ++-- plugins/in_tail/tail_file.h | 2 +- plugins/in_tail/tail_file_internal.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/in_tail/tail_file.c b/plugins/in_tail/tail_file.c index 13127b7e2b8..4ac39b3ee8b 100644 --- a/plugins/in_tail/tail_file.c +++ b/plugins/in_tail/tail_file.c @@ -819,7 +819,7 @@ void flb_tail_file_remove(struct flb_tail_file *file) flb_free(file->buf_data); flb_free(file->name); -#if !defined(__linux__) +#if !defined(__linux__) || !defined(FLB_HAVE_INOTIFY) flb_free(file->real_name); #endif @@ -1121,7 +1121,7 @@ int flb_tail_file_name_dup(char *path, struct flb_tail_file *file) } file->name_len = strlen(file->name); -#if !defined(__linux__) +#if !defined(__linux__) || !defined(FLB_HAVE_INOTIFY) if (file->real_name) { flb_free(file->real_name); } diff --git a/plugins/in_tail/tail_file.h b/plugins/in_tail/tail_file.h index 5fa80fc25d0..a935fc0e13b 100644 --- a/plugins/in_tail/tail_file.h +++ b/plugins/in_tail/tail_file.h @@ -51,7 +51,7 @@ static inline int flb_tail_file_name_cmp(char *name, static inline int flb_tail_target_file_name_cmp(char *name, struct flb_tail_file *file) { -#if defined(__linux__) +#if defined(__linux__) && defined(FLB_HAVE_INOTIFY) return strcmp(name, file->name); #elif defined(FLB_SYSTEM_WINDOWS) return _stricmp(name, file->real_name); diff --git a/plugins/in_tail/tail_file_internal.h b/plugins/in_tail/tail_file_internal.h index c59c297864e..9baa8e3cad4 100644 --- a/plugins/in_tail/tail_file_internal.h +++ b/plugins/in_tail/tail_file_internal.h @@ -44,7 +44,7 @@ struct flb_tail_file { ino_t inode; #endif char *name; /* target file name given by scan routine */ -#if !defined(__linux) +#if !defined(__linux) || !defined(FLB_HAVE_INOTIFY) char *real_name; /* real file name in the file system */ #endif size_t name_len;