Fix epoll not handling signal interruption
[lttng-tools.git] / ltt-sessiond / ust-ctl.c
CommitLineData
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
d4a2a84a 20#include <stdlib.h>
baa0e4a9 21#include <stdio.h>
1657e9bb 22#include <string.h>
baa0e4a9
DG
23#include <unistd.h>
24
e88129fc 25#include <lttng-sessiond-comm.h>
0177d773 26#include <lttngerr.h>
d4a2a84a 27
0177d773
DG
28#include "ust-comm.h"
29#include "ust-ctl.h"
1657e9bb
DG
30
31/*
0177d773 32 * Send registration done packet to the application.
1657e9bb 33 */
0177d773 34int ustctl_register_done(int sock)
1657e9bb 35{
0177d773
DG
36 struct lttcomm_ust_msg command;
37 struct lttcomm_ust_reply *reply;
471d1693 38
0177d773 39 DBG("Sending register done command to %d", sock);
471d1693 40
0177d773
DG
41 command.cmd = LTTNG_UST_REGISTER_DONE;
42 command.handle = LTTNG_UST_ROOT_HANDLE;
471d1693 43
0177d773
DG
44 reply = ustcomm_send_command(sock, &command);
45 if (reply == NULL) {
471d1693
DG
46 goto error;
47 }
48
0177d773
DG
49 if (reply->ret_code != LTTCOMM_OK) {
50 DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
51 goto error;
471d1693 52 }
a55dd136 53
0177d773 54 return 0;
471d1693
DG
55
56error:
0177d773 57 return -1;
471d1693
DG
58}
59
60/*
0177d773 61 * Create an UST session on the tracer.
471d1693 62 */
44d3bd01 63int ustctl_create_session(int sock, struct ltt_ust_session *session)
471d1693 64{
0177d773 65 struct lttcomm_ust_msg command;
44d3bd01 66 struct lttcomm_ust_reply *reply = NULL;
471d1693 67
0177d773
DG
68 command.cmd = LTTNG_UST_SESSION;
69 command.handle = LTTNG_UST_ROOT_HANDLE;
471d1693 70
44d3bd01 71 reply = ustcomm_send_command(sock, &command);
0177d773 72 if (reply == NULL) {
471d1693
DG
73 goto error;
74 }
75
0177d773
DG
76 if (reply->ret_code != LTTCOMM_OK) {
77 DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
471d1693
DG
78 goto error;
79 }
80
0177d773 81 /* Save session handle */
44d3bd01
DG
82 session->handle = reply->ret_val;
83 free(reply);
84
85 DBG2("ustctl create session command successful");
86 return 0;
87
88error:
89 free(reply);
90 return -1;
91}
92
93/*
94 * Create UST channel to the tracer.
95 */
96int ustctl_create_channel(int sock, struct ltt_ust_session *session,
97 struct lttng_channel *channel)
98{
99 struct lttcomm_ust_msg command;
100 struct lttcomm_ust_reply *reply = NULL;
101 struct ltt_ust_channel *uchan;
102
103 uchan = trace_ust_create_channel(channel, session->path);
104 if (uchan == NULL) {
105 goto error;
106 }
107
108 memset(&command, 0, sizeof(command));
109
110 command.cmd = LTTNG_UST_CHANNEL;
111 command.handle = session->handle;
112
113 /* Copy channel attributes to command */
114 memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel));
115
116 reply = ustcomm_send_command(sock, &command);
117 if (reply == NULL) {
118 goto error;
119 }
120
121 if (reply->ret_code != LTTCOMM_OK) {
122 DBG("Return code (%d): %s", reply->ret_code,
123 lttcomm_get_readable_code(reply->ret_code));
124 goto error;
125 }
126
127 uchan->handle = reply->ret_val;
128
129 /* Add channel to session */
130 cds_list_add(&uchan->list, &session->channels.head);
131 session->channels.count++;
132
133 free(reply);
134
135 return 0;
136
137error:
138 free(reply);
139 return -1;
140}
141
142/*
143 * Enable UST channel.
144 */
145int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
146 struct ltt_ust_channel *chan)
147{
148 struct lttcomm_ust_msg command;
149 struct lttcomm_ust_reply *reply = NULL;
150
151 memset(&command, 0, sizeof(command));
152
153 command.cmd = LTTNG_UST_ENABLE;
154 command.handle = chan->handle;
155
156 reply = ustcomm_send_command(sock, &command);
157 if (reply == NULL) {
158 goto error;
159 }
160
161 if (reply->ret_code != LTTCOMM_OK) {
162 DBG("Return code (%d): %s", reply->ret_code,
163 lttcomm_get_readable_code(reply->ret_code));
164 goto error;
165 } else if (reply->handle != chan->handle) {
166 ERR("Receive wrong handle from UST reply on enable channel");
167 goto error;
168 }
169
170 chan->enabled = 1;
171 free(reply);
172
173 DBG2("ustctl enable channel successful for sock %d", sock);
174 return 0;
175
176error:
177 free(reply);
178 return -1;
179}
180
181/*
182 * Disable UST channel.
183 */
184int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
185 struct ltt_ust_channel *chan)
186{
187 struct lttcomm_ust_msg command;
188 struct lttcomm_ust_reply *reply = NULL;
189
190 memset(&command, 0, sizeof(command));
191
192 command.cmd = LTTNG_UST_DISABLE;
193 command.handle = chan->handle;
194
195 reply = ustcomm_send_command(sock, &command);
196 if (reply == NULL) {
197 goto error;
198 }
199
200 if (reply->ret_code != LTTCOMM_OK) {
201 DBG("Return code (%d): %s", reply->ret_code,
202 lttcomm_get_readable_code(reply->ret_code));
203 goto error;
204 } else if (reply->handle != chan->handle) {
205 ERR("Receive wrong handle from UST reply on enable channel");
206 goto error;
207 }
208
209 chan->enabled = 1;
210 free(reply);
471d1693 211
44d3bd01 212 DBG2("ustctl disable channel successful for sock %d", sock);
0177d773 213 return 0;
5461b305 214
471d1693 215error:
44d3bd01 216 free(reply);
0177d773 217 return -1;
471d1693 218}
This page took 0.033049 seconds and 4 git commands to generate.