X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flvm.c;h=3077c93cc5ee4ff185efb1369bce647fcf117257;hb=956a2f4996d9fb0526b6f60c29be9b17c0ad27ba;hp=f6ca577e2cf51ef16c2d960a74a9754103fd36de;hpb=79963d13c1884d1d92667cc502ad20758b084a12;p=collectd.git diff --git a/src/lvm.c b/src/lvm.c index f6ca577e..3077c93c 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -18,15 +18,19 @@ * * Authors: * Chad Malfait - * Benjamin Gilbert + * 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 @@ -52,15 +56,11 @@ static char const *get_lv_property_string(lv_t lv, char const *property) { static void lvm_submit(char const *plugin_instance, char const *type_instance, uint64_t ivalue) { - value_t v; value_list_t vl = VALUE_LIST_INIT; - v.gauge = (gauge_t)ivalue; - - vl.values = &v; + vl.values = &(value_t){.gauge = (gauge_t)ivalue}; vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "lvm", sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, "df_complex", sizeof(vl.type)); @@ -160,14 +160,14 @@ static int lvm_read(void) { lvm = lvm_init(NULL); if (!lvm) { ERROR("lvm plugin: lvm_init failed."); - return (-1); + return -1; } vg_names = lvm_list_vg_names(lvm); if (!vg_names) { ERROR("lvm plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm)); lvm_quit(lvm); - return (-1); + return -1; } dm_list_iterate_items(name_list, vg_names) { @@ -185,9 +185,27 @@ static int lvm_read(void) { } lvm_quit(lvm); - return (0); + 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 */