lttng_strerror(): accept positive and negative codes
[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 <stddef.h>
14
15 #include <common/error.h>
16 #include <common/sessiond-comm/sessiond-comm.h>
17 #include <lttng/event-internal.h>
18 #include <lttng/event.h>
19 #include <lttng/lttng-error.h>
20 #include <lttng/userspace-probe-internal.h>
21
22 struct lttng_event *lttng_event_create(void)
23 {
24 struct lttng_event *event;
25 struct lttng_event_extended *event_extended;
26
27 event = (lttng_event *) zmalloc(sizeof(*event));
28 if (!event) {
29 PERROR("Error allocating event structure");
30 goto end;
31 }
32
33 event_extended = (lttng_event_extended *) zmalloc(sizeof(*event_extended));
34 if (!event_extended) {
35 PERROR("Error allocating event extended structure");
36 goto error;
37 }
38 event->extended.ptr = event_extended;
39 end:
40 return event;
41 error:
42 free(event);
43 event = NULL;
44 goto end;
45 }
46
47 void lttng_event_destroy(struct lttng_event *event)
48 {
49 struct lttng_event_extended *event_extended;
50
51 if (!event) {
52 return;
53 }
54
55 event_extended = (struct lttng_event_extended *) event->extended.ptr;
56
57 if (event_extended) {
58 if (event_extended->probe_location) {
59 lttng_userspace_probe_location_destroy(
60 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,
68 const char **filter_expression)
69 {
70 int ret = 0;
71 struct lttng_event_extended *event_extended;
72
73 if (!event || !filter_expression) {
74 ret = -LTTNG_ERR_INVALID;
75 goto end;
76 }
77
78 event_extended = (struct lttng_event_extended *) event->extended.ptr;
79 if (!event_extended) {
80 /*
81 * This can happen since the lttng_event structure is
82 * used for other tasks where this pointer is never set.
83 */
84 *filter_expression = NULL;
85 goto end;
86 }
87
88 *filter_expression = event_extended->filter_expression;
89 end:
90 return ret;
91 }
92
93 int lttng_event_get_exclusion_name_count(struct lttng_event *event)
94 {
95 int ret = 0;
96 struct lttng_event_extended *event_extended;
97
98 if (!event) {
99 ret = -LTTNG_ERR_INVALID;
100 goto end;
101 }
102
103 event_extended = (struct lttng_event_extended *) event->extended.ptr;
104 if (!event_extended) {
105 /*
106 * This can happen since the lttng_event structure is
107 * used for other tasks where this pointer is never set.
108 */
109 goto end;
110 }
111
112 if (event_extended->exclusions.count > INT_MAX) {
113 ret = -LTTNG_ERR_OVERFLOW;
114 goto end;
115 }
116 ret = (int) event_extended->exclusions.count;
117 end:
118 return ret;
119 }
120
121 int lttng_event_get_exclusion_name(struct lttng_event *event,
122 size_t index, 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 +
153 (index * LTTNG_SYMBOL_NAME_LEN);
154 end:
155 return ret;
156 }
157
158 const struct lttng_userspace_probe_location *
159 lttng_event_get_userspace_probe_location(const struct lttng_event *event)
160 {
161 struct lttng_userspace_probe_location *probe_location = NULL;
162 struct lttng_event_extended *event_extended;
163
164 if (!event) {
165 goto end;
166 }
167
168 event_extended = (struct lttng_event_extended *) event->extended.ptr;
169 if (!event_extended) {
170 goto end;
171 }
172 probe_location = event_extended->probe_location;
173 end:
174 return probe_location;
175 }
176
177 int lttng_event_set_userspace_probe_location(struct lttng_event *event,
178 struct lttng_userspace_probe_location *probe_location)
179 {
180 int ret = 0;
181 struct lttng_event_extended *event_extended;
182
183 if (!event || !probe_location) {
184 ret = -LTTNG_ERR_INVALID;
185 goto end;
186 }
187
188 event_extended = (struct lttng_event_extended *) event->extended.ptr;
189 LTTNG_ASSERT(event_extended);
190 if (event_extended->probe_location) {
191 lttng_userspace_probe_location_destroy(
192 event_extended->probe_location);
193 }
194 event_extended->probe_location = probe_location;
195 end:
196 return ret;
197 }
This page took 0.035449 seconds and 4 git commands to generate.