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