Merge branch 'collectd-5.6' into collectd-5.7
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 30 Jun 2017 14:17:06 +0000 (16:17 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 30 Jun 2017 14:17:06 +0000 (16:17 +0200)
1  2 
src/email.c
src/exec.c
src/openldap.c
src/unixsock.c

diff --combined src/email.c
@@@ -361,6 -361,8 +361,6 @@@ static void *collect(void *arg) 
  } /* static void *collect (void *) */
  
  static void *open_connection(void __attribute__((unused)) * arg) {
 -  struct sockaddr_un addr;
 -
    const char *path = (NULL == sock_file) ? SOCK_PATH : sock_file;
    const char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group;
  
      pthread_exit((void *)1);
    }
  
 -  addr.sun_family = AF_UNIX;
 +  struct sockaddr_un addr = {
 +    .sun_family = AF_UNIX
 +  };
    sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
  
    errno = 0;
    {
      struct group sg;
      struct group *grp;
-     char grbuf[2048];
+     char grbuf[4096];
      int status;
  
      grp = NULL;
      if (status != 0) {
        char errbuf[1024];
        log_warn("getgrnam_r (%s) failed: %s", group,
-                sstrerror(errno, errbuf, sizeof(errbuf)));
+                sstrerror(status, errbuf, sizeof(errbuf)));
      } else if (grp == NULL) {
        log_warn("No such group: `%s'", group);
      } else {
        collectors[i]->socket = NULL;
  
        if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
 -                               collectors[i]) != 0) {
 +                               collectors[i], "email collector") != 0) {
          char errbuf[1024];
          log_err("plugin_thread_create() failed: %s",
                  sstrerror(errno, errbuf, sizeof(errbuf)));
  } /* static void *open_connection (void *) */
  
  static int email_init(void) {
 -  if (plugin_thread_create(&connector, NULL, open_connection, NULL) != 0) {
 +  if (plugin_thread_create(&connector, NULL, open_connection, NULL,
 +                           "email listener") != 0) {
      char errbuf[1024];
      disabled = 1;
      log_err("plugin_thread_create() failed: %s",
@@@ -614,10 -613,14 +614,10 @@@ static int email_shutdown(void) 
  
  static void email_submit(const char *type, const char *type_instance,
                           gauge_t value) {
 -  value_t values[1];
    value_list_t vl = VALUE_LIST_INIT;
  
 -  values[0].gauge = value;
 -
 -  vl.values = values;
 +  vl.values = &(value_t){.gauge = value};
    vl.values_len = 1;
 -  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
    sstrncpy(vl.plugin, "email", sizeof(vl.plugin));
    sstrncpy(vl.type, type, sizeof(vl.type));
    sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
diff --combined src/exec.c
@@@ -250,7 -250,7 +250,7 @@@ static void set_environment(void) /* {{
              CDTIME_T_TO_DOUBLE(plugin_get_interval()));
    setenv("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
  
 -  ssnprintf(buffer, sizeof(buffer), "%s", hostname_g);
 +  sstrncpy(buffer, hostname_g, sizeof(buffer));
    setenv("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
  #else
    ssnprintf(buffer, sizeof(buffer), "COLLECTD_INTERVAL=%.3f",
@@@ -369,7 -369,7 +369,7 @@@ static int fork_child(program_list_t *p
  
    struct passwd *sp_ptr;
    struct passwd sp;
-   char nambuf[2048];
+   char nambuf[4096];
  
    if (pl->pid != 0)
      return (-1);
    status = getpwnam_r(pl->user, &sp, nambuf, sizeof(nambuf), &sp_ptr);
    if (status != 0) {
      ERROR("exec plugin: Failed to get user information for user ``%s'': %s",
-           pl->user, sstrerror(errno, errbuf, sizeof(errbuf)));
+           pl->user, sstrerror(status, errbuf, sizeof(errbuf)));
      goto failed;
    }
  
        if (0 != status) {
          ERROR("exec plugin: Failed to get group information "
                "for group ``%s'': %s",
-               pl->group, sstrerror(errno, errbuf, sizeof(errbuf)));
+               pl->group, sstrerror(status, errbuf, sizeof(errbuf)));
          goto failed;
        }
        if (NULL == gr_ptr) {
@@@ -500,7 -500,7 +500,7 @@@ failed
  static int parse_line(char *buffer) /* {{{ */
  {
    if (strncasecmp("PUTVAL", buffer, strlen("PUTVAL")) == 0)
 -    return (handle_putval(stdout, buffer));
 +    return (cmd_handle_putval(stdout, buffer));
    else if (strncasecmp("PUTNOTIF", buffer, strlen("PUTNOTIF")) == 0)
      return (handle_putnotif(stdout, buffer));
    else {
@@@ -787,7 -787,7 +787,7 @@@ static int exec_read(void) /* {{{ *
  
      pthread_attr_init(&attr);
      pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 -    plugin_thread_create(&t, &attr, exec_read_one, (void *)pl);
 +    plugin_thread_create(&t, &attr, exec_read_one, (void *)pl, "exec read");
      pthread_attr_destroy(&attr);
    } /* for (pl) */
  
@@@ -826,8 -826,7 +826,8 @@@ static int exec_notification(const noti
  
      pthread_attr_init(&attr);
      pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 -    plugin_thread_create(&t, &attr, exec_notification_one, (void *)pln);
 +    plugin_thread_create(&t, &attr, exec_notification_one, (void *)pln,
 +                         "exec notify");
      pthread_attr_destroy(&attr);
    } /* for (pl) */
  
diff --combined src/openldap.c
@@@ -92,7 -92,8 +92,8 @@@ static int cldap_init_host(cldap_t *st
    if (rc != LDAP_SUCCESS) {
      ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc));
      st->state = 0;
-     ldap_unbind_ext_s(ld, NULL, NULL);
+     if (ld != NULL)
+       ldap_unbind_ext_s(ld, NULL, NULL);
      return (-1);
    }
  
        ERROR("openldap plugin: Failed to start tls on %s: %s", st->url,
              ldap_err2string(rc));
        st->state = 0;
-       ldap_unbind_ext_s(st->ld, NULL, NULL);
+       if (st->ld != NULL)
+         ldap_unbind_ext_s(st->ld, NULL, NULL);
        return (-1);
      }
    }
      ERROR("openldap plugin: Failed to bind to %s: %s", st->url,
            ldap_err2string(rc));
      st->state = 0;
-     ldap_unbind_ext_s(st->ld, NULL, NULL);
+     if (st->ld != NULL)
+       ldap_unbind_ext_s(st->ld, NULL, NULL);
      return (-1);
    } else {
      DEBUG("openldap plugin: Successfully connected to %s", st->url);
@@@ -156,7 -159,10 +159,7 @@@ static void cldap_submit_value(const ch
    vl.values = &value;
    vl.values_len = 1;
  
 -  if ((st->host == NULL) || (strcmp("", st->host) == 0) ||
 -      (strcmp("localhost", st->host) == 0))
 -    sstrncpy(vl.host, hostname_g, sizeof(vl.host));
 -  else
 +  if ((st->host != NULL) && (strcmp("localhost", st->host) != 0))
      sstrncpy(vl.host, st->host, sizeof(vl.host));
  
    sstrncpy(vl.plugin, "openldap", sizeof(vl.plugin));
  static void cldap_submit_derive(const char *type,
                                  const char *type_instance, /* {{{ */
                                  derive_t d, cldap_t *st) {
 -  value_t v;
 -  v.derive = d;
 -  cldap_submit_value(type, type_instance, v, st);
 +  cldap_submit_value(type, type_instance, (value_t){.derive = d}, st);
  } /* }}} void cldap_submit_derive */
  
  static void cldap_submit_gauge(const char *type,
                                 const char *type_instance, /* {{{ */
                                 gauge_t g, cldap_t *st) {
 -  value_t v;
 -  v.gauge = g;
 -  cldap_submit_value(type, type_instance, v, st);
 +  cldap_submit_value(type, type_instance, (value_t){.gauge = g}, st);
  } /* }}} void cldap_submit_gauge */
  
  static int cldap_read_host(user_data_t *ud) /* {{{ */
      ERROR("openldap plugin: Failed to execute search: %s", ldap_err2string(rc));
      ldap_msgfree(result);
      st->state = 0;
-     ldap_unbind_ext_s(st->ld, NULL, NULL);
+     if (st->ld != NULL)
+       ldap_unbind_ext_s(st->ld, NULL, NULL);
      return (-1);
    }
  
@@@ -403,7 -414,7 +407,7 @@@ static int cldap_config_add(oconfig_ite
    }
  
    st->starttls = 0;
 -  st->timeout = (long)(CDTIME_T_TO_MS(plugin_get_interval()) / 1000);
 +  st->timeout = (long)CDTIME_T_TO_TIME_T(plugin_get_interval());
    st->verifyhost = 1;
    st->version = LDAP_VERSION3;
  
                  (st->host != NULL) ? st->host : hostname_g,
                  (st->name != NULL) ? st->name : "default");
  
 -      user_data_t ud = {.data = st};
 -
        status = plugin_register_complex_read(/* group = */ NULL,
                                              /* name      = */ callback_name,
                                              /* callback  = */ cldap_read_host,
 -                                            /* interval  = */ 0,
 -                                            /* user_data = */ &ud);
 +                                            /* interval  = */ 0, &(user_data_t){
 +                                                                     .data = st,
 +                                                                 });
      }
    }
  
