From 9abb68637d6d448cccfa06daa05d9c5bf59f5d3e Mon Sep 17 00:00:00 2001
From: David Vossel <dvossel@redhat.com>
Date: Thu, 17 Oct 2013 21:44:12 -0500
Subject: [PATCH] Fix: log: Filtering by function and file must match exactly,
no substring matches
---
lib/log.c | 4 ++--
tests/check_log.c | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index 6d3435e..3b4d6bd 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -103,9 +103,9 @@ _cs_matches_filter_(struct qb_log_callsite *cs,
snprintf(token, 499, "%.*s", (int)(next - offset), offset);
if (type == QB_LOG_FILTER_FILE) {
- match = (strstr(cs->filename, token) != NULL);
+ match = (strcmp(cs->filename, token) == 0) ? 1 : 0;
} else {
- match = (strstr(cs->function, token) != NULL);
+ match = (strcmp(cs->function, token) == 0) ? 1 : 0;
}
if (!match && next[0] != 0) {
next++;
diff --git a/tests/check_log.c b/tests/check_log.c
index 3653b50..896bd7d 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -191,6 +191,7 @@ _test_logger(int32_t t,
test_buf[0] = '\0';
qb_log_target_format(t, cs, timestamp, msg, test_buf);
test_priority = cs->priority;
+
num_msgs++;
}
@@ -282,6 +283,7 @@ START_TEST(test_log_basic)
rc = qb_log_ctl(t, QB_LOG_CONF_ENABLED, QB_TRUE);
ck_assert_int_eq(rc, 0);
+ /* captures last log */
memset(test_buf, 0, sizeof(test_buf));
test_priority = 0;
num_msgs = 0;
@@ -304,7 +306,7 @@ START_TEST(test_log_basic)
qb_log_filter_ctl(t, QB_LOG_FILTER_CLEAR_ALL,
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_filter_ctl(t, QB_LOG_FILTER_ADD,
- QB_LOG_FILTER_FUNCTION, "log_it_please", LOG_WARNING);
+ QB_LOG_FILTER_FUNCTION, "otherlogging,log_it_please,morelogging", LOG_WARNING);
num_msgs = 0;
qb_log(LOG_ERR, "try if you: log_it_please()");
@@ -336,7 +338,7 @@ START_TEST(test_log_basic)
qb_log_filter_ctl(t, QB_LOG_FILTER_CLEAR_ALL,
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_filter_ctl(t, QB_LOG_FILTER_ADD,
- QB_LOG_FILTER_FILE, __FILE__, LOG_DEBUG);
+ QB_LOG_FILTER_FILE, "fakefile.c,"__FILE__",otherfakefile", LOG_DEBUG);
/*
* make sure we can pass in a null filename or function name.
*/
--
1.8.4.2