Merge pull request #3342 from zebity/master
authorMatthias Runge <mrunge@redhat.com>
Thu, 6 Feb 2020 09:57:01 +0000 (10:57 +0100)
committerGitHub <noreply@github.com>
Thu, 6 Feb 2020 09:57:01 +0000 (10:57 +0100)
Restrict use of sys/systl to BSD variants in alignment with gclib deprecation on Linux

.travis.yml
configure.ac
src/aggregation.c
src/amqp1.c
src/battery.c
src/daemon/configfile.c
src/network.c
src/processes.c
src/thermal.c
src/utils/common/common.c
src/utils/common/common.h

index f715343..45fb898 100644 (file)
@@ -111,7 +111,6 @@ addons:
     packages:
     - curl
     - glib
-    - grpc
     - hiredis
     - libdbi
     - libmemcached
index 9fc40b1..00e1f6a 100644 (file)
@@ -4711,7 +4711,7 @@ if test "$PYTHON_CONFIG" != ""; then
   if test $? -ne 0; then
     with_libpython="no"
   fi
-  LIBPYTHON_LDFLAGS="`${PYTHON_CONFIG} --ldflags`"
+  LIBPYTHON_LDFLAGS="`${PYTHON_CONFIG} --ldflags --embed`" || LIBPYTHON_LDFLAGS="`${PYTHON_CONFIG} --ldflags`"
   if test $? -ne 0; then
     with_libpython="no"
   fi
