};
/* We use this in order to track the last n log messages in order to prevent flooding */
-#define LOG_FLOODING_MAXCOUNT 10 /* this controls after how many consecutive messages we force a
- "repeated x times" message */
+#define LOG_FLOODING_MINCOUNT 5 /* this controls after how many consecutive messages must be detected
+ before we start to hide them */
+#define LOG_FLOODING_MAXCOUNT 1000 /* this controls after how many consecutive messages we force a
+ "repeated x times" message */
#define LOG_FLOODING_ARRAY_SIZE 3 /* this contols how many messages in flow we track */
struct log_flood_entry {
int count;
}
/* Prevent flooding: hash the message and check if we got the same one recently */
- int hash = hash_message(temp_buffer);
+ int hash = hash_message(temp_buffer) + log_src_linenumber;
/* Search for the same message by hash */
for (int i = log_flood_entries - 1; i >= 0; i--) {
/* yes, log it and remove from array */
/* reusing log_details_buffer */
- sprintf(log_details_buffer, "message repeated %i times: ", log_flood_array[i].count);
+ sprintf(log_details_buffer, "message repeated %i times: ", LOG_FLOODING_MAXCOUNT - 1);
iov[0].iov_base = log_details_buffer;
iov[0].iov_len = strlen(log_details_buffer);
iov[1].iov_base = temp_buffer;
log_flood_array[j-1] = log_flood_array[j];
log_flood_entries--;
}
+
+ if (log_flood_array[i].count < LOG_FLOODING_MINCOUNT)
+ /* log it */
+ goto log;
+ /* discard it */
goto exit;
} /* if */
} /* for */
/* No matching message found, add this message to array*/
if (log_flood_entries == LOG_FLOODING_ARRAY_SIZE) {
/* array is full, discard oldest entry printing "message repeated..." if count > 1 */
- if (log_flood_array[0].count > 1) {
- /* reusing log_details_buffer */
- sprintf(log_details_buffer, "message repeated %i times: ", log_flood_array[0].count);
- iov[0].iov_base = log_details_buffer;
- iov[0].iov_len = strlen(log_details_buffer);
- iov[1].iov_base = temp_buffer;
- iov[1].iov_len = strlen(temp_buffer);
-
- /* Write "message repeated x times: ..." to log */
- writev( fd, iov, 2);
+ if (log_flood_array[0].count >= LOG_FLOODING_MINCOUNT) {
+ /* reusing log_details_buffer */
+ sprintf(log_details_buffer, "message %i lines before repeated %i times\n",
+ LOG_FLOODING_ARRAY_SIZE , log_flood_array[0].count - 1);
+ /* Write "message repeated x times: ..." to log */
+ write(fd, log_details_buffer, strlen(log_details_buffer));
}
for (int i = 1; i < LOG_FLOODING_ARRAY_SIZE; i++) {
log_flood_array[i-1] = log_flood_array[i];
}
log_flood_entries--;
}
- log_flood_array[log_flood_entries-1].count = 1;
- log_flood_array[log_flood_entries-1].hash = hash;
+ log_flood_array[log_flood_entries].count = 1;
+ log_flood_array[log_flood_entries].hash = hash;
log_flood_entries++;
+log:
if ( ! log_config.console) {
generate_message_details(log_details_buffer, sizeof(log_details_buffer),
type_configs[logtype].set ?
LOG(log_maxdebug, logtype_dsi, "This should still log.");
/* flooding prevention check */
- LOG(log_debug, logtype_default, "Flooding 12x1");
- for (int i = 0; i < 12; i++) {
- LOG(log_error, logtype_default, "flooding 12x1 1");
+ LOG(log_debug, logtype_default, "Flooding 3x");
+ for (int i = 0; i < 3; i++) {
+ LOG(log_debug, logtype_default, "Flooding...");
}
+ LOG(log_debug, logtype_default, "1");
+ LOG(log_debug, logtype_default, "2");
+ LOG(log_debug, logtype_default, "3");
- LOG(log_debug, logtype_default, "=============");
- LOG(log_debug, logtype_default, "Flooding 12x3");
- for (int i = 0; i < 12; i++) {
- LOG(log_error, logtype_default, "flooding 12x3 1");
- LOG(log_error, logtype_default, "flooding 12x3 2");
- LOG(log_error, logtype_default, "flooding 12x3 3");
+ LOG(log_debug, logtype_default, "0============");
+ LOG(log_debug, logtype_default, "Flooding 11x1");
+ for (int i = 0; i < 11; i++) {
+ LOG(log_error, logtype_default, "flooding 11x1 1");
}
- LOG(log_debug, logtype_default, "=============");
- LOG(log_debug, logtype_default, "Flooding 12x4");
- for (int i = 0; i < 12; i++) {
- LOG(log_error, logtype_default, "flooding 12x4 1");
- LOG(log_error, logtype_default, "flooding 12x4 2");
- LOG(log_error, logtype_default, "flooding 12x4 3");
- LOG(log_error, logtype_default, "flooding 12x4 4");
+ LOG(log_debug, logtype_default, "1============");
+ LOG(log_debug, logtype_default, "Flooding 11x2");
+ for (int i = 0; i < 11; i++) {
+ LOG(log_error, logtype_default, "flooding 11x2 1");
+ LOG(log_error, logtype_default, "flooding 11x2 2");
}
- LOG(log_debug, logtype_default, "=============");
- LOG(log_debug, logtype_default, "Flooding 12x5");
- for (int i = 0; i < 12; i++) {
- LOG(log_error, logtype_default, "flooding 12x5 1");
- LOG(log_error, logtype_default, "flooding 12x5 2");
- LOG(log_error, logtype_default, "flooding 12x5 3");
- LOG(log_error, logtype_default, "flooding 12x5 4");
- LOG(log_error, logtype_default, "flooding 12x5 5");
+ LOG(log_debug, logtype_default, "2============");
+ LOG(log_debug, logtype_default, "Flooding 11x3");
+ for (int i = 0; i < 11; i++) {
+ LOG(log_error, logtype_default, "flooding 11x3 1");
+ LOG(log_error, logtype_default, "flooding 11x3 2");
+ LOG(log_error, logtype_default, "flooding 11x3 3");
}
+ LOG(log_debug, logtype_default, "3============");
+ LOG(log_debug, logtype_default, "Flooding 11x4");
+ for (int i = 0; i < 11; i++) {
+ LOG(log_error, logtype_default, "flooding 11x4 1");
+ LOG(log_error, logtype_default, "flooding 11x4 2");
+ LOG(log_error, logtype_default, "flooding 11x4 3");
+ LOG(log_error, logtype_default, "flooding 11x4 4");
+ }
+
+
return 0;
}