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