Commit | Line | Data |
---|---|---|
d4a2a84a DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
82a3637f DG |
6 | * as published by the Free Software Foundation; only version 2 |
7 | * of the License. | |
d4a2a84a DG |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
3bd1e081 | 20 | #include <config.h> |
d4a2a84a | 21 | #include <stdlib.h> |
baa0e4a9 | 22 | #include <stdio.h> |
1657e9bb | 23 | #include <string.h> |
baa0e4a9 DG |
24 | #include <unistd.h> |
25 | ||
f158a754 | 26 | #include <ust/lttng-ust-comm.h> |
0177d773 | 27 | #include <lttngerr.h> |
d4a2a84a | 28 | |
0177d773 DG |
29 | #include "ust-comm.h" |
30 | #include "ust-ctl.h" | |
1657e9bb DG |
31 | |
32 | /* | |
0177d773 | 33 | * Send registration done packet to the application. |
1657e9bb | 34 | */ |
0177d773 | 35 | int ustctl_register_done(int sock) |
1657e9bb | 36 | { |
0177d773 DG |
37 | struct lttcomm_ust_msg command; |
38 | struct lttcomm_ust_reply *reply; | |
471d1693 | 39 | |
0177d773 | 40 | DBG("Sending register done command to %d", sock); |
471d1693 | 41 | |
0177d773 DG |
42 | command.cmd = LTTNG_UST_REGISTER_DONE; |
43 | command.handle = LTTNG_UST_ROOT_HANDLE; | |
471d1693 | 44 | |
0177d773 DG |
45 | reply = ustcomm_send_command(sock, &command); |
46 | if (reply == NULL) { | |
471d1693 DG |
47 | goto error; |
48 | } | |
49 | ||
f158a754 MD |
50 | if (reply->ret_code != USTCOMM_OK) { |
51 | DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code)); | |
0177d773 | 52 | goto error; |
471d1693 | 53 | } |
a55dd136 | 54 | |
0177d773 | 55 | return 0; |
471d1693 DG |
56 | |
57 | error: | |
0177d773 | 58 | return -1; |
471d1693 DG |
59 | } |
60 | ||
61 | /* | |
0177d773 | 62 | * Create an UST session on the tracer. |
471d1693 | 63 | */ |
44d3bd01 | 64 | int ustctl_create_session(int sock, struct ltt_ust_session *session) |
471d1693 | 65 | { |
0177d773 | 66 | struct lttcomm_ust_msg command; |
44d3bd01 | 67 | struct lttcomm_ust_reply *reply = NULL; |
471d1693 | 68 | |
0177d773 DG |
69 | command.cmd = LTTNG_UST_SESSION; |
70 | command.handle = LTTNG_UST_ROOT_HANDLE; | |
471d1693 | 71 | |
44d3bd01 | 72 | reply = ustcomm_send_command(sock, &command); |
0177d773 | 73 | if (reply == NULL) { |
471d1693 DG |
74 | goto error; |
75 | } | |
76 | ||
f158a754 MD |
77 | if (reply->ret_code != USTCOMM_OK) { |
78 | DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code)); | |
471d1693 DG |
79 | goto error; |
80 | } | |
81 | ||
0177d773 | 82 | /* Save session handle */ |
44d3bd01 DG |
83 | session->handle = reply->ret_val; |
84 | free(reply); | |
85 | ||
86 | DBG2("ustctl create session command successful"); | |
87 | return 0; | |
88 | ||
89 | error: | |
90 | free(reply); | |
91 | return -1; | |
92 | } | |
93 | ||
94 | /* | |
95 | * Create UST channel to the tracer. | |
96 | */ | |
97 | int ustctl_create_channel(int sock, struct ltt_ust_session *session, | |
98 | struct lttng_channel *channel) | |
99 | { | |
100 | struct lttcomm_ust_msg command; | |
101 | struct lttcomm_ust_reply *reply = NULL; | |
102 | struct ltt_ust_channel *uchan; | |
103 | ||
104 | uchan = trace_ust_create_channel(channel, session->path); | |
105 | if (uchan == NULL) { | |
106 | goto error; | |
107 | } | |
108 | ||
109 | memset(&command, 0, sizeof(command)); | |
110 | ||
111 | command.cmd = LTTNG_UST_CHANNEL; | |
112 | command.handle = session->handle; | |
113 | ||
114 | /* Copy channel attributes to command */ | |
115 | memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel)); | |
116 | ||
117 | reply = ustcomm_send_command(sock, &command); | |
118 | if (reply == NULL) { | |
119 | goto error; | |
120 | } | |
121 | ||
f158a754 | 122 | if (reply->ret_code != USTCOMM_OK) { |
44d3bd01 | 123 | DBG("Return code (%d): %s", reply->ret_code, |
f158a754 | 124 | ustcomm_get_readable_code(reply->ret_code)); |
44d3bd01 DG |
125 | goto error; |
126 | } | |
127 | ||
128 | uchan->handle = reply->ret_val; | |
129 | ||
130 | /* Add channel to session */ | |
131 | cds_list_add(&uchan->list, &session->channels.head); | |
132 | session->channels.count++; | |
133 | ||
134 | free(reply); | |
135 | ||
136 | return 0; | |
137 | ||
138 | error: | |
139 | free(reply); | |
140 | return -1; | |
141 | } | |
142 | ||
143 | /* | |
144 | * Enable UST channel. | |
145 | */ | |
146 | int ustctl_enable_channel(int sock, struct ltt_ust_session *session, | |
147 | struct ltt_ust_channel *chan) | |
148 | { | |
149 | struct lttcomm_ust_msg command; | |
150 | struct lttcomm_ust_reply *reply = NULL; | |
151 | ||
152 | memset(&command, 0, sizeof(command)); | |
153 | ||
154 | command.cmd = LTTNG_UST_ENABLE; | |
155 | command.handle = chan->handle; | |
156 | ||
157 | reply = ustcomm_send_command(sock, &command); | |
158 | if (reply == NULL) { | |
159 | goto error; | |
160 | } | |
161 | ||
f158a754 | 162 | if (reply->ret_code != USTCOMM_OK) { |
44d3bd01 | 163 | DBG("Return code (%d): %s", reply->ret_code, |
f158a754 | 164 | ustcomm_get_readable_code(reply->ret_code)); |
44d3bd01 DG |
165 | goto error; |
166 | } else if (reply->handle != chan->handle) { | |
167 | ERR("Receive wrong handle from UST reply on enable channel"); | |
168 | goto error; | |
169 | } | |
170 | ||
171 | chan->enabled = 1; | |
172 | free(reply); | |
173 | ||
174 | DBG2("ustctl enable channel successful for sock %d", sock); | |
175 | return 0; | |
176 | ||
177 | error: | |
178 | free(reply); | |
179 | return -1; | |
180 | } | |
181 | ||
182 | /* | |
183 | * Disable UST channel. | |
184 | */ | |
185 | int ustctl_disable_channel(int sock, struct ltt_ust_session *session, | |
186 | struct ltt_ust_channel *chan) | |
187 | { | |
188 | struct lttcomm_ust_msg command; | |
189 | struct lttcomm_ust_reply *reply = NULL; | |
190 | ||
191 | memset(&command, 0, sizeof(command)); | |
192 | ||
193 | command.cmd = LTTNG_UST_DISABLE; | |
194 | command.handle = chan->handle; | |
195 | ||
196 | reply = ustcomm_send_command(sock, &command); | |
197 | if (reply == NULL) { | |
198 | goto error; | |
199 | } | |
200 | ||
f158a754 | 201 | if (reply->ret_code != USTCOMM_OK) { |
44d3bd01 | 202 | DBG("Return code (%d): %s", reply->ret_code, |
f158a754 | 203 | ustcomm_get_readable_code(reply->ret_code)); |
44d3bd01 DG |
204 | goto error; |
205 | } else if (reply->handle != chan->handle) { | |
206 | ERR("Receive wrong handle from UST reply on enable channel"); | |
207 | goto error; | |
208 | } | |
209 | ||
210 | chan->enabled = 1; | |
211 | free(reply); | |
471d1693 | 212 | |
44d3bd01 | 213 | DBG2("ustctl disable channel successful for sock %d", sock); |
0177d773 | 214 | return 0; |
5461b305 | 215 | |
471d1693 | 216 | error: |
44d3bd01 | 217 | free(reply); |
0177d773 | 218 | return -1; |
471d1693 | 219 | } |