Fix: memcpy of string is larger than source
[lttng-ust.git] / liblttng-ust / ltt-events.c
1 /*
2 * ltt-events.c
3 *
4 * Holds LTTng per-session event registry.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
27 #include <pthread.h>
28 #include <errno.h>
29 #include <sys/shm.h>
30 #include <sys/ipc.h>
31 #include <stdint.h>
32 #include <stddef.h>
33 #include <inttypes.h>
34 #include <time.h>
35 #include <lttng/ust-endian.h>
36 #include "clock.h"
37
38 #include <urcu-bp.h>
39 #include <urcu/compiler.h>
40 #include <urcu/uatomic.h>
41 #include <urcu/arch.h>
42
43 #include <lttng/tracepoint.h>
44 #include <lttng/ust-events.h>
45
46 #include <usterr-signal-safe.h>
47 #include <helper.h>
48 #include "error.h"
49 #include "compat.h"
50 #include "lttng-ust-uuid.h"
51
52 #include "tracepoint-internal.h"
53 #include "ltt-tracer.h"
54 #include "ltt-tracer-core.h"
55 #include "wait.h"
56 #include "../libringbuffer/shm.h"
57 #include "jhash.h"
58
59 /*
60 * The sessions mutex is the centralized mutex across UST tracing
61 * control and probe registration. All operations within this file are
62 * called by the communication thread, under ust_lock protection.
63 */
64 static pthread_mutex_t sessions_mutex = PTHREAD_MUTEX_INITIALIZER;
65
66 void ust_lock(void)
67 {
68 pthread_mutex_lock(&sessions_mutex);
69 }
70
71 void ust_unlock(void)
72 {
73 pthread_mutex_unlock(&sessions_mutex);
74 }
75
76 static CDS_LIST_HEAD(sessions);
77
78 /*
79 * Wildcard list, containing the active wildcards.
80 * Protected by ust lock.
81 */
82 static CDS_LIST_HEAD(wildcard_list);
83
84 /*
85 * Pending probes hash table, containing the registered ltt events for
86 * which tracepoint probes are still missing. Protected by the sessions
87 * mutex.
88 */
89 #define PENDING_PROBE_HASH_BITS 6
90 #define PENDING_PROBE_HASH_SIZE (1 << PENDING_PROBE_HASH_BITS)
91 static struct cds_hlist_head pending_probe_table[PENDING_PROBE_HASH_SIZE];
92
93 struct ust_pending_probe {
94 struct ltt_event *event;
95 struct cds_hlist_node node;
96 enum lttng_ust_loglevel_type loglevel_type;
97 int loglevel;
98 char name[];
99 };
100
101 static void _ltt_event_destroy(struct ltt_event *event);
102 static void _ltt_wildcard_destroy(struct session_wildcard *sw);
103 static void _ltt_channel_destroy(struct ltt_channel *chan);
104 static int _ltt_event_unregister(struct ltt_event *event);
105 static
106 int _ltt_event_metadata_statedump(struct ltt_session *session,
107 struct ltt_channel *chan,
108 struct ltt_event *event);
109 static
110 int _ltt_session_metadata_statedump(struct ltt_session *session);
111
112 int ltt_loglevel_match(const struct lttng_event_desc *desc,
113 enum lttng_ust_loglevel_type req_type,
114 int req_loglevel)
115 {
116 int ev_loglevel;
117
118 if (req_type == LTTNG_UST_LOGLEVEL_ALL)
119 return 1;
120 if (!desc->loglevel)
121 ev_loglevel = TRACE_DEFAULT;
122 else
123 ev_loglevel = *(*desc->loglevel);
124 switch (req_type) {
125 case LTTNG_UST_LOGLEVEL_RANGE:
126 if (ev_loglevel <= req_loglevel || req_loglevel == -1)
127 return 1;
128 else
129 return 0;
130 case LTTNG_UST_LOGLEVEL_SINGLE:
131 if (ev_loglevel == req_loglevel || req_loglevel == -1)
132 return 1;
133 else
134 return 0;
135 case LTTNG_UST_LOGLEVEL_ALL:
136 default:
137 return 1;
138 }
139 }
140
141 /*
142 * Return wildcard for a given event name if the event name match the
143 * one of the wildcards.
144 * Must be called with ust lock held.
145 * Returns NULL if not present.
146 */
147 static
148 struct wildcard_entry *match_wildcard(const struct lttng_event_desc *desc)
149 {
150 struct wildcard_entry *e;
151
152 cds_list_for_each_entry(e, &wildcard_list, list) {
153 /* If only contain '*' */
154 if (strlen(e->name) == 1)
155 goto possible_match;
156 /* Compare excluding final '*' */
157 if (!strncmp(desc->name, e->name, strlen(e->name) - 1))
158 goto possible_match;
159 continue; /* goto next, no match */
160 possible_match:
161 if (ltt_loglevel_match(desc,
162 e->loglevel_type,
163 e->loglevel)) {
164 return e;
165 }
166 /* no match, loop to next */
167 }
168 return NULL;
169 }
170
171 /*
172 * called at event creation if probe is missing.
173 * called with session mutex held.
174 */
175 static
176 int add_pending_probe(struct ltt_event *event, const char *name,
177 enum lttng_ust_loglevel_type loglevel_type,
178 int loglevel)
179 {
180 struct cds_hlist_head *head;
181 struct ust_pending_probe *e;
182 size_t name_len = strlen(name) + 1;
183 uint32_t hash;
184
185 if (name_len > LTTNG_UST_SYM_NAME_LEN) {
186 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
187 name_len = LTTNG_UST_SYM_NAME_LEN;
188 }
189 hash = jhash(name, name_len - 1, 0);
190 head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
191 e = zmalloc(sizeof(struct ust_pending_probe) + name_len);
192 if (!e)
193 return -ENOMEM;
194 memcpy(&e->name[0], name, name_len);
195 e->name[name_len - 1] = '\0';
196 e->loglevel_type = loglevel_type;
197 e->loglevel = loglevel;
198 cds_hlist_add_head(&e->node, head);
199 e->event = event;
200 event->pending_probe = e;
201 return 0;
202 }
203
204 /*
205 * remove a pending probe. called when at event teardown and when an
206 * event is fixed (probe is loaded).
207 * called with session mutex held.
208 */
209 static
210 void remove_pending_probe(struct ust_pending_probe *e)
211 {
212 if (!e)
213 return;
214 cds_hlist_del(&e->node);
215 free(e);
216 }
217
218 /*
219 * Called at library load: connect the probe on the events pending on
220 * probe load.
221 * called with session mutex held.
222 */
223 int pending_probe_fix_events(const struct lttng_event_desc *desc)
224 {
225 struct cds_hlist_head *head;
226 struct cds_hlist_node *node, *p;
227 struct ust_pending_probe *e;
228 const char *name = desc->name;
229 int ret = 0;
230 struct lttng_ust_event event_param;
231 size_t name_len = strlen(name) + 1;
232 uint32_t hash;
233
234 /* Wildcard */
235 {
236 struct wildcard_entry *wildcard;
237
238 wildcard = match_wildcard(desc);
239 if (strcmp(desc->name, "lttng_ust:metadata") && wildcard) {
240 struct session_wildcard *sw;
241
242 cds_list_for_each_entry(sw, &wildcard->session_list,
243 session_list) {
244 struct ltt_event *ev;
245 int ret;
246
247 memcpy(&event_param, &sw->event_param,
248 sizeof(event_param));
249 strncpy(event_param.name,
250 desc->name,
251 sizeof(event_param.name));
252 event_param.name[sizeof(event_param.name) - 1] = '\0';
253 /* create event */
254 ret = ltt_event_create(sw->chan,
255 &event_param, &ev);
256 if (ret) {
257 DBG("Error creating event");
258 continue;
259 }
260 cds_list_add(&ev->wildcard_list,
261 &sw->events);
262 lttng_filter_event_link_bytecode(ev,
263 sw->filter_bytecode);
264 }
265 }
266 }
267
268 if (name_len > LTTNG_UST_SYM_NAME_LEN) {
269 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
270 name_len = LTTNG_UST_SYM_NAME_LEN;
271 }
272 hash = jhash(name, name_len - 1, 0);
273 head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
274 cds_hlist_for_each_entry_safe(e, node, p, head, node) {
275 struct ltt_event *event;
276 struct ltt_channel *chan;
277
278 if (!ltt_loglevel_match(desc,
279 e->loglevel_type,
280 e->loglevel)) {
281 continue;
282 }
283 if (strncmp(name, e->name, LTTNG_UST_SYM_NAME_LEN - 1)) {
284 continue;
285 }
286 event = e->event;
287 chan = event->chan;
288 assert(!event->desc);
289 event->desc = desc;
290 event->pending_probe = NULL;
291 remove_pending_probe(e);
292 ret |= __tracepoint_probe_register(name,
293 event->desc->probe_callback,
294 event, event->desc->signature);
295 if (ret)
296 continue;
297 event->id = chan->free_event_id++;
298 ret |= _ltt_event_metadata_statedump(chan->session, chan,
299 event);
300 lttng_filter_event_link_bytecode(event,
301 event->filter_bytecode);
302 }
303 return ret;
304 }
305
306 void synchronize_trace(void)
307 {
308 synchronize_rcu();
309 }
310
311 struct ltt_session *ltt_session_create(void)
312 {
313 struct ltt_session *session;
314 int ret;
315
316 session = zmalloc(sizeof(struct ltt_session));
317 if (!session)
318 return NULL;
319 CDS_INIT_LIST_HEAD(&session->chan);
320 CDS_INIT_LIST_HEAD(&session->events);
321 CDS_INIT_LIST_HEAD(&session->wildcards);
322 ret = lttng_ust_uuid_generate(session->uuid);
323 if (ret != 0) {
324 session->uuid[0] = '\0';
325 }
326 cds_list_add(&session->list, &sessions);
327 return session;
328 }
329
330 void ltt_session_destroy(struct ltt_session *session)
331 {
332 struct ltt_channel *chan, *tmpchan;
333 struct ltt_event *event, *tmpevent;
334 struct session_wildcard *wildcard, *tmpwildcard;
335 int ret;
336
337 CMM_ACCESS_ONCE(session->active) = 0;
338 cds_list_for_each_entry(event, &session->events, list) {
339 ret = _ltt_event_unregister(event);
340 WARN_ON(ret);
341 }
342 synchronize_trace(); /* Wait for in-flight events to complete */
343 cds_list_for_each_entry_safe(wildcard, tmpwildcard, &session->wildcards, list)
344 _ltt_wildcard_destroy(wildcard);
345 cds_list_for_each_entry_safe(event, tmpevent, &session->events, list)
346 _ltt_event_destroy(event);
347 cds_list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
348 _ltt_channel_destroy(chan);
349 cds_list_del(&session->list);
350 free(session);
351 }
352
353 int ltt_session_enable(struct ltt_session *session)
354 {
355 int ret = 0;
356 struct ltt_channel *chan;
357
358 if (session->active) {
359 ret = -EBUSY;
360 goto end;
361 }
362
363 /*
364 * Snapshot the number of events per channel to know the type of header
365 * we need to use.
366 */
367 cds_list_for_each_entry(chan, &session->chan, list) {
368 if (chan->header_type)
369 continue; /* don't change it if session stop/restart */
370 if (chan->free_event_id < 31)
371 chan->header_type = 1; /* compact */
372 else
373 chan->header_type = 2; /* large */
374 }
375
376 CMM_ACCESS_ONCE(session->active) = 1;
377 CMM_ACCESS_ONCE(session->been_active) = 1;
378 ret = _ltt_session_metadata_statedump(session);
379 if (ret)
380 CMM_ACCESS_ONCE(session->active) = 0;
381 end:
382 return ret;
383 }
384
385 int ltt_session_disable(struct ltt_session *session)
386 {
387 int ret = 0;
388
389 if (!session->active) {
390 ret = -EBUSY;
391 goto end;
392 }
393 CMM_ACCESS_ONCE(session->active) = 0;
394 end:
395 return ret;
396 }
397
398 int ltt_channel_enable(struct ltt_channel *channel)
399 {
400 int old;
401
402 if (channel == channel->session->metadata)
403 return -EPERM;
404 old = uatomic_xchg(&channel->enabled, 1);
405 if (old)
406 return -EEXIST;
407 return 0;
408 }
409
410 int ltt_channel_disable(struct ltt_channel *channel)
411 {
412 int old;
413
414 if (channel == channel->session->metadata)
415 return -EPERM;
416 old = uatomic_xchg(&channel->enabled, 0);
417 if (!old)
418 return -EEXIST;
419 return 0;
420 }
421
422 int ltt_event_enable(struct ltt_event *event)
423 {
424 int old;
425
426 if (event->chan == event->chan->session->metadata)
427 return -EPERM;
428 old = uatomic_xchg(&event->enabled, 1);
429 if (old)
430 return -EEXIST;
431 return 0;
432 }
433
434 int ltt_event_disable(struct ltt_event *event)
435 {
436 int old;
437
438 if (event->chan == event->chan->session->metadata)
439 return -EPERM;
440 old = uatomic_xchg(&event->enabled, 0);
441 if (!old)
442 return -EEXIST;
443 return 0;
444 }
445
446 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
447 const char *transport_name,
448 void *buf_addr,
449 size_t subbuf_size, size_t num_subbuf,
450 unsigned int switch_timer_interval,
451 unsigned int read_timer_interval,
452 int **shm_fd, int **wait_fd,
453 uint64_t **memory_map_size,
454 struct ltt_channel *chan_priv_init)
455 {
456 struct ltt_channel *chan = NULL;
457 struct ltt_transport *transport;
458
459 if (session->been_active)
460 goto active; /* Refuse to add channel to active session */
461 transport = ltt_transport_find(transport_name);
462 if (!transport) {
463 DBG("LTTng transport %s not found\n",
464 transport_name);
465 goto notransport;
466 }
467 chan_priv_init->id = session->free_chan_id++;
468 chan_priv_init->session = session;
469 /*
470 * Note: the channel creation op already writes into the packet
471 * headers. Therefore the "chan" information used as input
472 * should be already accessible.
473 */
474 chan = transport->ops.channel_create(transport_name, buf_addr,
475 subbuf_size, num_subbuf, switch_timer_interval,
476 read_timer_interval, shm_fd, wait_fd,
477 memory_map_size, chan_priv_init);
478 if (!chan)
479 goto create_error;
480 chan->enabled = 1;
481 chan->ops = &transport->ops;
482 cds_list_add(&chan->list, &session->chan);
483 return chan;
484
485 create_error:
486 notransport:
487 active:
488 return NULL;
489 }
490
491 /*
492 * Only used internally at session destruction.
493 */
494 static
495 void _ltt_channel_destroy(struct ltt_channel *chan)
496 {
497 cds_list_del(&chan->list);
498 lttng_destroy_context(chan->ctx);
499 chan->ops->channel_destroy(chan);
500 }
501
502 /*
503 * Supports event creation while tracing session is active.
504 */
505 int ltt_event_create(struct ltt_channel *chan,
506 struct lttng_ust_event *event_param,
507 struct ltt_event **_event)
508 {
509 const struct lttng_event_desc *desc = NULL; /* silence gcc */
510 struct ltt_event *event;
511 int ret = 0;
512
513 if (chan->used_event_id == -1U) {
514 ret = -ENOMEM;
515 goto full;
516 }
517 /*
518 * This is O(n^2) (for each event, the loop is called at event
519 * creation). Might require a hash if we have lots of events.
520 */
521 cds_list_for_each_entry(event, &chan->session->events, list) {
522 if (event->desc && !strncmp(event->desc->name,
523 event_param->name,
524 LTTNG_UST_SYM_NAME_LEN - 1)) {
525 ret = -EEXIST;
526 goto exist;
527 }
528 }
529
530 /*
531 * Check if loglevel match. Refuse to connect event if not.
532 */
533 if (event_param->instrumentation == LTTNG_UST_TRACEPOINT) {
534 desc = ltt_event_get(event_param->name);
535 if (desc) {
536 if (!ltt_loglevel_match(desc,
537 event_param->loglevel_type,
538 event_param->loglevel)) {
539 ret = -EPERM;
540 goto no_loglevel_match;
541 }
542 }
543 /*
544 * If descriptor is not there, it will be added to
545 * pending probes.
546 */
547 }
548 event = zmalloc(sizeof(struct ltt_event));
549 if (!event) {
550 ret = -ENOMEM;
551 goto cache_error;
552 }
553 event->chan = chan;
554 /*
555 * used_event_id counts the maximum number of event IDs that can
556 * register if all probes register.
557 */
558 chan->used_event_id++;
559 event->enabled = 1;
560 event->instrumentation = event_param->instrumentation;
561 /* Populate ltt_event structure before tracepoint registration. */
562 cmm_smp_wmb();
563 switch (event_param->instrumentation) {
564 case LTTNG_UST_TRACEPOINT:
565 event->desc = desc;
566 if (event->desc) {
567 ret = __tracepoint_probe_register(event_param->name,
568 event->desc->probe_callback,
569 event, event->desc->signature);
570 if (ret)
571 goto register_error;
572 event->id = chan->free_event_id++;
573 } else {
574 /*
575 * If the probe is not present, event->desc stays NULL,
576 * waiting for the probe to register, and the event->id
577 * stays unallocated.
578 */
579 ret = add_pending_probe(event, event_param->name,
580 event_param->loglevel_type,
581 event_param->loglevel);
582 if (ret)
583 goto add_pending_error;
584 }
585 break;
586 default:
587 WARN_ON_ONCE(1);
588 }
589 if (event->desc) {
590 ret = _ltt_event_metadata_statedump(chan->session, chan, event);
591 if (ret)
592 goto statedump_error;
593 }
594 cds_list_add(&event->list, &chan->session->events);
595 *_event = event;
596 return 0;
597
598 statedump_error:
599 if (event->desc) {
600 WARN_ON_ONCE(__tracepoint_probe_unregister(event_param->name,
601 event->desc->probe_callback,
602 event));
603 ltt_event_put(event->desc);
604 }
605 add_pending_error:
606 register_error:
607 free(event);
608 cache_error:
609 no_loglevel_match:
610 exist:
611 full:
612 return ret;
613 }
614
615 /*
616 * Only used internally at session destruction.
617 */
618 int _ltt_event_unregister(struct ltt_event *event)
619 {
620 int ret = -EINVAL;
621
622 switch (event->instrumentation) {
623 case LTTNG_UST_TRACEPOINT:
624 if (event->desc) {
625 ret = __tracepoint_probe_unregister(event->desc->name,
626 event->desc->probe_callback,
627 event);
628 if (ret)
629 return ret;
630 } else {
631 remove_pending_probe(event->pending_probe);
632 ret = 0;
633 }
634 break;
635 default:
636 WARN_ON_ONCE(1);
637 }
638 return ret;
639 }
640
641 /*
642 * Only used internally at session destruction.
643 */
644 static
645 void _ltt_event_destroy(struct ltt_event *event)
646 {
647 switch (event->instrumentation) {
648 case LTTNG_UST_TRACEPOINT:
649 if (event->desc) {
650 ltt_event_put(event->desc);
651 }
652 break;
653 default:
654 WARN_ON_ONCE(1);
655 }
656 cds_list_del(&event->list);
657 lttng_destroy_context(event->ctx);
658 free(event->filter_bytecode);
659 free(event->filter_data);
660 free(event);
661 }
662
663 /*
664 * We have exclusive access to our metadata buffer (protected by the
665 * ust_lock), so we can do racy operations such as looking for
666 * remaining space left in packet and write, since mutual exclusion
667 * protects us from concurrent writes.
668 */
669 int lttng_metadata_printf(struct ltt_session *session,
670 const char *fmt, ...)
671 {
672 struct lttng_ust_lib_ring_buffer_ctx ctx;
673 struct ltt_channel *chan = session->metadata;
674 char *str = NULL;
675 int ret = 0, waitret;
676 size_t len, reserve_len, pos;
677 va_list ap;
678
679 WARN_ON_ONCE(!CMM_ACCESS_ONCE(session->active));
680
681 va_start(ap, fmt);
682 ret = vasprintf(&str, fmt, ap);
683 va_end(ap);
684 if (ret < 0)
685 return -ENOMEM;
686
687 len = strlen(str);
688 pos = 0;
689
690 for (pos = 0; pos < len; pos += reserve_len) {
691 reserve_len = min_t(size_t,
692 chan->ops->packet_avail_size(chan->chan, chan->handle),
693 len - pos);
694 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
695 sizeof(char), -1, chan->handle);
696 /*
697 * We don't care about metadata buffer's records lost
698 * count, because we always retry here. Report error if
699 * we need to bail out after timeout or being
700 * interrupted.
701 */
702 waitret = wait_cond_interruptible_timeout(
703 ({
704 ret = chan->ops->event_reserve(&ctx, 0);
705 ret != -ENOBUFS || !ret;
706 }),
707 LTTNG_METADATA_TIMEOUT_MSEC);
708 if (waitret == -ETIMEDOUT || waitret == -EINTR || ret) {
709 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
710 waitret == -EINTR ? "interrupted" :
711 (ret == -ENOBUFS ? "timeout" : "I/O error"));
712 if (waitret == -EINTR)
713 ret = waitret;
714 goto end;
715 }
716 chan->ops->event_write(&ctx, &str[pos], reserve_len);
717 chan->ops->event_commit(&ctx);
718 }
719 end:
720 free(str);
721 return ret;
722 }
723
724 static
725 int _ltt_field_statedump(struct ltt_session *session,
726 const struct lttng_event_field *field)
727 {
728 int ret = 0;
729
730 if (field->nowrite)
731 return 0;
732
733 switch (field->type.atype) {
734 case atype_integer:
735 ret = lttng_metadata_printf(session,
736 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
737 field->type.u.basic.integer.size,
738 field->type.u.basic.integer.alignment,
739 field->type.u.basic.integer.signedness,
740 (field->type.u.basic.integer.encoding == lttng_encode_none)
741 ? "none"
742 : (field->type.u.basic.integer.encoding == lttng_encode_UTF8)
743 ? "UTF8"
744 : "ASCII",
745 field->type.u.basic.integer.base,
746 #if (BYTE_ORDER == BIG_ENDIAN)
747 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
748 #else
749 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
750 #endif
751 field->name);
752 break;
753 case atype_float:
754 ret = lttng_metadata_printf(session,
755 " floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
756 field->type.u.basic._float.exp_dig,
757 field->type.u.basic._float.mant_dig,
758 field->type.u.basic._float.alignment,
759 #if (BYTE_ORDER == BIG_ENDIAN)
760 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
761 #else
762 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
763 #endif
764 field->name);
765 break;
766 case atype_enum:
767 ret = lttng_metadata_printf(session,
768 " %s %s;\n",
769 field->type.u.basic.enumeration.name,
770 field->name);
771 break;
772 case atype_array:
773 {
774 const struct lttng_basic_type *elem_type;
775
776 elem_type = &field->type.u.array.elem_type;
777 ret = lttng_metadata_printf(session,
778 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
779 elem_type->u.basic.integer.size,
780 elem_type->u.basic.integer.alignment,
781 elem_type->u.basic.integer.signedness,
782 (elem_type->u.basic.integer.encoding == lttng_encode_none)
783 ? "none"
784 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
785 ? "UTF8"
786 : "ASCII",
787 elem_type->u.basic.integer.base,
788 #if (BYTE_ORDER == BIG_ENDIAN)
789 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
790 #else
791 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
792 #endif
793 field->name, field->type.u.array.length);
794 break;
795 }
796 case atype_sequence:
797 {
798 const struct lttng_basic_type *elem_type;
799 const struct lttng_basic_type *length_type;
800
801 elem_type = &field->type.u.sequence.elem_type;
802 length_type = &field->type.u.sequence.length_type;
803 ret = lttng_metadata_printf(session,
804 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
805 length_type->u.basic.integer.size,
806 (unsigned int) length_type->u.basic.integer.alignment,
807 length_type->u.basic.integer.signedness,
808 (length_type->u.basic.integer.encoding == lttng_encode_none)
809 ? "none"
810 : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8)
811 ? "UTF8"
812 : "ASCII"),
813 length_type->u.basic.integer.base,
814 #if (BYTE_ORDER == BIG_ENDIAN)
815 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
816 #else
817 length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
818 #endif
819 field->name);
820 if (ret)
821 return ret;
822
823 ret = lttng_metadata_printf(session,
824 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
825 elem_type->u.basic.integer.size,
826 (unsigned int) elem_type->u.basic.integer.alignment,
827 elem_type->u.basic.integer.signedness,
828 (elem_type->u.basic.integer.encoding == lttng_encode_none)
829 ? "none"
830 : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
831 ? "UTF8"
832 : "ASCII"),
833 elem_type->u.basic.integer.base,
834 #if (BYTE_ORDER == BIG_ENDIAN)
835 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
836 #else
837 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
838 #endif
839 field->name,
840 field->name);
841 break;
842 }
843
844 case atype_string:
845 /* Default encoding is UTF8 */
846 ret = lttng_metadata_printf(session,
847 " string%s _%s;\n",
848 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
849 " { encoding = ASCII; }" : "",
850 field->name);
851 break;
852 default:
853 WARN_ON_ONCE(1);
854 return -EINVAL;
855 }
856 return ret;
857 }
858
859 static
860 int _ltt_context_metadata_statedump(struct ltt_session *session,
861 struct lttng_ctx *ctx)
862 {
863 int ret = 0;
864 int i;
865
866 if (!ctx)
867 return 0;
868 for (i = 0; i < ctx->nr_fields; i++) {
869 const struct lttng_ctx_field *field = &ctx->fields[i];
870
871 ret = _ltt_field_statedump(session, &field->event_field);
872 if (ret)
873 return ret;
874 }
875 return ret;
876 }
877
878 static
879 int _ltt_fields_metadata_statedump(struct ltt_session *session,
880 struct ltt_event *event)
881 {
882 const struct lttng_event_desc *desc = event->desc;
883 int ret = 0;
884 int i;
885
886 for (i = 0; i < desc->nr_fields; i++) {
887 const struct lttng_event_field *field = &desc->fields[i];
888
889 ret = _ltt_field_statedump(session, field);
890 if (ret)
891 return ret;
892 }
893 return ret;
894 }
895
896 static
897 int _ltt_event_metadata_statedump(struct ltt_session *session,
898 struct ltt_channel *chan,
899 struct ltt_event *event)
900 {
901 int ret = 0;
902 int loglevel = TRACE_DEFAULT;
903
904 if (event->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
905 return 0;
906 if (chan == session->metadata)
907 return 0;
908 /*
909 * Don't print events for which probe load is pending.
910 */
911 if (!event->desc)
912 return 0;
913
914 ret = lttng_metadata_printf(session,
915 "event {\n"
916 " name = \"%s\";\n"
917 " id = %u;\n"
918 " stream_id = %u;\n",
919 event->desc->name,
920 event->id,
921 event->chan->id);
922 if (ret)
923 goto end;
924
925 if (event->desc->loglevel)
926 loglevel = *(*event->desc->loglevel);
927
928 ret = lttng_metadata_printf(session,
929 " loglevel = %d;\n",
930 loglevel);
931 if (ret)
932 goto end;
933
934 if (event->desc->u.ext.model_emf_uri) {
935 ret = lttng_metadata_printf(session,
936 " model.emf.uri = \"%s\";\n",
937 *(event->desc->u.ext.model_emf_uri));
938 if (ret)
939 goto end;
940 }
941
942 if (event->ctx) {
943 ret = lttng_metadata_printf(session,
944 " context := struct {\n");
945 if (ret)
946 goto end;
947 }
948 ret = _ltt_context_metadata_statedump(session, event->ctx);
949 if (ret)
950 goto end;
951 if (event->ctx) {
952 ret = lttng_metadata_printf(session,
953 " };\n");
954 if (ret)
955 goto end;
956 }
957
958 ret = lttng_metadata_printf(session,
959 " fields := struct {\n"
960 );
961 if (ret)
962 goto end;
963
964 ret = _ltt_fields_metadata_statedump(session, event);
965 if (ret)
966 goto end;
967
968 /*
969 * LTTng space reservation can only reserve multiples of the
970 * byte size.
971 */
972 ret = lttng_metadata_printf(session,
973 " };\n"
974 "};\n\n");
975 if (ret)
976 goto end;
977
978 event->metadata_dumped = 1;
979 end:
980 return ret;
981
982 }
983
984 static
985 int _ltt_channel_metadata_statedump(struct ltt_session *session,
986 struct ltt_channel *chan)
987 {
988 int ret = 0;
989
990 if (chan->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
991 return 0;
992 if (chan == session->metadata)
993 return 0;
994
995 WARN_ON_ONCE(!chan->header_type);
996 ret = lttng_metadata_printf(session,
997 "stream {\n"
998 " id = %u;\n"
999 " event.header := %s;\n"
1000 " packet.context := struct packet_context;\n",
1001 chan->id,
1002 chan->header_type == 1 ? "struct event_header_compact" :
1003 "struct event_header_large");
1004 if (ret)
1005 goto end;
1006
1007 if (chan->ctx) {
1008 ret = lttng_metadata_printf(session,
1009 " event.context := struct {\n");
1010 if (ret)
1011 goto end;
1012 }
1013 ret = _ltt_context_metadata_statedump(session, chan->ctx);
1014 if (ret)
1015 goto end;
1016 if (chan->ctx) {
1017 ret = lttng_metadata_printf(session,
1018 " };\n");
1019 if (ret)
1020 goto end;
1021 }
1022
1023 ret = lttng_metadata_printf(session,
1024 "};\n\n");
1025
1026 chan->metadata_dumped = 1;
1027 end:
1028 return ret;
1029 }
1030
1031 static
1032 int _ltt_stream_packet_context_declare(struct ltt_session *session)
1033 {
1034 return lttng_metadata_printf(session,
1035 "struct packet_context {\n"
1036 " uint64_clock_monotonic_t timestamp_begin;\n"
1037 " uint64_clock_monotonic_t timestamp_end;\n"
1038 " uint64_t content_size;\n"
1039 " uint64_t packet_size;\n"
1040 " unsigned long events_discarded;\n"
1041 " uint32_t cpu_id;\n"
1042 "};\n\n"
1043 );
1044 }
1045
1046 /*
1047 * Compact header:
1048 * id: range: 0 - 30.
1049 * id 31 is reserved to indicate an extended header.
1050 *
1051 * Large header:
1052 * id: range: 0 - 65534.
1053 * id 65535 is reserved to indicate an extended header.
1054 */
1055 static
1056 int _ltt_event_header_declare(struct ltt_session *session)
1057 {
1058 return lttng_metadata_printf(session,
1059 "struct event_header_compact {\n"
1060 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
1061 " variant <id> {\n"
1062 " struct {\n"
1063 " uint27_clock_monotonic_t timestamp;\n"
1064 " } compact;\n"
1065 " struct {\n"
1066 " uint32_t id;\n"
1067 " uint64_clock_monotonic_t timestamp;\n"
1068 " } extended;\n"
1069 " } v;\n"
1070 "} align(%u);\n"
1071 "\n"
1072 "struct event_header_large {\n"
1073 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1074 " variant <id> {\n"
1075 " struct {\n"
1076 " uint32_clock_monotonic_t timestamp;\n"
1077 " } compact;\n"
1078 " struct {\n"
1079 " uint32_t id;\n"
1080 " uint64_clock_monotonic_t timestamp;\n"
1081 " } extended;\n"
1082 " } v;\n"
1083 "} align(%u);\n\n",
1084 lttng_alignof(uint32_t) * CHAR_BIT,
1085 lttng_alignof(uint16_t) * CHAR_BIT
1086 );
1087 }
1088
1089 /*
1090 * Approximation of NTP time of day to clock monotonic correlation,
1091 * taken at start of trace.
1092 * Yes, this is only an approximation. Yes, we can (and will) do better
1093 * in future versions.
1094 */
1095 static
1096 uint64_t measure_clock_offset(void)
1097 {
1098 uint64_t offset, monotonic[2], realtime;
1099 struct timespec rts = { 0, 0 };
1100 int ret;
1101
1102 monotonic[0] = trace_clock_read64();
1103 ret = clock_gettime(CLOCK_REALTIME, &rts);
1104 if (ret < 0)
1105 return 0;
1106 monotonic[1] = trace_clock_read64();
1107 offset = (monotonic[0] + monotonic[1]) >> 1;
1108 realtime = (uint64_t) rts.tv_sec * 1000000000ULL;
1109 realtime += rts.tv_nsec;
1110 offset = realtime - offset;
1111 return offset;
1112 }
1113
1114 /*
1115 * Output metadata into this session's metadata buffers.
1116 */
1117 static
1118 int _ltt_session_metadata_statedump(struct ltt_session *session)
1119 {
1120 unsigned char *uuid_c = session->uuid;
1121 char uuid_s[LTTNG_UST_UUID_STR_LEN],
1122 clock_uuid_s[LTTNG_UST_UUID_STR_LEN];
1123 struct ltt_channel *chan;
1124 struct ltt_event *event;
1125 int ret = 0;
1126 char procname[LTTNG_UST_PROCNAME_LEN] = "";
1127 char hostname[HOST_NAME_MAX];
1128
1129 if (!CMM_ACCESS_ONCE(session->active))
1130 return 0;
1131 if (session->metadata_dumped)
1132 goto skip_session;
1133 if (!session->metadata) {
1134 DBG("LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
1135 return -EPERM;
1136 }
1137
1138 snprintf(uuid_s, sizeof(uuid_s),
1139 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1140 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
1141 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
1142 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
1143 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
1144
1145 ret = lttng_metadata_printf(session,
1146 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1147 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1148 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1149 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1150 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
1151 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1152 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1153 "\n"
1154 "trace {\n"
1155 " major = %u;\n"
1156 " minor = %u;\n"
1157 " uuid = \"%s\";\n"
1158 " byte_order = %s;\n"
1159 " packet.header := struct {\n"
1160 " uint32_t magic;\n"
1161 " uint8_t uuid[16];\n"
1162 " uint32_t stream_id;\n"
1163 " };\n"
1164 "};\n\n",
1165 lttng_alignof(uint8_t) * CHAR_BIT,
1166 lttng_alignof(uint16_t) * CHAR_BIT,
1167 lttng_alignof(uint32_t) * CHAR_BIT,
1168 lttng_alignof(uint64_t) * CHAR_BIT,
1169 sizeof(unsigned long) * CHAR_BIT,
1170 lttng_alignof(unsigned long) * CHAR_BIT,
1171 CTF_SPEC_MAJOR,
1172 CTF_SPEC_MINOR,
1173 uuid_s,
1174 #if (BYTE_ORDER == BIG_ENDIAN)
1175 "be"
1176 #else
1177 "le"
1178 #endif
1179 );
1180 if (ret)
1181 goto end;
1182
1183 /* ignore error, just use empty string if error. */
1184 hostname[0] = '\0';
1185 ret = gethostname(hostname, sizeof(hostname));
1186 if (ret && errno == ENAMETOOLONG)
1187 hostname[HOST_NAME_MAX - 1] = '\0';
1188 lttng_ust_getprocname(procname);
1189 procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0';
1190 ret = lttng_metadata_printf(session,
1191 "env {\n"
1192 " hostname = \"%s\";\n"
1193 " vpid = %d;\n"
1194 " procname = \"%s\";\n"
1195 " domain = \"ust\";\n"
1196 " tracer_name = \"lttng-ust\";\n"
1197 " tracer_major = %u;\n"
1198 " tracer_minor = %u;\n"
1199 " tracer_patchlevel = %u;\n"
1200 "};\n\n",
1201 hostname,
1202 (int) getpid(),
1203 procname,
1204 LTTNG_UST_MAJOR_VERSION,
1205 LTTNG_UST_MINOR_VERSION,
1206 LTTNG_UST_PATCHLEVEL_VERSION
1207 );
1208 if (ret)
1209 goto end;
1210
1211 ret = lttng_metadata_printf(session,
1212 "clock {\n"
1213 " name = %s;\n",
1214 "monotonic"
1215 );
1216 if (ret)
1217 goto end;
1218
1219 if (!trace_clock_uuid(clock_uuid_s)) {
1220 ret = lttng_metadata_printf(session,
1221 " uuid = \"%s\";\n",
1222 clock_uuid_s
1223 );
1224 if (ret)
1225 goto end;
1226 }
1227
1228 ret = lttng_metadata_printf(session,
1229 " description = \"Monotonic Clock\";\n"
1230 " freq = %" PRIu64 "; /* Frequency, in Hz */\n"
1231 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1232 " offset = %" PRIu64 ";\n"
1233 "};\n\n",
1234 trace_clock_freq(),
1235 measure_clock_offset()
1236 );
1237 if (ret)
1238 goto end;
1239
1240 ret = lttng_metadata_printf(session,
1241 "typealias integer {\n"
1242 " size = 27; align = 1; signed = false;\n"
1243 " map = clock.monotonic.value;\n"
1244 "} := uint27_clock_monotonic_t;\n"
1245 "\n"
1246 "typealias integer {\n"
1247 " size = 32; align = %u; signed = false;\n"
1248 " map = clock.monotonic.value;\n"
1249 "} := uint32_clock_monotonic_t;\n"
1250 "\n"
1251 "typealias integer {\n"
1252 " size = 64; align = %u; signed = false;\n"
1253 " map = clock.monotonic.value;\n"
1254 "} := uint64_clock_monotonic_t;\n\n",
1255 lttng_alignof(uint32_t) * CHAR_BIT,
1256 lttng_alignof(uint64_t) * CHAR_BIT
1257 );
1258 if (ret)
1259 goto end;
1260
1261 ret = _ltt_stream_packet_context_declare(session);
1262 if (ret)
1263 goto end;
1264
1265 ret = _ltt_event_header_declare(session);
1266 if (ret)
1267 goto end;
1268
1269 skip_session:
1270 cds_list_for_each_entry(chan, &session->chan, list) {
1271 ret = _ltt_channel_metadata_statedump(session, chan);
1272 if (ret)
1273 goto end;
1274 }
1275
1276 cds_list_for_each_entry(event, &session->events, list) {
1277 ret = _ltt_event_metadata_statedump(session, event->chan, event);
1278 if (ret)
1279 goto end;
1280 }
1281 session->metadata_dumped = 1;
1282 end:
1283 return ret;
1284 }
1285
1286 void lttng_ust_events_exit(void)
1287 {
1288 struct ltt_session *session, *tmpsession;
1289
1290 cds_list_for_each_entry_safe(session, tmpsession, &sessions, list)
1291 ltt_session_destroy(session);
1292 }
1293
1294 /* WILDCARDS */
1295
1296 static
1297 int wildcard_same_loglevel(struct wildcard_entry *e,
1298 enum lttng_ust_loglevel_type loglevel_type,
1299 int loglevel)
1300 {
1301 if (e->loglevel_type == loglevel_type && e->loglevel == loglevel)
1302 return 1;
1303 else
1304 return 0;
1305 }
1306
1307 #if 0
1308 static
1309 int wildcard_is_within(struct wildcard_entry *e,
1310 enum lttng_ust_loglevel_type loglevel_type,
1311 int loglevel)
1312 {
1313 if (e->loglevel_type == LTTNG_UST_LOGLEVEL_ALL
1314 || e->loglevel == -1)
1315 return 1;
1316 switch (e->loglevel_type) {
1317 case LTTNG_UST_LOGLEVEL_RANGE:
1318 switch (loglevel_type) {
1319 case LTTNG_UST_LOGLEVEL_RANGE:
1320 if (e->loglevel >= loglevel)
1321 return 1;
1322 else
1323 return 0;
1324 case LTTNG_UST_LOGLEVEL_SINGLE:
1325 if (e->loglevel <= 0 && loglevel == 0)
1326 return 1;
1327 else
1328 return 0;
1329 }
1330 case LTTNG_UST_LOGLEVEL_SINGLE:
1331 switch (loglevel_type) {
1332 case LTTNG_UST_LOGLEVEL_RANGE:
1333 if (loglevel <= 0)
1334 return 1;
1335 else
1336 return 0;
1337 case LTTNG_UST_LOGLEVEL_SINGLE:
1338 if (e->loglevel == loglevel)
1339 return 1;
1340 else
1341 return 0;
1342 }
1343 }
1344 }
1345 #endif
1346
1347 /*
1348 * Add the wildcard to the wildcard list. Must be called with
1349 * ust lock held.
1350 */
1351 static
1352 struct session_wildcard *add_wildcard(struct ltt_channel *chan,
1353 struct lttng_ust_event *event_param)
1354 {
1355 struct wildcard_entry *e;
1356 struct session_wildcard *sw;
1357 size_t name_len = strlen(event_param->name) + 1;
1358 int found = 0;
1359
1360 /*
1361 * Try to find global wildcard entry. Given that this is shared
1362 * across all sessions, we need to check for exact loglevel
1363 * match, not just whether contained within the existing ones.
1364 */
1365 cds_list_for_each_entry(e, &wildcard_list, list) {
1366 if (!strncmp(event_param->name, e->name,
1367 LTTNG_UST_SYM_NAME_LEN - 1)) {
1368 if (wildcard_same_loglevel(e,
1369 event_param->loglevel_type,
1370 event_param->loglevel)) {
1371 found = 1;
1372 break;
1373 }
1374 }
1375 }
1376
1377 if (!found) {
1378 /*
1379 * Create global wildcard entry if not found. Using
1380 * zmalloc here to allocate a variable length element.
1381 * Could cause some memory fragmentation if overused.
1382 */
1383 e = zmalloc(sizeof(struct wildcard_entry) + name_len);
1384 if (!e)
1385 return ERR_PTR(-ENOMEM);
1386 memcpy(&e->name[0], event_param->name, name_len);
1387 e->loglevel_type = event_param->loglevel_type;
1388 e->loglevel = event_param->loglevel;
1389 cds_list_add(&e->list, &wildcard_list);
1390 CDS_INIT_LIST_HEAD(&e->session_list);
1391 }
1392
1393 /* session wildcard */
1394 cds_list_for_each_entry(sw, &e->session_list, session_list) {
1395 if (chan == sw->chan) {
1396 DBG("wildcard %s busy for this channel",
1397 event_param->name);
1398 return ERR_PTR(-EEXIST); /* Already there */
1399 }
1400 }
1401 sw = zmalloc(sizeof(struct session_wildcard));
1402 if (!sw)
1403 return ERR_PTR(-ENOMEM);
1404 sw->chan = chan;
1405 sw->enabled = 1;
1406 memcpy(&sw->event_param, event_param, sizeof(sw->event_param));
1407 sw->event_param.instrumentation = LTTNG_UST_TRACEPOINT;
1408 sw->event_param.loglevel_type = event_param->loglevel_type;
1409 sw->event_param.loglevel = event_param->loglevel;
1410 CDS_INIT_LIST_HEAD(&sw->events);
1411 cds_list_add(&sw->list, &chan->session->wildcards);
1412 cds_list_add(&sw->session_list, &e->session_list);
1413 sw->entry = e;
1414 ltt_probes_create_wildcard_events(e, sw);
1415 return sw;
1416 }
1417
1418 /*
1419 * Remove the wildcard from the wildcard list. Must be called with
1420 * ust_lock held. Only called at session teardown.
1421 */
1422 static
1423 void _remove_wildcard(struct session_wildcard *wildcard)
1424 {
1425 struct ltt_event *ev, *tmp;
1426
1427 /*
1428 * Just remove the events owned (for enable/disable) by this
1429 * wildcard from the list. The session teardown will take care
1430 * of freeing the event memory.
1431 */
1432 cds_list_for_each_entry_safe(ev, tmp, &wildcard->events,
1433 wildcard_list) {
1434 cds_list_del(&ev->wildcard_list);
1435 }
1436 cds_list_del(&wildcard->session_list);
1437 cds_list_del(&wildcard->list);
1438 if (cds_list_empty(&wildcard->entry->session_list)) {
1439 cds_list_del(&wildcard->entry->list);
1440 free(wildcard->entry);
1441 }
1442 free(wildcard->filter_bytecode);
1443 free(wildcard);
1444 }
1445
1446 int ltt_wildcard_create(struct ltt_channel *chan,
1447 struct lttng_ust_event *event_param,
1448 struct session_wildcard **_sw)
1449 {
1450 struct session_wildcard *sw;
1451
1452 sw = add_wildcard(chan, event_param);
1453 if (!sw || IS_ERR(sw)) {
1454 return PTR_ERR(sw);
1455 }
1456 *_sw = sw;
1457 return 0;
1458 }
1459
1460 static
1461 void _ltt_wildcard_destroy(struct session_wildcard *sw)
1462 {
1463 _remove_wildcard(sw);
1464 }
1465
1466 int ltt_wildcard_enable(struct session_wildcard *wildcard)
1467 {
1468 struct ltt_event *ev;
1469 int ret;
1470
1471 if (wildcard->enabled)
1472 return -EEXIST;
1473 cds_list_for_each_entry(ev, &wildcard->events, wildcard_list) {
1474 ret = ltt_event_enable(ev);
1475 if (ret) {
1476 DBG("Error: enable error.\n");
1477 return ret;
1478 }
1479 }
1480 wildcard->enabled = 1;
1481 return 0;
1482 }
1483
1484 int ltt_wildcard_disable(struct session_wildcard *wildcard)
1485 {
1486 struct ltt_event *ev;
1487 int ret;
1488
1489 if (!wildcard->enabled)
1490 return -EEXIST;
1491 cds_list_for_each_entry(ev, &wildcard->events, wildcard_list) {
1492 ret = ltt_event_disable(ev);
1493 if (ret) {
1494 DBG("Error: disable error.\n");
1495 return ret;
1496 }
1497 }
1498 wildcard->enabled = 0;
1499 return 0;
1500 }
1501
1502 /*
1503 * Take the TLS "fault" in libuuid if dlopen'd, which can take the
1504 * dynamic linker mutex, outside of the UST lock, since the UST lock is
1505 * taken in constructors, which are called with dynamic linker mutex
1506 * held.
1507 */
1508 void lttng_fixup_event_tls(void)
1509 {
1510 unsigned char uuid[LTTNG_UST_UUID_STR_LEN];
1511
1512 (void) lttng_ust_uuid_generate(uuid);
1513 }
This page took 0.062794 seconds and 4 git commands to generate.