From: Florian Forster Date: Sun, 22 Oct 2017 17:59:19 +0000 (+0200) Subject: lvm update: Check for the CAP_SYS_ADMIN capability. X-Git-Tag: collectd-5.8.0~28 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=0fd27c3d33f8729989b00df386cae5b14a34445d lvm update: Check for the CAP_SYS_ADMIN capability. Fixes: #2426 --- diff --git a/src/lvm.c b/src/lvm.c index 63107279..4bb1c340 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -21,13 +21,17 @@ * Benjamin Gilbert **/ -#include - #include "collectd.h" #include "common.h" #include "plugin.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 lvm_init(void) { +#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SYS_ADMIN) + if (check_capability(CAP_SYS_ADMIN) != 0) { + if (getuid() == 0) + WARNING("smart 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("smart 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", lvm_init); plugin_register_read("lvm", lvm_read); } /* void module_register */