Allow to log but no more than a fixed number of times. This to log for instance number of times client do something wrong but without causing excessive log or DoS. I didn't use atomic operation for decrementing the counter to reduce possible contention on the system bus, this will just cause some more messages to be printed. The signed variable and the check assure that counter does not underflow (unless machine has billions of processors and millions of clients are connected). Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- common/log.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/log.h b/common/log.h index d9e6023..bd5edc5 100644 --- a/common/log.h +++ b/common/log.h @@ -103,6 +103,14 @@ void spice_log(const char *log_domain, } SPICE_STMT_END #endif +#define spice_warning_limit(n, format, ...) SPICE_STMT_START { \ + static int warn_limit = (n); \ + if (warn_limit > 0) { \ + --warn_limit; \ + spice_warning(format, ## __VA_ARGS__); \ + } \ +} SPICE_STMT_END + #ifndef spice_critical #define spice_critical(format, ...) SPICE_STMT_START { \ spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \ -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel