[collectd] email plugin: Limit the `MaxConns' option by a hardcoded
value.
Florian Forster
octo<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>verplant.org
Sun Dec 3 18:45:09 CET 2006
From: Florian Forster <octo<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>leeloo.lan.home.verplant.org>
Because typos (and ``typos'', i. e. dumb users) happen, it's better to not
allow INT_MAX connections. The problem is that on 32bit machines this would
a) create 2147483648 threads
b) allocate (at least) 512 GBytes of memory
which would result in certain death of either the daemon or the system.
This patch limits the number of connections (and thus threads and allocated
memory) to 16384, which ought to be enough for most people. Those, who need
more connections (and can accomplish this, even though there are quite narrow
OS limits) will need to recompile themselves.
Signed-off-by: Florian Forster <octo<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>leeloo.lan.home.verplant.org>
---
src/email.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/email.c b/src/email.c
index 6838ead..b799597 100644
--- a/src/email.c
+++ b/src/email.c
@@ -73,6 +73,7 @@
#define SOCK_PATH "/tmp/.collectd-email"
#define MAX_CONNS 5
+#define MAX_CONNS_LIMIT 16384
/*
* Private data structures
@@ -205,8 +206,17 @@ static int email_config (char *key, char
else if (0 == strcasecmp (key, "MaxConns")) {
long int tmp = strtol (value, NULL, 0);
- if (INT_MAX < tmp) {
- max_conns = INT_MAX;
+ if (tmp < 1) {
+ fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
+ "value %li, will use default %i.\n",
+ tmp, MAX_CONNS);
+ max_conns = MAX_CONNS;
+ }
+ else if (tmp > MAX_CONNS_LIMIT) {
+ fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
+ "value %li, will use hardcoded limit %i.\n",
+ tmp, MAX_CONNS_LIMIT);
+ max_conns = MAX_CONNS_LIMIT;
}
else {
max_conns = (int)tmp;
--
1.4.3.5
More information about the collectd
mailing list