Consumer: add testpoints
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
CommitLineData
54d01ffb
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
d14d33bf
AM
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.
54d01ffb 7 *
d14d33bf
AM
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.
54d01ffb 12 *
d14d33bf
AM
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.
54d01ffb
DG
16 */
17
be040666 18#define _GNU_SOURCE
d87bfb32 19#include <errno.h>
54d01ffb 20#include <urcu/list.h>
2bdd86d4 21#include <string.h>
54d01ffb
DG
22
23#include <lttng/lttng.h>
db758600 24#include <common/error.h>
10a8a223 25#include <common/sessiond-comm/sessiond-comm.h>
54d01ffb
DG
26
27#include "channel.h"
28#include "event.h"
4771f025 29#include "kernel.h"
9df8df5e 30#include "ust-ctl.h"
edb67388
DG
31#include "ust-app.h"
32#include "trace-kernel.h"
33#include "trace-ust.h"
54d01ffb 34
025faf73
DG
35/*
36 * Add unique UST event based on the event name, filter bytecode and loglevel.
37 */
18eace3b
DG
38static void add_unique_ust_event(struct lttng_ht *ht,
39 struct ltt_ust_event *event)
40{
41 struct cds_lfht_node *node_ptr;
42 struct ltt_ust_ht_key key;
43
44 assert(ht);
45 assert(ht->ht);
46 assert(event);
47
48 key.name = event->attr.name;
49 key.filter = (struct lttng_filter_bytecode *) event->filter;
50 key.loglevel = event->attr.loglevel;
4031e53e 51 key.exclusion = event->exclusion;
18eace3b
DG
52
53 node_ptr = cds_lfht_add_unique(ht->ht,
54 ht->hash_fct(event->node.key, lttng_ht_seed),
55 trace_ust_ht_match_event, &key, &event->node.node);
56 assert(node_ptr == &event->node.node);
57}
58
8c9ae521
DG
59/*
60 * Setup a lttng_event used to enable *all* syscall tracing.
61 */
62static void init_syscalls_kernel_event(struct lttng_event *event)
63{
0525e9ae
DG
64 assert(event);
65
8c9ae521
DG
66 event->name[0] = '\0';
67 /*
68 * We use LTTNG_EVENT* here since the trace kernel creation will make the
69 * right changes for the kernel.
70 */
71 event->type = LTTNG_EVENT_SYSCALL;
72}
73
54d01ffb 74/*
7a3d1328 75 * Disable kernel tracepoint event for a channel from the kernel session.
54d01ffb 76 */
d3a56674
DG
77int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan,
78 char *event_name)
54d01ffb
DG
79{
80 int ret;
81 struct ltt_kernel_event *kevent;
82
0525e9ae
DG
83 assert(kchan);
84
54d01ffb
DG
85 kevent = trace_kernel_get_event_by_name(event_name, kchan);
86 if (kevent == NULL) {
f73fabfd 87 ret = LTTNG_ERR_NO_EVENT;
54d01ffb
DG
88 goto error;
89 }
90
91 ret = kernel_disable_event(kevent);
92 if (ret < 0) {
f73fabfd 93 ret = LTTNG_ERR_KERN_DISABLE_FAIL;
54d01ffb
DG
94 goto error;
95 }
96
97 DBG("Kernel event %s disable for channel %s.",
98 kevent->event->name, kchan->channel->name);
99
f73fabfd 100 ret = LTTNG_OK;
54d01ffb
DG
101
102error:
103 return ret;
104}
105
106/*
7a3d1328 107 * Disable kernel tracepoint events for a channel from the kernel session.
54d01ffb 108 */
d3a56674 109int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan)
54d01ffb
DG
110{
111 int ret;
112 struct ltt_kernel_event *kevent;
113
0525e9ae
DG
114 assert(kchan);
115
54d01ffb
DG
116 /* For each event in the kernel session */
117 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
118 ret = kernel_disable_event(kevent);
119 if (ret < 0) {
120 /* We continue disabling the rest */
121 continue;
122 }
123 }
f73fabfd 124 ret = LTTNG_OK;
7a3d1328
MD
125 return ret;
126}
127
128/*
129 * Disable kernel syscall events for a channel from the kernel session.
130 */
d3a56674 131int event_kernel_disable_all_syscalls(struct ltt_kernel_channel *kchan)
7a3d1328
MD
132{
133 ERR("Cannot disable syscall tracing for existing session. Please destroy session instead.");
f73fabfd 134 return LTTNG_OK; /* Return OK so disable all succeeds */
7a3d1328 135}
54d01ffb 136
7a3d1328
MD
137/*
138 * Disable all kernel event for a channel from the kernel session.
139 */
d3a56674 140int event_kernel_disable_all(struct ltt_kernel_channel *kchan)
7a3d1328
MD
141{
142 int ret;
143
0525e9ae
DG
144 assert(kchan);
145
d3a56674 146 ret = event_kernel_disable_all_tracepoints(kchan);
f73fabfd 147 if (ret != LTTNG_OK)
7a3d1328 148 return ret;
d3a56674 149 ret = event_kernel_disable_all_syscalls(kchan);
54d01ffb
DG
150 return ret;
151}
152
153/*
7a3d1328 154 * Enable kernel tracepoint event for a channel from the kernel session.
54d01ffb 155 */
d3a56674
DG
156int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan,
157 struct lttng_event *event)
54d01ffb
DG
158{
159 int ret;
160 struct ltt_kernel_event *kevent;
161
0525e9ae
DG
162 assert(kchan);
163 assert(event);
164
54d01ffb
DG
165 kevent = trace_kernel_get_event_by_name(event->name, kchan);
166 if (kevent == NULL) {
167 ret = kernel_create_event(event, kchan);
168 if (ret < 0) {
bd29c13d
DG
169 switch (-ret) {
170 case EEXIST:
f73fabfd 171 ret = LTTNG_ERR_KERN_EVENT_EXIST;
bd29c13d
DG
172 break;
173 case ENOSYS:
f73fabfd 174 ret = LTTNG_ERR_KERN_EVENT_ENOSYS;
bd29c13d
DG
175 break;
176 default:
f73fabfd 177 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
bd29c13d 178 break;
d87bfb32 179 }
7a3d1328 180 goto end;
54d01ffb
DG
181 }
182 } else if (kevent->enabled == 0) {
183 ret = kernel_enable_event(kevent);
184 if (ret < 0) {
f73fabfd 185 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
7a3d1328 186 goto end;
54d01ffb 187 }
42224349
DG
188 } else {
189 /* At this point, the event is considered enabled */
f73fabfd 190 ret = LTTNG_ERR_KERN_EVENT_EXIST;
42224349 191 goto end;
54d01ffb 192 }
42224349 193
f73fabfd 194 ret = LTTNG_OK;
7a3d1328 195end:
54d01ffb
DG
196 return ret;
197}
198
199/*
7a3d1328 200 * Enable all kernel tracepoint events of a channel of the kernel session.
54d01ffb 201 */
d3a56674
DG
202int event_kernel_enable_all_tracepoints(struct ltt_kernel_channel *kchan,
203 int kernel_tracer_fd)
54d01ffb
DG
204{
205 int size, i, ret;
206 struct ltt_kernel_event *kevent;
8f69e5eb 207 struct lttng_event *event_list = NULL;
54d01ffb 208
0525e9ae
DG
209 assert(kchan);
210
54d01ffb
DG
211 /* For each event in the kernel session */
212 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
8f69e5eb
DG
213 if (kevent->enabled == 0) {
214 ret = kernel_enable_event(kevent);
215 if (ret < 0) {
216 /* Enable failed but still continue */
217 continue;
218 }
54d01ffb
DG
219 }
220 }
221
222 size = kernel_list_events(kernel_tracer_fd, &event_list);
223 if (size < 0) {
f73fabfd 224 ret = LTTNG_ERR_KERN_LIST_FAIL;
7a3d1328 225 goto end;
54d01ffb
DG
226 }
227
228 for (i = 0; i < size; i++) {
229 kevent = trace_kernel_get_event_by_name(event_list[i].name, kchan);
230 if (kevent == NULL) {
231 /* Default event type for enable all */
232 event_list[i].type = LTTNG_EVENT_TRACEPOINT;
233 /* Enable each single tracepoint event */
234 ret = kernel_create_event(&event_list[i], kchan);
235 if (ret < 0) {
236 /* Ignore error here and continue */
237 }
238 }
239 }
54d01ffb 240 free(event_list);
8f69e5eb 241
f73fabfd 242 ret = LTTNG_OK;
7a3d1328 243end:
54d01ffb
DG
244 return ret;
245}
8c9ae521
DG
246
247/*
8b037137 248 * Enable all kernel sycalls events of a channel of the kernel session.
8c9ae521 249 */
d3a56674
DG
250int event_kernel_enable_all_syscalls(struct ltt_kernel_channel *kchan,
251 int kernel_tracer_fd)
8c9ae521
DG
252{
253 int ret;
254 struct lttng_event event;
255
0525e9ae
DG
256 assert(kchan);
257
8c9ae521
DG
258 init_syscalls_kernel_event(&event);
259
260 DBG("Enabling all syscall tracing");
261
262 ret = kernel_create_event(&event, kchan);
263 if (ret < 0) {
8f69e5eb 264 if (ret == -EEXIST) {
f73fabfd 265 ret = LTTNG_ERR_KERN_EVENT_EXIST;
8f69e5eb 266 } else {
f73fabfd 267 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
8f69e5eb 268 }
7a3d1328 269 goto end;
8c9ae521 270 }
8f69e5eb 271
f73fabfd 272 ret = LTTNG_OK;
7a3d1328
MD
273end:
274 return ret;
275}
8c9ae521 276
7a3d1328
MD
277/*
278 * Enable all kernel events of a channel of the kernel session.
279 */
d3a56674
DG
280int event_kernel_enable_all(struct ltt_kernel_channel *kchan,
281 int kernel_tracer_fd)
7a3d1328 282{
6bd8707a 283 int tp_ret;
7a3d1328 284
0525e9ae
DG
285 assert(kchan);
286
d3a56674 287 tp_ret = event_kernel_enable_all_tracepoints(kchan, kernel_tracer_fd);
f73fabfd 288 if (tp_ret != LTTNG_OK) {
7a3d1328
MD
289 goto end;
290 }
bd29c13d
DG
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 */
d3a56674 301 (void) event_kernel_enable_all_syscalls(kchan, kernel_tracer_fd);
bd29c13d 302
7a3d1328 303end:
bd29c13d 304 return tp_ret;
8c9ae521 305}
2bdd86d4 306
7f79d3a1
DG
307/*
308 * ============================
309 * UST : The Ultimate Frontier!
310 * ============================
311 */
312
76d45b40
DG
313/*
314 * Enable all UST tracepoints for a channel from a UST session.
315 */
7972aab2 316int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess,
025faf73 317 struct ltt_ust_channel *uchan, struct lttng_filter_bytecode *filter)
76d45b40 318{
6775595e 319 int ret, i, size;
bec39940 320 struct lttng_ht_iter iter;
76d45b40 321 struct ltt_ust_event *uevent = NULL;
7f79d3a1 322 struct lttng_event *events = NULL;
76d45b40 323
0525e9ae
DG
324 assert(usess);
325 assert(uchan);
326
025faf73
DG
327 rcu_read_lock();
328
7972aab2
DG
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) {
76d45b40
DG
335 continue;
336 }
7972aab2
DG
337 uevent->enabled = 1;
338 }
339 }
76d45b40 340
7972aab2
DG
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 }
76d45b40 347
7972aab2
DG
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,
10646003 354 events[i].loglevel, NULL);
7972aab2 355 if (uevent != NULL) {
76d45b40
DG
356 ret = ust_app_enable_event_pid(usess, uchan, uevent,
357 events[i].pid);
358 if (ret < 0) {
7972aab2 359 if (ret != -LTTNG_UST_ERR_EXIST) {
f73fabfd 360 ret = LTTNG_ERR_UST_ENABLE_FAIL;
7972aab2 361 goto error;
76d45b40 362 }
76d45b40 363 }
7972aab2
DG
364 continue;
365 }
76d45b40 366
7972aab2 367 /* Create ust event */
561c6897 368 uevent = trace_ust_create_event(&events[i], filter, NULL);
7972aab2
DG
369 if (uevent == NULL) {
370 ret = LTTNG_ERR_FATAL;
371 goto error_destroy;
76d45b40
DG
372 }
373
7972aab2
DG
374 /* Create event for the specific PID */
375 ret = ust_app_enable_event_pid(usess, uchan, uevent,
376 events[i].pid);
377 if (ret < 0) {
378 if (ret == -LTTNG_UST_ERR_EXIST) {
379 ret = LTTNG_ERR_UST_EVENT_EXIST;
380 goto error;
381 } else {
382 ret = LTTNG_ERR_UST_ENABLE_FAIL;
383 goto error_destroy;
384 }
385 }
386
387 uevent->enabled = 1;
388 /* Add ltt ust event to channel */
389 rcu_read_lock();
390 add_unique_ust_event(uchan->events, uevent);
391 rcu_read_unlock();
76d45b40 392 }
7972aab2 393 free(events);
76d45b40 394
025faf73 395 rcu_read_unlock();
f73fabfd 396 return LTTNG_OK;
76d45b40 397
7f79d3a1 398error_destroy:
76d45b40 399 trace_ust_destroy_event(uevent);
7f79d3a1
DG
400
401error:
402 free(events);
025faf73 403 rcu_read_unlock();
76d45b40
DG
404 return ret;
405}
406
2bdd86d4
MD
407/*
408 * Enable UST tracepoint event for a channel from a UST session.
409 */
7972aab2 410int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
025faf73 411 struct ltt_ust_channel *uchan, struct lttng_event *event,
f1613f52
JI
412 struct lttng_filter_bytecode *filter,
413 struct lttng_event_exclusion *exclusion)
2bdd86d4 414{
f73fabfd 415 int ret = LTTNG_OK, to_create = 0;
edb67388
DG
416 struct ltt_ust_event *uevent;
417
0525e9ae
DG
418 assert(usess);
419 assert(uchan);
420 assert(event);
421
18eace3b
DG
422 rcu_read_lock();
423
025faf73 424 uevent = trace_ust_find_event(uchan->events, event->name, filter,
10646003 425 event->loglevel, exclusion);
edb67388 426 if (uevent == NULL) {
561c6897 427 uevent = trace_ust_create_event(event, filter, exclusion);
edb67388 428 if (uevent == NULL) {
95a82664 429 ret = LTTNG_ERR_UST_ENABLE_FAIL;
edb67388
DG
430 goto error;
431 }
025faf73 432
fc34caaa 433 /* Valid to set it after the goto error since uevent is still NULL */
edb67388
DG
434 to_create = 1;
435 }
2bdd86d4 436
7f79d3a1
DG
437 if (uevent->enabled) {
438 /* It's already enabled so everything is OK */
5bcdda4f 439 ret = LTTNG_ERR_UST_EVENT_ENABLED;
7f79d3a1
DG
440 goto end;
441 }
442
fc34caaa
DG
443 uevent->enabled = 1;
444
7972aab2
DG
445 if (to_create) {
446 /* Create event on all UST registered apps for session */
447 ret = ust_app_create_event_glb(usess, uchan, uevent);
448 } else {
449 /* Enable event on all UST registered apps for session */
450 ret = ust_app_enable_event_glb(usess, uchan, uevent);
451 }
48842b30 452
7972aab2
DG
453 if (ret < 0) {
454 if (ret == -LTTNG_UST_ERR_EXIST) {
455 ret = LTTNG_ERR_UST_EVENT_EXIST;
456 goto end;
457 } else {
458 ret = LTTNG_ERR_UST_ENABLE_FAIL;
459 goto error;
edb67388 460 }
2bdd86d4 461 }
48842b30 462
7f79d3a1 463 if (to_create) {
fc34caaa 464 /* Add ltt ust event to channel */
18eace3b 465 add_unique_ust_event(uchan->events, uevent);
7f79d3a1 466 }
edb67388 467
7f79d3a1
DG
468 DBG("Event UST %s %s in channel %s", uevent->attr.name,
469 to_create ? "created" : "enabled", uchan->name);
470
f73fabfd 471 ret = LTTNG_OK;
fc34caaa 472
fb89d070 473end:
18eace3b 474 rcu_read_unlock();
fc34caaa 475 return ret;
edb67388
DG
476
477error:
fc34caaa
DG
478 /*
479 * Only destroy event on creation time (not enabling time) because if the
480 * event is found in the channel (to_create == 0), it means that at some
481 * point the enable_event worked and it's thus valid to keep it alive.
482 * Destroying it also implies that we also destroy it's shadow copy to sync
483 * everyone up.
484 */
485 if (to_create) {
486 /* In this code path, the uevent was not added to the hash table */
487 trace_ust_destroy_event(uevent);
488 }
18eace3b 489 rcu_read_unlock();
2bdd86d4
MD
490 return ret;
491}
492
7f79d3a1
DG
493/*
494 * Disable UST tracepoint of a channel from a UST session.
495 */
7972aab2 496int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
7f79d3a1 497 struct ltt_ust_channel *uchan, char *event_name)
2bdd86d4
MD
498{
499 int ret;
7f79d3a1 500 struct ltt_ust_event *uevent;
18eace3b
DG
501 struct lttng_ht_node_str *node;
502 struct lttng_ht_iter iter;
18eace3b 503 struct lttng_ht *ht;
2bdd86d4 504
0525e9ae
DG
505 assert(usess);
506 assert(uchan);
507 assert(event_name);
508
18eace3b
DG
509 ht = uchan->events;
510
18eace3b 511 rcu_read_lock();
025faf73
DG
512
513 /*
514 * We use a custom lookup since we need the iterator for the next_duplicate
515 * call in the do while loop below.
516 */
517 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
518 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
18eace3b
DG
519 node = lttng_ht_iter_get_node_str(&iter);
520 if (node == NULL) {
521 DBG2("Trace UST event NOT found by name %s", event_name);
f73fabfd 522 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
7f79d3a1 523 goto error;
2bdd86d4 524 }
7f79d3a1 525
18eace3b
DG
526 do {
527 uevent = caa_container_of(node, struct ltt_ust_event, node);
025faf73
DG
528 assert(uevent);
529
18eace3b
DG
530 if (uevent->enabled == 0) {
531 /* It's already disabled so everything is OK */
a1dcaf0f 532 goto next;
7f79d3a1 533 }
18eace3b 534
7972aab2
DG
535 ret = ust_app_disable_event_glb(usess, uchan, uevent);
536 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
537 ret = LTTNG_ERR_UST_DISABLE_FAIL;
18eace3b
DG
538 goto error;
539 }
18eace3b
DG
540 uevent->enabled = 0;
541
025faf73
DG
542 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
543 uchan->name);
544
a1dcaf0f 545next:
18eace3b
DG
546 /* Get next duplicate event by name. */
547 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
548 event_name, &iter.iter);
549 node = lttng_ht_iter_get_node_str(&iter);
550 } while (node);
7f79d3a1 551
f73fabfd 552 ret = LTTNG_OK;
7f79d3a1 553
7f79d3a1 554error:
18eace3b 555 rcu_read_unlock();
7f79d3a1
DG
556 return ret;
557}
558
559/*
560 * Disable all UST tracepoints for a channel from a UST session.
561 */
7972aab2 562int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
7f79d3a1
DG
563 struct ltt_ust_channel *uchan)
564{
6775595e 565 int ret, i, size;
bec39940 566 struct lttng_ht_iter iter;
7f79d3a1
DG
567 struct ltt_ust_event *uevent = NULL;
568 struct lttng_event *events = NULL;
569
0525e9ae
DG
570 assert(usess);
571 assert(uchan);
572
025faf73
DG
573 rcu_read_lock();
574
7972aab2
DG
575 /* Disabling existing events */
576 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
577 node.node) {
578 if (uevent->enabled == 1) {
579 ret = event_ust_disable_tracepoint(usess, uchan,
580 uevent->attr.name);
581 if (ret < 0) {
7f79d3a1
DG
582 continue;
583 }
584 }
7f79d3a1 585 }
7972aab2
DG
586
587 /* Get all UST available events */
588 size = ust_app_list_events(&events);
589 if (size < 0) {
590 ret = LTTNG_ERR_UST_LIST_FAIL;
7f79d3a1
DG
591 goto error;
592 }
593
7972aab2
DG
594 for (i = 0; i < size; i++) {
595 ret = event_ust_disable_tracepoint(usess, uchan,
596 events[i].name);
597 if (ret != LTTNG_OK) {
598 /* Continue to disable the rest... */
599 continue;
600 }
601 }
602 free(events);
603
025faf73 604 rcu_read_unlock();
f73fabfd 605 return LTTNG_OK;
7f79d3a1
DG
606
607error:
608 free(events);
025faf73 609 rcu_read_unlock();
2bdd86d4
MD
610 return ret;
611}
f20baf8e
DG
612
613/*
614 * Enable all JUL event for a given UST session.
615 *
616 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
617 */
618int event_jul_enable_all(struct ltt_ust_session *usess)
619{
620 int ret;
621 struct jul_event *jevent;
622 struct lttng_event event;
623 struct lttng_ht_iter iter;
624
625 assert(usess);
626
627 DBG("Event JUL enabling ALL events for session %" PRIu64, usess->id);
628
629 /* Create the * wildcard event name for the Java agent. */
630 memset(event.name, 0, sizeof(event.name));
631 strncpy(event.name, "*", sizeof(event.name));
632 event.name[sizeof(event.name) - 1] = '\0';
633
634 /* Enable event on JUL application through TCP socket. */
635 ret = event_jul_enable(usess, &event);
636 if (ret != LTTNG_OK) {
637 goto error;
638 }
639
640 /* Flag every event that they are now enabled. */
641 rcu_read_lock();
642 cds_lfht_for_each_entry(usess->domain_jul.events->ht, &iter.iter, jevent,
643 node.node) {
644 jevent->enabled = 1;
645 }
646 rcu_read_unlock();
647
648 ret = LTTNG_OK;
649
650error:
651 return ret;
652}
653
654/*
655 * Enable a single JUL event for a given UST session.
656 *
657 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
658 */
659int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event)
660{
661 int ret, created = 0;
662 struct jul_event *jevent;
663
664 assert(usess);
665 assert(event);
666
667 DBG("Event JUL enabling %s for session %" PRIu64, event->name, usess->id);
668
669 jevent = jul_find_by_name(event->name, &usess->domain_jul);
670 if (!jevent) {
671 jevent = jul_create_event(event->name);
672 if (!jevent) {
673 ret = LTTNG_ERR_NOMEM;
674 goto error;
675 }
676 created = 1;
677 }
678
679 /* Already enabled? */
680 if (jevent->enabled) {
681 goto end;
682 }
683
684 ret = jul_enable_event(jevent);
685 if (ret != LTTNG_OK) {
686 goto error;
687 }
688
689 /* If the event was created prior to the enable, add it to the domain. */
690 if (created) {
691 jul_add_event(jevent, &usess->domain_jul);
692 }
693
694end:
695 return LTTNG_OK;
696
697error:
698 if (created) {
699 jul_destroy_event(jevent);
700 }
701 return ret;
702}
703
704/*
705 * Disable a single JUL event for a given UST session.
706 *
707 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
708 */
709int event_jul_disable(struct ltt_ust_session *usess, char *event_name)
710{
711 int ret;
712 struct jul_event *jevent;
713
714 assert(usess);
715 assert(event_name);
716
717 DBG("Event JUL disabling %s for session %" PRIu64, event_name, usess->id);
718
719 jevent = jul_find_by_name(event_name, &usess->domain_jul);
720 if (!jevent) {
721 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
722 goto error;
723 }
724
725 /* Already disabled? */
726 if (!jevent->enabled) {
727 goto end;
728 }
729
730 ret = jul_disable_event(jevent);
731 if (ret != LTTNG_OK) {
732 goto error;
733 }
734
735end:
736 return LTTNG_OK;
737
738error:
739 return ret;
740}
741/*
742 * Disable all JUL event for a given UST session.
743 *
744 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
745 */
746int event_jul_disable_all(struct ltt_ust_session *usess)
747{
748 int ret, do_disable = 0;
749 struct jul_event *jevent;
750 struct lttng_ht_iter iter;
751
752 assert(usess);
753
754 /* Enable event on JUL application through TCP socket. */
755 ret = event_jul_disable(usess, "*");
756 if (ret != LTTNG_OK) {
757 if (ret == LTTNG_ERR_UST_EVENT_NOT_FOUND) {
758 /*
759 * This means that no enable all was done before but still a user
760 * could want to disable everything even though the * wild card
761 * event does not exists.
762 */
763 do_disable = 1;
764 } else {
765 goto error;
766 }
767 }
768
769 /* Flag every event that they are now enabled. */
770 rcu_read_lock();
771 cds_lfht_for_each_entry(usess->domain_jul.events->ht, &iter.iter, jevent,
772 node.node) {
773 if (jevent->enabled && do_disable) {
774 ret = event_jul_disable(usess, jevent->name);
775 if (ret != LTTNG_OK) {
776 rcu_read_unlock();
777 goto error;
778 }
779 }
780 jevent->enabled = 0;
781 }
782 rcu_read_unlock();
783
784 ret = LTTNG_OK;
785
786error:
787 return ret;
788}
This page took 0.07155 seconds and 4 git commands to generate.