summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 844b714)
raw | patch | inline | side by side (parent: 844b714)
author | Vincent Brillault <git@lerya.net> | |
Fri, 17 Apr 2015 15:03:35 +0000 (17:03 +0200) | ||
committer | Vincent Brillault <git@lerya.net> | |
Fri, 17 Apr 2015 15:03:35 +0000 (17:03 +0200) |
configure.ac | patch | blob | history | |
src/turbostat.c | patch | blob | history |
diff --git a/configure.ac b/configure.ac
index 0f9f33be6081db2f671290436e854679221502c0..ba629107f35a7c5eda79605809d2890566e0da51 100644 (file)
--- a/configure.ac
+++ b/configure.ac
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 648ec4043b6e5d5704619184b582fc13fe581ad9..61c2abd4f61727893a11fcccc0e43f280a54e015 100644 (file)
--- a/src/turbostat.c
+++ b/src/turbostat.c
#include <asm/msr-index.h>
#include <cpuid.h>
+#ifdef HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
+#endif /* HAVE_SYS_CAPABILITY_H */
#define PLUGIN_NAME "turbostat"
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 */
"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