Merge pull request #2151 from mfournier/check_capability-rewrite-fix
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 24 Feb 2017 16:40:41 +0000 (17:40 +0100)
committerGitHub <noreply@github.com>
Fri, 24 Feb 2017 16:40:41 +0000 (17:40 +0100)
daemon/common.c: Fix check_capability() by using cap_get_proc()

contrib/redhat/collectd.spec
contrib/systemd.collectd.service
src/Makefile.am
src/daemon/collectd.c
src/daemon/utils_match.c
src/log_logstash.c
src/logfile.c
src/smart.c

index 33cc985..4d8041f 100644 (file)
 Summary:       Statistics collection and monitoring daemon
 Name:          collectd
 Version:       5.6.1
-Release:       2%{?dist}
+Release:       3%{?dist}
 URL:           https://collectd.org
 Source:                https://collectd.org/files/%{name}-%{version}.tar.bz2
 License:       GPLv2
 Group:         System Environment/Daemons
 BuildRoot:     %{_tmppath}/%{name}-%{version}-root
-BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, which
+BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, which, xfsprogs-devel
 Vendor:                collectd development team <collectd@verplant.org>
 
 %if 0%{?fedora} || 0%{?rhel} >= 7
@@ -2515,6 +2515,9 @@ fi
 %doc contrib/
 
 %changelog
+* Wed Feb 22 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.6.1-3
+- Enable XFS support in df plugin
+
 * Tue Nov 29 2016 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.6.1-2
 - Disable redis plugin on RHEL < 7, hiredis has been retired from EPEL6
 
index d0f1bde..7bc15d7 100644 (file)
@@ -20,6 +20,7 @@ ProtectHome=true
 #   exec            CAP_SETUID CAP_SETGID
 #   iptables        CAP_NET_ADMIN
 #   ping            CAP_NET_RAW
+#   smart           CAP_SYS_RAWIO
 #   turbostat       CAP_SYS_RAWIO
 #
 # Example, if you use the iptables plugin alongside the dns or ping plugin:
index eb55de3..f8dc283 100644 (file)
@@ -787,7 +787,7 @@ if BUILD_PLUGIN_NOTIFY_EMAIL
 pkglib_LTLIBRARIES += notify_email.la
 notify_email_la_SOURCES = notify_email.c
 notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-notify_email_la_LIBADD = -lesmtp -lssl -lcrypto
+notify_email_la_LIBADD = -lesmtp
 endif
 
 if BUILD_PLUGIN_NOTIFY_NAGIOS
index 60ce91f..b947349 100644 (file)
@@ -522,7 +522,7 @@ int main(int argc, char **argv) {
    */
   if (cf_read(configfile)) {
     fprintf(stderr, "Error: Reading the config file failed!\n"
-                    "Read the syslog for details.\n");
+                    "Read the logs for details.\n");
     return (1);
   }
 
index cd81582..be5dfd6 100644 (file)
@@ -35,6 +35,7 @@
 
 #define UTILS_MATCH_FLAGS_FREE_USER_DATA 0x01
 #define UTILS_MATCH_FLAGS_EXCLUDE_REGEX 0x02
