Merge branch 'collectd-5.7'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 30 Jun 2017 14:20:16 +0000 (16:20 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 30 Jun 2017 14:20:16 +0000 (16:20 +0200)
Conflicts:
src/openldap.c

1  2 
src/email.c
src/exec.c
src/openldap.c
src/unixsock.c

diff --combined src/email.c
@@@ -357,7 -357,7 +357,7 @@@ static void *collect(void *arg) 
    } /* while (1) */
  
    pthread_exit((void *)0);
 -  return ((void *)0);
 +  return (void *)0;
  } /* static void *collect (void *) */
  
  static void *open_connection(void __attribute__((unused)) * arg) {
    {
      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 {
    }
  
    pthread_exit((void *)0);
 -  return ((void *)0);
 +  return (void *)0;
  } /* static void *open_connection (void *) */
  
  static int email_init(void) {
      disabled = 1;
      log_err("plugin_thread_create() failed: %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* int email_init */
  
  static void type_list_free(type_list_t *t) {
@@@ -609,7 -609,7 +609,7 @@@ static int email_shutdown(void) 
  
    sfree(sock_file);
    sfree(sock_group);
 -  return (0);
 +  return 0;
  } /* static void email_shutdown (void) */
  
  static void email_submit(const char *type, const char *type_instance,
@@@ -663,7 -663,7 +663,7 @@@ static int email_read(void) 
    int score_count_old;
  
    if (disabled)
 -    return (-1);
 +    return -1;
  
    /* email count */
    pthread_mutex_lock(&count_mutex);
    for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
      email_submit("spam_check", ptr->name, ptr->value);
  
 -  return (0);
 +  return 0;
  } /* int email_read */
  
  void module_register(void) {
    plugin_register_read("email", email_read);
    plugin_register_shutdown("email", email_shutdown);
  } /* void module_register */
 -
 -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
diff --combined src/exec.c
@@@ -108,26 -108,26 +108,26 @@@ static int exec_config_exec(oconfig_ite
  
    if (ci->children_num != 0) {
      WARNING("exec plugin: The config option `%s' may not be a block.", ci->key);
 -    return (-1);
 +    return -1;
    }
    if (ci->values_num < 2) {
      WARNING("exec plugin: The config option `%s' needs at least two "
              "arguments.",
              ci->key);
 -    return (-1);
 +    return -1;
    }
    if ((ci->values[0].type != OCONFIG_TYPE_STRING) ||
        (ci->values[1].type != OCONFIG_TYPE_STRING)) {
      WARNING("exec plugin: The first two arguments to the `%s' option must "
              "be string arguments.",
              ci->key);
 -    return (-1);
 +    return -1;
    }
  
    pl = calloc(1, sizeof(*pl));
    if (pl == NULL) {
      ERROR("exec plugin: calloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    if (strcasecmp("NotificationExec", ci->key) == 0)
    if (pl->user == NULL) {
      ERROR("exec plugin: strdup failed.");
      sfree(pl);
 -    return (-1);
 +    return -1;
    }
  
    pl->group = strchr(pl->user, ':');
      ERROR("exec plugin: strdup failed.");
      sfree(pl->user);
      sfree(pl);
 -    return (-1);
 +    return -1;
    }
  
    pl->argv = calloc(ci->values_num, sizeof(*pl->argv));
      sfree(pl->exec);
      sfree(pl->user);
      sfree(pl);
 -    return (-1);
 +    return -1;
    }
  
    {
      sfree(pl->exec);
      sfree(pl->user);
      sfree(pl);
 -    return (-1);
 +    return -1;
    }
  
    for (i = 1; i < (ci->values_num - 1); i++) {
      sfree(pl->exec);
      sfree(pl->user);
      sfree(pl);
 -    return (-1);
 +    return -1;
    }
  
    for (i = 0; pl->argv[i] != NULL; i++) {
    pl->next = pl_head;
    pl_head = pl;
  
 -  return (0);
 +  return 0;
  } /* int exec_config_exec }}} */
  
  static int exec_config(oconfig_item_t *ci) /* {{{ */
      }
    } /* for (i) */
  
 -  return (0);
 +  return 0;
  } /* int exec_config }}} */
  
  static void set_environment(void) /* {{{ */
@@@ -332,7 -332,7 +332,7 @@@ static int create_pipe(int fd_pipe[2]) 
    if (status != 0) {
      ERROR("exec plugin: pipe failed: %s",
            sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
    return 0;
@@@ -369,10 -369,10 +369,10 @@@ 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);
 +    return -1;
  
    if ((create_pipe(fd_pipe_in) == -1) || (create_pipe(fd_pipe_out) == -1) ||
        (create_pipe(fd_pipe_err) == -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) {
    else
      close(fd_pipe_err[0]);
  
 -  return (pid);
 +  return pid;
  
  failed:
    close_pipe(fd_pipe_in);
    close_pipe(fd_pipe_out);
    close_pipe(fd_pipe_err);
  
 -  return (-1);
 +  return -1;
  } /* int fork_child }}} */
  
  static int parse_line(char *buffer) /* {{{ */
  {
    if (strncasecmp("PUTVAL", buffer, strlen("PUTVAL")) == 0)
 -    return (cmd_handle_putval(stdout, buffer));
 +    return cmd_handle_putval(stdout, buffer);
    else if (strncasecmp("PUTNOTIF", buffer, strlen("PUTNOTIF")) == 0)
 -    return (handle_putnotif(stdout, buffer));
 +    return handle_putnotif(stdout, buffer);
    else {
      ERROR("exec plugin: Unable to parse command, ignoring line: \"%s\"",
            buffer);
 -    return (-1);
 +    return -1;
    }
  } /* int parse_line }}} */
  
@@@ -655,7 -655,7 +655,7 @@@ static void *exec_read_one(void *arg) /
      close(fd_err);
  
    pthread_exit((void *)0);
 -  return (NULL);
 +  return NULL;
  } /* void *exec_read_one }}} */
  
  static void *exec_notification_one(void *arg) /* {{{ */
    n->meta = NULL;
    sfree(arg);
    pthread_exit((void *)0);
 -  return (NULL);
 +  return NULL;
  } /* void *exec_notification_one }}} */
  
  static int exec_init(void) /* {{{ */
    }
  #endif
  
 -  return (0);
 +  return 0;
  } /* int exec_init }}} */
  
  static int exec_read(void) /* {{{ */
      pthread_attr_destroy(&attr);
    } /* for (pl) */
  
 -  return (0);
 +  return 0;
  } /* int exec_read }}} */
  
  static int exec_notification(const notification_t *n, /* {{{ */
      pthread_attr_destroy(&attr);
    } /* for (pl) */
  
 -  return (0);
 +  return 0;
  } /* }}} int exec_notification */
  
  static int exec_shutdown(void) /* {{{ */
    } /* while (pl) */
    pl_head = NULL;
  
 -  return (0);
 +  return 0;
  } /* int exec_shutdown }}} */
  
  void module_register(void) {
                                 /* user_data = */ NULL);
    plugin_register_shutdown("exec", exec_shutdown);
  } /* void module_register */
 -
 -/*
 - * vim:shiftwidth=2:softtabstop=2:tabstop=8:fdm=marker
 - */
