From: Ruben Kerkhof Date: Sat, 31 Mar 2018 10:18:39 +0000 (+0200) Subject: Merge pull request #2716 from dago/kstat X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=182556dd5a43942797591f0f49ac6f488c07010d;hp=45df07a30926475b2a33f63f79cda615928a7d96;p=collectd.git Merge pull request #2716 from dago/kstat Include kstat.h when available --- diff --git a/README b/README index ca86c84d..a47b669d 100644 --- a/README +++ b/README @@ -100,6 +100,9 @@ Features Collect DPDK interface statistics. See docs/BUILD.dpdkstat.md for detailed build instructions. + This plugin should be compiled with compiler defenses enabled, for + example -fstack-protector. + - drbd Collect individual drbd resource statistics. @@ -140,6 +143,9 @@ Features hugepages can be found here: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt. + This plugin should be compiled with compiler defenses enabled, for + example -fstack-protector. + - intel_pmu The intel_pmu plugin reads performance counters provided by the Linux kernel perf interface. The plugin uses jevents library to resolve named diff --git a/contrib/exec-munin.px b/contrib/exec-munin.px index 3e62ce00..5309cc66 100755 --- a/contrib/exec-munin.px +++ b/contrib/exec-munin.px @@ -56,7 +56,7 @@ exit (0); =head1 CONFIGURATION -This script reads it's configuration from F. The +This script reads its configuration from F. The configuration is read using C which understands a Apache-like config syntax, so it's very similar to the F syntax, too. diff --git a/contrib/exec-nagios.px b/contrib/exec-nagios.px index ec13b0a0..b9758ec9 100755 --- a/contrib/exec-nagios.px +++ b/contrib/exec-nagios.px @@ -36,7 +36,7 @@ exit (0); =head1 CONFIGURATION -This script reads it's configuration from F. The +This script reads its configuration from F. The configuration is read using C which understands a Apache-like config syntax, so it's very similar to the F syntax, too. diff --git a/contrib/php-collection/functions.php b/contrib/php-collection/functions.php index fa2badce..c063d57d 100644 --- a/contrib/php-collection/functions.php +++ b/contrib/php-collection/functions.php @@ -536,7 +536,7 @@ function rrd_get_color($code, $line = true) { } /** - * Draw RRD file based on it's structure + * Draw RRD file based on its structure * @host * @plugin * @pinst @@ -635,7 +635,7 @@ function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null, } /** - * Draw RRD file based on it's structure + * Draw RRD file based on its structure * @timespan * @host * @plugin diff --git a/src/collectd-exec.pod b/src/collectd-exec.pod index c65966bd..b8786579 100644 --- a/src/collectd-exec.pod +++ b/src/collectd-exec.pod @@ -73,7 +73,7 @@ Each line beginning with a C<#> (hash mark) is ignored. =item B I [I] I Submits one or more values (identified by I, see below) to the -daemon which will dispatch it to all it's write-plugins. +daemon which will dispatch it to all its write-plugins. An I is of the form CBIB<->IBIB<->I> with both diff --git a/src/collectd-nagios.pod b/src/collectd-nagios.pod index e28ff4b8..4ff0bf67 100644 --- a/src/collectd-nagios.pod +++ b/src/collectd-nagios.pod @@ -107,7 +107,7 @@ consolidations simply ignore NaN values. =head1 RETURN VALUE As usual for Nagios plugins, this program writes a short, one line status -message to STDOUT and signals success or failure with it's return value. It +message to STDOUT and signals success or failure with its return value. It exits with a return value of B<0> for I, B<1> for I and B<2> for I. If the values are not available or some other error occurred, it returns B<3> for I. diff --git a/src/collectd-threshold.pod b/src/collectd-threshold.pod index 35f8a9fc..14f2c8ce 100644 --- a/src/collectd-threshold.pod +++ b/src/collectd-threshold.pod @@ -40,7 +40,7 @@ Also, all values that match a threshold are considered to be relevant or "interesting". As a consequence collectd will issue a notification if they are not received for B iterations. The B configuration option is explained in section L. If, for example, -B is set to "2" (the default) and some hosts sends it's CPU statistics +B is set to "2" (the default) and some hosts sends its CPU statistics to the server every 60 seconds, a notification will be dispatched after about 120 seconds. It may take a little longer because the timeout is checked only once each B on the server. diff --git a/src/collectd-unixsock.pod b/src/collectd-unixsock.pod index b241a9f3..db7000a1 100644 --- a/src/collectd-unixsock.pod +++ b/src/collectd-unixsock.pod @@ -84,7 +84,7 @@ Example: =item B I [I] I Submits one or more values (identified by I, see below) to the -daemon which will dispatch it to all it's write-plugins. +daemon which will dispatch it to all its write-plugins. An I is of the form CBIB<->IBIB<->I> with both diff --git a/src/collectd.pod b/src/collectd.pod index 1dd899b8..60707a1d 100644 --- a/src/collectd.pod +++ b/src/collectd.pod @@ -69,7 +69,7 @@ Output usage information and exit. =head1 PLUGINS -As noted above, the real power of collectd lies within it's plugins. A +As noted above, the real power of collectd lies within its plugins. A (hopefully complete) list of plugins and short descriptions can be found in the F file that is distributed with the sourcecode. If you're using a package it's a good bet to search somewhere near F. diff --git a/src/disk.c b/src/disk.c index 45706bc2..116fc244 100644 --- a/src/disk.c +++ b/src/disk.c @@ -142,7 +142,7 @@ static int pnumdisk; #error "No applicable input method." #endif -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H #include static char *conf_udev_name_attr = NULL; @@ -176,7 +176,7 @@ static int disk_config(const char *key, const char *value) { "on Mach / Mac OS X and will be ignored."); #endif } else if (strcasecmp("UdevNameAttr", key) == 0) { -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (conf_udev_name_attr != NULL) { free(conf_udev_name_attr); conf_udev_name_attr = NULL; @@ -212,7 +212,7 @@ static int disk_init(void) { /* #endif HAVE_IOKIT_IOKITLIB_H */ #elif KERNEL_LINUX -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (conf_udev_name_attr != NULL) { handle_udev = udev_new(); if (handle_udev == NULL) { @@ -220,7 +220,7 @@ static int disk_init(void) { return -1; } } -#endif /* HAVE_UDEV_H */ +#endif /* HAVE_LIBUDEV_H */ /* #endif KERNEL_LINUX */ #elif KERNEL_FREEBSD @@ -263,10 +263,10 @@ static int disk_init(void) { static int disk_shutdown(void) { #if KERNEL_LINUX -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (handle_udev != NULL) udev_unref(handle_udev); -#endif /* HAVE_UDEV_H */ +#endif /* HAVE_LIBUDEV_H */ #endif /* KERNEL_LINUX */ return 0; } /* int disk_shutdown */ @@ -328,7 +328,7 @@ static counter_t disk_calc_time_incr(counter_t delta_time, } #endif -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /** * Attempt to provide an rename disk instance from an assigned udev attribute. * @@ -844,7 +844,7 @@ static int disk_read(void) { output_name = disk_name; -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H char *alt_name = NULL; if (conf_udev_name_attr != NULL) { alt_name = @@ -855,7 +855,7 @@ static int disk_read(void) { #endif if (ignorelist_match(ignorelist, output_name) != 0) { -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif @@ -881,7 +881,7 @@ static int disk_read(void) { submit_io_time(output_name, io_time, weighted_time); } /* if (is_disk) */ -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif diff --git a/src/ipmi.c b/src/ipmi.c index 2db344e6..6a72b2b7 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -785,11 +785,9 @@ entity_sensor_update_handler(enum ipmi_update_e op, if (st->sel_enabled) { int status = 0; - /* register threshold event if threshold sensor support events */ - if ((ipmi_sensor_get_event_reading_type(sensor) == - IPMI_EVENT_READING_TYPE_THRESHOLD) && - (ipmi_sensor_get_threshold_access(sensor) != - IPMI_THRESHOLD_ACCESS_SUPPORT_NONE)) + /* register threshold event handler */ + if (ipmi_sensor_get_event_reading_type(sensor) == + IPMI_EVENT_READING_TYPE_THRESHOLD) status = ipmi_sensor_add_threshold_event_handler( sensor, sensor_threshold_event_handler, st); /* register discrete handler if discrete/specific sensor support events */ @@ -1210,7 +1208,7 @@ static int c_ipmi_init(void) { } /* Don't send `ADD' notifications during startup (~ 1 minute) */ - int cycles = 1 + (60 / CDTIME_T_TO_TIME_T(plugin_get_interval())); + int cycles = 1 + (int)(TIME_T_TO_CDTIME_T(60) / plugin_get_interval()); st = instances; while (NULL != st) { diff --git a/src/mysql.c b/src/mysql.c index 7fe6d764..448f7cba 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -270,12 +270,16 @@ static MYSQL *getconnection(mysql_database_t *db) { } db->is_connected = 0; + /* Close the old connection before initializing a new one. */ + if (db->con != NULL) { + mysql_close(db->con); + db->con = NULL; + } + + db->con = mysql_init(NULL); if (db->con == NULL) { - db->con = mysql_init(NULL); - if (db->con == NULL) { - ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); - return NULL; - } + ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); + return NULL; } /* Configure TCP connect timeout (default: 0) */ diff --git a/src/netlink.c b/src/netlink.c index 0f71ce7c..1978eb43 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -358,10 +358,9 @@ static int link_filter_cb(const struct nlmsghdr *nlh, continue; if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats64)) < 0) { - char errbuf[1024]; ERROR("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 " "failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return MNL_CB_ERROR; } stats.stats64 = mnl_attr_get_payload(attr); @@ -376,10 +375,9 @@ static int link_filter_cb(const struct nlmsghdr *nlh, continue; if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats32)) < 0) { - char errbuf[1024]; ERROR("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 " "failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return MNL_CB_ERROR; } stats.stats32 = mnl_attr_get_payload(attr); @@ -404,10 +402,9 @@ static int qos_attr_cb(const struct nlattr *attr, void *data) { if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) { if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) { - char errbuf[1024]; ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 " "failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return MNL_CB_ERROR; } q_stats->bs = mnl_attr_get_payload(attr); @@ -556,10 +553,9 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { continue; if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*ts)) < 0) { - char errbuf[1024]; ERROR("netlink plugin: qos_filter_cb: TCA_STATS mnl_attr_validate2 " "failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return MNL_CB_ERROR; } ts = mnl_attr_get_payload(attr); @@ -694,9 +690,7 @@ static int ir_read(void) { ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); } if (ret < 0) { - char errbuf[1024]; - ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s", STRERRNO); return (-1); } @@ -741,9 +735,8 @@ static int ir_read(void) { ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); } if (ret < 0) { - char errbuf[1024]; ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); continue; } } /* for (type_index) */ diff --git a/src/ovs_events.c b/src/ovs_events.c index bf457fdb..ef59b4c2 100644 --- a/src/ovs_events.c +++ b/src/ovs_events.c @@ -404,14 +404,14 @@ static int ovs_events_get_iface_info(yajl_val jobject, if (!YAJL_IS_OBJECT(jobject)) return -1; - /* zero the interface info structure */ - memset(ifinfo, 0, sizeof(*ifinfo)); - /* try to find external_ids, name and link_state fields */ jexternal_ids = ovs_utils_get_value_by_key(jobject, "external_ids"); if (jexternal_ids == NULL || ifinfo == NULL) return -1; + /* zero the interface info structure */ + memset(ifinfo, 0, sizeof(*ifinfo)); + /* get iface-id from external_ids field */ jvalue = ovs_utils_get_map_value(jexternal_ids, "iface-id"); if (jvalue != NULL && YAJL_IS_STRING(jvalue)) diff --git a/src/ovs_stats.c b/src/ovs_stats.c index e027845e..f513e72e 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -244,6 +244,9 @@ static port_list_t *ovs_stats_get_port_by_name(const char *name) { /* Create or get port by port uuid */ static port_list_t *ovs_stats_new_port(bridge_list_t *bridge, const char *uuid) { + if (uuid == NULL) + return NULL; + port_list_t *port = ovs_stats_get_port(uuid); if (port == NULL) { @@ -357,21 +360,33 @@ static int ovs_stats_update_bridge(yajl_val bridge) { yajl_val *array = YAJL_GET_ARRAY(br_ports)->values; size_t array_len = YAJL_GET_ARRAY(br_ports)->len; if (array != NULL && array_len > 0 && YAJL_IS_ARRAY(array[1])) { - yajl_val *ports_arr = YAJL_GET_ARRAY(array[1])->values; - size_t ports_num = YAJL_GET_ARRAY(array[1])->len; - for (size_t i = 0; i < ports_num && ports_arr != NULL; i++) - ovs_stats_new_port( - br, YAJL_GET_STRING(ports_arr[i]->u.array.values[1])); + if (YAJL_GET_ARRAY(array[1]) == NULL) + goto failure; + else { + yajl_val *ports_arr = YAJL_GET_ARRAY(array[1])->values; + size_t ports_num = YAJL_GET_ARRAY(array[1])->len; + for (size_t i = 0; i < ports_num && ports_arr != NULL; i++) { + tmp = YAJL_GET_STRING(ports_arr[i]->u.array.values[1]); + if (tmp != NULL) + ovs_stats_new_port(br, tmp); + else + goto failure; + } + } } } else ovs_stats_new_port(br, YAJL_GET_STRING(br_ports->u.array.values[1])); } } } else { - ERROR("Incorrect JSON Bridge data"); - return -1; + goto failure; } + return 0; + +failure: + ERROR("Incorrect JSON Bridge data"); + return -1; } /* Handle JSON with Bridge Table change event */ @@ -629,10 +644,15 @@ static int ovs_stats_update_iface(yajl_val iface) { ovs_stats_update_iface_ext_ids(port, YAJL_GET_ARRAY(iface_ext_ids)->values[1]); if (iface_uuid && YAJL_IS_ARRAY(iface_uuid) && - YAJL_GET_ARRAY(iface_uuid)->len == 2) + YAJL_GET_ARRAY(iface_uuid)->len == 2 && + YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]) != NULL) sstrncpy(port->iface_uuid, YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]), sizeof(port->iface_uuid)); + else { + ERROR("ovs_stats plugin: incorrect JSON interface data"); + return -1; + } return 0; } @@ -833,6 +853,7 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) { char *br_name_dup = strdup(br_name); if (br_name_dup == NULL) { ERROR("%s: strdup() copy bridge name fail", plugin_name); + sfree(bridge); goto cleanup_fail; } diff --git a/src/utils_dpdk.c b/src/utils_dpdk.c index 30a10574..adc55306 100644 --- a/src/utils_dpdk.c +++ b/src/utils_dpdk.c @@ -831,7 +831,7 @@ uint128_t str_to_uint128(const char *str, int len) { return lcore_mask; } else { char low_str[DATA_MAX_NAME_LEN]; - char high_str[DATA_MAX_NAME_LEN]; + char high_str[DATA_MAX_NAME_LEN * 2]; memset(high_str, 0, sizeof(high_str)); memset(low_str, 0, sizeof(low_str)); diff --git a/src/utils_latency.c b/src/utils_latency.c index 625fc42e..1d3bf2e9 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -65,7 +65,7 @@ struct latency_counter_s { * When a value above this range is added, Histogram's range is increased by * increasing the bin width (note that number of bins remains always at 1000). * This operation of increasing bin width is little expensive as each bin need -* to be visited to update it's count. To reduce frequent change of bin width, +* to be visited to update its count. To reduce frequent change of bin width, * new bin width will be the next nearest power of 2. Example: 2, 4, 8, 16, 32, * 64, 128, 256, 512, 1024, 2048, 5086, ... * diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 0ee05e00..ca631812 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -1001,6 +1001,8 @@ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { ovs_db_t *ovs_db_init(const char *node, const char *service, const char *unix_path, ovs_db_callback_t *cb) { + int ret; + /* sanity check */ if (node == NULL || service == NULL || unix_path == NULL) return NULL; @@ -1046,16 +1048,25 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, /* init event thread */ if (ovs_db_event_thread_init(pdb) < 0) { - ovs_db_destroy(pdb); - return NULL; + ret = ovs_db_destroy(pdb); + if (ret > 0) + goto failure; } /* init polling thread */ if (ovs_db_poll_thread_init(pdb) < 0) { - ovs_db_destroy(pdb); - return NULL; + ret = ovs_db_destroy(pdb); + if (ret > 0) { + ovs_db_event_thread_data_destroy(pdb); + goto failure; + } } return pdb; + +failure: + pthread_mutex_destroy(&pdb->mutex); + sfree(pdb); + return NULL; } int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params, @@ -1265,7 +1276,7 @@ int ovs_db_destroy(ovs_db_t *pdb) { /* try to lock the structure before releasing */ if ((ret = pthread_mutex_lock(&pdb->mutex))) { OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret); - return -1; + return ret; } /* stop poll thread and destroy thread's private data */ @@ -1364,15 +1375,18 @@ yajl_val ovs_utils_get_map_value(yajl_val jval, const char *key) { /* check first element of the array */ str_val = YAJL_GET_STRING(array_values[0]); - if (strcmp("map", str_val) != 0) + if (str_val == NULL || strcmp("map", str_val) != 0) return NULL; /* try to find map value by map key */ + if (YAJL_GET_ARRAY(array_values[1]) == NULL) + return NULL; + map_len = YAJL_GET_ARRAY(array_values[1])->len; map_values = YAJL_GET_ARRAY(array_values[1])->values; for (size_t i = 0; i < map_len; i++) { /* check YAJL array */ - if (!YAJL_IS_ARRAY(map_values[i])) + if (!YAJL_IS_ARRAY(map_values[i]) || YAJL_GET_ARRAY(map_values[i]) == NULL) break; /* check a database pair value (2-element, first one represents a key @@ -1384,7 +1398,7 @@ yajl_val ovs_utils_get_map_value(yajl_val jval, const char *key) { /* return map value if given key equals map key */ str_val = YAJL_GET_STRING(array_values[0]); - if (strcmp(key, str_val) == 0) + if (str_val != NULL && strcmp(key, str_val) == 0) return array_values[1]; } return NULL; diff --git a/src/uuid.c b/src/uuid.c index 4846841b..1cb90270 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -193,7 +193,7 @@ static int uuid_init(void) { char *uuid = uuid_get_local(); if (uuid) { - sstrncpy(hostname_g, uuid, DATA_MAX_NAME_LEN); + hostname_set(uuid); sfree(uuid); return 0; } diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 7c4e59e7..26b0b4d4 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -59,7 +59,7 @@ static struct MHD_Daemon *httpd; static cdtime_t staleness_delta = PROMETHEUS_DEFAULT_STALENESS_DELTA; -/* Unfortunately, protoc-c doesn't export it's implementation of varint, so we +/* Unfortunately, protoc-c doesn't export its implementation of varint, so we * need to implement our own. */ static size_t varint(uint8_t buffer[static VARINT_UINT32_BYTES], uint32_t value) { @@ -766,9 +766,8 @@ static int prom_open_socket(int addrfamily) { int tmp = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp)) != 0) { - char errbuf[1024]; WARNING("write_prometheus: setsockopt(SO_REUSEADDR) failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); close(fd); fd = -1; continue;