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.
#define SOCK_PATH "/tmp/.collectd-email"
#define MAX_CONNS 5
+#define MAX_CONNS_LIMIT 16384
/*
* Private data structures
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;