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