iopsys-feed/fluent-bit/patches/0003-prepend_number_in_syslog_output.patch
Mohd Husaam Mehdi 16c919b1ee for build
2025-05-24 15:25:38 +05:30

71 lines
2 KiB
Diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 72b950e7b..58e76b349 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -205,6 +205,9 @@ option(FLB_CUSTOM_CALYPTIA "Enable Calyptia Support" Yes)
# Config formats
option(FLB_CONFIG_YAML "Enable YAML config format" Yes)
+# out syslog message format
+option(FLUENT_BIT_SYSLOG_PREPEND_LENGTH "Enable prepending of length to syslog message" Yes)
+
# List of plugins available and defaults for each option
include(cmake/plugins_options.cmake)
diff --git a/plugins/out_syslog/CMakeLists.txt b/plugins/out_syslog/CMakeLists.txt
index 556d8e1a4..a848020e9 100644
--- a/plugins/out_syslog/CMakeLists.txt
+++ b/plugins/out_syslog/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(FLUENT_BIT_SYSLOG_PREPEND_LENGTH)
+ add_definitions(-DFLUENT_BIT_SYSLOG_PREPEND_LENGTH)
+endif()
+
set(src
syslog.c
syslog_conf.c)
diff --git a/plugins/out_syslog/syslog.c b/plugins/out_syslog/syslog.c
index 4ecc7c4ac..f85c38b51 100644
--- a/plugins/out_syslog/syslog.c
+++ b/plugins/out_syslog/syslog.c
@@ -156,7 +156,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
return NULL;
}
*s = tmp;
- return *s;
+ goto finalize;
}
prival = (msg->facility << 3) + msg->severity;
@@ -291,6 +291,31 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
*s = tmp;
}
+finalize:
+#ifdef FLUENT_BIT_SYSLOG_PREPEND_LENGTH
+ // Create new SDS with length prefix
+ // Allocate enough space for "%u "
+ flb_sds_t prefix = flb_sds_create_size(32);
+ if (!prefix) {
+ return NULL;
+ }
+
+ unsigned int msg_len = flb_sds_len(*s);
+ prefix = flb_sds_printf(&prefix, "%u ", msg_len);
+ if (!prefix) {
+ return NULL;
+ }
+
+ flb_sds_t new_s = flb_sds_cat(prefix, *s, msg_len);
+ if (!new_s) {
+ flb_sds_destroy(prefix);
+ return NULL;
+ }
+
+ flb_sds_destroy(*s);
+ *s = new_s;
+#endif
+
return *s;
}