diff --combined src/unixsock.c
@@@ -134,7 -134,7 +134,7 @@@ static int us_open_socket(void) 
      const char *grpname;
      struct group *g;
      struct group sg;
-     char grbuf[2048];
+     char grbuf[4096];
  
      grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME;
      g = NULL;
      if (status != 0) {
        char errbuf[1024];
        WARNING("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
-               sstrerror(errno, errbuf, sizeof(errbuf)));
+               sstrerror(status, errbuf, sizeof(errbuf)));
        break;
      }
      if (g == NULL) {
@@@ -257,17 -257,17 +257,17 @@@ static void *us_handle_client(void *arg
      }
  
      if (strcasecmp(fields[0], "getval") == 0) {
 -      handle_getval(fhout, buffer);
 +      cmd_handle_getval(fhout, buffer);
      } else if (strcasecmp(fields[0], "getthreshold") == 0) {
        handle_getthreshold(fhout, buffer);
      } else if (strcasecmp(fields[0], "putval") == 0) {
 -      handle_putval(fhout, buffer);
 +      cmd_handle_putval(fhout, buffer);
      } else if (strcasecmp(fields[0], "listval") == 0) {
 -      handle_listval(fhout, buffer);
 +      cmd_handle_listval(fhout, buffer);
      } else if (strcasecmp(fields[0], "putnotif") == 0) {
        handle_putnotif(fhout, buffer);
      } else if (strcasecmp(fields[0], "flush") == 0) {
 -      handle_flush(fhout, buffer);
 +      cmd_handle_flush(fhout, buffer);
      } else {
        if (fprintf(fhout, "-1 Unknown command: %s\n", fields[0]) < 0) {
          char errbuf[1024];
@@@ -328,7 -328,7 +328,7 @@@ static void *us_server_thread(void __at
      DEBUG("Spawning child to handle connection on fd #%i", *remote_fd);
  
      status = plugin_thread_create(&th, &th_attr, us_handle_client,
 -                                  (void *)remote_fd);
 +                                  (void *)remote_fd, "unixsock conn");
      if (status != 0) {
        char errbuf[1024];
        WARNING("unixsock plugin: pthread_create failed: %s",
@@@ -395,8 -395,7 +395,8 @@@ static int us_init(void) 
  
    loop = 1;
  
 -  status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL);
 +  status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL,
 +                                "unixsock listen");
    if (status != 0) {
      char errbuf[1024];
      ERROR("unixsock plugin: pthread_create failed: %s",