Fix: move JUL filter creation to a function
authorDavid Goulet <dgoulet@efficios.com>
Wed, 7 May 2014 18:12:13 +0000 (14:12 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 12 May 2014 14:03:59 +0000 (10:03 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/lib/lttng-ctl/lttng-ctl.c

index b2663f59311e22126686d1d873a9088feb474d57..280651c08a2f8310bc777f4b4a2381a806d80f4d 100644 (file)
@@ -694,6 +694,62 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle,
                        filter_expression, 0, NULL);
 }
 
+/*
+ * Depending on the event, return a newly allocated JUL filter expression or
+ * NULL if not applicable.
+ *
+ * An event with NO loglevel and the name is * will return NULL.
+ */
+static char *set_jul_filter(const char *filter, struct lttng_event *ev)
+{
+       int err;
+       char *jul_filter = NULL;
+
+       assert(ev);
+
+       /* Don't add filter for the '*' event. */
+       if (ev->name[0] != '*') {
+               if (filter) {
+                       err = asprintf(&jul_filter, "%s && logger_name == \"%s\"", filter,
+                                       ev->name);
+               } else {
+                       err = asprintf(&jul_filter, "logger_name == \"%s\"", ev->name);
+               }
+               if (err < 0) {
+                       PERROR("asprintf");
+                       goto end;
+               }
+       }
+
+       /* Add loglevel filtering if any for the JUL domain. */
+       if (ev->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
+               char *op;
+
+               if (ev->loglevel_type == LTTNG_EVENT_LOGLEVEL_RANGE) {
+                       op = ">=";
+               } else {
+                       op = "==";
+               }
+
+               if (filter) {
+                       err = asprintf(&jul_filter, "%s && int_loglevel %s %d", filter, op,
+                                       ev->loglevel);
+               } else {
+                       err = asprintf(&jul_filter, "int_loglevel %s %d", op,
+                                       ev->loglevel);
+               }
+               if (err < 0) {
+                       PERROR("asprintf");
+                       free(jul_filter);
+                       jul_filter = NULL;
+                       goto end;
+               }
+       }
+
+end:
+       return jul_filter;
+}
+
 /*
  * Enable event(s) for a channel, possibly with exclusions and a filter.
  * If no event name is specified, all events are enabled.
@@ -768,47 +824,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
        /* Parse filter expression */
        if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL) {
                if (handle->domain.type == LTTNG_DOMAIN_JUL) {
-                       int err;
-
-                       if (ev->name[0] != '*') {
-                               if (filter_expression) {
-                                       err = asprintf(&jul_filter, "%s && logger_name == \"%s\"",
-                                                       filter_expression, ev->name);
-                               } else {
-                                       err = asprintf(&jul_filter, "logger_name == \"%s\"",
-                                                       ev->name);
-                               }
-                               if (err < 0) {
-                                       PERROR("asprintf");
-                                       return -LTTNG_ERR_NOMEM;
-                               }
-                               filter_expression = jul_filter;
-                       }
-
-                       /* Add loglevel filtering if any for the JUL domain. */
-                       if (ev->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
-                               char *op;
-
-                               if (ev->loglevel_type == LTTNG_EVENT_LOGLEVEL_RANGE) {
-                                       op = ">=";
-                               } else {
-                                       op = "==";
-                               }
-
-                               if (filter_expression) {
-                                       err = asprintf(&jul_filter, "%s && int_loglevel %s %d",
-                                                       filter_expression, op, ev->loglevel);
-                               } else {
-                                       err = asprintf(&jul_filter, "int_loglevel %s %d", op,
-                                                       ev->loglevel);
-                               }
-                               if (err < 0) {
-                                       PERROR("asprintf");
-                                       return -LTTNG_ERR_NOMEM;
-                               }
-                               filter_expression = jul_filter;
-                       }
-
+                       /* Setup JUL filter if needed. */
+                       filter_expression = set_jul_filter(filter_expression, ev);
                        if (!filter_expression) {
                                goto ask_sessiond;
                        }
This page took 0.027827 seconds and 4 git commands to generate.