X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmatch_regex.c;h=cd6301673a1a3673b8912375554da3a32bfd8bb1;hb=5523a080010dcb7a61dc0dccc3969a2a048e52f9;hp=1defc18026241e6580e777b6ec8324c84c1411b7;hpb=593ea76dca367478b92e17f91e663fe7c67b4df9;p=collectd.git diff --git a/src/match_regex.c b/src/match_regex.c index 1defc180..cd630167 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -1,24 +1,29 @@ /** * collectd - src/match_regex.c - * Copyright (C) 2008 Sebastian Harl - * Copyright (C) 2008 Florian Forster + * Copyright (C) 2008 Sebastian Harl + * Copyright (C) 2008 Florian 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: * Sebastian Harl - * Florian Forster + * Florian Forster **/ /* @@ -27,6 +32,7 @@ */ #include "collectd.h" + #include "filter_chain.h" #include @@ -94,12 +100,10 @@ static void mr_free_match (mr_match_t *m) /* {{{ */ static int mr_match_regexen (mr_regex_t *re_head, /* {{{ */ const char *string) { - mr_regex_t *re; - if (re_head == NULL) return (FC_MATCH_MATCHES); - for (re = re_head; re != NULL; re = re->next) + for (mr_regex_t *re = re_head; re != NULL; re = re->next) { int status; @@ -135,13 +139,12 @@ static int mr_config_add_regex (mr_regex_t **re_head, /* {{{ */ return (-1); } - re = (mr_regex_t *) malloc (sizeof (*re)); + re = calloc (1, sizeof (*re)); if (re == NULL) { - log_err ("mr_config_add_regex: malloc failed."); + log_err ("mr_config_add_regex: calloc failed."); return (-1); } - memset (re, 0, sizeof (*re)); re->next = NULL; re->re_str = strdup (ci->values[0].value.string); @@ -158,7 +161,7 @@ static int mr_config_add_regex (mr_regex_t **re_head, /* {{{ */ char errmsg[1024]; regerror (status, &re->re, errmsg, sizeof (errmsg)); errmsg[sizeof (errmsg) - 1] = 0; - log_err ("Compiling regex `%s' for `%s' failed: %s.", + log_err ("Compiling regex `%s' for `%s' failed: %s.", re->re_str, ci->key, errmsg); free (re->re_str); free (re); @@ -187,20 +190,18 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mr_match_t *m; int status; - int i; - m = (mr_match_t *) malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - log_err ("mr_create: malloc failed."); + log_err ("mr_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); - + m->invert = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -300,9 +301,8 @@ static int mr_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mr_create; mproc.destroy = mr_destroy; mproc.match = mr_match;