Commit | Line | Data |
---|---|---|
099e26bd 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 | |
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 | ||
3bd1e081 | 19 | #include <config.h> |
0177d773 | 20 | #include <stdlib.h> |
099e26bd | 21 | #include <lttngerr.h> |
f158a754 | 22 | #include <ust/lttng-ust-comm.h> |
099e26bd DG |
23 | #include "ust-comm.h" |
24 | ||
25 | /* | |
26 | * Send msg containing a command to an UST application via sock and wait for | |
44d3bd01 | 27 | * the reply. Caller must free() the reply structure sent back. |
099e26bd | 28 | * |
0177d773 | 29 | * Return the replied structure or NULL. |
099e26bd | 30 | */ |
0177d773 DG |
31 | struct lttcomm_ust_reply *ustcomm_send_command(int sock, |
32 | struct lttcomm_ust_msg *msg) | |
099e26bd DG |
33 | { |
34 | ssize_t len; | |
0177d773 DG |
35 | struct lttcomm_ust_reply *reply; |
36 | ||
37 | /* Extra safety */ | |
38 | if (msg == NULL || sock < 0) { | |
39 | goto error; | |
40 | } | |
099e26bd | 41 | |
44d3bd01 | 42 | DBG2("Sending UST command %d to sock %d", msg->cmd, sock); |
099e26bd DG |
43 | |
44 | /* Send UST msg */ | |
f158a754 | 45 | len = ustcomm_send_unix_sock(sock, msg, sizeof(*msg)); |
099e26bd DG |
46 | if (len < 0) { |
47 | goto error; | |
48 | } | |
49 | ||
0177d773 DG |
50 | reply = malloc(sizeof(struct lttcomm_ust_reply)); |
51 | if (reply == NULL) { | |
52 | perror("malloc ust reply"); | |
099e26bd DG |
53 | goto error; |
54 | } | |
55 | ||
44d3bd01 | 56 | DBG2("Receiving UST reply on sock %d", sock); |
0177d773 DG |
57 | |
58 | /* Get UST reply */ | |
f158a754 | 59 | len = ustcomm_recv_unix_sock(sock, reply, sizeof(*reply)); |
0177d773 | 60 | if (len < 0 || len < sizeof(*reply)) { |
099e26bd DG |
61 | goto error; |
62 | } | |
63 | ||
0177d773 | 64 | return reply; |
099e26bd DG |
65 | |
66 | error: | |
0177d773 | 67 | return NULL; |
099e26bd | 68 | } |