From: Ruben Kerkhof Date: Fri, 24 Feb 2017 16:40:41 +0000 (+0100) Subject: Merge pull request #2151 from mfournier/check_capability-rewrite-fix X-Git-Tag: collectd-5.7.2~10^2~4 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=a2ddc38;hp=f1b6145ce2bf1bc5061c4aafcf63e90bdc6b8b5c;p=collectd.git Merge pull request #2151 from mfournier/check_capability-rewrite-fix daemon/common.c: Fix check_capability() by using cap_get_proc() --- diff --git a/contrib/redhat/collectd.spec b/contrib/redhat/collectd.spec index 33cc985e..4d8041fc 100644 --- a/contrib/redhat/collectd.spec +++ b/contrib/redhat/collectd.spec @@ -230,13 +230,13 @@ 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 %if 0%{?fedora} || 0%{?rhel} >= 7 @@ -2515,6 +2515,9 @@ fi %doc contrib/ %changelog +* Wed Feb 22 2017 Ruben Kerkhof - 5.6.1-3 +- Enable XFS support in df plugin + * Tue Nov 29 2016 Ruben Kerkhof - 5.6.1-2 - Disable redis plugin on RHEL < 7, hiredis has been retired from EPEL6 diff --git a/contrib/systemd.collectd.service b/contrib/systemd.collectd.service index d0f1bdea..7bc15d7c 100644 --- a/contrib/systemd.collectd.service +++ b/contrib/systemd.collectd.service @@ -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: diff --git a/src/Makefile.am b/src/Makefile.am index eb55de30..f8dc2837 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 60ce91fd..b947349e 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -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); } diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c index cd815825..be5dfd6e 100644 --- a/src/daemon/utils_match.c +++ b/src/daemon/utils_match.c @@ -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 */ diff --git a/src/log_logstash.c b/src/log_logstash.c index 83779619..3ef71397 100644 --- a/src/log_logstash.c +++ b/src/log_logstash.c @@ -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); diff --git a/src/logfile.c b/src/logfile.c index e51c9db9..ef3aa97e 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -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) diff --git a/src/smart.c b/src/smart.c index 93bfcbec..5bb6af43 100644 --- a/src/smart.c +++ b/src/smart.c @@ -33,6 +33,10 @@ #include #include +#ifdef HAVE_SYS_CAPABILITY_H +#include +#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 */