From: Ruben Kerkhof Date: Fri, 24 Feb 2017 16:44:55 +0000 (+0100) Subject: Merge branch 'collectd-5.6' into collectd-5.7 X-Git-Tag: collectd-5.7.2~14 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=11c8a760c2d354b2f4637bdb297efb253bfaa519;hp=004074af297a219208fa9e903db8c5dcdd7e1950 Merge branch 'collectd-5.6' into collectd-5.7 --- diff --git a/configure.ac b/configure.ac index ab6f2298..366ef9b6 100644 --- a/configure.ac +++ b/configure.ac @@ -835,12 +835,12 @@ AC_CHECK_HEADERS(sys/capability.h, [have_capability="yes"], [have_capability="no ( not found)"]) if test "x$have_capability" = "xyes"; then -AC_CHECK_LIB(cap, cap_get_bound, +AC_CHECK_LIB(cap, cap_get_proc, [have_capability="yes"], - [have_capability="no (cap_get_bound() not found)"]) + [have_capability="no (cap_get_proc() not found)"]) fi if test "x$have_capability" = "xyes"; then - AC_DEFINE(HAVE_CAPABILITY, 1, [Define to 1 if you have cap_get_bound() (-lcap).]) + AC_DEFINE(HAVE_CAPABILITY, 1, [Define to 1 if you have cap_get_proc() (-lcap).]) fi AM_CONDITIONAL(BUILD_WITH_CAPABILITY, test "x$have_capability" = "xyes") diff --git a/src/daemon/common.c b/src/daemon/common.c index 1fa99eb2..ec5c7aba 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -1568,16 +1568,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) /* {{{ */ diff --git a/src/daemon/common.h b/src/daemon/common.h index a1a25289..8947c575 100644 --- a/src/daemon/common.h +++ b/src/daemon/common.h @@ -385,7 +385,7 @@ void strarray_free(char **array, size_t array_len); * argument. Returns zero if it does, less than zero if it doesn't or on error. * See capabilities(7) for the list of possible capabilities. * */ -int check_capability(int capability); +int check_capability(int arg); #endif /* HAVE_SYS_CAPABILITY_H */ #endif /* COMMON_H */