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