diff --combined src/openldap.c
@@@ -85,15 -85,16 +85,16 @@@ static int cldap_init_host(cldap_t *st
  
    if (st->state && st->ld) {
      DEBUG("openldap plugin: Already connected to %s", st->url);
 -    return (0);
 +    return 0;
    }
  
    rc = ldap_initialize(&ld, st->url);
    if (rc != LDAP_SUCCESS) {
      ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc));
      st->state = 0;
-     ldap_unbind_ext_s(ld, NULL, NULL);
-     return -1;
+     if (ld != NULL)
+       ldap_unbind_ext_s(ld, NULL, NULL);
+     return (-1);
    }
  
    st->ld = ld;
        ERROR("openldap plugin: Failed to start tls on %s: %s", st->url,
              ldap_err2string(rc));
        st->state = 0;
++<<<<<<< HEAD
 +      ldap_unbind_ext_s(st->ld, NULL, NULL);
 +      return -1;
++=======
+       if (st->ld != NULL)
+         ldap_unbind_ext_s(st->ld, NULL, NULL);
+       return (-1);
++>>>>>>> collectd-5.7
      }
    }
  
      ERROR("openldap plugin: Failed to bind to %s: %s", st->url,
            ldap_err2string(rc));
      st->state = 0;
++<<<<<<< HEAD
 +    ldap_unbind_ext_s(st->ld, NULL, NULL);
 +    return -1;
++=======
+     if (st->ld != NULL)
+       ldap_unbind_ext_s(st->ld, NULL, NULL);
+     return (-1);
++>>>>>>> collectd-5.7
    } else {
      DEBUG("openldap plugin: Successfully connected to %s", st->url);
      st->state = 1;
 -    return (0);
 +    return 0;
    }
  } /* }}} static cldap_init_host */
  
@@@ -197,14 -200,14 +210,14 @@@ static int cldap_read_host(user_data_t 
  
    if ((ud == NULL) || (ud->data == NULL)) {
      ERROR("openldap plugin: cldap_read_host: Invalid user data.");
 -    return (-1);
 +    return -1;
    }
  
    st = (cldap_t *)ud->data;
  
    status = cldap_init_host(st);
    if (status != 0)
 -    return (-1);
 +    return -1;
  
    rc = ldap_search_ext_s(st->ld, "cn=Monitor", LDAP_SCOPE_SUBTREE,
                           "(|(!(cn=* *))(cn=Database*))", attrs, 0, NULL, NULL,
      ERROR("openldap plugin: Failed to execute search: %s", ldap_err2string(rc));
      ldap_msgfree(result);
      st->state = 0;
++<<<<<<< HEAD
 +    ldap_unbind_ext_s(st->ld, NULL, NULL);
 +    return -1;
++=======
+     if (st->ld != NULL)
+       ldap_unbind_ext_s(st->ld, NULL, NULL);
+     return (-1);
++>>>>>>> collectd-5.7
    }
  
    for (LDAPMessage *e = ldap_first_entry(st->ld, result); e != NULL;
    }
  
    ldap_msgfree(result);
 -  return (0);
 +  return 0;
  } /* }}} int cldap_read_host */
  
  /* Configuration handling functions {{{
@@@ -393,13 -397,13 +412,13 @@@ static int cldap_config_add(oconfig_ite
    st = calloc(1, sizeof(*st));
    if (st == NULL) {
      ERROR("openldap plugin: calloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    status = cf_util_get_string(ci, &st->name);
    if (status != 0) {
      sfree(st);
 -    return (status);
 +    return status;
    }
  
    st->starttls = 0;
  
    if (status != 0) {
      cldap_free(st);
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int cldap_config_add */
  
  static int cldap_config(oconfig_item_t *ci) /* {{{ */
                child->key);
    } /* for (ci->children) */
  
 -  return (status);
 +  return status;
  } /* }}} int cldap_config */
  
  /* }}} End of configuration handling functions */