index 2c8ef88..e2f8ff1 100644 (file)
@@ -194,17 +194,21 @@ static int agg_instance_create_name(agg_instance_t *inst, /* {{{ */
       sstrncpy(tmp_plugin_instance, agg->ident.plugin_instance,
                sizeof(tmp_plugin_instance));
 
+    // Both tmp_plugin and tmp_plugin_instance are empty.
     if ((strcmp("", tmp_plugin) == 0) && (strcmp("", tmp_plugin_instance) == 0))
       sstrncpy(inst->ident.plugin_instance, AGG_FUNC_PLACEHOLDER,
                sizeof(inst->ident.plugin_instance));
-    else if (strcmp("", tmp_plugin) != 0)
+    // tmp_plugin is non-empty, and tmp_plugin_instance is empty.
+    else if (strcmp("", tmp_plugin_instance) == 0)
       ssnprintf(inst->ident.plugin_instance,
                 sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin,
                 AGG_FUNC_PLACEHOLDER);
-    else if (strcmp("", tmp_plugin_instance) != 0)
+    // tmp_plugin is empty, and tmp_plugin_instance is non-empty.
+    else if (strcmp("", tmp_plugin) == 0)
       ssnprintf(inst->ident.plugin_instance,
                 sizeof(inst->ident.plugin_instance), "%s-%s",
                 tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
+    // Both tmp_plugin and tmp_plugin_instance are non-empty.
     else
       ssnprintf(inst->ident.plugin_instance,
                 sizeof(inst->ident.plugin_instance), "%s-%s-%s", tmp_plugin,
index 67c96b7..4325f00 100644 (file)
@@ -572,8 +572,10 @@ static int amqp1_config_instance(oconfig_item_t *ci) /* {{{ */
     else if (strcasecmp("Format", child->key) == 0) {
       char *key = NULL;
       status = cf_util_get_string(child, &key);
-      if (status != 0)
+      if (status != 0) {
+        amqp1_config_instance_free(instance);
         return status;
+      }
       assert(key != NULL);
       if (strcasecmp(key, "Command") == 0) {
         instance->format = AMQP1_FORMAT_COMMAND;
@@ -627,12 +629,14 @@ static int amqp1_config_instance(oconfig_item_t *ci) /* {{{ */
     status = ssnprintf(tpname, sizeof(tpname), "amqp1/%s", instance->name);
     if ((status < 0) || (size_t)status >= sizeof(tpname)) {
       ERROR("amqp1 plugin: Instance name would have been truncated.");
+      amqp1_config_instance_free(instance);
       return -1;
     }
     status = ssnprintf(instance->send_to, sizeof(instance->send_to), "/%s/%s",
                        transport->address, instance->name);
     if ((status < 0) || (size_t)status >= sizeof(instance->send_to)) {
       ERROR("amqp1 plugin: send_to address would have been truncated.");
+      amqp1_config_instance_free(instance);
       return -1;
     }
     if (instance->notify) {
index 20ec261..9b5b82d 100644 (file)
@@ -349,12 +349,10 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */
 
   snprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, basename);
 
-  status = (int)read_file_contents(filename, buffer, buffer_size - 1);
+  status = (int)read_text_file_contents(filename, buffer, buffer_size);
   if (status < 0)
     return status;
 
-  buffer[status] = '\0';
-
   strstripnewline(buffer);
   return 0;
 } /* }}} int sysfs_file_to_buffer */
index 3a7364e..61fa901 100644 (file)
@@ -404,6 +404,10 @@ static int dispatch_block_plugin(oconfig_item_t *ci) {
     }
   }
 
+  /* Try to be backward-compatible with previous versions */
+  if (ci->children_num == 0)
+    return 0;
+
   /* Hm, no complex plugin found. Dispatch the values one by one */
   cf_callback_t *cf_cb = cf_search(plugin_name);
   if (cf_cb == NULL) {
index a1a6e3d..613caa7 100644 (file)
@@ -2762,6 +2762,7 @@ network_config_set_bind_address(const oconfig_item_t *ci,
   *bind_address = malloc(sizeof(**bind_address));
   if (*bind_address == NULL) {
     ERROR("network plugin: network_config_set_bind_address: malloc failed.");
+    freeaddrinfo(res);
     return -1;
   }
   (*bind_address)->ss_family = res->ai_family;
index f83913a..4761f60 100644 (file)
@@ -1316,11 +1316,10 @@ static int ps_read_process(long pid, process_entry_t *ps, char *state) {
 
   snprintf(filename, sizeof(filename), "/proc/%li/stat", pid);
 
-  status = read_file_contents(filename, buffer, sizeof(buffer) - 1);
+  status = read_text_file_contents(filename, buffer, sizeof(buffer));
   if (status <= 0)
     return -1;
   buffer_len = (size_t)status;
-  buffer[buffer_len] = 0;
 
   /* The name of the process is enclosed in parens. Since the name can
    * contain parens itself, spaces, numbers and pretty much everything
@@ -1569,7 +1568,7 @@ static char *ps_get_cmdline(long pid,
 
   snprintf(path, sizeof(path), "/proc/%li/psinfo", pid);
 
-  status = read_file_contents(path, (void *)&info, sizeof(info));
+  status = read_file_contents(path, &info, sizeof(info));
   if ((status < 0) || (((size_t)status) != sizeof(info))) {
     ERROR("processes plugin: Unexpected return value "
           "while reading \"%s\": "
index 5f44836..1ed5617 100644 (file)
@@ -103,7 +103,7 @@ static int thermal_procfs_device_read(const char __attribute__((unused)) * dir,
   if ((len < 0) || ((size_t)len >= sizeof(filename)))
     return -1;
 
-  len = (ssize_t)read_file_contents(filename, data, sizeof(data));
+  len = (ssize_t)read_text_file_contents(filename, data, sizeof(data));
   if ((len > 0) && ((size_t)len > sizeof(str_temp)) && (data[--len] == '\n') &&
       (!strncmp(data, str_temp, sizeof(str_temp) - 1))) {
     char *endptr = NULL;
index aad767e..2cebc0d 100644 (file)
@@ -1263,7 +1263,7 @@ int walk_directory(const char *dir, dirwalk_callback_f callback,
   return 0;
 }
 
-ssize_t read_file_contents(const char *filename, char *buf, size_t bufsize) {
+ssize_t read_file_contents(const char *filename, void *buf, size_t bufsize) {
   FILE *fh;
   ssize_t ret;
 
@@ -1281,6 +1281,16 @@ ssize_t read_file_contents(const char *filename, char *buf, size_t bufsize) {
   return ret;
 }
 
+ssize_t read_text_file_contents(const char *filename, char *buf,
+                                size_t bufsize) {
+  ssize_t ret = read_file_contents(filename, buf, bufsize - 1);
+  if (ret < 0)
+    return ret;
+
+  buf[ret] = '\0';
+  return ret + 1;
+}
+
 counter_t counter_diff(counter_t old_value, counter_t new_value) {
   counter_t diff;
 
index 1ca6505..4e2eced 100644 (file)
@@ -356,7 +356,11 @@ typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename,
 int walk_directory(const char *dir, dirwalk_callback_f callback,
                    void *user_data, int hidden);
 /* Returns the number of bytes read or negative on error. */
-ssize_t read_file_contents(char const *filename, char *buf, size_t bufsize);
+ssize_t read_file_contents(char const *filename, void *buf, size_t bufsize);
+/* Writes the contents of the file into the buffer with a trailing NUL.
+ * Returns the number of bytes written to the buffer or negative on error. */
+ssize_t read_text_file_contents(char const *filename, char *buf,
+                                size_t bufsize);
 
 counter_t counter_diff(counter_t old_value, counter_t new_value);