X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=a167122cd9dcf6412ebc297fb902b3336a2465e3;hb=4d3d0c9713859c9edd7cd88b5ef786e3630a846c;hp=1fa99eb245682114ea04e85457c4462121426b34;hpb=e4504c3cc5582ab915903e1b4ba010545ffc8354;p=collectd.git diff --git a/src/daemon/common.c b/src/daemon/common.c index 1fa99eb2..a167122c 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -37,10 +37,6 @@ #include "plugin.h" #include "utils_cache.h" -#ifdef HAVE_MATH_H -#include -#endif - /* for getaddrinfo */ #include #include @@ -154,7 +150,7 @@ char *sstrdup(const char *s) { ERROR("sstrdup: Out of memory."); exit(3); } - memcpy(r, s, sizeof(char) * sz); + memcpy(r, s, sz); return (r); } /* char *sstrdup */ @@ -1568,16 +1564,26 @@ void strarray_free(char **array, size_t array_len) /* {{{ */ #if HAVE_CAPABILITY int check_capability(int arg) /* {{{ */ { - cap_value_t cap = (cap_value_t)arg; + cap_value_t cap_value = (cap_value_t)arg; + cap_t cap; + cap_flag_value_t cap_flag_value; - if (!CAP_IS_SUPPORTED(cap)) + if (!CAP_IS_SUPPORTED(cap_value)) return (-1); - int have_cap = cap_get_bound(cap); - if (have_cap != 1) + if (!(cap = cap_get_proc())) { + ERROR("check_capability: cap_get_proc failed."); return (-1); + } - return (0); + if (cap_get_flag(cap, cap_value, CAP_EFFECTIVE, &cap_flag_value) < 0) { + ERROR("check_capability: cap_get_flag failed."); + cap_free(cap); + return (-1); + } + cap_free(cap); + + return (cap_flag_value != CAP_SET); } /* }}} int check_capability */ #else int check_capability(__attribute__((unused)) int arg) /* {{{ */