[Spice-devel] [PATCH 2/2] log: define a new spice_warning_limit macro
Frediano Ziglio
fziglio at redhat.com
Wed Dec 23 06:25:00 PST 2015
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 at redhat.com>
---
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
More information about the Spice-devel
mailing list