Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Thu, 17 Dec 2015 14:18:45 +0000 (15:18 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 17 Dec 2015 14:18:45 +0000 (15:18 +0100)
1  2 
src/email.c
src/gmond.c
src/perl.c

diff --combined src/email.c
@@@ -2,25 -2,20 +2,25 @@@
   * collectd - src/email.c
   * Copyright (C) 2006-2008  Sebastian Harl
   *
 - * This program is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License as published by the
 - * Free Software Foundation; only version 2 of the License is applicable.
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
   *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 - * General Public License for more details.
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
   *
 - * You should have received a copy of the GNU General Public License along
 - * with this program; if not, write to the Free Software Foundation, Inc.,
 - * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 + * DEALINGS IN THE SOFTWARE.
   *
 - * Author:
 + * Authors:
   *   Sebastian Harl <sh at tokkee.org>
   **/
  
@@@ -306,8 -301,11 +306,11 @@@ static void *collect (void *arg
                                                break;
                                continue;
                        }
+                       if (len < 3) { /* [a-z] ':' '\n' */
+                               continue;
+                       }
  
-                       line[len - 1] = '\0';
+                       line[len - 1] = 0;
  
                        log_debug ("collect: line = '%s'", line);
  
                                bytes = atoi (tmp);
  
                                pthread_mutex_lock (&count_mutex);
-                               type_list_incr (&list_count, type, 1);
+                               type_list_incr (&list_count, type, /* increment = */ 1);
                                pthread_mutex_unlock (&count_mutex);
  
                                if (bytes > 0) {
                                        pthread_mutex_lock (&size_mutex);
-                                       type_list_incr (&list_size, type, bytes);
+                                       type_list_incr (&list_size, type, /* increment = */ bytes);
                                        pthread_mutex_unlock (&size_mutex);
                                }
                        }
                                pthread_mutex_unlock (&score_mutex);
                        }
                        else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
-                               char *ptr  = NULL;
-                               char *type = strtok_r (line + 2, ",", &ptr);
-                               do {
-                                       pthread_mutex_lock (&check_mutex);
-                                       type_list_incr (&list_check, type, 1);
-                                       pthread_mutex_unlock (&check_mutex);
-                               } while (NULL != (type = strtok_r (NULL, ",", &ptr)));
+                               char *dummy = line + 2;
+                               char *endptr = NULL;
+                               char *type;
+                               pthread_mutex_lock (&check_mutex);
+                               while ((type = strtok_r (dummy, ",", &endptr)) != NULL)
+                               {
+                                       dummy = NULL;
+                                       type_list_incr (&list_check, type, /* increment = */ 1);
+                               }
+                               pthread_mutex_unlock (&check_mutex);
                        }
                        else {
                                log_err ("collect: unknown type '%c'", line[0]);
diff --combined src/gmond.c
@@@ -1,24 -1,19 +1,24 @@@
  /**
   * collectd - src/gmond.c
-  * Copyright (C) 2009,2010  Florian octo Forster
+  * Copyright (C) 2009-2015  Florian octo Forster
   *
 - * This program is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License as published by the
 - * Free Software Foundation; only version 2 of the License is applicable.
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
   *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 - * General Public License for more details.
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
   *
 - * You should have received a copy of the GNU General Public License along
 - * with this program; if not, write to the Free Software Foundation, Inc.,
 - * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 + * DEALINGS IN THE SOFTWARE.
   *
   * Authors:
   *   Florian octo Forster <octo at collectd.org>
@@@ -291,8 -286,14 +291,14 @@@ static int create_sockets (socket_entry
      {
        int yes = 1;
  
-       setsockopt (sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR,
+       status = setsockopt (sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR,
            (void *) &yes, sizeof (yes));
+       if (status != 0)
+       {
+         char errbuf[1024];
+         WARNING ("gmond plugin: setsockopt(2) failed: %s",
+                  sstrerror (errno, errbuf, sizeof (errbuf)));
+       }
      }
  
      status = bind (sockets[sockets_num].fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
@@@ -410,10 -411,19 +416,19 @@@ static int request_meta_data (const cha
  
    pthread_mutex_lock (&mc_send_sockets_lock);
    for (i = 0; i < mc_send_sockets_num; i++)
-     sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size,
+   {
+     ssize_t status = sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size,
          /* flags = */ 0,
          (struct sockaddr *) &mc_send_sockets[i].addr,
          mc_send_sockets[i].addrlen);
