[lttng-dev] [PATCH lttng-ust] Add exclusion checking
Ikaheimonen, JP
jp_ikaheimonen at mentor.com
Fri Sep 27 03:14:30 EDT 2013
If event enabler name contains wildcards, it's a wildcarded enabler.
Wildcarded enablers can now have exceptions to the rule; these are
called excluders. Excluders are embedded in the name of the enabler,
trailing the base name. If there are multiple excluders, they are
separated with a separator character (',').
---
include/lttng/ust-events.h | 6 ++++++
liblttng-ust/lttng-events.c | 43 ++++++++++++++++++++++++++++++++++++++++---
liblttng-ust/lttng-ust-abi.c | 7 +++----
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h
index 74a3bc6..ca7be56 100644
--- a/include/lttng/ust-events.h
+++ b/include/lttng/ust-events.h
@@ -292,6 +292,12 @@ enum lttng_enabler_type {
LTTNG_ENABLER_EVENT,
};
+/* special characters for event enablers. */
+#define LTTNG_ENABLER_WILDCARD_CHARACTER '*'
+#define LTTNG_ENABLER_WILDCARD_STRING "*"
+#define LTTNG_ENABLER_SEPARATOR_CHARACTER ','
+#define LTTNG_ENABLER_SEPARATOR_STRING ","
+
/*
* Enabler field, within whatever object is enabling an event. Target of
* backward reference.
diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c
index 26601a6..b1d3d1a 100644
--- a/liblttng-ust/lttng-events.c
+++ b/liblttng-ust/lttng-events.c
@@ -442,6 +442,43 @@ exist:
}
static
+int match_enabler_with_exclusions(const char * eventname,
+ const char * enablername)
+{
+
+ /* first check if matches the enabler name */
+ int name_length = strcspn(enablername, LTTNG_ENABLER_WILDCARD_STRING) + 1;
+ int matches = strncmp(enablername, eventname, name_length - 1);
+ if (matches != 0)
+ return 0;
+ matches = 1;
+ enablername = enablername + name_length;
+ while (*enablername != 0) {
+ /* find end of excluder */
+ name_length = strcspn(enablername, LTTNG_ENABLER_SEPARATOR_STRING);
+ if (strcspn(enablername, LTTNG_ENABLER_WILDCARD_STRING) < name_length) {
+ /* excluder has a wildcard */
+ if (strncmp(enablername, eventname, name_length - 1) == 0) {
+ matches = 0;
+ break;
+ }
+ } else {
+ /* no wildcard in excluder */
+ if (name_length == strlen(eventname)
+ && strncmp(enablername, eventname, name_length) == 0) {
+ matches = 0;
+ break;
+ }
+ }
+ /* next excluder */
+ enablername = enablername + name_length;
+ if (*enablername == LTTNG_ENABLER_SEPARATOR_CHARACTER)
+ enablername++;
+ }
+ return matches;
+}
+
+static
int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc *desc,
struct lttng_enabler *enabler)
{
@@ -449,9 +486,9 @@ int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc *desc,
unsigned int has_loglevel = 0;
assert(enabler->type == LTTNG_ENABLER_WILDCARD);
- /* Compare excluding final '*' */
- if (strncmp(desc->name, enabler->event_param.name,
- strlen(enabler->event_param.name) - 1))
+
+ /* Compare against the enabler specification */
+ if (!match_enabler_with_exclusions(desc->name, enabler->event_param.name))
return 0;
if (desc->loglevel) {
loglevel = *(*desc->loglevel);
diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c
index a852aae..462eb82 100644
--- a/liblttng-ust/lttng-ust-abi.c
+++ b/liblttng-ust/lttng-ust-abi.c
@@ -875,14 +875,13 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
{
struct lttng_ust_event *event_param =
(struct lttng_ust_event *) arg;
- if (event_param->name[strlen(event_param->name) - 1] == '*') {
- /* If ends with wildcard, create wildcard. */
+ /* if event name contains a wildcard, it's a wildcard event. */
+ if (strchr(event_param->name, LTTNG_ENABLER_WILDCARD_CHARACTER) != NULL)
return lttng_abi_create_enabler(objd, event_param,
owner, LTTNG_ENABLER_WILDCARD);
- } else {
+ else
return lttng_abi_create_enabler(objd, event_param,
owner, LTTNG_ENABLER_EVENT);
- }
}
case LTTNG_UST_CONTEXT:
return lttng_abi_add_context(objd,
--
1.8.1.2
More information about the lttng-dev
mailing list