+#define UTILS_MATCH_FLAGS_REGEX 0x04
 
 struct cu_match_s {
   regex_t regex;
@@ -218,6 +219,7 @@ match_create_callback(const char *regex, const char *excluderegex,
     sfree(obj);
     return (NULL);
   }
+  obj->flags |= UTILS_MATCH_FLAGS_REGEX;
 
   if (excluderegex && strcmp(excluderegex, "") != 0) {
     status = regcomp(&obj->excluderegex, excluderegex, REG_EXTENDED);
@@ -271,9 +273,12 @@ void match_destroy(cu_match_t *obj) {
   if (obj == NULL)
     return;
 
-  if (obj->flags & UTILS_MATCH_FLAGS_FREE_USER_DATA) {
+  if (obj->flags & UTILS_MATCH_FLAGS_FREE_USER_DATA)
     sfree(obj->user_data);
-  }
+  if (obj->flags & UTILS_MATCH_FLAGS_REGEX)
+    regfree(&obj->regex);
+  if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX)
+    regfree(&obj->excluderegex);
 
   sfree(obj);
 } /* void match_destroy */
index 8377961..3ef7139 100644 (file)
@@ -41,8 +41,6 @@
 #define HAVE_YAJL_V2 1
 #endif
 
-#define DEFAULT_LOGFILE LOCALSTATEDIR "/log/" PACKAGE_NAME ".json.log"
-
 #if COLLECT_DEBUG
 static int log_level = LOG_DEBUG;
 #else
@@ -151,8 +149,7 @@ static void log_logstash_print(yajl_gen g, int severity,
   pthread_mutex_lock(&file_lock);
 
   if (log_file == NULL) {
-    fh = fopen(DEFAULT_LOGFILE, "a");
-    do_close = 1;
+    fh = stderr;
   } else if (strcasecmp(log_file, "stdout") == 0) {
     fh = stdout;
     do_close = 0;
@@ -166,8 +163,7 @@ static void log_logstash_print(yajl_gen g, int severity,
 
   if (fh == NULL) {
     char errbuf[1024];
-    fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n",
-            (log_file == NULL) ? DEFAULT_LOGFILE : log_file,
+    fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", log_file,
             sstrerror(errno, errbuf, sizeof(errbuf)));
   } else {
     fprintf(fh, "%s\n", buf);
index e51c9db..ef3aa97 100644 (file)
@@ -31,8 +31,6 @@
 #include "common.h"
 #include "plugin.h"
 
-#define DEFAULT_LOGFILE LOCALSTATEDIR "/log/collectd.log"
-
 #if COLLECT_DEBUG
 static int log_level = LOG_DEBUG;
 #else
@@ -118,8 +116,7 @@ static void logfile_print(const char *msg, int severity,
   pthread_mutex_lock(&file_lock);
 
   if (log_file == NULL) {
-    fh = fopen(DEFAULT_LOGFILE, "a");
-    do_close = 1;
+    fh = stderr;
   } else if (strcasecmp(log_file, "stderr") == 0)
     fh = stderr;
   else if (strcasecmp(log_file, "stdout") == 0)
@@ -131,8 +128,7 @@ static void logfile_print(const char *msg, int severity,
 
   if (fh == NULL) {
     char errbuf[1024];
-    fprintf(stderr, "logfile plugin: fopen (%s) failed: %s\n",
-            (log_file == NULL) ? DEFAULT_LOGFILE : log_file,
+    fprintf(stderr, "logfile plugin: fopen (%s) failed: %s\n", log_file,
             sstrerror(errno, errbuf, sizeof(errbuf)));
   } else {
     if (print_timestamp)
index 93bfcbe..5bb6af4 100644 (file)
 #include <atasmart.h>
 #include <libudev.h>
 
+#ifdef HAVE_SYS_CAPABILITY_H
+#include <sys/capability.h>
+#endif
+
 static const char *config_keys[] = {"Disk", "IgnoreSelected", "IgnoreSleepMode",
                                     "UseSerial"};
 
@@ -241,7 +245,25 @@ static int smart_read(void) {
   return (0);
 } /* int smart_read */
 
+static int smart_init(void) {
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SYS_RAWIO)
+  if (check_capability(CAP_SYS_RAWIO) != 0) {
+    if (getuid() == 0)
+      WARNING("smart plugin: Running collectd as root, but the "
+              "CAP_SYS_RAWIO capability is missing. The plugin's read "
+              "function will probably fail. Is your init system dropping "
+              "capabilities?");
+    else
+      WARNING("smart plugin: collectd doesn't have the CAP_SYS_RAWIO "
+              "capability. If you don't want to run collectd as root, try "
+              "running \"setcap cap_sys_rawio=ep\" on the collectd binary.");
+  }
+#endif
+  return (0);
+} /* int smart_init */
+
 void module_register(void) {
   plugin_register_config("smart", smart_config, config_keys, config_keys_num);
+  plugin_register_init("smart", smart_init);
   plugin_register_read("smart", smart_read);
 } /* void module_register */