Merge branch 'collectd-5.7' into collectd-5.8
authorFlorian Forster <octo@collectd.org>
Sun, 10 Feb 2019 20:44:20 +0000 (21:44 +0100)
committerFlorian Forster <octo@collectd.org>
Sun, 10 Feb 2019 20:44:20 +0000 (21:44 +0100)
src/daemon/common.c
src/daemon/common_test.c
src/log_logstash.c
src/write_prometheus.c

index d5322ed..eb9f590 100644 (file)
@@ -338,6 +338,9 @@ int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num,
       buffer_req += sep_len;
     buffer_req += field_len;
 
+    if (buffer_size == 0)
+      continue;
+
     if ((i != 0) && (sep_len > 0)) {
       if (sep_len >= avail) {
         /* prevent subsequent iterations from writing to the
index af2840e..93a19d1 100644 (file)
@@ -168,10 +168,12 @@ DEF_TEST(strjoin) {
                      cases[i].fields_num, cases[i].separator);
     EXPECT_EQ_INT(cases[i].want_return, status);
     EXPECT_EQ_STR(cases[i].want_buffer, buffer);
-  }
 
-  /* use (NULL, 0) to determine required buffer size. */
-  EXPECT_EQ_INT(3, strjoin(NULL, 0, (char *[]){"a", "b"}, 2, "-"));
+    /* use (NULL, 0) to determine required buffer size. */
+    EXPECT_EQ_INT(cases[i].want_return,
+                  strjoin(NULL, 0, cases[i].fields, cases[i].fields_num,
+                          cases[i].separator));
+  }
 
   return 0;
 }
index 28cc34c..8ff9045 100644 (file)
@@ -183,22 +183,14 @@ err:
 
 static void log_logstash_log(int severity, const char *msg,
                              user_data_t __attribute__((unused)) * user_data) {
-  yajl_gen g;
-#if !defined(HAVE_YAJL_V2)
-  yajl_gen_config conf = {};
-
-  conf.beautify = 0;
-#endif
-
   if (severity > log_level)
     return;
 
 #if HAVE_YAJL_V2
-  g = yajl_gen_alloc(NULL);
+  yajl_gen g = yajl_gen_alloc(NULL);
 #else
-  g = yajl_gen_alloc(&conf, NULL);
+  yajl_gen g = yajl_gen_alloc(&(yajl_gen_config){0}, NULL);
 #endif
-
   if (g == NULL) {
     fprintf(stderr, "Could not allocate JSON generator.\n");
     return;
index 28ab6ce..8554580 100644 (file)
@@ -760,7 +760,12 @@ static int prom_open_socket(int addrfamily) {
 
   int fd = -1;
   for (struct addrinfo *ai = res; ai != NULL; ai = ai->ai_next) {
-    fd = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC, 0);
+    int flags = ai->ai_socktype;
+#ifdef SOCK_CLOEXEC
+    flags |= SOCK_CLOEXEC;
+#endif
+
+    fd = socket(ai->ai_family, flags, 0);
     if (fd == -1)
       continue;