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:16 +0000 (10:03 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/lib/lttng-ctl/lttng-ctl.c

index 38fe271b09b6ee4e112d8080f40c4b886a2786e8..921db6f598fb30195398750f9a906e355e36707e 100644 (file)
@@ -687,6 +687,62 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle,
                        filter_expression, 0, NULL);
 }
 
                        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.
 /*
  * Enable event(s) for a channel, possibly with exclusions and a filter.
  * If no event name is specified, all events are enabled.
@@ -761,47 +817,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) {
        /* 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;
                        }
                        if (!filter_expression) {
                                goto ask_sessiond;
                        }
This page took 0.027798 seconds and 4 git commands to generate.