+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Logging - Filtered file log target
* Copyright (C) 2019 Cumulus Networks, Inc.
* Stephen Worley
- *
- * 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; either version 2 of the License, or (at your option)
- * any later version.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
void zlog_filter_clear(void)
{
- frr_with_mutex(&logfilterlock) {
+ frr_with_mutex (&logfilterlock) {
zlog_filter_count = 0;
}
}
int zlog_filter_add(const char *filter)
{
- frr_with_mutex(&logfilterlock) {
+ frr_with_mutex (&logfilterlock) {
if (zlog_filter_count >= ZLOG_FILTERS_MAX)
return 1;
int zlog_filter_del(const char *filter)
{
- frr_with_mutex(&logfilterlock) {
+ frr_with_mutex (&logfilterlock) {
int found_idx = zlog_filter_lookup(filter);
int last_idx = zlog_filter_count - 1;
{
int len = 0;
- frr_with_mutex(&logfilterlock) {
+ frr_with_mutex (&logfilterlock) {
for (int i = 0; i < zlog_filter_count; i++) {
int ret;
return len;
}
-static int search_buf(const char *buf)
+static int search_buf(const char *buf, size_t len)
{
char *found = NULL;
- frr_with_mutex(&logfilterlock) {
+ frr_with_mutex (&logfilterlock) {
for (int i = 0; i < zlog_filter_count; i++) {
- found = strstr(buf, zlog_filters[i]);
+ found = memmem(buf, len, zlog_filters[i],
+ strlen(zlog_filters[i]));
if (found != NULL)
return 0;
}
{
struct zlog_msg *msgfilt[nmsgs];
size_t i, o = 0;
+ const char *text;
+ size_t text_len;
for (i = 0; i < nmsgs; i++) {
- if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG
- && search_buf(zlog_msg_text(msgs[i], NULL)) < 0)
- continue;
-
+ if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG) {
+ text = zlog_msg_text(msgs[i], &text_len);
+ if (search_buf(text, text_len) < 0)
+ continue;
+ }
msgfilt[o++] = msgs[i];
}