/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
+ * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _GNU_SOURCE
#define _LGPL_SOURCE
-#include <errno.h>
#include <urcu/list.h>
#include <string.h>
+#include <common/compat/errno.h>
#include <lttng/lttng.h>
+#include <lttng/condition/condition.h>
+#include <lttng/condition/event-rule-matches.h>
+#include <lttng/event-rule/event-rule.h>
+#include <lttng/event-rule/event-rule-internal.h>
+#include <common/bytecode/bytecode.h>
#include <common/error.h>
#include <common/sessiond-comm/sessiond-comm.h>
+#include <common/filter.h>
+#include <common/context.h>
#include "channel.h"
#include "event.h"
#include "kernel.h"
#include "lttng-sessiond.h"
-#include "ust-ctl.h"
+#include "lttng-ust-ctl.h"
+#include "lttng-ust-error.h"
#include "ust-app.h"
#include "trace-kernel.h"
#include "trace-ust.h"
#include "agent.h"
+#include "utils.h"
/*
* Add unique UST event based on the event name, filter bytecode and loglevel.
assert(event);
key.name = event->attr.name;
- key.filter = (struct lttng_filter_bytecode *) event->filter;
- key.loglevel = event->attr.loglevel;
+ key.filter = (struct lttng_bytecode *) event->filter;
+ key.loglevel_type = event->attr.loglevel_type;
+ key.loglevel_value = event->attr.loglevel;
key.exclusion = event->exclusion;
node_ptr = cds_lfht_add_unique(ht->ht,
}
/*
- * Disable kernel tracepoint event for a channel from the kernel session.
+ * Disable kernel tracepoint events for a channel from the kernel session of
+ * a specified event_name and event type.
+ * On type LTTNG_EVENT_ALL all events with event_name are disabled.
+ * If event_name is NULL all events of the specified type are disabled.
*/
int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
- char *event_name)
-{
- int ret;
- struct ltt_kernel_event *kevent;
-
- assert(kchan);
-
- kevent = trace_kernel_get_event_by_name(event_name, kchan,
- LTTNG_EVENT_ALL);
- if (kevent == NULL) {
- ret = LTTNG_ERR_NO_EVENT;
- goto error;
- }
-
- ret = kernel_disable_event(kevent);
- if (ret < 0) {
- ret = LTTNG_ERR_KERN_DISABLE_FAIL;
- goto error;
- }
-
- DBG("Kernel event %s disable for channel %s.",
- kevent->event->name, kchan->channel->name);
-
- ret = LTTNG_OK;
-
-error:
- return ret;
-}
-
-/*
- * Disable kernel tracepoint events for a channel from the kernel session.
- */
-int event_kernel_disable_event_type(struct ltt_kernel_channel *kchan,
- enum lttng_event_type type)
+ const char *event_name, enum lttng_event_type type)
{
- int ret;
+ int ret, error = 0, found = 0;
struct ltt_kernel_event *kevent;
assert(kchan);
cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
if (type != LTTNG_EVENT_ALL && kevent->type != type)
continue;
+ if (event_name != NULL && strcmp(event_name, kevent->event->name)) {
+ continue;
+ }
+ found++;
ret = kernel_disable_event(kevent);
if (ret < 0) {
- /* We continue disabling the rest */
+ error = 1;
continue;
}
}
- ret = LTTNG_OK;
- return ret;
-}
+ DBG("Disable kernel event: found %d events with name: %s and type: %d",
+ found, event_name ? event_name : "NULL", type);
-/*
- * Disable all kernel event for a channel from the kernel session.
- */
-int event_kernel_disable_event_all(struct ltt_kernel_channel *kchan)
-{
- return event_kernel_disable_event_type(kchan, LTTNG_EVENT_ALL);
+ if (event_name != NULL && !found) {
+ ret = LTTNG_ERR_NO_EVENT;
+ } else {
+ ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK;
+ }
+
+ return ret;
}
/*
*/
int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
struct lttng_event *event, char *filter_expression,
- struct lttng_filter_bytecode *filter)
+ struct lttng_bytecode *filter)
{
int ret;
struct ltt_kernel_event *kevent;
kevent = trace_kernel_find_event(event->name, kchan,
event->type, filter);
if (kevent == NULL) {
- ret = kernel_create_event(event, kchan,
- filter_expression, filter);
+ ret = kernel_create_event(event, kchan, filter_expression, filter);
/* We have passed ownership */
filter_expression = NULL;
filter = NULL;
- if (ret < 0) {
- switch (-ret) {
- case EEXIST:
- ret = LTTNG_ERR_KERN_EVENT_EXIST;
- break;
- case ENOSYS:
- ret = LTTNG_ERR_KERN_EVENT_ENOSYS;
- break;
- default:
- ret = LTTNG_ERR_KERN_ENABLE_FAIL;
- break;
- }
+ if (ret) {
goto end;
}
} else if (kevent->enabled == 0) {
int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
struct ltt_ust_channel *uchan, struct lttng_event *event,
char *filter_expression,
- struct lttng_filter_bytecode *filter,
+ struct lttng_bytecode *filter,
struct lttng_event_exclusion *exclusion,
bool internal_event)
{
rcu_read_lock();
uevent = trace_ust_find_event(uchan->events, event->name, filter,
+ (enum lttng_ust_abi_loglevel_type) event->loglevel_type,
event->loglevel, exclusion);
if (!uevent) {
- uevent = trace_ust_create_event(event, filter_expression,
- filter, exclusion, internal_event);
+ ret = trace_ust_create_event(event, filter_expression,
+ filter, exclusion, internal_event, &uevent);
/* We have passed ownership */
filter_expression = NULL;
filter = NULL;
exclusion = NULL;
- if (uevent == NULL) {
- ret = LTTNG_ERR_UST_ENABLE_FAIL;
- goto error;
+ if (ret != LTTNG_OK) {
+ goto end;
}
/* Valid to set it after the goto error since uevent is still NULL */
if (uevent->enabled) {
/* It's already enabled so everything is OK */
+ assert(!to_create);
ret = LTTNG_ERR_UST_EVENT_ENABLED;
goto end;
}
uevent->enabled = 1;
+ if (to_create) {
+ /* Add ltt ust event to channel */
+ add_unique_ust_event(uchan->events, uevent);
+ }
+
+ if (!usess->active) {
+ goto end;
+ }
if (to_create) {
/* Create event on all UST registered apps for session */
if (ret < 0) {
if (ret == -LTTNG_UST_ERR_EXIST) {
ret = LTTNG_ERR_UST_EVENT_EXIST;
- goto end;
} else {
ret = LTTNG_ERR_UST_ENABLE_FAIL;
- goto error;
}
- }
-
- if (to_create) {
- /* Add ltt ust event to channel */
- add_unique_ust_event(uchan->events, uevent);
+ goto end;
}
DBG("Event UST %s %s in channel %s", uevent->attr.name,
free(filter);
free(exclusion);
return ret;
-
-error:
- /*
- * Only destroy event on creation time (not enabling time) because if the
- * event is found in the channel (to_create == 0), it means that at some
- * point the enable_event worked and it's thus valid to keep it alive.
- * Destroying it also implies that we also destroy it's shadow copy to sync
- * everyone up.
- */
- if (to_create) {
- /* In this code path, the uevent was not added to the hash table */
- trace_ust_destroy_event(uevent);
- }
- rcu_read_unlock();
- free(filter_expression);
- free(filter);
- free(exclusion);
- return ret;
}
/*
* Disable UST tracepoint of a channel from a UST session.
*/
int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
- struct ltt_ust_channel *uchan, char *event_name)
+ struct ltt_ust_channel *uchan, const char *event_name)
{
int ret;
struct ltt_ust_event *uevent;
/* It's already disabled so everything is OK */
goto next;
}
+ uevent->enabled = 0;
+ DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
+ uchan->name);
+ if (!usess->active) {
+ goto next;
+ }
ret = ust_app_disable_event_glb(usess, uchan, uevent);
if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
ret = LTTNG_ERR_UST_DISABLE_FAIL;
goto error;
}
- uevent->enabled = 0;
-
- DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
- uchan->name);
-
next:
/* Get next duplicate event by name. */
cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
return ret;
}
+/*
+ * Disable all UST tracepoints for a channel from a UST session.
+ */
+int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan)
+{
+ int ret, i, size, error = 0;
+ struct lttng_ht_iter iter;
+ struct ltt_ust_event *uevent = NULL;
+ struct lttng_event *events = NULL;
+
+ assert(usess);
+ assert(uchan);
+
+ rcu_read_lock();
+
+ /* Disabling existing events */
+ cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
+ node.node) {
+ if (uevent->enabled == 1) {
+ ret = event_ust_disable_tracepoint(usess, uchan,
+ uevent->attr.name);
+ if (ret < 0) {
+ error = LTTNG_ERR_UST_DISABLE_FAIL;
+ continue;
+ }
+ }
+ }
+
+ /* Get all UST available events */
+ size = ust_app_list_events(&events);
+ if (size < 0) {
+ ret = LTTNG_ERR_UST_LIST_FAIL;
+ goto error;
+ }
+
+ for (i = 0; i < size; i++) {
+ ret = event_ust_disable_tracepoint(usess, uchan,
+ events[i].name);
+ if (ret < 0) {
+ /* Continue to disable the rest... */
+ error = LTTNG_ERR_UST_DISABLE_FAIL;
+ continue;
+ }
+ }
+
+ ret = error ? error : LTTNG_OK;
+error:
+ rcu_read_unlock();
+ free(events);
+ return ret;
+}
+
+static void agent_enable_all(struct agent *agt)
+{
+ struct agent_event *aevent;
+ struct lttng_ht_iter iter;
+
+ /* Flag every event as enabled. */
+ rcu_read_lock();
+ cds_lfht_for_each_entry (
+ agt->events->ht, &iter.iter, aevent, node.node) {
+ aevent->enabled_count++;
+ }
+ rcu_read_unlock();
+}
+
/*
* Enable all agent event for a given UST session.
*
*/
int event_agent_enable_all(struct ltt_ust_session *usess,
struct agent *agt, struct lttng_event *event,
- struct lttng_filter_bytecode *filter)
+ struct lttng_bytecode *filter ,char *filter_expression)
{
int ret;
- struct agent_event *aevent;
- struct lttng_ht_iter iter;
assert(usess);
DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
/* Enable event on agent application through TCP socket. */
- ret = event_agent_enable(usess, agt, event, filter);
+ ret = event_agent_enable(usess, agt, event, filter, filter_expression);
if (ret != LTTNG_OK) {
goto error;
}
- /* Flag every event that they are now enabled. */
- rcu_read_lock();
- cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
- node.node) {
- aevent->enabled = 1;
- }
- rcu_read_unlock();
+ agent_enable_all(agt);
ret = LTTNG_OK;
}
/*
- * Enable a single agent event for a given UST session.
- *
- * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ * Check if this event's filter requires the activation of application contexts
+ * and enable them in the agent.
+ * TODO: bytecode iterator does not support non-legacy application
+ * contexts yet. Not an issue for now, since they are not generated by
+ * the lttng-ctl library.
*/
-int event_agent_enable(struct ltt_ust_session *usess,
- struct agent *agt, struct lttng_event *event,
- struct lttng_filter_bytecode *filter)
+static int add_filter_app_ctx(struct lttng_bytecode *bytecode,
+ const char *filter_expression, struct agent *agt)
+{
+ int ret = LTTNG_OK;
+ char *provider_name = NULL, *ctx_name = NULL;
+ struct bytecode_symbol_iterator *it =
+ bytecode_symbol_iterator_create(bytecode);
+
+ if (!it) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ do {
+ struct lttng_event_context ctx;
+ const char *symbol_name =
+ bytecode_symbol_iterator_get_name(it);
+
+ if (parse_application_context(symbol_name, &provider_name,
+ &ctx_name)) {
+ /* Not an application context. */
+ continue;
+ }
+
+ ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
+ ctx.u.app_ctx.provider_name = provider_name;
+ ctx.u.app_ctx.ctx_name = ctx_name;
+
+ /* Recognized an application context. */
+ DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.",
+ filter_expression, provider_name, ctx_name);
+
+ ret = agent_add_context(&ctx, agt);
+ if (ret != LTTNG_OK) {
+ ERR("Failed to add application context %s:%s.",
+ provider_name, ctx_name);
+ goto end;
+ }
+
+ ret = agent_enable_context(&ctx, agt->domain);
+ if (ret != LTTNG_OK) {
+ ERR("Failed to enable application context %s:%s.",
+ provider_name, ctx_name);
+ goto end;
+ }
+
+ free(provider_name);
+ free(ctx_name);
+ provider_name = ctx_name = NULL;
+ } while (bytecode_symbol_iterator_next(it) == 0);
+end:
+ free(provider_name);
+ free(ctx_name);
+ bytecode_symbol_iterator_destroy(it);
+ return ret;
+}
+
+static int agent_enable(struct agent *agt,
+ struct lttng_event *event,
+ struct lttng_bytecode *filter,
+ char *filter_expression)
{
int ret, created = 0;
struct agent_event *aevent;
- assert(usess);
assert(event);
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);
-
- aevent = agent_find_event(event->name, event->loglevel, agt);
+ rcu_read_lock();
+ aevent = agent_find_event(event->name, event->loglevel_type,
+ event->loglevel, filter_expression, agt);
if (!aevent) {
- aevent = agent_create_event(event->name, filter);
+ aevent = agent_create_event(event->name, event->loglevel_type,
+ event->loglevel, filter,
+ filter_expression);
if (!aevent) {
ret = LTTNG_ERR_NOMEM;
goto error;
}
- aevent->loglevel = event->loglevel;
- aevent->loglevel_type = event->loglevel_type;
+ filter = NULL;
+ filter_expression = NULL;
created = 1;
+ assert(!AGENT_EVENT_IS_ENABLED(aevent));
+ }
+
+ if (created && aevent->filter) {
+ ret = add_filter_app_ctx(
+ aevent->filter, aevent->filter_expression, agt);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
}
/* Already enabled? */
- if (aevent->enabled) {
+ if (AGENT_EVENT_IS_ENABLED(aevent)) {
+ ret = LTTNG_OK;
goto end;
}
agent_add_event(aevent, agt);
}
-end:
- return LTTNG_OK;
+ ret = LTTNG_OK;
+ goto end;
error:
if (created) {
agent_destroy_event(aevent);
}
+end:
+ rcu_read_unlock();
+ free(filter);
+ free(filter_expression);
+ return ret;
+}
+
+/*
+ * Enable a single agent event for a given UST session.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int event_agent_enable(struct ltt_ust_session *usess,
+ struct agent *agt,
+ struct lttng_event *event,
+ struct lttng_bytecode *filter,
+ char *filter_expression)
+{
+ assert(usess);
+ assert(event);
+ assert(agt);
+
+ DBG("Enabling agent event: event pattern = '%s', session id = %" PRIu64 ", loglevel type = %d, loglevel = %d, filter expression = '%s'",
+ event->name, usess->id, event->loglevel_type,
+ event->loglevel,
+ filter_expression ? filter_expression : "(none)");
+
+ return agent_enable(agt, event, filter, filter_expression);
+}
+
+/*
+ * Enable a single agent event for a trigger.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
+{
+ int ret;
+ enum lttng_condition_status c_status;
+ enum lttng_trigger_status t_status;
+ enum lttng_domain_type d_type;
+ const struct lttng_condition *condition;
+ const struct lttng_event_rule *rule;
+ const char *filter_expression;
+ char *filter_expression_copy = NULL;
+ const struct lttng_bytecode *filter_bytecode;
+ struct lttng_bytecode *filter_bytecode_copy = NULL;
+ struct lttng_event *event = NULL;
+ uid_t trigger_owner_uid = 0;
+ const char *trigger_name;
+
+ assert(trigger);
+ assert(agt);
+
+ t_status = lttng_trigger_get_name(trigger, &trigger_name);
+ if (t_status != LTTNG_TRIGGER_STATUS_OK) {
+ trigger_name = "(anonymous)";
+ }
+
+ t_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner_uid);
+ assert(t_status == LTTNG_TRIGGER_STATUS_OK);
+
+ condition = lttng_trigger_get_const_condition(trigger);
+
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
+
+ c_status = lttng_condition_event_rule_matches_get_rule(
+ condition, &rule);
+ assert(c_status == LTTNG_CONDITION_STATUS_OK);
+
+ switch (lttng_event_rule_get_type(rule)) {
+ case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING:
+ case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING:
+ case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING:
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ d_type = lttng_event_rule_get_domain_type(rule);
+ assert(d_type == agt->domain);
+
+ event = lttng_event_rule_generate_lttng_event(rule);
+ if (!event) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Get the internal filter expression and bytecode. */
+ filter_expression = lttng_event_rule_get_filter(rule);
+ if (filter_expression) {
+ filter_expression_copy = strdup(filter_expression);
+ if (!filter_expression_copy) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Get the filter bytecode */
+ filter_bytecode = lttng_event_rule_get_filter_bytecode(rule);
+ if (filter_bytecode) {
+ filter_bytecode_copy =
+ lttng_bytecode_copy(filter_bytecode);
+ if (!filter_bytecode_copy) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+ }
+
+ DBG("Enabling agent event from trigger: trigger name = '%s', trigger owner uid = %d, token = %" PRIu64,
+ trigger_name, trigger_owner_uid,
+ lttng_trigger_get_tracer_token(trigger));
+
+ ret = agent_enable(agt, event, filter_bytecode_copy,
+ filter_expression_copy);
+ /* Ownership was passed even in case of error. */
+ filter_expression_copy = NULL;
+ filter_bytecode_copy = NULL;
+
+end:
+ free(filter_expression_copy);
+ free(filter_bytecode_copy);
+ free(event);
return ret;
}
return default_event_name;
}
+static int trigger_agent_disable_one(const struct lttng_trigger *trigger,
+ struct agent *agt,
+ struct agent_event *aevent)
+
+{
+ int ret;
+
+ assert(agt);
+ assert(trigger);
+ assert(aevent);
+
+ /*
+ * Actual ust event un-registration happens on the trigger
+ * un-registration at that point.
+ */
+
+ DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for trigger %" PRIu64,
+ aevent->name, aevent->loglevel_type,
+ aevent->loglevel_value, lttng_trigger_get_tracer_token(trigger));
+
+ /* Already disabled? */
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
+ goto end;
+ }
+
+ ret = agent_disable_event(aevent, agt->domain);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+
+end:
+ return LTTNG_OK;
+
+error:
+ return ret;
+}
+
/*
- * Disable a single agent event for a given UST session.
+ * Disable a given agent event for a given UST session.
*
+ * Must be called with the RCU read lock held.
* Return LTTNG_OK on success or else a LTTNG_ERR* code.
*/
-int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
- char *event_name)
+static int event_agent_disable_one(struct ltt_ust_session *usess,
+ struct agent *agt, struct agent_event *aevent)
{
int ret;
- struct agent_event *aevent;
struct ltt_ust_event *uevent = NULL;
struct ltt_ust_channel *uchan = NULL;
const char *ust_event_name, *ust_channel_name;
assert(agt);
assert(usess);
- assert(event_name);
+ assert(aevent);
- DBG("Event agent disabling %s for session %" PRIu64, event_name, usess->id);
-
- aevent = agent_find_event_by_name(event_name, agt);
- if (!aevent) {
- ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
- goto error;
- }
+ DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64,
+ aevent->name, aevent->loglevel_type, aevent->loglevel_value,
+ usess->id);
/* Already disabled? */
- if (!aevent->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
goto end;
}
}
/*
- * The loglevel is hardcoded with 0 here since the agent ust event is set
- * with the loglevel type to ALL thus the loglevel stays 0. The event's
- * filter is the one handling the loglevel for agent.
+ * Agent UST event has its loglevel type forced to
+ * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering
+ * happens thanks to an UST filter. The following -1 is actually
+ * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
*/
uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
- aevent->filter, 0, NULL);
+ aevent->filter, LTTNG_UST_ABI_LOGLEVEL_ALL, -1, NULL);
/* If the agent event exists, it must be available on the UST side. */
assert(uevent);
- ret = ust_app_disable_event_glb(usess, uchan, uevent);
- if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
- ret = LTTNG_ERR_UST_DISABLE_FAIL;
- goto error;
+ if (usess->active) {
+ ret = ust_app_disable_event_glb(usess, uchan, uevent);
+ if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
+ ret = LTTNG_ERR_UST_DISABLE_FAIL;
+ goto error;
+ }
}
/*
error:
return ret;
}
+
+/*
+ * Disable agent event matching a given trigger.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int trigger_agent_disable(
+ const struct lttng_trigger *trigger, struct agent *agt)
+{
+ int ret = LTTNG_OK;
+ struct agent_event *aevent;
+
+ assert(trigger);
+ assert(agt);
+
+ DBG("Event agent disabling for trigger %" PRIu64,
+ lttng_trigger_get_tracer_token(trigger));
+
+ rcu_read_lock();
+ aevent = agent_find_event_by_trigger(trigger, agt);
+
+ if (aevent == NULL) {
+ DBG2("Event agent NOT found by trigger %" PRIu64,
+ lttng_trigger_get_tracer_token(trigger));
+ ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
+ goto end;
+ }
+
+ ret = trigger_agent_disable_one(trigger, agt, aevent);
+
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+end:
+ rcu_read_unlock();
+ return ret;
+}
+
+/*
+ * Disable all agent events matching a given name for a given UST session.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
+ const char *event_name)
+{
+ int ret = LTTNG_OK;
+ struct agent_event *aevent;
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_str *node;
+
+ assert(agt);
+ assert(usess);
+ assert(event_name);
+
+ DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id);
+
+ rcu_read_lock();
+ agent_find_events_by_name(event_name, agt, &iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+
+ if (node == NULL) {
+ DBG2("Event agent NOT found by name %s", event_name);
+ ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
+ goto end;
+ }
+
+ do {
+ aevent = caa_container_of(node, struct agent_event, node);
+ ret = event_agent_disable_one(usess, agt, aevent);
+
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Get next duplicate agent event by name. */
+ agent_event_next_duplicate(event_name, agt, &iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ } while (node);
+end:
+ rcu_read_unlock();
+ return ret;
+}
/*
* Disable all agent event for a given UST session.
*
goto error;
}
- /* Flag every event that they are now enabled. */
+ /* Disable every event. */
rcu_read_lock();
cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
node.node) {
- if (!aevent->enabled) {
+ if (!AGENT_EVENT_IS_ENABLED(aevent)) {
continue;
}
ret = event_agent_disable(usess, agt, aevent->name);
if (ret != LTTNG_OK) {
- rcu_read_unlock();
- goto error;
+ goto error_unlock;
}
}
- rcu_read_unlock();
-
ret = LTTNG_OK;
+error_unlock:
+ rcu_read_unlock();
error:
return ret;
}