+     if (status == -1)
+     {
+       char errbuf[1024];
+       ERROR ("gmond plugin: sendto(2) failed: %s",
+              sstrerror (errno, errbuf, sizeof (errbuf)));
+       continue;
+     }
+   }
    pthread_mutex_unlock (&mc_send_sockets_lock);
  
    sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
@@@ -479,36 -489,6 +494,6 @@@ static staging_entry_t *staging_entry_g
    return (se);
  } /* }}} staging_entry_t *staging_entry_get */
  
- static int staging_entry_submit (const char *host, const char *name, /* {{{ */
-     staging_entry_t *se)
- {
-   value_list_t vl;
-   value_t values[se->vl.values_len];
-   if (se->vl.interval == 0)
-   {
-     /* No meta data has been received for this metric yet. */
-     se->flags = 0;
-     pthread_mutex_unlock (&staging_lock);
-     request_meta_data (host, name);
-     return (0);
-   }
-   se->flags = 0;
-   memcpy (values, se->vl.values, sizeof (values));
-   memcpy (&vl, &se->vl, sizeof (vl));
-   /* Unlock before calling `plugin_dispatch_values'.. */
-   pthread_mutex_unlock (&staging_lock);
-   vl.values = values;
-   plugin_dispatch_values (&vl);
-   return (0);
- } /* }}} int staging_entry_submit */
  static int staging_entry_update (const char *host, const char *name, /* {{{ */
      const char *type, const char *type_instance,
      int ds_index, int ds_type, value_t value)
  
    se->flags |= (0x01 << ds_index);
  
-   /* Check if all values have been set and submit if so. */
-   if (se->flags == ((0x01 << se->vl.values_len) - 1))
+   /* Check if all data sources have been set. If not, return here. */
+   if (se->flags != ((0x01 << se->vl.values_len) - 1))
    {
-     /* `staging_lock' is unlocked in `staging_entry_submit'. */
-     staging_entry_submit (host, name, se);
+     pthread_mutex_unlock (&staging_lock);
+     return (0);
    }
-   else
+   /* Check if the interval of this metric is known. If not, request meta data
+    * and return. */
+   if (se->vl.interval == 0)
    {
+     /* No meta data has been received for this metric yet. */
+     se->flags = 0;
      pthread_mutex_unlock (&staging_lock);
+     request_meta_data (host, name);
+     return (0);
    }
  
+   plugin_dispatch_values (&se->vl);
+   se->flags = 0;
+   pthread_mutex_unlock (&staging_lock);
    return (0);
  } /* }}} int staging_entry_update */
  
diff --combined src/perl.c
@@@ -2,25 -2,20 +2,25 @@@
   * collectd - src/perl.c
   * Copyright (C) 2007-2009  Sebastian Harl
   *
 - * This program is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License as published by the
 - * Free Software Foundation; only version 2 of the License is applicable.
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
   *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 - * General Public License for more details.
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
   *
 - * You should have received a copy of the GNU General Public License along
 - * with this program; if not, write to the Free Software Foundation, Inc.,
 - * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 + * DEALINGS IN THE SOFTWARE.
   *
 - * Author:
 + * Authors:
   *   Sebastian Harl <sh at tokkee.org>
   **/
  
@@@ -46,7 -41,6 +46,7 @@@
  #include <perl.h>
  
  #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
 +# undef sprintf
  # pragma GCC poison sprintf
  #endif
  
@@@ -2515,7 -2509,10 +2515,10 @@@ static int perl_config (oconfig_item_t 
                int current_status = 0;
  
                if (NULL != perl_threads)
-                       aTHX = PERL_GET_CONTEXT;
+               {
+                       if ((aTHX = PERL_GET_CONTEXT) == NULL)
+                               return -1;
+               }
  
                if (0 == strcasecmp (c->key, "LoadPlugin"))
                        current_status = perl_config_loadplugin (aTHX_ c);