Use pkgconfig to detect and configure liblttng-ust
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
CommitLineData
54d01ffb
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
71a559f8 3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
54d01ffb 4 *
d14d33bf
AM
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
54d01ffb 8 *
d14d33bf
AM
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
54d01ffb 13 *
d14d33bf
AM
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
54d01ffb
DG
17 */
18
6c1c0768 19#define _LGPL_SOURCE
d87bfb32 20#include <errno.h>
54d01ffb 21#include <urcu/list.h>
2bdd86d4 22#include <string.h>
54d01ffb
DG
23
24#include <lttng/lttng.h>
db758600 25#include <common/error.h>
10a8a223 26#include <common/sessiond-comm/sessiond-comm.h>
71a559f8
JG
27#include <common/filter.h>
28#include <common/context.h>
54d01ffb
DG
29
30#include "channel.h"
31#include "event.h"
4771f025 32#include "kernel.h"
be6a6276 33#include "lttng-sessiond.h"
75018ab6
JG
34#include "lttng-ust-ctl.h"
35#include "lttng-ust-error.h"
edb67388
DG
36#include "ust-app.h"
37#include "trace-kernel.h"
38#include "trace-ust.h"
7c1d2758 39#include "agent.h"
54d01ffb 40
025faf73
DG
41/*
42 * Add unique UST event based on the event name, filter bytecode and loglevel.
43 */
18eace3b
DG
44static void add_unique_ust_event(struct lttng_ht *ht,
45 struct ltt_ust_event *event)
46{
47 struct cds_lfht_node *node_ptr;
48 struct ltt_ust_ht_key key;
49
50 assert(ht);
51 assert(ht->ht);
52 assert(event);
53
54 key.name = event->attr.name;
55 key.filter = (struct lttng_filter_bytecode *) event->filter;
b953b8cd
PP
56 key.loglevel_type = event->attr.loglevel_type;
57 key.loglevel_value = event->attr.loglevel;
4031e53e 58 key.exclusion = event->exclusion;
18eace3b
DG
59
60 node_ptr = cds_lfht_add_unique(ht->ht,
61 ht->hash_fct(event->node.key, lttng_ht_seed),
62 trace_ust_ht_match_event, &key, &event->node.node);
63 assert(node_ptr == &event->node.node);
64}
65
54d01ffb 66/*
9550ee81
JR
67 * Disable kernel tracepoint events for a channel from the kernel session of
68 * a specified event_name and event type.
69 * On type LTTNG_EVENT_ALL all events with event_name are disabled.
70 * If event_name is NULL all events of the specified type are disabled.
54d01ffb 71 */
d0ae4ea8 72int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
df4f5a87 73 const char *event_name, enum lttng_event_type type)
54d01ffb 74{
9550ee81 75 int ret, error = 0, found = 0;
54d01ffb
DG
76 struct ltt_kernel_event *kevent;
77
0525e9ae
DG
78 assert(kchan);
79
54d01ffb
DG
80 /* For each event in the kernel session */
81 cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
d0ae4ea8
MD
82 if (type != LTTNG_EVENT_ALL && kevent->type != type)
83 continue;
9550ee81
JR
84 if (event_name != NULL && strcmp(event_name, kevent->event->name)) {
85 continue;
86 }
87 found++;
54d01ffb
DG
88 ret = kernel_disable_event(kevent);
89 if (ret < 0) {
9550ee81 90 error = 1;
54d01ffb
DG
91 continue;
92 }
93 }
9550ee81
JR
94 DBG("Disable kernel event: found %d events with name: %s and type: %d",
95 found, event_name ? event_name : "NULL", type);
7a3d1328 96
9550ee81
JR
97 if (event_name != NULL && !found) {
98 ret = LTTNG_ERR_NO_EVENT;
99 } else {
100 ret = error ? LTTNG_ERR_KERN_DISABLE_FAIL : LTTNG_OK;
101 }
102
103 return ret;
54d01ffb
DG
104}
105
106/*
7a3d1328 107 * Enable kernel tracepoint event for a channel from the kernel session.
49d21f93 108 * We own filter_expression and filter.
54d01ffb 109 */
d0ae4ea8 110int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
00a62084
MD
111 struct lttng_event *event, char *filter_expression,
112 struct lttng_filter_bytecode *filter)
54d01ffb
DG
113{
114 int ret;
115 struct ltt_kernel_event *kevent;
116
0525e9ae
DG
117 assert(kchan);
118 assert(event);
119
00a62084
MD
120 kevent = trace_kernel_find_event(event->name, kchan,
121 event->type, filter);
54d01ffb 122 if (kevent == NULL) {
71a3bb01 123 ret = kernel_create_event(event, kchan, filter_expression, filter);
a969e101
MD
124 /* We have passed ownership */
125 filter_expression = NULL;
126 filter = NULL;
71a3bb01 127 if (ret) {
7a3d1328 128 goto end;
54d01ffb
DG
129 }
130 } else if (kevent->enabled == 0) {
131 ret = kernel_enable_event(kevent);
132 if (ret < 0) {
f73fabfd 133 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
7a3d1328 134 goto end;
54d01ffb 135 }
42224349
DG
136 } else {
137 /* At this point, the event is considered enabled */
f73fabfd 138 ret = LTTNG_ERR_KERN_EVENT_EXIST;
42224349 139 goto end;
54d01ffb 140 }
42224349 141
f73fabfd 142 ret = LTTNG_OK;
7a3d1328 143end:
a969e101
MD
144 free(filter_expression);
145 free(filter);
54d01ffb
DG
146 return ret;
147}
148
7f79d3a1
DG
149/*
150 * ============================
151 * UST : The Ultimate Frontier!
152 * ============================
153 */
154
2bdd86d4
MD
155/*
156 * Enable UST tracepoint event for a channel from a UST session.
49d21f93 157 * We own filter_expression, filter, and exclusion.
2bdd86d4 158 */
7972aab2 159int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
025faf73 160 struct ltt_ust_channel *uchan, struct lttng_event *event,
6b453b5e 161 char *filter_expression,
f1613f52 162 struct lttng_filter_bytecode *filter,
88f06f15
JG
163 struct lttng_event_exclusion *exclusion,
164 bool internal_event)
2bdd86d4 165{
88e3c2f5 166 int ret = LTTNG_OK, to_create = 0;
edb67388
DG
167 struct ltt_ust_event *uevent;
168
0525e9ae
DG
169 assert(usess);
170 assert(uchan);
171 assert(event);
172
18eace3b
DG
173 rcu_read_lock();
174
025faf73 175 uevent = trace_ust_find_event(uchan->events, event->name, filter,
abda88ad
JG
176 (enum lttng_ust_loglevel_type) event->loglevel_type,
177 event->loglevel, exclusion);
87c6e328 178 if (!uevent) {
39687410
FD
179 ret = trace_ust_create_event(event, filter_expression,
180 filter, exclusion, internal_event, &uevent);
49d21f93
MD
181 /* We have passed ownership */
182 filter_expression = NULL;
183 filter = NULL;
184 exclusion = NULL;
39687410 185 if (ret != LTTNG_OK) {
edb67388
DG
186 goto error;
187 }
025faf73 188
fc34caaa 189 /* Valid to set it after the goto error since uevent is still NULL */
edb67388
DG
190 to_create = 1;
191 }
2bdd86d4 192
7f79d3a1
DG
193 if (uevent->enabled) {
194 /* It's already enabled so everything is OK */
0359fdbc 195 assert(!to_create);
5bcdda4f 196 ret = LTTNG_ERR_UST_EVENT_ENABLED;
7f79d3a1
DG
197 goto end;
198 }
199
fc34caaa 200 uevent->enabled = 1;
88e3c2f5
JG
201 if (to_create) {
202 /* Add ltt ust event to channel */
203 add_unique_ust_event(uchan->events, uevent);
204 }
205
206 if (!usess->active) {
207 goto end;
208 }
fc34caaa 209
7972aab2
DG
210 if (to_create) {
211 /* Create event on all UST registered apps for session */
212 ret = ust_app_create_event_glb(usess, uchan, uevent);
213 } else {
214 /* Enable event on all UST registered apps for session */
215 ret = ust_app_enable_event_glb(usess, uchan, uevent);
216 }
48842b30 217
7972aab2
DG
218 if (ret < 0) {
219 if (ret == -LTTNG_UST_ERR_EXIST) {
220 ret = LTTNG_ERR_UST_EVENT_EXIST;
221 goto end;
222 } else {
223 ret = LTTNG_ERR_UST_ENABLE_FAIL;
224 goto error;
edb67388 225 }
2bdd86d4 226 }
48842b30 227
7f79d3a1
DG
228 DBG("Event UST %s %s in channel %s", uevent->attr.name,
229 to_create ? "created" : "enabled", uchan->name);
230
f73fabfd 231 ret = LTTNG_OK;
fc34caaa 232
fb89d070 233end:
18eace3b 234 rcu_read_unlock();
49d21f93
MD
235 free(filter_expression);
236 free(filter);
237 free(exclusion);
fc34caaa 238 return ret;
edb67388
DG
239
240error:
fc34caaa
DG
241 /*
242 * Only destroy event on creation time (not enabling time) because if the
243 * event is found in the channel (to_create == 0), it means that at some
244 * point the enable_event worked and it's thus valid to keep it alive.
245 * Destroying it also implies that we also destroy it's shadow copy to sync
246 * everyone up.
247 */
248 if (to_create) {
249 /* In this code path, the uevent was not added to the hash table */
250 trace_ust_destroy_event(uevent);
251 }
18eace3b 252 rcu_read_unlock();
49d21f93
MD
253 free(filter_expression);
254 free(filter);
255 free(exclusion);
2bdd86d4
MD
256 return ret;
257}
258
7f79d3a1
DG
259/*
260 * Disable UST tracepoint of a channel from a UST session.
261 */
7972aab2 262int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
df4f5a87 263 struct ltt_ust_channel *uchan, const char *event_name)
2bdd86d4
MD
264{
265 int ret;
7f79d3a1 266 struct ltt_ust_event *uevent;
18eace3b
DG
267 struct lttng_ht_node_str *node;
268 struct lttng_ht_iter iter;
18eace3b 269 struct lttng_ht *ht;
2bdd86d4 270
0525e9ae
DG
271 assert(usess);
272 assert(uchan);
273 assert(event_name);
274
18eace3b
DG
275 ht = uchan->events;
276
18eace3b 277 rcu_read_lock();
025faf73
DG
278
279 /*
280 * We use a custom lookup since we need the iterator for the next_duplicate
281 * call in the do while loop below.
282 */
283 cds_lfht_lookup(ht->ht, ht->hash_fct((void *) event_name, lttng_ht_seed),
284 trace_ust_ht_match_event_by_name, event_name, &iter.iter);
18eace3b
DG
285 node = lttng_ht_iter_get_node_str(&iter);
286 if (node == NULL) {
287 DBG2("Trace UST event NOT found by name %s", event_name);
f73fabfd 288 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
7f79d3a1 289 goto error;
2bdd86d4 290 }
7f79d3a1 291
18eace3b
DG
292 do {
293 uevent = caa_container_of(node, struct ltt_ust_event, node);
025faf73
DG
294 assert(uevent);
295
18eace3b
DG
296 if (uevent->enabled == 0) {
297 /* It's already disabled so everything is OK */
a1dcaf0f 298 goto next;
7f79d3a1 299 }
88e3c2f5
JG
300 uevent->enabled = 0;
301 DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
302 uchan->name);
18eace3b 303
88e3c2f5
JG
304 if (!usess->active) {
305 goto next;
306 }
7972aab2
DG
307 ret = ust_app_disable_event_glb(usess, uchan, uevent);
308 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
309 ret = LTTNG_ERR_UST_DISABLE_FAIL;
18eace3b
DG
310 goto error;
311 }
a1dcaf0f 312next:
18eace3b
DG
313 /* Get next duplicate event by name. */
314 cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
315 event_name, &iter.iter);
316 node = lttng_ht_iter_get_node_str(&iter);
317 } while (node);
7f79d3a1 318
f73fabfd 319 ret = LTTNG_OK;
7f79d3a1 320
7f79d3a1 321error:
18eace3b 322 rcu_read_unlock();
7f79d3a1
DG
323 return ret;
324}
325
b1e7fe2d
JR
326/*
327 * Disable all UST tracepoints for a channel from a UST session.
328 */
329int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
330 struct ltt_ust_channel *uchan)
331{
3e81c0f2 332 int ret, i, size, error = 0;
b1e7fe2d
JR
333 struct lttng_ht_iter iter;
334 struct ltt_ust_event *uevent = NULL;
335 struct lttng_event *events = NULL;
336
337 assert(usess);
338 assert(uchan);
339
340 rcu_read_lock();
341
342 /* Disabling existing events */
343 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent,
344 node.node) {
345 if (uevent->enabled == 1) {
346 ret = event_ust_disable_tracepoint(usess, uchan,
347 uevent->attr.name);
348 if (ret < 0) {
3e81c0f2 349 error = LTTNG_ERR_UST_DISABLE_FAIL;
b1e7fe2d
JR
350 continue;
351 }
352 }
353 }
354
355 /* Get all UST available events */
356 size = ust_app_list_events(&events);
357 if (size < 0) {
358 ret = LTTNG_ERR_UST_LIST_FAIL;
359 goto error;
360 }
361
362 for (i = 0; i < size; i++) {
363 ret = event_ust_disable_tracepoint(usess, uchan,
364 events[i].name);
3e81c0f2 365 if (ret < 0) {
b1e7fe2d 366 /* Continue to disable the rest... */
3e81c0f2 367 error = LTTNG_ERR_UST_DISABLE_FAIL;
b1e7fe2d
JR
368 continue;
369 }
370 }
371
3e81c0f2 372 ret = error ? error : LTTNG_OK;
b1e7fe2d
JR
373error:
374 rcu_read_unlock();
375 free(events);
376 return ret;
377}
378
f20baf8e 379/*
022d91ba 380 * Enable all agent event for a given UST session.
f20baf8e
DG
381 *
382 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
383 */
022d91ba 384int event_agent_enable_all(struct ltt_ust_session *usess,
fefd409b 385 struct agent *agt, struct lttng_event *event,
51755dc8 386 struct lttng_filter_bytecode *filter ,char *filter_expression)
f20baf8e
DG
387{
388 int ret;
fefd409b 389 struct agent_event *aevent;
f20baf8e
DG
390 struct lttng_ht_iter iter;
391
392 assert(usess);
393
022d91ba 394 DBG("Event agent enabling ALL events for session %" PRIu64, usess->id);
f20baf8e 395
022d91ba 396 /* Enable event on agent application through TCP socket. */
8404118c 397 ret = event_agent_enable(usess, agt, event, filter, filter_expression);
f20baf8e
DG
398 if (ret != LTTNG_OK) {
399 goto error;
400 }
401
402 /* Flag every event that they are now enabled. */
403 rcu_read_lock();
fefd409b 404 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
f20baf8e 405 node.node) {
fefd409b 406 aevent->enabled = 1;
f20baf8e
DG
407 }
408 rcu_read_unlock();
409
410 ret = LTTNG_OK;
411
412error:
413 return ret;
414}
415
71a559f8
JG
416/*
417 * Check if this event's filter requires the activation of application contexts
418 * and enable them in the agent.
b4bc01f7
MD
419 * TODO: bytecode iterator does not support non-legacy application
420 * contexts yet. Not an issue for now, since they are not generated by
421 * the lttng-ctl library.
71a559f8
JG
422 */
423static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode,
424 const char *filter_expression, struct agent *agt)
425{
426 int ret = LTTNG_OK;
427 char *provider_name = NULL, *ctx_name = NULL;
428 struct bytecode_symbol_iterator *it =
429 bytecode_symbol_iterator_create(bytecode);
430
431 if (!it) {
432 ret = LTTNG_ERR_NOMEM;
433 goto end;
434 }
435
436 do {
437 struct lttng_event_context ctx;
438 const char *symbol_name =
439 bytecode_symbol_iterator_get_name(it);
440
441 if (parse_application_context(symbol_name, &provider_name,
442 &ctx_name)) {
443 /* Not an application context. */
444 continue;
445 }
446
447 ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
448 ctx.u.app_ctx.provider_name = provider_name;
449 ctx.u.app_ctx.ctx_name = ctx_name;
450
451 /* Recognized an application context. */
452 DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.",
453 filter_expression, provider_name, ctx_name);
454
455 ret = agent_add_context(&ctx, agt);
456 if (ret != LTTNG_OK) {
457 ERR("Failed to add application context %s:%s.",
458 provider_name, ctx_name);
459 goto end;
460 }
461
462 ret = agent_enable_context(&ctx, agt->domain);
463 if (ret != LTTNG_OK) {
464 ERR("Failed to enable application context %s:%s.",
465 provider_name, ctx_name);
466 goto end;
467 }
468
469 free(provider_name);
470 free(ctx_name);
471 provider_name = ctx_name = NULL;
472 } while (bytecode_symbol_iterator_next(it) == 0);
473end:
474 free(provider_name);
475 free(ctx_name);
476 bytecode_symbol_iterator_destroy(it);
477 return ret;
478}
479
f20baf8e 480/*
022d91ba 481 * Enable a single agent event for a given UST session.
f20baf8e
DG
482 *
483 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
484 */
fefd409b
DG
485int event_agent_enable(struct ltt_ust_session *usess,
486 struct agent *agt, struct lttng_event *event,
8404118c
JG
487 struct lttng_filter_bytecode *filter,
488 char *filter_expression)
f20baf8e
DG
489{
490 int ret, created = 0;
fefd409b 491 struct agent_event *aevent;
f20baf8e
DG
492
493 assert(usess);
494 assert(event);
fefd409b 495 assert(agt);
f20baf8e 496
022d91ba 497 DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
51755dc8
JG
498 ", loglevel %d and filter \"%s\"", event->name,
499 usess->id, event->loglevel_type, event->loglevel,
500 filter_expression ? filter_expression : "NULL");
f20baf8e 501
a9319624 502 aevent = agent_find_event(event->name, event->loglevel_type,
71a559f8 503 event->loglevel, filter_expression, agt);
fefd409b 504 if (!aevent) {
a9319624
PP
505 aevent = agent_create_event(event->name, event->loglevel_type,
506 event->loglevel, filter,
51755dc8 507 filter_expression);
fefd409b 508 if (!aevent) {
f20baf8e
DG
509 ret = LTTNG_ERR_NOMEM;
510 goto error;
511 }
b0a23296
JG
512 filter = NULL;
513 filter_expression = NULL;
f20baf8e 514 created = 1;
6fe2a7d0 515 assert(!aevent->enabled);
f20baf8e
DG
516 }
517
bf7886d8
JR
518 if (created && aevent->filter) {
519 ret = add_filter_app_ctx(
520 aevent->filter, aevent->filter_expression, agt);
71a559f8
JG
521 if (ret != LTTNG_OK) {
522 goto error;
523 }
524 }
525
88e3c2f5
JG
526 /* Already enabled? */
527 if (aevent->enabled) {
528 ret = LTTNG_OK;
529 goto end;
530 }
531
fefd409b 532 ret = agent_enable_event(aevent, agt->domain);
f20baf8e
DG
533 if (ret != LTTNG_OK) {
534 goto error;
535 }
536
537 /* If the event was created prior to the enable, add it to the domain. */
538 if (created) {
fefd409b 539 agent_add_event(aevent, agt);
f20baf8e
DG
540 }
541
b0a23296
JG
542 ret = LTTNG_OK;
543 goto end;
f20baf8e
DG
544
545error:
546 if (created) {
fefd409b 547 agent_destroy_event(aevent);
f20baf8e 548 }
b0a23296
JG
549end:
550 free(filter);
551 free(filter_expression);
f20baf8e
DG
552 return ret;
553}
554
da6c3a50 555/*
d1ec8e20
JG
556 * Return the default event name associated with the provided UST domain. Return
557 * NULL on error.
da6c3a50
DG
558 */
559const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
560{
561 const char *default_event_name = NULL;
562
0e115563
DG
563 switch (domain) {
564 case LTTNG_DOMAIN_LOG4J:
d1ec8e20 565 default_event_name = DEFAULT_LOG4J_EVENT_NAME;
0e115563
DG
566 break;
567 case LTTNG_DOMAIN_JUL:
d1ec8e20 568 default_event_name = DEFAULT_JUL_EVENT_NAME;
0e115563
DG
569 break;
570 case LTTNG_DOMAIN_PYTHON:
e7c82272 571 default_event_name = DEFAULT_PYTHON_EVENT_NAME;
0e115563
DG
572 break;
573 default:
da6c3a50
DG
574 assert(0);
575 }
576
577 return default_event_name;
578}
579
f20baf8e 580/*
e261a6cc 581 * Disable a given agent event for a given UST session.
f20baf8e 582 *
e261a6cc 583 * Must be called with the RCU read lock held.
f20baf8e
DG
584 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
585 */
e261a6cc
PP
586static int event_agent_disable_one(struct ltt_ust_session *usess,
587 struct agent *agt, struct agent_event *aevent)
f20baf8e
DG
588{
589 int ret;
be6a6276
DG
590 struct ltt_ust_event *uevent = NULL;
591 struct ltt_ust_channel *uchan = NULL;
71aecbf8 592 const char *ust_event_name, *ust_channel_name;
f20baf8e 593
fefd409b 594 assert(agt);
f20baf8e 595 assert(usess);
e261a6cc 596 assert(aevent);
f20baf8e 597
e261a6cc
PP
598 DBG("Event agent disabling %s (loglevel type %d, loglevel value %d) for session %" PRIu64,
599 aevent->name, aevent->loglevel_type, aevent->loglevel_value,
600 usess->id);
f20baf8e
DG
601
602 /* Already disabled? */
fefd409b 603 if (!aevent->enabled) {
f20baf8e
DG
604 goto end;
605 }
606
71aecbf8
DG
607 if (agt->domain == LTTNG_DOMAIN_JUL) {
608 ust_channel_name = DEFAULT_JUL_CHANNEL_NAME;
609 } else if (agt->domain == LTTNG_DOMAIN_LOG4J) {
610 ust_channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
0e115563
DG
611 } else if (agt->domain == LTTNG_DOMAIN_PYTHON) {
612 ust_channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
71aecbf8
DG
613 } else {
614 ret = LTTNG_ERR_INVALID;
615 goto error;
616 }
617
be6a6276
DG
618 /*
619 * Disable it on the UST side. First get the channel reference then find
620 * the event and finally disable it.
621 */
622 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
71aecbf8 623 (char *) ust_channel_name);
be6a6276
DG
624 if (!uchan) {
625 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
626 goto error;
627 }
628
da6c3a50
DG
629 ust_event_name = event_get_default_agent_ust_name(agt->domain);
630 if (!ust_event_name) {
631 ret = LTTNG_ERR_FATAL;
632 goto error;
be6a6276
DG
633 }
634
635 /*
b953b8cd
PP
636 * Agent UST event has its loglevel type forced to
637 * LTTNG_UST_LOGLEVEL_ALL. The actual loglevel type/value filtering
638 * happens thanks to an UST filter. The following -1 is actually
639 * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
be6a6276 640 */
da6c3a50 641 uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
b953b8cd 642 aevent->filter, LTTNG_UST_LOGLEVEL_ALL, -1, NULL);
022d91ba 643 /* If the agent event exists, it must be available on the UST side. */
be6a6276
DG
644 assert(uevent);
645
88e3c2f5
JG
646 if (usess->active) {
647 ret = ust_app_disable_event_glb(usess, uchan, uevent);
648 if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
649 ret = LTTNG_ERR_UST_DISABLE_FAIL;
650 goto error;
651 }
be6a6276
DG
652 }
653
0dcfcf94
DG
654 /*
655 * Flag event that it's disabled so the shadow copy on the ust app side
656 * will disable it if an application shows up.
657 */
658 uevent->enabled = 0;
659
fefd409b 660 ret = agent_disable_event(aevent, agt->domain);
f20baf8e
DG
661 if (ret != LTTNG_OK) {
662 goto error;
663 }
664
665end:
666 return LTTNG_OK;
667
668error:
669 return ret;
670}
e261a6cc
PP
671
672/*
673 * Disable all agent events matching a given name for a given UST session.
674 *
675 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
676 */
677int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
df4f5a87 678 const char *event_name)
e261a6cc
PP
679{
680 int ret = LTTNG_OK;
681 struct agent_event *aevent;
682 struct lttng_ht_iter iter;
683 struct lttng_ht_node_str *node;
684
685 assert(agt);
686 assert(usess);
687 assert(event_name);
688
689 DBG("Event agent disabling %s (all loglevels) for session %" PRIu64, event_name, usess->id);
690
691 rcu_read_lock();
692 agent_find_events_by_name(event_name, agt, &iter);
693 node = lttng_ht_iter_get_node_str(&iter);
694
695 if (node == NULL) {
696 DBG2("Event agent NOT found by name %s", event_name);
697 ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
698 goto end;
699 }
700
701 do {
702 aevent = caa_container_of(node, struct agent_event, node);
703 ret = event_agent_disable_one(usess, agt, aevent);
704
705 if (ret != LTTNG_OK) {
706 goto end;
707 }
708
709 /* Get next duplicate agent event by name. */
710 agent_event_next_duplicate(event_name, agt, &iter);
711 node = lttng_ht_iter_get_node_str(&iter);
712 } while (node);
713end:
714 rcu_read_unlock();
715 return ret;
716}
f20baf8e 717/*
022d91ba 718 * Disable all agent event for a given UST session.
f20baf8e
DG
719 *
720 * Return LTTNG_OK on success or else a LTTNG_ERR* code.
721 */
fefd409b
DG
722int event_agent_disable_all(struct ltt_ust_session *usess,
723 struct agent *agt)
f20baf8e 724{
0dcfcf94 725 int ret;
fefd409b 726 struct agent_event *aevent;
f20baf8e
DG
727 struct lttng_ht_iter iter;
728
fefd409b 729 assert(agt);
f20baf8e
DG
730 assert(usess);
731
0dcfcf94
DG
732 /*
733 * Disable event on agent application. Continue to disable all other events
734 * if the * event is not found.
735 */
fefd409b 736 ret = event_agent_disable(usess, agt, "*");
0dcfcf94
DG
737 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
738 goto error;
f20baf8e
DG
739 }
740
b9866e08 741 /* Disable every event. */
f20baf8e 742 rcu_read_lock();
fefd409b 743 cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
f20baf8e 744 node.node) {
0dcfcf94
DG
745 if (!aevent->enabled) {
746 continue;
747 }
748
749 ret = event_agent_disable(usess, agt, aevent->name);
750 if (ret != LTTNG_OK) {
b9866e08 751 goto error_unlock;
f20baf8e 752 }
f20baf8e 753 }
f20baf8e
DG
754 ret = LTTNG_OK;
755
b9866e08
JG
756error_unlock:
757 rcu_read_unlock();
f20baf8e
DG
758error:
759 return ret;
760}
This page took 0.098075 seconds and 4 git commands to generate.