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