From a3b73247f54fed7e020e01bdc6432f06f2954048 Mon Sep 17 00:00:00 2001 From: Vincent Brillault Date: Fri, 17 Apr 2015 17:03:35 +0200 Subject: [PATCH] Turbostat: Only check capabilities if supported --- configure.ac | 2 ++ src/turbostat.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/configure.ac b/configure.ac index 0f9f33be..ba629107 100644 --- a/configure.ac +++ b/configure.ac @@ -589,6 +589,8 @@ AC_CHECK_HEADERS(net/pfvar.h, have_termios_h="no" AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"]) +# For the turbostat plugin +AC_CHECK_HEADERS(sys/capability.h) # # Checks for typedefs, structures, and compiler characteristics. # diff --git a/src/turbostat.c b/src/turbostat.c index 648ec404..61c2abd4 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -42,7 +42,9 @@ #include #include +#ifdef HAVE_SYS_CAPABILITY_H #include +#endif /* HAVE_SYS_CAPABILITY_H */ #define PLUGIN_NAME "turbostat" @@ -1463,15 +1465,24 @@ out: static int check_permissions(void) { +#ifdef HAVE_SYS_CAPABILITY_H struct __user_cap_header_struct cap_header_data; cap_user_header_t cap_header = &cap_header_data; struct __user_cap_data_struct cap_data_data; cap_user_data_t cap_data = &cap_data_data; int ret = 0; +#endif /* HAVE_SYS_CAPABILITY_H */ if (getuid() == 0) { /* We have everything we need */ return 0; +#ifndef HAVE_SYS_CAPABILITY_H + } else { + ERROR("Turbostat plugin: Initialization failed: this plugin " + "requires collectd to run as root"); + return -1; + } +#else /* HAVE_SYS_CAPABILITY_H */ } /* check for CAP_SYS_RAWIO */ @@ -1504,6 +1515,7 @@ check_permissions(void) "collectd a special capability (CAP_SYS_RAWIO) and read " "access to /dev/cpu/*/msr (see previous warnings)"); return ret; +#endif /* HAVE_SYS_CAPABILITY_H */ } static int -- 2.30.2