From 0a3fca4d597b02143affd90d50aa33409709024a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 30 Aug 2015 17:44:41 -0400 Subject: [PATCH] Save filter expression as part of agent events and save them MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/agent.c | 31 +++-- src/bin/lttng-sessiond/agent.h | 11 +- src/bin/lttng-sessiond/channel.c | 15 ++- src/bin/lttng-sessiond/cmd.c | 37 +++--- src/bin/lttng-sessiond/event.c | 14 +- src/bin/lttng-sessiond/save.c | 206 +++++++++++++++++++++-------- src/bin/lttng-sessiond/trace-ust.c | 9 +- src/bin/lttng-sessiond/trace-ust.h | 13 +- src/bin/lttng-sessiond/ust-app.c | 81 ++++++++++-- src/bin/lttng-sessiond/ust-app.h | 8 +- tests/unit/test_ust_data.c | 2 +- 11 files changed, 308 insertions(+), 119 deletions(-) diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index 4a8473ebb..4342c94db 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -784,33 +784,37 @@ error: } /* - * Create a newly allocated agent event data structure. If name is valid, it's - * copied into the created event. + * Create a newly allocated agent event data structure. + * Ownership of filter_expression is taken. * * Return a new object else NULL on error. */ struct agent_event *agent_create_event(const char *name, - struct lttng_filter_bytecode *filter) + int loglevel, enum lttng_loglevel_type loglevel_type, + struct lttng_filter_bytecode *filter, char *filter_expression) { - struct agent_event *event; + struct agent_event *event = NULL; DBG3("Agent create new event with name %s", name); - event = zmalloc(sizeof(*event)); - if (!event) { + if (!name) { + ERR("Failed to create agent event; no name provided."); goto error; } - if (name) { - strncpy(event->name, name, sizeof(event->name)); - event->name[sizeof(event->name) - 1] = '\0'; - lttng_ht_node_init_str(&event->node, event->name); + event = zmalloc(sizeof(*event)); + if (!event) { + goto error; } - if (filter) { - event->filter = filter; - } + strncpy(event->name, name, sizeof(event->name)); + event->name[sizeof(event->name) - 1] = '\0'; + lttng_ht_node_init_str(&event->node, event->name); + event->loglevel = loglevel; + event->loglevel_type = loglevel_type; + event->filter = filter; + event->filter_expression = filter_expression; error: return event; } @@ -918,6 +922,7 @@ void agent_destroy_event(struct agent_event *event) free(event->filter); free(event->filter_expression); + free(event->exclusion); free(event); } diff --git a/src/bin/lttng-sessiond/agent.h b/src/bin/lttng-sessiond/agent.h index de95b31d9..293426e0e 100644 --- a/src/bin/lttng-sessiond/agent.h +++ b/src/bin/lttng-sessiond/agent.h @@ -91,9 +91,10 @@ struct agent_event { /* Hash table node of the agent domain object. */ struct lttng_ht_node_str node; - /* Bytecode filter associated with the event . NULL if none. */ - char *filter_expression; + /* Filter associated with the event. NULL if none. */ struct lttng_filter_bytecode *filter; + char *filter_expression; + struct lttng_event_exclusion *exclusion; }; /* @@ -130,8 +131,10 @@ void agent_destroy(struct agent *agt); void agent_add(struct agent *agt, struct lttng_ht *ht); /* Agent event API. */ -struct agent_event *agent_create_event(const char *name, - struct lttng_filter_bytecode *filter); +struct agent_event *agent_create_event(const char *name, int loglevel, + enum lttng_loglevel_type loglevel_type, + struct lttng_filter_bytecode *filter, + char *filter_expression); void agent_add_event(struct agent_event *event, struct agent *agt); struct agent_event *agent_find_event(const char *name, int loglevel, diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index 7ea43b8f3..69498050e 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -333,11 +333,24 @@ int channel_ust_create(struct ltt_ust_session *usess, } /* Create UST channel */ - uchan = trace_ust_create_channel(attr); + uchan = trace_ust_create_channel(attr, LTTNG_DOMAIN_UST); if (uchan == NULL) { ret = LTTNG_ERR_FATAL; goto error; } + + /* + * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.) + * based on the default name. + */ + if (!strcmp(uchan->name, DEFAULT_JUL_CHANNEL_NAME)) { + uchan->domain = LTTNG_DOMAIN_JUL; + } else if (!strcmp(uchan->name, DEFAULT_LOG4J_CHANNEL_NAME)) { + uchan->domain = LTTNG_DOMAIN_LOG4J; + } else if (!strcmp(uchan->name, DEFAULT_PYTHON_CHANNEL_NAME)) { + uchan->domain = LTTNG_DOMAIN_PYTHON; + } + uchan->enabled = 1; if (trace_ust_is_max_id(usess->used_channel_id)) { ret = LTTNG_ERR_UST_CHAN_FAIL; diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 63d91f53d..6259ed089 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1737,7 +1737,8 @@ static int _cmd_enable_event(struct ltt_session *session, memset(&uevent, 0, sizeof(uevent)); uevent.type = LTTNG_EVENT_TRACEPOINT; uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - default_event_name = event_get_default_agent_ust_name(domain->type); + default_event_name = event_get_default_agent_ust_name( + domain->type); if (!default_event_name) { ret = LTTNG_ERR_FATAL; goto error; @@ -1769,29 +1770,30 @@ static int _cmd_enable_event(struct ltt_session *session, } { - struct lttng_filter_bytecode *filter_copy = NULL; char *filter_expression_copy = NULL; + struct lttng_filter_bytecode *filter_copy = NULL; if (filter) { - filter_copy = zmalloc( - sizeof(struct lttng_filter_bytecode) - + filter->len); + const size_t filter_size = sizeof( + struct lttng_filter_bytecode) + + filter->len; + + filter_copy = zmalloc(filter_size); if (!filter_copy) { ret = LTTNG_ERR_NOMEM; - goto error; } + memcpy(filter_copy, filter, filter_size); - memcpy(filter_copy, filter, - sizeof(struct lttng_filter_bytecode) - + filter->len); - } - - if (filter_expression) { filter_expression_copy = strdup(filter_expression); if (!filter_expression) { ret = LTTNG_ERR_NOMEM; - goto error_free_copy; + } + + if (!filter_expression_copy || !filter_copy) { + free(filter_expression_copy); + free(filter_copy); + goto error; } } @@ -1799,11 +1801,6 @@ static int _cmd_enable_event(struct ltt_session *session, (char *) default_chan_name, &uevent, filter_expression_copy, filter_copy, NULL, wpipe); - filter_copy = NULL; - filter_expression_copy = NULL; -error_free_copy: - free(filter_copy); - free(filter_expression_copy); } if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { @@ -1814,12 +1811,12 @@ error_free_copy: if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) { ret = event_agent_enable_all(usess, agt, event, filter, filter_expression); - filter = NULL; } else { ret = event_agent_enable(usess, agt, event, filter, filter_expression); - filter = NULL; } + filter = NULL; + filter_expression = NULL; if (ret != LTTNG_OK) { goto error; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index a5b4774ca..223a13d0e 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -509,8 +509,7 @@ error: */ int event_agent_enable_all(struct ltt_ust_session *usess, struct agent *agt, struct lttng_event *event, - struct lttng_filter_bytecode *filter, - char *filter_expression) + struct lttng_filter_bytecode *filter ,char *filter_expression) { int ret; struct agent_event *aevent; @@ -558,18 +557,19 @@ int event_agent_enable(struct ltt_ust_session *usess, assert(agt); DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d " - "and loglevel %d", event->name, usess->id, event->loglevel_type, - event->loglevel); + ", loglevel %d and filter \"%s\"", event->name, + usess->id, event->loglevel_type, event->loglevel, + filter_expression ? filter_expression : "NULL"); aevent = agent_find_event(event->name, event->loglevel, agt); if (!aevent) { - aevent = agent_create_event(event->name, filter); + aevent = agent_create_event(event->name, event->loglevel, + event->loglevel_type, filter, + filter_expression); if (!aevent) { ret = LTTNG_ERR_NOMEM; goto error; } - aevent->loglevel = event->loglevel; - aevent->loglevel_type = event->loglevel_type; created = 1; } diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 8c35d749e..8558b5219 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -35,6 +35,7 @@ #include "session.h" #include "syscall.h" #include "trace-ust.h" +#include "agent.h" static int save_kernel_channel_attributes(struct config_writer *writer, @@ -740,6 +741,68 @@ end: return ret; } +static +void init_ust_event_from_agent_event(struct ltt_ust_event *ust_event, + struct agent_event *agent_event) +{ + ust_event->enabled = agent_event->enabled; + ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT; + strncpy(ust_event->attr.name, agent_event->name, LTTNG_SYMBOL_NAME_LEN); + ust_event->attr.loglevel_type = agent_event->loglevel_type; + ust_event->attr.loglevel = agent_event->loglevel; + ust_event->filter_expression = agent_event->filter_expression; + ust_event->exclusion = agent_event->exclusion; +} + +static +int save_agent_events(struct config_writer *writer, + struct ltt_ust_channel *chan, + struct agent *agent) +{ + int ret; + struct lttng_ht_iter iter; + struct lttng_ht_node_str *node; + + ret = config_writer_open_element(writer, config_element_events); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + rcu_read_lock(); + cds_lfht_for_each_entry(agent->events->ht, &iter.iter, node, node) { + int ret; + struct agent_event *agent_event; + struct ltt_ust_event fake_event; + + memset(&fake_event, 0, sizeof(fake_event)); + agent_event = caa_container_of(node, struct agent_event, node); + + /* + * Initialize a fake ust event to reuse the same serialization + * function since UST and agent events contain the same info + * (and one could wonder why they don't reuse the same + * structures...). + */ + init_ust_event_from_agent_event(&fake_event, agent_event); + ret = save_ust_event(writer, &fake_event); + if (ret) { + rcu_read_unlock(); + goto end; + } + } + rcu_read_unlock(); + + /* /events */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} + static int save_kernel_context(struct config_writer *writer, struct lttng_kernel_context *ctx) @@ -1068,10 +1131,31 @@ int save_ust_channel(struct config_writer *writer, goto end; } - ret = save_ust_events(writer, ust_chan->events); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; + if (ust_chan->domain == LTTNG_DOMAIN_UST) { + ret = save_ust_events(writer, ust_chan->events); + if (ret) { + goto end; + } + } else { + struct agent *agent = NULL; + + agent = trace_ust_find_agent(session, ust_chan->domain); + if (!agent) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + ERR("Could not find agent associated to UST subdomain"); + goto end; + } + + /* + * Channels associated with a UST sub-domain (such as JUL, Log4j + * or Python) don't have any non-internal events. We retrieve + * the "agent" events associated with this channel and serialize + * them. + */ + ret = save_agent_events(writer, ust_chan, agent); + if (ret) { + goto end; + } } ret = save_ust_context(writer, &ust_chan->ctx_list); @@ -1139,20 +1223,62 @@ end: } static -int save_ust_session(struct config_writer *writer, - struct ltt_session *session, int save_agent) +const char *get_config_domain_str(enum lttng_domain_type domain) +{ + const char *str_dom; + + switch (domain) { + case LTTNG_DOMAIN_KERNEL: + str_dom = config_domain_type_kernel; + break; + case LTTNG_DOMAIN_UST: + str_dom = config_domain_type_ust; + break; + case LTTNG_DOMAIN_JUL: + str_dom = config_domain_type_jul; + break; + case LTTNG_DOMAIN_LOG4J: + str_dom = config_domain_type_log4j; + break; + case LTTNG_DOMAIN_PYTHON: + str_dom = config_domain_type_python; + break; + default: + assert(0); + } + + return str_dom; +} + +static +int save_ust_domain(struct config_writer *writer, + struct ltt_session *session, enum lttng_domain_type domain) { int ret; struct ltt_ust_channel *ust_chan; const char *buffer_type_string; struct lttng_ht_node_str *node; struct lttng_ht_iter iter; + const char *config_domain_name; assert(writer); assert(session); - ret = config_writer_write_element_string(writer, config_element_type, - save_agent ? config_domain_type_jul : config_domain_type_ust); + ret = config_writer_open_element(writer, + config_element_domain); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + config_domain_name = get_config_domain_str(domain); + if (!config_domain_name) { + ret = LTTNG_ERR_INVALID; + goto end; + } + + ret = config_writer_write_element_string(writer, + config_element_type, config_domain_name); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; @@ -1182,13 +1308,8 @@ int save_ust_session(struct config_writer *writer, rcu_read_lock(); cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht, &iter.iter, node, node) { - int agent_channel; - ust_chan = caa_container_of(node, struct ltt_ust_channel, node); - agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) || - !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name) || - !strcmp(DEFAULT_PYTHON_CHANNEL_NAME, ust_chan->name); - if (!(save_agent ^ agent_channel)) { + if (domain == ust_chan->domain) { ret = save_ust_channel(writer, ust_chan, session->ust_session); if (ret) { rcu_read_unlock(); @@ -1204,6 +1325,14 @@ int save_ust_session(struct config_writer *writer, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } + + /* /domain */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + end: return ret; } @@ -1360,22 +1489,13 @@ int save_domains(struct config_writer *writer, struct ltt_session *session) } if (session->ust_session) { - unsigned long agent_count; - - ret = config_writer_open_element(writer, - config_element_domain); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = save_ust_session(writer, session, 0); + ret = save_ust_domain(writer, session, LTTNG_DOMAIN_UST); if (ret) { goto end; } ret = config_writer_open_element(writer, - config_element_trackers); + config_element_trackers); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; @@ -1389,40 +1509,22 @@ int save_domains(struct config_writer *writer, struct ltt_session *session) /* /trackers */ ret = config_writer_close_element(writer); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - /* /domain */ - ret = config_writer_close_element(writer); + + ret = save_ust_domain(writer, session, LTTNG_DOMAIN_JUL); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - rcu_read_lock(); - agent_count = - lttng_ht_get_count(session->ust_session->agents); - rcu_read_unlock(); - - if (agent_count > 0) { - ret = config_writer_open_element(writer, - config_element_domain); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = save_ust_session(writer, session, 1); - if (ret) { - goto end; - } + ret = save_ust_domain(writer, session, LTTNG_DOMAIN_LOG4J); + if (ret) { + goto end; + } - /* /domain */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } + ret = save_ust_domain(writer, session, LTTNG_DOMAIN_PYTHON); + if (ret) { + goto end; } } diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index f8064a4c9..8ae8dfdb1 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -308,7 +308,8 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan) +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan, + enum lttng_domain_type domain) { struct ltt_ust_channel *luc; @@ -320,6 +321,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan) goto error; } + luc->domain = domain; + /* Copy UST channel attributes */ luc->attr.overwrite = chan->attr.overwrite; luc->attr.subbuf_size = chan->attr.subbuf_size; @@ -431,8 +434,8 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, /* Same layout. */ lue->filter_expression = filter_expression; - lue->filter = (struct lttng_ust_filter_bytecode *) filter; - lue->exclusion = (struct lttng_event_exclusion *) exclusion; + lue->filter = filter; + lue->exclusion = exclusion; /* Init node */ lttng_ht_node_init_str(&lue->node, lue->attr.name); diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index 121d3b0cc..343ce3e49 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -50,7 +50,7 @@ struct ltt_ust_event { struct lttng_ust_event attr; struct lttng_ht_node_str node; char *filter_expression; - struct lttng_ust_filter_bytecode *filter; + struct lttng_filter_bytecode *filter; struct lttng_event_exclusion *exclusion; bool internal; }; @@ -59,6 +59,11 @@ struct ltt_ust_event { struct ltt_ust_channel { uint64_t id; /* unique id per session. */ unsigned int enabled; + /* + * A UST channel can be part of a userspace sub-domain such as JUL, + * Log4j, Python. + */ + enum lttng_domain_type domain; char name[LTTNG_UST_SYM_NAME_LEN]; struct lttng_ust_channel_attr attr; struct lttng_ht *ctx; @@ -182,7 +187,8 @@ struct agent *trace_ust_find_agent(struct ltt_ust_session *session, * Create functions malloc() the data structure. */ struct ltt_ust_session *trace_ust_create_session(uint64_t session_id); -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr); +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, + enum lttng_domain_type domain); struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, char *filter_expression, struct lttng_filter_bytecode *filter, @@ -236,7 +242,8 @@ struct ltt_ust_session *trace_ust_create_session(unsigned int session_id) return NULL; } static inline -struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr) +struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, + enum lttng_domain_type domain) { return NULL; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 6f032da11..5cc9622f4 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -980,15 +980,15 @@ error: * * Return allocated filter or NULL on error. */ -static struct lttng_ust_filter_bytecode *alloc_copy_ust_app_filter( - struct lttng_ust_filter_bytecode *orig_f) +static struct lttng_filter_bytecode *copy_filter_bytecode( + struct lttng_filter_bytecode *orig_f) { - struct lttng_ust_filter_bytecode *filter = NULL; + struct lttng_filter_bytecode *filter = NULL; /* Copy filter bytecode */ filter = zmalloc(sizeof(*filter) + orig_f->len); if (!filter) { - PERROR("zmalloc alloc ust app filter"); + PERROR("zmalloc alloc filter bytecode"); goto error; } @@ -998,6 +998,30 @@ error: return filter; } +/* + * Create a liblttng-ust filter bytecode from given bytecode. + * + * Return allocated filter or NULL on error. + */ +static struct lttng_ust_filter_bytecode *create_ust_bytecode_from_bytecode( + struct lttng_filter_bytecode *orig_f) +{ + struct lttng_ust_filter_bytecode *filter = NULL; + + /* Copy filter bytecode */ + filter = zmalloc(sizeof(*filter) + orig_f->len); + if (!filter) { + PERROR("zmalloc alloc ust filter bytecode"); + goto error; + } + + assert(sizeof(struct lttng_filter_bytecode) == + sizeof(struct lttng_ust_filter_bytecode)); + memcpy(filter, orig_f, sizeof(*filter) + orig_f->len); +error: + return filter; +} + /* * Find an ust_app using the sock and return it. RCU read side lock must be * held before calling this helper function. @@ -1050,7 +1074,7 @@ error: * Return an ust_app_event object or NULL on error. */ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht, - char *name, struct lttng_ust_filter_bytecode *filter, int loglevel, + char *name, struct lttng_filter_bytecode *filter, int loglevel, const struct lttng_event_exclusion *exclusion) { struct lttng_ht_iter iter; @@ -1066,7 +1090,7 @@ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht, key.filter = filter; key.loglevel = loglevel; /* lttng_event_exclusion and lttng_ust_event_exclusion structures are similar */ - key.exclusion = (struct lttng_ust_event_exclusion *)exclusion; + key.exclusion = exclusion; /* Lookup using the event name as hash and a custom match fct. */ cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed), @@ -1131,6 +1155,7 @@ int set_ust_event_filter(struct ust_app_event *ua_event, struct ust_app *app) { int ret; + struct lttng_ust_filter_bytecode *ust_bytecode = NULL; health_code_update(); @@ -1139,7 +1164,12 @@ int set_ust_event_filter(struct ust_app_event *ua_event, goto error; } - ret = ustctl_set_filter(app->sock, ua_event->filter, + ust_bytecode = create_ust_bytecode_from_bytecode(ua_event->filter); + if (!ust_bytecode) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + ret = ustctl_set_filter(app->sock, ust_bytecode, ua_event->obj); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { @@ -1161,9 +1191,31 @@ int set_ust_event_filter(struct ust_app_event *ua_event, error: health_code_update(); + free(ust_bytecode); return ret; } +static +struct lttng_ust_event_exclusion *create_ust_exclusion_from_exclusion( + struct lttng_event_exclusion *exclusion) +{ + struct lttng_ust_event_exclusion *ust_exclusion = NULL; + size_t exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) + + LTTNG_UST_SYM_NAME_LEN * exclusion->count; + + ust_exclusion = zmalloc(exclusion_alloc_size); + if (!ust_exclusion) { + PERROR("malloc"); + goto end; + } + + assert(sizeof(struct lttng_event_exclusion) == + sizeof(struct lttng_ust_event_exclusion)); + memcpy(ust_exclusion, exclusion, exclusion_alloc_size); +end: + return ust_exclusion; +} + /* * Set event exclusions on the tracer. */ @@ -1172,6 +1224,7 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event, struct ust_app *app) { int ret; + struct lttng_ust_event_exclusion *ust_exclusion = NULL; health_code_update(); @@ -1180,8 +1233,13 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event, goto error; } - ret = ustctl_set_exclusion(app->sock, ua_event->exclusion, - ua_event->obj); + ust_exclusion = create_ust_exclusion_from_exclusion( + ua_event->exclusion); + if (!ust_exclusion) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + ret = ustctl_set_exclusion(app->sock, ust_exclusion, ua_event->obj); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app event %s exclusions failed for app (pid: %d) " @@ -1202,6 +1260,7 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event, error: health_code_update(); + free(ust_exclusion); return ret; } @@ -1503,13 +1562,13 @@ static void shadow_copy_event(struct ust_app_event *ua_event, /* Copy filter bytecode */ if (uevent->filter) { - ua_event->filter = alloc_copy_ust_app_filter(uevent->filter); + ua_event->filter = copy_filter_bytecode(uevent->filter); /* Filter might be NULL here in case of ENONEM. */ } /* Copy exclusion data */ if (uevent->exclusion) { - exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) + + exclusion_alloc_size = sizeof(struct lttng_event_exclusion) + LTTNG_UST_SYM_NAME_LEN * uevent->exclusion->count; ua_event->exclusion = zmalloc(exclusion_alloc_size); if (ua_event->exclusion == NULL) { diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index 66cda8c08..37ced6765 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -48,9 +48,9 @@ struct ust_app_notify_sock_obj { struct ust_app_ht_key { const char *name; - const struct lttng_ust_filter_bytecode *filter; + const struct lttng_filter_bytecode *filter; enum lttng_ust_loglevel_type loglevel; - const struct lttng_ust_event_exclusion *exclusion; + const struct lttng_event_exclusion *exclusion; }; /* @@ -115,8 +115,8 @@ struct ust_app_event { struct lttng_ust_event attr; char name[LTTNG_UST_SYM_NAME_LEN]; struct lttng_ht_node_str node; - struct lttng_ust_filter_bytecode *filter; - struct lttng_ust_event_exclusion *exclusion; + struct lttng_filter_bytecode *filter; + struct lttng_event_exclusion *exclusion; }; struct ust_app_stream { diff --git a/tests/unit/test_ust_data.c b/tests/unit/test_ust_data.c index d83b8b5e3..f945aef8f 100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.c @@ -101,7 +101,7 @@ static void test_create_ust_channel(void) strncpy(attr.name, "channel0", 8); - uchan = trace_ust_create_channel(&attr); + uchan = trace_ust_create_channel(&attr, LTTNG_DOMAIN_UST); ok(uchan != NULL, "Create UST channel"); ok(uchan->enabled == 0 && -- 2.34.1