UST 2.0 support
[lttng-tools.git] / ltt-sessiond / ust-comm.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 #include <config.h>
20 #include <stdlib.h>
21 #include <lttngerr.h>
22 #include "ust-comm.h"
23
24 /*
25 * Send msg containing a command to an UST application via sock and wait for
26 * the reply. Caller must free() the reply structure sent back.
27 *
28 * Return the replied structure or NULL.
29 */
30 struct lttcomm_ust_reply *ustcomm_send_command(int sock,
31 struct lttcomm_ust_msg *msg)
32 {
33 ssize_t len;
34 struct lttcomm_ust_reply *reply;
35
36 /* Extra safety */
37 if (msg == NULL || sock < 0) {
38 goto error;
39 }
40
41 DBG2("Sending UST command %d to sock %d", msg->cmd, sock);
42
43 /* Send UST msg */
44 len = lttcomm_send_unix_sock(sock, msg, sizeof(*msg));
45 if (len < 0) {
46 goto error;
47 }
48
49 reply = malloc(sizeof(struct lttcomm_ust_reply));
50 if (reply == NULL) {
51 perror("malloc ust reply");
52 goto error;
53 }
54
55 DBG2("Receiving UST reply on sock %d", sock);
56
57 /* Get UST reply */
58 len = lttcomm_recv_unix_sock(sock, reply, sizeof(*reply));
59 if (len < 0 || len < sizeof(*reply)) {
60 goto error;
61 }
62
63 return reply;
64
65 error:
66 return NULL;
67 }
This page took 0.030657 seconds and 5 git commands to generate.