fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / src / lib / lttng-ctl / event.cpp
1 /*
2 * event.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
6 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * SPDX-License-Identifier: LGPL-2.1-only
9 *
10 */
11
12 #define _LGPL_SOURCE
13 #include <common/error.hpp>
14 #include <common/sessiond-comm/sessiond-comm.hpp>
15
16 #include <lttng/event-internal.hpp>
17 #include <lttng/event.h>
18 #include <lttng/lttng-error.h>
19 #include <lttng/userspace-probe-internal.hpp>
20
21 #include <stddef.h>
22
23 struct lttng_event *lttng_event_create(void)
24 {
25 struct lttng_event *event;
26 struct lttng_event_extended *event_extended;
27
28 event = zmalloc<lttng_event>();
29 if (!event) {
30 PERROR("Error allocating event structure");
31 goto end;
32 }
33
34 event_extended = zmalloc<lttng_event_extended>();
35 if (!event_extended) {
36 PERROR("Error allocating event extended structure");
37 goto error;
38 }
39 event->extended.ptr = event_extended;
40 end:
41 return event;
42 error:
43 free(event);
44 event = nullptr;
45 goto end;
46 }
47
48 void lttng_event_destroy(struct lttng_event *event)
49 {
50 struct lttng_event_extended *event_extended;
51
52 if (!event) {
53 return;
54 }
55
56 event_extended = (struct lttng_event_extended *) event->extended.ptr;
57
58 if (event_extended) {
59 if (event_extended->probe_location) {
60 lttng_userspace_probe_location_destroy(event_extended->probe_location);
61 }
62 free(event_extended);
63 }
64 free(event);
65 }
66
67 int lttng_event_get_filter_expression(struct lttng_event *event, const char **filter_expression)
68 {
69 int ret = 0;
70 struct lttng_event_extended *event_extended;
71
72 if (!event || !filter_expression) {
73 ret = -LTTNG_ERR_INVALID;
74 goto end;
75 }
76
77 event_extended = (struct lttng_event_extended *) event->extended.ptr;
78 if (!event_extended) {
79 /*
80 * This can happen since the lttng_event structure is
81 * used for other tasks where this pointer is never set.
82 */
83 *filter_expression = nullptr;
84 goto end;
85 }
86
87 *filter_expression = event_extended->filter_expression;
88 end:
89 return ret;
90 }
91
92 int lttng_event_get_exclusion_name_count(struct lttng_event *event)
93 {
94 int ret = 0;
95 struct lttng_event_extended *event_extended;
96
97 if (!event) {
98 ret = -LTTNG_ERR_INVALID;
99 goto end;
100 }
101
102 event_extended = (struct lttng_event_extended *) event->extended.ptr;
103 if (!event_extended) {
104 /*
105 * This can happen since the lttng_event structure is
106 * used for other tasks where this pointer is never set.
107 */
108 goto end;
109 }
110
111 if (event_extended->exclusions.count > INT_MAX) {
112 ret = -LTTNG_ERR_OVERFLOW;
113 goto end;
114 }
115 ret = (int) event_extended->exclusions.count;
116 end:
117 return ret;
118 }
119
120 int lttng_event_get_exclusion_name(struct lttng_event *event,
121 size_t index,
122 const char **exclusion_name)
123 {
124 int ret = 0;
125 struct lttng_event_extended *event_extended;
126
127 if (!event || !exclusion_name) {
128 ret = -LTTNG_ERR_INVALID;
129 goto end;
130 }
131
132 if (index > UINT_MAX) {
133 ret = -LTTNG_ERR_OVERFLOW;
134 goto end;
135 }
136
137 event_extended = (struct lttng_event_extended *) event->extended.ptr;
138 if (!event_extended) {
139 /*
140 * This can happen since the lttng_event structure is
141 * used for other tasks where this pointer is never set.
142 */
143 ret = -LTTNG_ERR_INVALID;
144 goto end;
145 }
146
147 if (index >= event_extended->exclusions.count) {
148 ret = -LTTNG_ERR_INVALID;
149 goto end;
150 }
151
152 *exclusion_name = event_extended->exclusions.strings + (index * LTTNG_SYMBOL_NAME_LEN);
153 end:
154 return ret;
155 }
156
157 const struct lttng_userspace_probe_location *
158 lttng_event_get_userspace_probe_location(const struct lttng_event *event)
159 {
160 struct lttng_userspace_probe_location *probe_location = nullptr;
161 struct lttng_event_extended *event_extended;
162
163 if (!event) {
164 goto end;
165 }
166
167 event_extended = (struct lttng_event_extended *) event->extended.ptr;
168 if (!event_extended) {
169 goto end;
170 }
171 probe_location = event_extended->probe_location;
172 end:
173 return probe_location;
174 }
175
176 int lttng_event_set_userspace_probe_location(struct lttng_event *event,
177 struct lttng_userspace_probe_location *probe_location)
178 {
179 int ret = 0;
180 struct lttng_event_extended *event_extended;
181
182 if (!event || !probe_location) {
183 ret = -LTTNG_ERR_INVALID;
184 goto end;
185 }
186
187 event_extended = (struct lttng_event_extended *) event->extended.ptr;
188 LTTNG_ASSERT(event_extended);
189 if (event_extended->probe_location) {
190 lttng_userspace_probe_location_destroy(event_extended->probe_location);
191 }
192 event_extended->probe_location = probe_location;
193 end:
194 return ret;
195 }
This page took 0.03229 seconds and 4 git commands to generate.