Fix kconsumerd number of fd expected
[lttng-tools.git] / ltt-sessiond / ust-ctl.c
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
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
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
20 #include <config.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include <ust/lttng-ust-comm.h>
27 #include <lttngerr.h>
28
29 #include "ust-comm.h"
30 #include "ust-ctl.h"
31
32 /*
33 * Send registration done packet to the application.
34 */
35 int ustctl_register_done(int sock)
36 {
37 struct lttcomm_ust_msg command;
38 struct lttcomm_ust_reply *reply;
39
40 DBG("Sending register done command to %d", sock);
41
42 command.cmd = LTTNG_UST_REGISTER_DONE;
43 command.handle = LTTNG_UST_ROOT_HANDLE;
44
45 reply = ustcomm_send_command(sock, &command);
46 if (reply == NULL) {
47 goto error;
48 }
49
50 if (reply->ret_code != USTCOMM_OK) {
51 DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code));
52 goto error;
53 }
54
55 return 0;
56
57 error:
58 return -1;
59 }
60
61 /*
62 * Create an UST session on the tracer.
63 */
64 int ustctl_create_session(int sock, struct ltt_ust_session *session)
65 {
66 struct lttcomm_ust_msg command;
67 struct lttcomm_ust_reply *reply = NULL;
68
69 command.cmd = LTTNG_UST_SESSION;
70 command.handle = LTTNG_UST_ROOT_HANDLE;
71
72 reply = ustcomm_send_command(sock, &command);
73 if (reply == NULL) {
74 goto error;
75 }
76
77 if (reply->ret_code != USTCOMM_OK) {
78 DBG("Return code: %s", ustcomm_get_readable_code(reply->ret_code));
79 goto error;
80 }
81
82 /* Save session handle */
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
122 if (reply->ret_code != USTCOMM_OK) {
123 DBG("Return code (%d): %s", reply->ret_code,
124 ustcomm_get_readable_code(reply->ret_code));
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
162 if (reply->ret_code != USTCOMM_OK) {
163 DBG("Return code (%d): %s", reply->ret_code,
164 ustcomm_get_readable_code(reply->ret_code));
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
201 if (reply->ret_code != USTCOMM_OK) {
202 DBG("Return code (%d): %s", reply->ret_code,
203 ustcomm_get_readable_code(reply->ret_code));
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);
212
213 DBG2("ustctl disable channel successful for sock %d", sock);
214 return 0;
215
216 error:
217 free(reply);
218 return -1;
219 }
This page took 0.033622 seconds and 4 git commands to generate.