Add utils to send file descriptors to the sessiond
[lttng-tools.git] / src / lib / lttng-ctl / event.c
CommitLineData
eb5c4f4e
JG
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 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#define _LGPL_SOURCE
ef0e06bc 23#include <assert.h>
eb5c4f4e 24#include <stddef.h>
ef0e06bc
JG
25
26#include <common/error.h>
eb5c4f4e 27#include <common/sessiond-comm/sessiond-comm.h>
ef0e06bc
JG
28#include <lttng/event-internal.h>
29#include <lttng/event.h>
30#include <lttng/lttng-error.h>
31#include <lttng/userspace-probe-internal.h>
32
33struct lttng_event *lttng_event_create(void)
34{
35 struct lttng_event *event;
36 struct lttng_event_extended *event_extended;
37
38 event = zmalloc(sizeof(*event));
39 if (!event) {
40 PERROR("Error allocating event structure");
41 goto end;
42 }
43
44 event_extended = zmalloc(sizeof(*event_extended));
45 if (!event_extended) {
46 PERROR("Error allocating event extended structure");
47 goto error;
48 }
49 event->extended.ptr = event_extended;
50end:
51 return event;
52error:
53 free(event);
54 goto end;
55}
56
57void lttng_event_destroy(struct lttng_event *event)
58{
59 struct lttng_event_extended *event_extended;
60
61 if (!event) {
62 return;
63 }
64
65 event_extended = (struct lttng_event_extended *) event->extended.ptr;
66
67 if (event_extended) {
68 if (event_extended->probe_location) {
69 lttng_userspace_probe_location_destroy(
70 event_extended->probe_location);
71 }
72 free(event_extended);
73 }
74 free(event);
75}
eb5c4f4e
JG
76
77int lttng_event_get_filter_expression(struct lttng_event *event,
78 const char **filter_expression)
79{
80 int ret = 0;
81 struct lttcomm_event_extended_header *ext_header;
82
83 if (!event || !filter_expression) {
84 ret = -LTTNG_ERR_INVALID;
85 goto end;
86 }
87
88 ext_header = event->extended.ptr;
89
90 if (!ext_header) {
91 /*
92 * This can happen since the lttng_event structure is
93 * used for other tasks where this pointer is never set.
94 */
95 *filter_expression = NULL;
96 goto end;
97 }
98
99 if (ext_header->filter_len) {
100 *filter_expression = ((const char *) (ext_header)) +
101 sizeof(*ext_header);
102 } else {
103 *filter_expression = NULL;
104 }
105
106end:
107 return ret;
108}
109
110int lttng_event_get_exclusion_name_count(struct lttng_event *event)
111{
112 int ret;
113 struct lttcomm_event_extended_header *ext_header;
114
115 if (!event) {
116 ret = -LTTNG_ERR_INVALID;
117 goto end;
118 }
119
120 ext_header = event->extended.ptr;
121 if (!ext_header) {
122 /*
123 * This can happen since the lttng_event structure is
124 * used for other tasks where this pointer is never set.
125 */
126 ret = 0;
127 goto end;
128 }
129
130 if (ext_header->nb_exclusions > INT_MAX) {
131 ret = -LTTNG_ERR_OVERFLOW;
132 goto end;
133 }
134 ret = (int) ext_header->nb_exclusions;
135end:
136 return ret;
137}
138
139int lttng_event_get_exclusion_name(struct lttng_event *event,
140 size_t index, const char **exclusion_name)
141{
142 int ret = 0;
143 struct lttcomm_event_extended_header *ext_header;
144 void *at;
145
146 if (!event || !exclusion_name) {
147 ret = -LTTNG_ERR_INVALID;
148 goto end;
149 }
150
151 ext_header = event->extended.ptr;
152 if (!ext_header) {
153 ret = -LTTNG_ERR_INVALID;
154 goto end;
155 }
156
157 if (index >= ext_header->nb_exclusions) {
158 ret = -LTTNG_ERR_INVALID;
159 goto end;
160 }
161
162 at = (void *) ext_header + sizeof(*ext_header);
163 at += ext_header->filter_len;
164 at += index * LTTNG_SYMBOL_NAME_LEN;
165 *exclusion_name = at;
166
167end:
168 return ret;
169}
ef0e06bc
JG
170
171struct lttng_userspace_probe_location *
172lttng_event_get_userspace_probe_location(struct lttng_event *event)
173{
174 struct lttng_userspace_probe_location *probe_location = NULL;
175 struct lttng_event_extended *event_extended;
176
177 if (!event) {
178 goto end;
179 }
180
181 event_extended = (struct lttng_event_extended *) event->extended.ptr;
182 if (!event_extended) {
183 goto end;
184 }
185 probe_location = event_extended->probe_location;
186end:
187 return probe_location;
188}
189
190int lttng_event_set_userspace_probe_location(struct lttng_event *event,
191 struct lttng_userspace_probe_location *probe_location)
192{
193 int ret = 0;
194 struct lttng_event_extended *event_extended;
195
196 if (!event || !probe_location) {
197 ret = -LTTNG_ERR_INVALID;
198 goto end;
199 }
200
201 event_extended = (struct lttng_event_extended *) event->extended.ptr;
202 assert(event_extended);
203 if (event_extended->probe_location) {
204 lttng_userspace_probe_location_destroy(
205 event_extended->probe_location);
206 }
207 event_extended->probe_location = probe_location;
208end:
209 return ret;
210}
This page took 0.030576 seconds and 5 git commands to generate.