2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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
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.
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.
25 #include <lttng-sessiond-comm.h>
30 #include "../hashtable/hash.h"
33 * Init command for tracer with cmd type and correct handle.
35 static void init_command(int cmd
, int handle
, struct lttcomm_ust_msg
*command
)
37 memset(command
, 0, sizeof(struct lttcomm_ust_msg
));
40 command
->handle
= handle
;
44 * Generic send command to ust tracer. Caller must free reply.
46 static struct lttcomm_ust_reply
*send_command(int sock
,
47 struct lttcomm_ust_msg
*command
)
49 struct lttcomm_ust_reply
*reply
;
51 reply
= ustcomm_send_command(sock
, command
);
56 if (reply
->ret_code
!= LTTCOMM_OK
) {
57 ERR("Return code (%d): %s", reply
->ret_code
,
58 lttcomm_get_readable_code(reply
->ret_code
));
69 * Send registration done packet to the application.
71 int ustctl_register_done(int sock
)
73 struct lttcomm_ust_msg command
;
74 struct lttcomm_ust_reply
*reply
;
76 DBG("Sending register done command to %d", sock
);
78 command
.cmd
= LTTNG_UST_REGISTER_DONE
;
79 command
.handle
= LTTNG_UST_ROOT_HANDLE
;
81 reply
= ustcomm_send_command(sock
, &command
);
86 if (reply
->ret_code
!= LTTCOMM_OK
) {
87 DBG("Return code: %s", lttcomm_get_readable_code(reply
->ret_code
));
98 * Create an UST session on the tracer.
100 * Return handle if success else negative value.
102 int ustctl_create_session(int sock
, struct ltt_ust_session
*session
)
105 struct lttcomm_ust_msg command
;
106 struct lttcomm_ust_reply
*reply
= NULL
;
108 command
.cmd
= LTTNG_UST_SESSION
;
109 command
.handle
= LTTNG_UST_ROOT_HANDLE
;
111 reply
= ustcomm_send_command(sock
, &command
);
116 /* Save session handle */
117 ret
= reply
->ret_val
;
120 DBG2("ustctl create session command successful with handle %d", ret
);
130 * Create UST channel to the tracer.
132 * Return handle if success else negative value.
134 int ustctl_create_channel(int sock
, struct ltt_ust_session
*session
,
135 struct lttng_ust_channel
*channel
)
138 struct lttcomm_ust_msg command
;
139 struct lttcomm_ust_reply
*reply
= NULL
;
141 init_command(LTTNG_UST_CHANNEL
, session
->handle
, &command
);
142 /* Copy channel attributes to command */
143 memcpy(&command
.u
.channel
, channel
, sizeof(command
.u
.channel
));
145 /* Send command to tracer */
146 reply
= send_command(sock
, &command
);
151 ret
= reply
->ret_val
;
162 * Enable UST channel.
164 int ustctl_enable_channel(int sock
, struct ltt_ust_session
*session
,
165 struct ltt_ust_channel
*chan
)
167 struct lttcomm_ust_msg command
;
168 struct lttcomm_ust_reply
*reply
= NULL
;
170 init_command(LTTNG_UST_ENABLE
, chan
->handle
, &command
);
172 reply
= ustcomm_send_command(sock
, &command
);
177 if (reply
->handle
!= chan
->handle
) {
178 ERR("Receive wrong handle from UST reply on enable channel");
185 DBG2("ustctl enable channel successful for sock %d", sock
);
194 * Disable UST channel.
196 int ustctl_disable_channel(int sock
, struct ltt_ust_session
*session
,
197 struct ltt_ust_channel
*chan
)
199 struct lttcomm_ust_msg command
;
200 struct lttcomm_ust_reply
*reply
= NULL
;
202 memset(&command
, 0, sizeof(command
));
204 command
.cmd
= LTTNG_UST_DISABLE
;
205 command
.handle
= chan
->handle
;
207 reply
= ustcomm_send_command(sock
, &command
);
212 if (reply
->handle
!= chan
->handle
) {
213 ERR("Receive wrong handle from UST reply on enable channel");
220 DBG2("ustctl disable channel successful for sock %d", sock
);
This page took 0.033179 seconds and 4 git commands to generate.