X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdns.c;h=0494b4baeb20494f3a00fdb629eb2d738b637077;hb=51181b899668ad2c232a152d6e5e787c4eb049cc;hp=5930dc5033ad85e74ae0f01a5d592a0086f71ad0;hpb=3fae5596643f1e361eb18c3d65448f8bc02fdd80;p=collectd.git diff --git a/src/dns.c b/src/dns.c index 5930dc50..0494b4ba 100644 --- a/src/dns.c +++ b/src/dns.c @@ -25,15 +25,19 @@ #define _BSD_SOURCE #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_dns.h" #include #include +#ifdef HAVE_SYS_CAPABILITY_H +# include +#endif + /* * Private data types */ @@ -346,6 +350,20 @@ static int dns_init (void) listen_thread_init = 1; +#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_RAW) + if (check_capability (CAP_NET_RAW) != 0) + { + if (getuid () == 0) + WARNING ("dns plugin: Running collectd as root, but the CAP_NET_RAW " + "capability is missing. The plugin's read function will probably " + "fail. Is your init system dropping capabilities?"); + else + WARNING ("dns plugin: collectd doesn't have the CAP_NET_RAW capability. " + "If you don't want to run collectd as root, try running \"setcap " + "cap_net_raw=ep\" on the collectd binary."); + } +#endif + return (0); } /* int dns_init */ @@ -389,7 +407,6 @@ static int dns_read (void) unsigned int keys[T_MAX]; unsigned int values[T_MAX]; int len; - int i; counter_list_t *ptr; @@ -411,7 +428,7 @@ static int dns_read (void) } pthread_mutex_unlock (&qtype_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: qtype = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_qtype", qtype_str (keys[i]), values[i]); @@ -427,7 +444,7 @@ static int dns_read (void) } pthread_mutex_unlock (&opcode_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: opcode = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_opcode", opcode_str (keys[i]), values[i]); @@ -443,7 +460,7 @@ static int dns_read (void) } pthread_mutex_unlock (&rcode_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: rcode = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_rcode", rcode_str (keys[i]), values[i]);