X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flvm.c;h=c30489cbddd231c681e541167d8e4f351228702d;hb=25824c65721f0f21cadf1607fad367c7e7831816;hp=63107279be19da94f6754caf7423f2140da29114;hpb=7f38ca96e3a54a4b02475f857c7d79c6a1257ada;p=collectd.git diff --git a/src/lvm.c b/src/lvm.c index 63107279..c30489cb 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -21,12 +21,16 @@ * Benjamin Gilbert **/ -#include - #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" + +#include + +#ifdef HAVE_SYS_CAPABILITY_H +#include +#endif /* HAVE_SYS_CAPABILITY_H */ #define NO_VALUE UINT64_MAX #define PERCENT_SCALE_FACTOR 1e-8 @@ -183,6 +187,24 @@ static int lvm_read(void) { return 0; } /*lvm_read */ +static int c_lvm_init(void) { +#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SYS_ADMIN) + if (check_capability(CAP_SYS_ADMIN) != 0) { + if (getuid() == 0) + WARNING("lvm plugin: Running collectd as root, but the " + "CAP_SYS_ADMIN capability is missing. The plugin's read " + "function will probably fail. Is your init system dropping " + "capabilities?"); + else + WARNING("lvm plugin: collectd doesn't have the CAP_SYS_ADMIN " + "capability. If you don't want to run collectd as root, try " + "running \"setcap cap_sys_admin=ep\" on the collectd binary."); + } +#endif + return 0; +} + void module_register(void) { + plugin_register_init("lvm", c_lvm_init); plugin_register_read("lvm", lvm_read); } /* void module_register */