- if (type_configs[logtype].level >= log_debug)
- goto log; /* bypass flooding checks */
-
- /* Prevent flooding: hash the message and check if we got the same one recently */
- 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--) {
- if (log_flood_array[i].hash == hash) {
-
- /* found same message */
- log_flood_array[i].count++;
-
- /* Check if that message has reached LOG_FLOODING_MAXCOUNT */
- if (log_flood_array[i].count >= LOG_FLOODING_MAXCOUNT) {
- /* yes, log it and remove from array */
-
- /* reusing log_details_buffer */
- sprintf(log_details_buffer, "message repeated %i times\n",
- LOG_FLOODING_MAXCOUNT - 1);
- write(fd, log_details_buffer, strlen(log_details_buffer));
-
- if ((i + 1) == LOG_FLOODING_ARRAY_SIZE) {
- /* last array element, just decrement count */
- log_flood_entries--;
- goto exit;
- }
- /* move array elements down */
- for (int j = i + 1; j != LOG_FLOODING_ARRAY_SIZE ; j++)
- 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 >= LOG_FLOODING_MINCOUNT) {
- /* reusing log_details_buffer */
- sprintf(log_details_buffer, "message repeated %i times\n",
- log_flood_array[0].count - LOG_FLOODING_MINCOUNT + 1);
- 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].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 ?
- type_configs[logtype].display_options :
- type_configs[logtype_default].display_options,
- loglevel, logtype);
-
- /* If default wasnt setup its fd is -1 */
- write(fd, log_details_buffer, strlen(log_details_buffer));
- write(fd, temp_buffer, strlen(temp_buffer));
- } else {
- write(fd, temp_buffer, strlen(temp_buffer));