@@@ -525,7 -529,7 +544,7 @@@ static int cldap_init(void) /* {{{ *
     * ldap_initialize(3) */
    int debug_level;
    ldap_get_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level);
 -  return (0);
 +  return 0;
  } /* }}} int cldap_init */
  
  static int cldap_shutdown(void) /* {{{ */
    sfree(databases);
    databases_num = 0;
  
 -  return (0);
 +  return 0;
  } /* }}} int cldap_shutdown */
  
  void module_register(void) /* {{{ */
diff --combined src/unixsock.c
@@@ -78,7 -78,7 +78,7 @@@ static int us_open_socket(void) 
      char errbuf[1024];
      ERROR("unixsock plugin: socket failed: %s",
            sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
    sa.sun_family = AF_UNIX;
      ERROR("unixsock plugin: bind failed: %s", errbuf);
      close(sock_fd);
      sock_fd = -1;
 -    return (-1);
 +    return -1;
    }
  
    status = chmod(sa.sun_path, sock_perms);
            sstrerror(errno, errbuf, sizeof(errbuf)));
      close(sock_fd);
      sock_fd = -1;
 -    return (-1);
 +    return -1;
    }
  
    status = listen(sock_fd, 8);
            sstrerror(errno, errbuf, sizeof(errbuf)));
      close(sock_fd);
      sock_fd = -1;
 -    return (-1);
 +    return -1;
    }
  
    do {
      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) {
      }
    } while (0);
  
 -  return (0);
 +  return 0;
  } /* int us_open_socket */
  
  static void *us_handle_client(void *arg) {
      close(fdin);
      close(fdout);
      pthread_exit((void *)1);
 -    return ((void *)1);
 +    return (void *)1;
    }
  
    fhout = fdopen(fdout, "w");
      fclose(fhin); /* this closes fdin as well */
      close(fdout);
      pthread_exit((void *)1);
 -    return ((void *)1);
 +    return (void *)1;
    }
  
    /* change output buffer to line buffered mode */
      fclose(fhin);
      fclose(fhout);
      pthread_exit((void *)1);
 -    return ((void *)0);
 +    return (void *)0;
    }
  
    while (42) {
        fclose(fhin);
        fclose(fhout);
        pthread_exit((void *)1);
 -      return ((void *)1);
 +      return (void *)1;
      }
  
      if (strcasecmp(fields[0], "getval") == 0) {
    fclose(fhout);
  
    pthread_exit((void *)0);
 -  return ((void *)0);
 +  return (void *)0;
  } /* void *us_handle_client */
  
  static void *us_server_thread(void __attribute__((unused)) * arg) {
             sstrerror(errno, errbuf, sizeof(errbuf)));
    }
  
 -  return ((void *)0);
 +  return (void *)0;
  } /* void *us_server_thread */
  
  static int us_config(const char *key, const char *val) {
    if (strcasecmp(key, "SocketFile") == 0) {
      char *new_sock_file = strdup(val);
      if (new_sock_file == NULL)
 -      return (1);
 +      return 1;
  
      sfree(sock_file);
      sock_file = new_sock_file;
    } else if (strcasecmp(key, "SocketGroup") == 0) {
      char *new_sock_group = strdup(val);
      if (new_sock_group == NULL)
 -      return (1);
 +      return 1;
  
      sfree(sock_group);
      sock_group = new_sock_group;
      else
        delete_socket = 0;
    } else {
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* int us_config */
  
  static int us_init(void) {
  
    /* Initialize only once. */
    if (have_init != 0)
 -    return (0);
 +    return 0;
    have_init = 1;
  
    loop = 1;
      char errbuf[1024];
      ERROR("unixsock plugin: pthread_create failed: %s",
            sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* int us_init */
  
  static int us_shutdown(void) {
    plugin_unregister_init("unixsock");
    plugin_unregister_shutdown("unixsock");
  
 -  return (0);
 +  return 0;
  } /* int us_shutdown */
  
  void module_register(void) {
    plugin_register_init("unixsock", us_init);
    plugin_register_shutdown("unixsock", us_shutdown);
  } /* void module_register (void) */
 -
 -/* vim: set sw=4 ts=4 sts=4 tw=78 : */