Build fix: rpath of test libraries results in non-reproducible build
[lttng-tools.git] / src / bin / lttng-sessiond / event.cpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <urcu/list.h>
11 #include <string.h>
12
13 #include <common/compat/errno.hpp>
14 #include <lttng/lttng.h>
15 #include <lttng/condition/condition.h>
16 #include <lttng/condition/event-rule-matches.h>
17 #include <lttng/event-rule/event-rule.h>
18 #include <lttng/event-rule/event-rule-internal.hpp>
19 #include <common/bytecode/bytecode.hpp>
20 #include <common/error.hpp>
21 #include <common/sessiond-comm/sessiond-comm.hpp>
22 #include <common/filter.hpp>
23 #include <common/context.hpp>
24
25 #include "channel.hpp"
26 #include "event.hpp"
27 #include "kernel.hpp"
28 #include "lttng-sessiond.hpp"
29 #include "lttng-ust-ctl.hpp"
30 #include "lttng-ust-error.hpp"
31 #include "ust-app.hpp"
32 #include "trace-kernel.hpp"
33 #include "trace-ust.hpp"
34 #include "agent.hpp"
35 #include "utils.hpp"
36
37 /*
38 * Add unique UST event based on the event name, filter bytecode and loglevel.
39 */
40 static void add_unique_ust_event(struct lttng_ht *ht,
41 struct ltt_ust_event *event)
42 {
43 struct cds_lfht_node *node_ptr;
44 struct ltt_ust_ht_key key;
45
46 LTTNG_ASSERT(ht);
47 LTTNG_ASSERT(ht->ht);
48 LTTNG_ASSERT(event);
49
50 key.name = event->attr.name;
51 key.filter = (struct lttng_bytecode *) event->filter;
52 key.loglevel_type = (lttng_ust_abi_loglevel_type) event->attr.loglevel_type;
53 key.loglevel_value = event->attr.loglevel;
54 key.exclusion = event->exclusion;
55
56 node_ptr = cds_lfht_add_unique(ht->ht,
57 ht->hash_fct(event->node.key, lttng_ht_seed),
58 trace_ust_ht_match_event, &key, &event->node.node);
59 LTTNG_ASSERT(node_ptr == &event->node.node);
60 }
61
62 /*
63 * Disable kernel tracepoint events for a channel from the kernel session of
64 * a specified event_name and event type.
65 * On type LTTNG_EVENT_ALL all events with event_name are disabled.
66 * If event_name is NULL all events of the specified type are disabled.
67 */
68 int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
69 const char *event_name, enum lttng_event_type type)
70 {
71 int ret, error = 0, found = 0;
72 struct ltt_kernel_event *kevent;
73
74 LTTNG_ASSERT(kchan);
75
76 /* For each event in the kernel session */
77 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
78 if (type != LTTNG_EVENT_ALL && kevent->type != type)
79 continue;
80 if (event_name != NULL && strcmp(event_name, kevent->event->name)) {
81 continue;
82 }
83 found++;
84 ret = kernel_disable_event(kevent);
85 if (ret < 0) {
86 error = 1;
87 continue;
88 }
89 }
90 DBG("Disable kernel event: found %d events with name: %s and type: %d",
91 found, event_name ? event_name : "NULL", type);
92
93 if (event_name != NULL && !found) {
94 ret = LTTNG_ERR_NO_EVENT;
95 } else {
96 ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK;
97 }
98
99 return ret;
100 }
101
102 /*
103 * Enable kernel tracepoint event for a channel from the kernel session.
104 * We own filter_expression and filter.
105 */
106 int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
107 struct lttng_event *event, char *filter_expression,
108 struct lttng_bytecode *filter)
109 {
110 int ret;
111 struct ltt_kernel_event *kevent;
112
113 LTTNG_ASSERT(kchan);
114 LTTNG_ASSERT(event);
115
116 kevent = trace_kernel_find_event(event->name, kchan,
117 event->type, filter);
118 if (kevent == NULL) {
119 ret = kernel_create_event(event, kchan, filter_expression, filter);
120 /* We have passed ownership */
121 filter_expression = NULL;
122 filter = NULL;
123 if (ret) {
124 goto end;
125 }
126 } else if (kevent->enabled == 0) {
127 ret = kernel_enable_event(kevent);
128 if (ret < 0) {
129 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
130 goto end;
131 }
132 } else {
133 /* At this point, the event is considered enabled */
134 ret = LTTNG_ERR_KERN_EVENT_EXIST;
135 goto end;
136 }
137
138 ret = LTTNG_OK;
139 end:
140 free(filter_expression);
141 free(filter);
142 return ret;
143 }
144
145 /*
146 * ============================
147 * UST : The Ultimate Frontier!
148 * ============================
149 */
150
151 /*
152 * Enable UST tracepoint event for a channel from a UST session.
153 * We own filter_expression, filter, and exclusion.
154 */
155 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
156 struct ltt_ust_channel *uchan, struct lttng_event *event,
157 char *filter_expression,
158 struct lttng_bytecode *filter,
159 struct lttng_event_exclusion *exclusion,
160 bool internal_event)
161 {
162 int ret = LTTNG_OK, to_create = 0;
163 struct ltt_ust_event *uevent;
164
165 LTTNG_ASSERT(usess);
166 LTTNG_ASSERT(uchan);
167 LTTNG_ASSERT(event);
168
169 rcu_read_lock();
170
171 uevent = trace_ust_find_event(uchan->events, event->name, filter,
172 (enum lttng_ust_abi_loglevel_type) event->loglevel_type,
173 event->loglevel, exclusion);
174 if (!uevent) {
175 ret = trace_ust_create_event(event, filter_expression,
176 filter, exclusion, internal_event, &uevent);
177 /* We have passed ownership */
178 filter_expression = NULL;
179 filter = NULL;
180 exclusion = NULL;
181 if (ret != LTTNG_OK) {
182 goto end;
183 }
184
185 /* Valid to set it after the goto error since uevent is still NULL */
186 to_create = 1;
187 }
188
189 if (uevent->enabled) {
190 /* It's already enabled so everything is OK */
191 LTTNG_ASSERT(!to_create);
192 ret = LTTNG_ERR_UST_EVENT_ENABLED;
193 goto end;
194 }
195
196 uevent->enabled = 1;
197 if (to_create) {
198 /* Add ltt ust event to channel */
199 add_unique_ust_event(uchan->events, uevent);
200 }
201
202 if (!usess->active) {
203 goto end;
204 }
205
206 if (to_create) {
207 /* Create event on all UST registered apps for session */
208 ret = ust_app_create_event_glb(usess, uchan, uevent);
209 } else {
210 /* Enable event on all UST registered apps for session */
211 ret = ust_app_enable_event_glb(usess, uchan, uevent);
212 }
213
214 if (ret < 0) {
215 if (ret == -LTTNG_UST_ERR_EXIST) {
216 ret = LTTNG_ERR_UST_EVENT_EXIST;
217 } else {
218 ret = LTTNG_ERR_UST_ENABLE_FAIL;
219 }
220 goto end;
221 }
222
223 DBG("Event UST %s %s in channel %s", uevent->attr.name,
224 to_create ? "created" : "enabled", uchan->name);
225
226 ret = LTTNG_OK;
227
228 end:
229 rcu_read_unlock();
230 free(filter_expression);
231 free(filter);
232 free(exclusion);
233 return ret;
234 }
235
236 /*
237 * Disable UST tracepoint of a channel from a UST session.
238 */
239 int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
240 struct ltt_ust_channel *uchan, const char *event_name)
241 {
242 int ret;
243 struct ltt_ust_event *uevent;
244 struct lttng_ht_node_str *node;
245 struct lttng_ht_iter iter;
246 struct lttng_ht *ht;
247
248 LTTNG_ASSERT(usess);
249 LTTNG_ASSERT(uchan);
250 LTTNG_ASSERT(event_name);
251
252 ht = uchan->events;
253
254 rcu_read_lock();
255
256 /*
257 * We use a custom lookup since we need the iterator for the next_duplicate
258 * call in the do while loop below.
259 */
260 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
261 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
262 node = lttng_ht_iter_get_node_str(&iter);
263 if (node == NULL) {
264 DBG2("Trace UST event NOT found by name %s", event_name);
265 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
266 goto error;
267 }
268
269 do {
270 uevent = lttng::utils::container_of(node, &ltt_ust_event::node);
271 LTTNG_ASSERT(uevent);
272
273 if (uevent->enabled == 0) {
274 /* It's already disabled so everything is OK */
275 goto next;
276 }
277 uevent->enabled = 0;
278 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
279 uchan->name);
280
281 if (!usess->active) {
282 goto next;
283 }
284 ret = ust_app_disable_event_glb(usess, uchan, uevent);
285 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
286 ret = LTTNG_ERR_UST_DISABLE_FAIL;
287 goto error;
288 }
289 next:
290 /* Get next duplicate event by name. */
291 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
292 event_name, &iter.iter);
293 node = lttng_ht_iter_get_node_str(&iter);
294 } while (node);
295
296 ret = LTTNG_OK;
297
298 error:
299 rcu_read_unlock();
300 return ret;
301 }
302
303 /*
304 * Disable all UST tracepoints for a channel from a UST session.
305 */
306 int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
307 struct ltt_ust_channel *uchan)
308 {
309 int ret, i, size, error = 0;
310 struct lttng_ht_iter iter;
311 struct ltt_ust_event *uevent = NULL;
312 struct lttng_event *events = NULL;
313
314 LTTNG_ASSERT(usess);
315 LTTNG_ASSERT(uchan);
316
317 rcu_read_lock();
318
319 /* Disabling existing events */
320 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
321 node.node) {
322 if (uevent->enabled == 1) {
323 ret = event_ust_disable_tracepoint(usess, uchan,
324 uevent->attr.name);
325 if (ret < 0) {
326 error = LTTNG_ERR_UST_DISABLE_FAIL;
327 continue;
328 }
329 }
330 }
331
332 /* Get all UST available events */
333 size = ust_app_list_events(&events);
334 if (size < 0) {
335 ret = LTTNG_ERR_UST_LIST_FAIL;
336 goto error;
337 }
338
339 for (i = 0; i < size; i++) {
340 ret = event_ust_disable_tracepoint(usess, uchan,
341 events[i].name);
342 if (ret < 0) {
343 /* Continue to disable the rest... */
344 error = LTTNG_ERR_UST_DISABLE_FAIL;
345 continue;
346 }
347 }
348
349 ret = error ? error : LTTNG_OK;
350 error:
351 rcu_read_unlock();
352 free(events);
353 return ret;
354 }
355
356 static void agent_enable_all(struct agent *agt)
357 {
358 struct agent_event *aevent;
359 struct lttng_ht_iter iter;
360
361 /* Flag every event as enabled. */
362 rcu_read_lock();
363 cds_lfht_for_each_entry (
364 agt->events->ht, &iter.iter, aevent, node.node) {
365 aevent->enabled_count++;
366 }
367 rcu_read_unlock();
368 }
369
370 /*
371 * Enable all agent event for a given UST session.
372 *
373 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
374 */
375 int event_agent_enable_all(struct ltt_ust_session *usess,
376 struct agent *agt, struct lttng_event *event,
377 struct lttng_bytecode *filter ,char *filter_expression)
378 {
379 int ret;
380
381 LTTNG_ASSERT(usess);
382
383 DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
384
385 /* Enable event on agent application through TCP socket. */
386 ret = event_agent_enable(usess, agt, event, filter, filter_expression);
387 if (ret != LTTNG_OK) {
388 goto error;
389 }
390
391 agent_enable_all(agt);
392
393 ret = LTTNG_OK;
394
395 error:
396 return ret;
397 }
398
399 /*
400 * Check if this event's filter requires the activation of application contexts
401 * and enable them in the agent.
402 * TODO: bytecode iterator does not support non-legacy application
403 * contexts yet. Not an issue for now, since they are not generated by
404 * the lttng-ctl library.
405 */
406 static int add_filter_app_ctx(struct lttng_bytecode *bytecode,
407 const char *filter_expression, struct agent *agt)
408 {
409 int ret = LTTNG_OK;
410 char *provider_name = NULL, *ctx_name = NULL;
411 struct bytecode_symbol_iterator *it =
412 bytecode_symbol_iterator_create(bytecode);
413
414 if (!it) {
415 ret = LTTNG_ERR_NOMEM;
416 goto end;
417 }
418
419 do {
420 struct lttng_event_context ctx;
421 const char *symbol_name =
422 bytecode_symbol_iterator_get_name(it);
423
424 if (parse_application_context(symbol_name, &provider_name,
425 &ctx_name)) {
426 /* Not an application context. */
427 continue;
428 }
429
430 ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
431 ctx.u.app_ctx.provider_name = provider_name;
432 ctx.u.app_ctx.ctx_name = ctx_name;
433
434 /* Recognized an application context. */
435 DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.",
436 filter_expression, provider_name, ctx_name);
437
438 ret = agent_add_context(&ctx, agt);
439 if (ret != LTTNG_OK) {
440 ERR("Failed to add application context %s:%s.",
441 provider_name, ctx_name);
442 goto end;
443 }
444
445 ret = agent_enable_context(&ctx, agt->domain);
446 if (ret != LTTNG_OK) {
447 ERR("Failed to enable application context %s:%s.",
448 provider_name, ctx_name);
449 goto end;
450 }
451
452 free(provider_name);
453 free(ctx_name);
454 provider_name = ctx_name = NULL;
455 } while (bytecode_symbol_iterator_next(it) == 0);
456 end:
457 free(provider_name);
458 free(ctx_name);
459 bytecode_symbol_iterator_destroy(it);
460 return ret;
461 }
462
463 static int agent_enable(struct agent *agt,
464 struct lttng_event *event,
465 struct lttng_bytecode *filter,
466 char *filter_expression)
467 {
468 int ret, created = 0;
469 struct agent_event *aevent;
470
471 LTTNG_ASSERT(event);
472 LTTNG_ASSERT(agt);
473
474 rcu_read_lock();
475 aevent = agent_find_event(event->name, event->loglevel_type,
476 event->loglevel, filter_expression, agt);
477 if (!aevent) {
478 aevent = agent_create_event(event->name, event->loglevel_type,
479 event->loglevel, filter,
480 filter_expression);
481 if (!aevent) {
482 ret = LTTNG_ERR_NOMEM;
483 goto error;
484 }
485 filter = NULL;
486 filter_expression = NULL;
487 created = 1;
488 LTTNG_ASSERT(!AGENT_EVENT_IS_ENABLED(aevent));
489 }
490
491 if (created && aevent->filter) {
492 ret = add_filter_app_ctx(
493 aevent->filter, aevent->filter_expression, agt);
494 if (ret != LTTNG_OK) {
495 goto error;
496 }
497 }
498
499 /* Already enabled? */
500 if (AGENT_EVENT_IS_ENABLED(aevent)) {
501 ret = LTTNG_OK;
502 goto end;
503 }
504
505 ret = agent_enable_event(aevent, agt->domain);
506 if (ret != LTTNG_OK) {
507 goto error;
508 }
509
510 /* If the event was created prior to the enable, add it to the domain. */
511 if (created) {
512 agent_add_event(aevent, agt);
513 }
514
515 ret = LTTNG_OK;
516 goto end;
517
518 error:
519 if (created) {
520 agent_destroy_event(aevent);
521 }
522 end:
523 rcu_read_unlock();
524 free(filter);
525 free(filter_expression);
526 return ret;
527 }
528
529 /*
530 * Enable a single agent event for a given UST session.
531 *
532 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
533 */
534 int event_agent_enable(struct ltt_ust_session *usess,
535 struct agent *agt,
536 struct lttng_event *event,
537 struct lttng_bytecode *filter,
538 char *filter_expression)
539 {
540 LTTNG_ASSERT(usess);
541 LTTNG_ASSERT(event);
542 LTTNG_ASSERT(agt);
543
544 DBG("Enabling agent event: event pattern = '%s', session id = %" PRIu64 ", loglevel type = %d, loglevel = %d, filter expression = '%s'",
545 event->name, usess->id, event->loglevel_type,
546 event->loglevel,
547 filter_expression ? filter_expression : "(none)");
548
549 return agent_enable(agt, event, filter, filter_expression);
550 }
551
552 /*
553 * Enable a single agent event for a trigger.
554 *
555 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
556 */
557 int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
558 {
559 int ret;
560 enum lttng_condition_status c_status;
561 enum lttng_trigger_status t_status;
562 enum lttng_domain_type d_type;
563 const struct lttng_condition *condition;
564 const struct lttng_event_rule *rule;
565 const char *filter_expression;
566 char *filter_expression_copy = NULL;
567 const struct lttng_bytecode *filter_bytecode;
568 struct lttng_bytecode *filter_bytecode_copy = NULL;
569 struct lttng_event *event = NULL;
570 uid_t trigger_owner_uid = 0;
571 const char *trigger_name;
572
573 LTTNG_ASSERT(trigger);
574 LTTNG_ASSERT(agt);
575
576 t_status = lttng_trigger_get_name(trigger, &trigger_name);
577 if (t_status != LTTNG_TRIGGER_STATUS_OK) {
578 trigger_name = "(anonymous)";
579 }
580
581 t_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner_uid);
582 LTTNG_ASSERT(t_status == LTTNG_TRIGGER_STATUS_OK);
583
584 condition = lttng_trigger_get_const_condition(trigger);
585
586 LTTNG_ASSERT(lttng_condition_get_type(condition) ==
587 LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
588
589 c_status = lttng_condition_event_rule_matches_get_rule(
590 condition, &rule);
591 LTTNG_ASSERT(c_status == LTTNG_CONDITION_STATUS_OK);
592
593 switch (lttng_event_rule_get_type(rule)) {
594 case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING:
595 case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING:
596 case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING:
597 break;
598 default:
599 abort();
600 break;
601 }
602
603 d_type = lttng_event_rule_get_domain_type(rule);
604 LTTNG_ASSERT(d_type == agt->domain);
605
606 event = lttng_event_rule_generate_lttng_event(rule);
607 if (!event) {
608 ret = LTTNG_ERR_NOMEM;
609 goto end;
610 }
611
612 /* Get the internal filter expression and bytecode. */
613 filter_expression = lttng_event_rule_get_filter(rule);
614 if (filter_expression) {
615 filter_expression_copy = strdup(filter_expression);
616 if (!filter_expression_copy) {
617 ret = LTTNG_ERR_NOMEM;
618 goto end;
619 }
620
621 /* Get the filter bytecode */
622 filter_bytecode = lttng_event_rule_get_filter_bytecode(rule);
623 if (filter_bytecode) {
624 filter_bytecode_copy =
625 lttng_bytecode_copy(filter_bytecode);
626 if (!filter_bytecode_copy) {
627 ret = LTTNG_ERR_NOMEM;
628 goto end;
629 }
630 }
631 }
632
633 DBG("Enabling agent event from trigger: trigger name = '%s', trigger owner uid = %d, token = %" PRIu64,
634 trigger_name, trigger_owner_uid,
635 lttng_trigger_get_tracer_token(trigger));
636
637 ret = agent_enable(agt, event, filter_bytecode_copy,
638 filter_expression_copy);
639 /* Ownership was passed even in case of error. */
640 filter_expression_copy = NULL;
641 filter_bytecode_copy = NULL;
642
643 end:
644 free(filter_expression_copy);
645 free(filter_bytecode_copy);
646 free(event);
647 return ret;
648 }
649
650 /*
651 * Return the default event name associated with the provided UST domain. Return
652 * NULL on error.
653 */
654 const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
655 {
656 const char *default_event_name = NULL;
657
658 switch (domain) {
659 case LTTNG_DOMAIN_LOG4J:
660 default_event_name = DEFAULT_LOG4J_EVENT_NAME;
661 break;
662 case LTTNG_DOMAIN_JUL:
663 default_event_name = DEFAULT_JUL_EVENT_NAME;
664 break;
665 case LTTNG_DOMAIN_PYTHON:
666 default_event_name = DEFAULT_PYTHON_EVENT_NAME;
667 break;
668 default:
669 abort();
670 }
671
672 return default_event_name;
673 }
674
675 static int trigger_agent_disable_one(const struct lttng_trigger *trigger,
676 struct agent *agt,
677 struct agent_event *aevent)
678
679 {
680 int ret;
681
682 LTTNG_ASSERT(agt);
683 LTTNG_ASSERT(trigger);
684 LTTNG_ASSERT(aevent);
685
686 /*
687 * Actual ust event un-registration happens on the trigger
688 * un-registration at that point.
689 */
690
691 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for trigger %" PRIu64,
692 aevent->name, aevent->loglevel_type,
693 aevent->loglevel_value, lttng_trigger_get_tracer_token(trigger));
694
695 /* Already disabled? */
696 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
697 goto end;
698 }
699
700 ret = agent_disable_event(aevent, agt->domain);
701 if (ret != LTTNG_OK) {
702 goto error;
703 }
704
705 end:
706 return LTTNG_OK;
707
708 error:
709 return ret;
710 }
711
712 /*
713 * Disable a given agent event for a given UST session.
714 *
715 * Must be called with the RCU read lock held.
716 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
717 */
718 static int event_agent_disable_one(struct ltt_ust_session *usess,
719 struct agent *agt, struct agent_event *aevent)
720 {
721 int ret;
722 struct ltt_ust_event *uevent = NULL;
723 struct ltt_ust_channel *uchan = NULL;
724 const char *ust_event_name, *ust_channel_name;
725
726 LTTNG_ASSERT(agt);
727 LTTNG_ASSERT(usess);
728 LTTNG_ASSERT(aevent);
729
730 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64,
731 aevent->name, aevent->loglevel_type, aevent->loglevel_value,
732 usess->id);
733
734 /* Already disabled? */
735 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
736 goto end;
737 }
738
739 if (agt->domain == LTTNG_DOMAIN_JUL) {
740 ust_channel_name = DEFAULT_JUL_CHANNEL_NAME;
741 } else if (agt->domain == LTTNG_DOMAIN_LOG4J) {
742 ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
743 } else if (agt->domain == LTTNG_DOMAIN_PYTHON) {
744 ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
745 } else {
746 ret = LTTNG_ERR_INVALID;
747 goto error;
748 }
749
750 /*
751 * Disable it on the UST side. First get the channel reference then find
752 * the event and finally disable it.
753 */
754 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
755 (char *) ust_channel_name);
756 if (!uchan) {
757 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
758 goto error;
759 }
760
761 ust_event_name = event_get_default_agent_ust_name(agt->domain);
762 if (!ust_event_name) {
763 ret = LTTNG_ERR_FATAL;
764 goto error;
765 }
766
767 /*
768 * Agent UST event has its loglevel type forced to
769 * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering
770 * happens thanks to an UST filter. The following -1 is actually
771 * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
772 */
773 uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
774 aevent->filter, LTTNG_UST_ABI_LOGLEVEL_ALL, -1, NULL);
775 /* If the agent event exists, it must be available on the UST side. */
776 LTTNG_ASSERT(uevent);
777
778 if (usess->active) {
779 ret = ust_app_disable_event_glb(usess, uchan, uevent);
780 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
781 ret = LTTNG_ERR_UST_DISABLE_FAIL;
782 goto error;
783 }
784 }
785
786 /*
787 * Flag event that it's disabled so the shadow copy on the ust app side
788 * will disable it if an application shows up.
789 */
790 uevent->enabled = 0;
791
792 ret = agent_disable_event(aevent, agt->domain);
793 if (ret != LTTNG_OK) {
794 goto error;
795 }
796
797 end:
798 return LTTNG_OK;
799
800 error:
801 return ret;
802 }
803
804 /*
805 * Disable agent event matching a given trigger.
806 *
807 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
808 */
809 int trigger_agent_disable(
810 const struct lttng_trigger *trigger, struct agent *agt)
811 {
812 int ret = LTTNG_OK;
813 struct agent_event *aevent;
814
815 LTTNG_ASSERT(trigger);
816 LTTNG_ASSERT(agt);
817
818 DBG("Event agent disabling for trigger %" PRIu64,
819 lttng_trigger_get_tracer_token(trigger));
820
821 rcu_read_lock();
822 aevent = agent_find_event_by_trigger(trigger, agt);
823
824 if (aevent == NULL) {
825 DBG2("Event agent NOT found by trigger %" PRIu64,
826 lttng_trigger_get_tracer_token(trigger));
827 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
828 goto end;
829 }
830
831 ret = trigger_agent_disable_one(trigger, agt, aevent);
832
833 if (ret != LTTNG_OK) {
834 goto end;
835 }
836
837 end:
838 rcu_read_unlock();
839 return ret;
840 }
841
842 /*
843 * Disable all agent events matching a given name for a given UST session.
844 *
845 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
846 */
847 int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
848 const char *event_name)
849 {
850 int ret = LTTNG_OK;
851 struct agent_event *aevent;
852 struct lttng_ht_iter iter;
853 struct lttng_ht_node_str *node;
854
855 LTTNG_ASSERT(agt);
856 LTTNG_ASSERT(usess);
857 LTTNG_ASSERT(event_name);
858
859 DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id);
860
861 rcu_read_lock();
862 agent_find_events_by_name(event_name, agt, &iter);
863 node = lttng_ht_iter_get_node_str(&iter);
864
865 if (node == NULL) {
866 DBG2("Event agent NOT found by name %s", event_name);
867 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
868 goto end;
869 }
870
871 do {
872 aevent = lttng::utils::container_of(node, &agent_event::node);
873 ret = event_agent_disable_one(usess, agt, aevent);
874
875 if (ret != LTTNG_OK) {
876 goto end;
877 }
878
879 /* Get next duplicate agent event by name. */
880 agent_event_next_duplicate(event_name, agt, &iter);
881 node = lttng_ht_iter_get_node_str(&iter);
882 } while (node);
883 end:
884 rcu_read_unlock();
885 return ret;
886 }
887 /*
888 * Disable all agent event for a given UST session.
889 *
890 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
891 */
892 int event_agent_disable_all(struct ltt_ust_session *usess,
893 struct agent *agt)
894 {
895 int ret;
896 struct agent_event *aevent;
897 struct lttng_ht_iter iter;
898
899 LTTNG_ASSERT(agt);
900 LTTNG_ASSERT(usess);
901
902 /*
903 * Disable event on agent application. Continue to disable all other events
904 * if the * event is not found.
905 */
906 ret = event_agent_disable(usess, agt, "*");
907 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
908 goto error;
909 }
910
911 /* Disable every event. */
912 rcu_read_lock();
913 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
914 node.node) {
915 if (!AGENT_EVENT_IS_ENABLED(aevent)) {
916 continue;
917 }
918
919 ret = event_agent_disable(usess, agt, aevent->name);
920 if (ret != LTTNG_OK) {
921 goto error_unlock;
922 }
923 }
924 ret = LTTNG_OK;
925
926 error_unlock:
927 rcu_read_unlock();
928 error:
929 return ret;
930 }
This page took 0.055697 seconds and 4 git commands to generate.