Fix: channel names are not validated
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #define _GNU_SOURCE
19 #define _LGPL_SOURCE
20 #include <errno.h>
21 #include <urcu/list.h>
22 #include <string.h>
23
24 #include <lttng/lttng.h>
25 #include <common/error.h>
26 #include <common/sessiond-comm/sessiond-comm.h>
27
28 #include "channel.h"
29 #include "event.h"
30 #include "kernel.h"
31 #include "lttng-sessiond.h"
32 #include "ust-ctl.h"
33 #include "ust-app.h"
34 #include "trace-kernel.h"
35 #include "trace-ust.h"
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 assert(ht);
47 assert(ht->ht);
48 assert(event);
49
50 key.name = event->attr.name;
51 key.filter = (struct lttng_filter_bytecode *) event->filter;
52 key.loglevel = event->attr.loglevel;
53 key.exclusion = event->exclusion;
54
55 node_ptr = cds_lfht_add_unique(ht->ht,
56 ht->hash_fct(event->node.key, lttng_ht_seed),
57 trace_ust_ht_match_event, &key, &event->node.node);
58 assert(node_ptr == &event->node.node);
59 }
60
61 /*
62 * Disable kernel tracepoint event for a channel from the kernel session.
63 */
64 int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan,
65 char *event_name)
66 {
67 int ret;
68 struct ltt_kernel_event *kevent;
69
70 assert(kchan);
71
72 kevent = trace_kernel_get_event_by_name(event_name, kchan);
73 if (kevent == NULL) {
74 ret = LTTNG_ERR_NO_EVENT;
75 goto error;
76 }
77
78 ret = kernel_disable_event(kevent);
79 if (ret < 0) {
80 ret = LTTNG_ERR_KERN_DISABLE_FAIL;
81 goto error;
82 }
83
84 DBG("Kernel event %s disable for channel %s.",
85 kevent->event->name, kchan->channel->name);
86
87 ret = LTTNG_OK;
88
89 error:
90 return ret;
91 }
92
93 /*
94 * Enable kernel system call for a channel from the kernel session.
95 */
96 int event_kernel_enable_syscall(struct ltt_kernel_channel *kchan,
97 char *syscall_name)
98 {
99 int ret;
100
101 assert(kchan);
102
103 ret = kernel_enable_syscall(syscall_name, kchan);
104 if (ret < 0) {
105 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
106 goto error;
107 }
108
109 DBG("Kernel event %s enable for channel %s.",
110 syscall_name, kchan->channel->name);
111
112 ret = LTTNG_OK;
113
114 error:
115 return ret;
116 }
117
118 /*
119 * Disable kernel system call for a channel from the kernel session.
120 */
121 int event_kernel_disable_syscall(struct ltt_kernel_channel *kchan,
122 char *syscall_name)
123 {
124 int ret;
125
126 assert(kchan);
127
128 ret = kernel_disable_syscall(syscall_name, kchan);
129 if (ret < 0) {
130 ret = LTTNG_ERR_KERN_DISABLE_FAIL;
131 goto error;
132 }
133
134 DBG("Kernel syscall %s disable for channel %s.",
135 syscall_name[0] == '\0' ? "<all>" : syscall_name,
136 kchan->channel->name);
137
138 ret = LTTNG_OK;
139
140 error:
141 return ret;
142 }
143
144 /*
145 * Disable kernel tracepoint events for a channel from the kernel session.
146 */
147 int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan)
148 {
149 int ret;
150 struct ltt_kernel_event *kevent;
151
152 assert(kchan);
153
154 /* For each event in the kernel session */
155 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
156 ret = kernel_disable_event(kevent);
157 if (ret < 0) {
158 /* We continue disabling the rest */
159 continue;
160 }
161 }
162 ret = LTTNG_OK;
163 return ret;
164 }
165
166 /*
167 * Disable all kernel event for a channel from the kernel session.
168 */
169 int event_kernel_disable_all(struct ltt_kernel_channel *kchan)
170 {
171 int ret;
172
173 assert(kchan);
174
175 ret = event_kernel_disable_all_tracepoints(kchan);
176 if (ret != LTTNG_OK)
177 return ret;
178 ret = event_kernel_disable_syscall(kchan, "");
179 return ret;
180 }
181
182 /*
183 * Enable kernel tracepoint event for a channel from the kernel session.
184 * We own filter_expression and filter.
185 */
186 int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan,
187 struct lttng_event *event)
188 {
189 int ret;
190 struct ltt_kernel_event *kevent;
191
192 assert(kchan);
193 assert(event);
194
195 kevent = trace_kernel_get_event_by_name(event->name, kchan);
196 if (kevent == NULL) {
197 ret = kernel_create_event(event, kchan);
198 if (ret < 0) {
199 switch (-ret) {
200 case EEXIST:
201 ret = LTTNG_ERR_KERN_EVENT_EXIST;
202 break;
203 case ENOSYS:
204 ret = LTTNG_ERR_KERN_EVENT_ENOSYS;
205 break;
206 default:
207 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
208 break;
209 }
210 goto end;
211 }
212 } else if (kevent->enabled == 0) {
213 ret = kernel_enable_event(kevent);
214 if (ret < 0) {
215 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
216 goto end;
217 }
218 } else {
219 /* At this point, the event is considered enabled */
220 ret = LTTNG_ERR_KERN_EVENT_EXIST;
221 goto end;
222 }
223
224 ret = LTTNG_OK;
225 end:
226 return ret;
227 }
228
229 /*
230 * Enable all kernel tracepoint events of a channel of the kernel session.
231 */
232 int event_kernel_enable_all_tracepoints(struct ltt_kernel_channel *kchan,
233 int kernel_tracer_fd)
234 {
235 int size, i, ret;
236 struct ltt_kernel_event *kevent;
237 struct lttng_event *event_list = NULL;
238
239 assert(kchan);
240
241 /* For each event in the kernel session */
242 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
243 if (kevent->enabled == 0) {
244 ret = kernel_enable_event(kevent);
245 if (ret < 0) {
246 /* Enable failed but still continue */
247 continue;
248 }
249 }
250 }
251
252 size = kernel_list_events(kernel_tracer_fd, &event_list);
253 if (size < 0) {
254 ret = LTTNG_ERR_KERN_LIST_FAIL;
255 goto end;
256 }
257
258 for (i = 0; i < size; i++) {
259 kevent = trace_kernel_get_event_by_name(event_list[i].name, kchan);
260 if (kevent == NULL) {
261 /* Default event type for enable all */
262 event_list[i].type = LTTNG_EVENT_TRACEPOINT;
263 /* Enable each single tracepoint event */
264 ret = kernel_create_event(&event_list[i], kchan);
265 if (ret < 0) {
266 /* Ignore error here and continue */
267 }
268 }
269 }
270 free(event_list);
271
272 ret = LTTNG_OK;
273 end:
274 return ret;
275 }
276
277 /*
278 * Enable all kernel events of a channel of the kernel session.
279 */
280 int event_kernel_enable_all(struct ltt_kernel_channel *kchan,
281 int kernel_tracer_fd)
282 {
283 int tp_ret;
284
285 assert(kchan);
286
287 tp_ret = event_kernel_enable_all_tracepoints(kchan, kernel_tracer_fd);
288 if (tp_ret != LTTNG_OK) {
289 goto end;
290 }
291
292 /*
293 * Reaching this code path means that all tracepoints were enabled without
294 * errors so we ignore the error value of syscalls.
295 *
296 * At the moment, failing to enable syscalls on "lttng enable-event -a -k"
297 * is not considered an error that need to be returned to the client since
298 * tracepoints did not fail. Future work will allow us to send back
299 * multiple errors to the client in one API call.
300 */
301 (void) event_kernel_enable_syscall(kchan, "");
302
303 end:
304 return tp_ret;
305 }
306
307 /*
308 * ============================
309 * UST : The Ultimate Frontier!
310 * ============================
311 */
312
313 /*
314 * Enable all UST tracepoints for a channel from a UST session.
315 */
316 int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess,
317 struct ltt_ust_channel *uchan,
318 char *filter_expression,
319 struct lttng_filter_bytecode *filter)
320 {
321 int ret, i, size;
322 struct lttng_ht_iter iter;
323 struct ltt_ust_event *uevent = NULL;
324 struct lttng_event *events = NULL;
325
326 assert(usess);
327 assert(uchan);
328
329 rcu_read_lock();
330
331 /* Enable existing events */
332 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
333 node.node) {
334 if (uevent->enabled == 0) {
335 ret = ust_app_enable_event_glb(usess, uchan, uevent);
336 if (ret < 0) {
337 continue;
338 }
339 uevent->enabled = 1;
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 /*
352 * Check if event exist and if so, continue since it was enable
353 * previously.
354 */
355 uevent = trace_ust_find_event(uchan->events, events[i].name, filter,
356 events[i].loglevel, NULL);
357 if (uevent != NULL) {
358 ret = ust_app_enable_event_pid(usess, uchan, uevent,
359 events[i].pid);
360 if (ret < 0) {
361 if (ret != -LTTNG_UST_ERR_EXIST) {
362 ret = LTTNG_ERR_UST_ENABLE_FAIL;
363 goto error;
364 }
365 }
366 continue;
367 }
368
369 /* Create ust event */
370 uevent = trace_ust_create_event(&events[i], filter_expression,
371 filter, NULL);
372 if (uevent == NULL) {
373 ret = LTTNG_ERR_FATAL;
374 goto error_destroy;
375 }
376
377 /* Create event for the specific PID */
378 ret = ust_app_enable_event_pid(usess, uchan, uevent,
379 events[i].pid);
380 if (ret < 0) {
381 if (ret == -LTTNG_UST_ERR_EXIST) {
382 ret = LTTNG_ERR_UST_EVENT_EXIST;
383 goto error;
384 } else {
385 ret = LTTNG_ERR_UST_ENABLE_FAIL;
386 goto error_destroy;
387 }
388 }
389
390 uevent->enabled = 1;
391 /* Add ltt ust event to channel */
392 rcu_read_lock();
393 add_unique_ust_event(uchan->events, uevent);
394 rcu_read_unlock();
395 }
396 free(events);
397
398 rcu_read_unlock();
399 return LTTNG_OK;
400
401 error_destroy:
402 trace_ust_destroy_event(uevent);
403
404 error:
405 free(events);
406 rcu_read_unlock();
407 return ret;
408 }
409
410 /*
411 * Enable UST tracepoint event for a channel from a UST session.
412 * We own filter_expression, filter, and exclusion.
413 */
414 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
415 struct ltt_ust_channel *uchan, struct lttng_event *event,
416 char *filter_expression,
417 struct lttng_filter_bytecode *filter,
418 struct lttng_event_exclusion *exclusion)
419 {
420 int ret = LTTNG_OK, to_create = 0;
421 struct ltt_ust_event *uevent;
422
423 assert(usess);
424 assert(uchan);
425 assert(event);
426
427 rcu_read_lock();
428
429 uevent = trace_ust_find_event(uchan->events, event->name, filter,
430 event->loglevel, exclusion);
431 if (uevent == NULL) {
432 uevent = trace_ust_create_event(event, filter_expression,
433 filter, exclusion);
434 /* We have passed ownership */
435 filter_expression = NULL;
436 filter = NULL;
437 exclusion = NULL;
438 if (uevent == NULL) {
439 ret = LTTNG_ERR_UST_ENABLE_FAIL;
440 goto error;
441 }
442
443 /* Valid to set it after the goto error since uevent is still NULL */
444 to_create = 1;
445 }
446
447 if (uevent->enabled) {
448 /* It's already enabled so everything is OK */
449 ret = LTTNG_ERR_UST_EVENT_ENABLED;
450 goto end;
451 }
452
453 uevent->enabled = 1;
454
455 if (to_create) {
456 /* Create event on all UST registered apps for session */
457 ret = ust_app_create_event_glb(usess, uchan, uevent);
458 } else {
459 /* Enable event on all UST registered apps for session */
460 ret = ust_app_enable_event_glb(usess, uchan, uevent);
461 }
462
463 if (ret < 0) {
464 if (ret == -LTTNG_UST_ERR_EXIST) {
465 ret = LTTNG_ERR_UST_EVENT_EXIST;
466 goto end;
467 } else {
468 ret = LTTNG_ERR_UST_ENABLE_FAIL;
469 goto error;
470 }
471 }
472
473 if (to_create) {
474 /* Add ltt ust event to channel */
475 add_unique_ust_event(uchan->events, uevent);
476 }
477
478 DBG("Event UST %s %s in channel %s", uevent->attr.name,
479 to_create ? "created" : "enabled", uchan->name);
480
481 ret = LTTNG_OK;
482
483 end:
484 rcu_read_unlock();
485 free(filter_expression);
486 free(filter);
487 free(exclusion);
488 return ret;
489
490 error:
491 /*
492 * Only destroy event on creation time (not enabling time) because if the
493 * event is found in the channel (to_create == 0), it means that at some
494 * point the enable_event worked and it's thus valid to keep it alive.
495 * Destroying it also implies that we also destroy it's shadow copy to sync
496 * everyone up.
497 */
498 if (to_create) {
499 /* In this code path, the uevent was not added to the hash table */
500 trace_ust_destroy_event(uevent);
501 }
502 rcu_read_unlock();
503 free(filter_expression);
504 free(filter);
505 free(exclusion);
506 return ret;
507 }
508
509 /*
510 * Disable UST tracepoint of a channel from a UST session.
511 */
512 int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
513 struct ltt_ust_channel *uchan, char *event_name)
514 {
515 int ret;
516 struct ltt_ust_event *uevent;
517 struct lttng_ht_node_str *node;
518 struct lttng_ht_iter iter;
519 struct lttng_ht *ht;
520
521 assert(usess);
522 assert(uchan);
523 assert(event_name);
524
525 ht = uchan->events;
526
527 rcu_read_lock();
528
529 /*
530 * We use a custom lookup since we need the iterator for the next_duplicate
531 * call in the do while loop below.
532 */
533 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
534 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
535 node = lttng_ht_iter_get_node_str(&iter);
536 if (node == NULL) {
537 DBG2("Trace UST event NOT found by name %s", event_name);
538 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
539 goto error;
540 }
541
542 do {
543 uevent = caa_container_of(node, struct ltt_ust_event, node);
544 assert(uevent);
545
546 if (uevent->enabled == 0) {
547 /* It's already disabled so everything is OK */
548 goto next;
549 }
550
551 ret = ust_app_disable_event_glb(usess, uchan, uevent);
552 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
553 ret = LTTNG_ERR_UST_DISABLE_FAIL;
554 goto error;
555 }
556 uevent->enabled = 0;
557
558 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
559 uchan->name);
560
561 next:
562 /* Get next duplicate event by name. */
563 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
564 event_name, &iter.iter);
565 node = lttng_ht_iter_get_node_str(&iter);
566 } while (node);
567
568 ret = LTTNG_OK;
569
570 error:
571 rcu_read_unlock();
572 return ret;
573 }
574
575 /*
576 * Disable all UST tracepoints for a channel from a UST session.
577 */
578 int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
579 struct ltt_ust_channel *uchan)
580 {
581 int ret, i, size;
582 struct lttng_ht_iter iter;
583 struct ltt_ust_event *uevent = NULL;
584 struct lttng_event *events = NULL;
585
586 assert(usess);
587 assert(uchan);
588
589 rcu_read_lock();
590
591 /* Disabling existing events */
592 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
593 node.node) {
594 if (uevent->enabled == 1) {
595 ret = event_ust_disable_tracepoint(usess, uchan,
596 uevent->attr.name);
597 if (ret < 0) {
598 continue;
599 }
600 }
601 }
602
603 /* Get all UST available events */
604 size = ust_app_list_events(&events);
605 if (size < 0) {
606 ret = LTTNG_ERR_UST_LIST_FAIL;
607 goto error;
608 }
609
610 for (i = 0; i < size; i++) {
611 ret = event_ust_disable_tracepoint(usess, uchan,
612 events[i].name);
613 if (ret != LTTNG_OK) {
614 /* Continue to disable the rest... */
615 continue;
616 }
617 }
618 free(events);
619
620 rcu_read_unlock();
621 return LTTNG_OK;
622
623 error:
624 free(events);
625 rcu_read_unlock();
626 return ret;
627 }
628
629 /*
630 * Enable all agent event for a given UST session.
631 *
632 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
633 */
634 int event_agent_enable_all(struct ltt_ust_session *usess,
635 struct agent *agt, struct lttng_event *event,
636 struct lttng_filter_bytecode *filter)
637 {
638 int ret;
639 struct agent_event *aevent;
640 struct lttng_ht_iter iter;
641
642 assert(usess);
643
644 DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
645
646 /* Enable event on agent application through TCP socket. */
647 ret = event_agent_enable(usess, agt, event, filter);
648 if (ret != LTTNG_OK) {
649 goto error;
650 }
651
652 /* Flag every event that they are now enabled. */
653 rcu_read_lock();
654 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
655 node.node) {
656 aevent->enabled = 1;
657 }
658 rcu_read_unlock();
659
660 ret = LTTNG_OK;
661
662 error:
663 return ret;
664 }
665
666 /*
667 * Enable a single agent event for a given UST session.
668 *
669 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
670 */
671 int event_agent_enable(struct ltt_ust_session *usess,
672 struct agent *agt, struct lttng_event *event,
673 struct lttng_filter_bytecode *filter)
674 {
675 int ret, created = 0;
676 struct agent_event *aevent;
677
678 assert(usess);
679 assert(event);
680 assert(agt);
681
682 DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
683 "and loglevel %d", event->name, usess->id, event->loglevel_type,
684 event->loglevel);
685
686 aevent = agent_find_event(event->name, event->loglevel, agt);
687 if (!aevent) {
688 aevent = agent_create_event(event->name, filter);
689 if (!aevent) {
690 ret = LTTNG_ERR_NOMEM;
691 goto error;
692 }
693 aevent->loglevel = event->loglevel;
694 aevent->loglevel_type = event->loglevel_type;
695 created = 1;
696 }
697
698 /* Already enabled? */
699 if (aevent->enabled) {
700 goto end;
701 }
702
703 ret = agent_enable_event(aevent, agt->domain);
704 if (ret != LTTNG_OK) {
705 goto error;
706 }
707
708 /* If the event was created prior to the enable, add it to the domain. */
709 if (created) {
710 agent_add_event(aevent, agt);
711 }
712
713 end:
714 return LTTNG_OK;
715
716 error:
717 if (created) {
718 agent_destroy_event(aevent);
719 }
720 return ret;
721 }
722
723 /*
724 * Return the agent default event name to use by testing if the process is root
725 * or not. Return NULL on error.
726 */
727 const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
728 {
729 const char *default_event_name = NULL;
730
731 switch (domain) {
732 case LTTNG_DOMAIN_LOG4J:
733 if (is_root) {
734 default_event_name = DEFAULT_SYS_LOG4J_EVENT_NAME;
735 } else {
736 default_event_name = DEFAULT_USER_LOG4J_EVENT_NAME;
737 }
738 break;
739 case LTTNG_DOMAIN_JUL:
740 if (is_root) {
741 default_event_name = DEFAULT_SYS_JUL_EVENT_NAME;
742 } else {
743 default_event_name = DEFAULT_USER_JUL_EVENT_NAME;
744 }
745 break;
746 case LTTNG_DOMAIN_PYTHON:
747 default_event_name = DEFAULT_USER_PYTHON_EVENT_NAME;
748 break;
749 default:
750 assert(0);
751 }
752
753 return default_event_name;
754 }
755
756 /*
757 * Disable a single agent event for a given UST session.
758 *
759 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
760 */
761 int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
762 char *event_name)
763 {
764 int ret;
765 struct agent_event *aevent;
766 struct ltt_ust_event *uevent = NULL;
767 struct ltt_ust_channel *uchan = NULL;
768 const char *ust_event_name, *ust_channel_name;
769
770 assert(agt);
771 assert(usess);
772 assert(event_name);
773
774 DBG("Event agent disabling %s for session %" PRIu64, event_name, usess->id);
775
776 aevent = agent_find_event_by_name(event_name, agt);
777 if (!aevent) {
778 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
779 goto error;
780 }
781
782 /* Already disabled? */
783 if (!aevent->enabled) {
784 goto end;
785 }
786
787 if (agt->domain == LTTNG_DOMAIN_JUL) {
788 ust_channel_name = DEFAULT_JUL_CHANNEL_NAME;
789 } else if (agt->domain == LTTNG_DOMAIN_LOG4J) {
790 ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
791 } else if (agt->domain == LTTNG_DOMAIN_PYTHON) {
792 ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
793 } else {
794 ret = LTTNG_ERR_INVALID;
795 goto error;
796 }
797
798 /*
799 * Disable it on the UST side. First get the channel reference then find
800 * the event and finally disable it.
801 */
802 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
803 (char *) ust_channel_name);
804 if (!uchan) {
805 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
806 goto error;
807 }
808
809 ust_event_name = event_get_default_agent_ust_name(agt->domain);
810 if (!ust_event_name) {
811 ret = LTTNG_ERR_FATAL;
812 goto error;
813 }
814
815 /*
816 * The loglevel is hardcoded with 0 here since the agent ust event is set
817 * with the loglevel type to ALL thus the loglevel stays 0. The event's
818 * filter is the one handling the loglevel for agent.
819 */
820 uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
821 aevent->filter, 0, NULL);
822 /* If the agent event exists, it must be available on the UST side. */
823 assert(uevent);
824
825 ret = ust_app_disable_event_glb(usess, uchan, uevent);
826 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
827 ret = LTTNG_ERR_UST_DISABLE_FAIL;
828 goto error;
829 }
830
831 /*
832 * Flag event that it's disabled so the shadow copy on the ust app side
833 * will disable it if an application shows up.
834 */
835 uevent->enabled = 0;
836
837 ret = agent_disable_event(aevent, agt->domain);
838 if (ret != LTTNG_OK) {
839 goto error;
840 }
841
842 end:
843 return LTTNG_OK;
844
845 error:
846 return ret;
847 }
848 /*
849 * Disable all agent event for a given UST session.
850 *
851 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
852 */
853 int event_agent_disable_all(struct ltt_ust_session *usess,
854 struct agent *agt)
855 {
856 int ret;
857 struct agent_event *aevent;
858 struct lttng_ht_iter iter;
859
860 assert(agt);
861 assert(usess);
862
863 /*
864 * Disable event on agent application. Continue to disable all other events
865 * if the * event is not found.
866 */
867 ret = event_agent_disable(usess, agt, "*");
868 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
869 goto error;
870 }
871
872 /* Flag every event that they are now enabled. */
873 rcu_read_lock();
874 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
875 node.node) {
876 if (!aevent->enabled) {
877 continue;
878 }
879
880 ret = event_agent_disable(usess, agt, aevent->name);
881 if (ret != LTTNG_OK) {
882 rcu_read_unlock();
883 goto error;
884 }
885 }
886 rcu_read_unlock();
887
888 ret = LTTNG_OK;
889
890 error:
891 return ret;
892 }
This page took 0.07606 seconds and 5 git commands to generate.