Commit | Line | Data |
---|---|---|
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 | 34 | int 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 | |
56 | error: | |
0177d773 | 57 | return -1; |
471d1693 DG |
58 | } |
59 | ||
60 | /* | |
0177d773 | 61 | * Create an UST session on the tracer. |
471d1693 | 62 | */ |
0177d773 | 63 | int ustctl_create_session(struct ltt_ust_session *session) |
471d1693 | 64 | { |
0177d773 DG |
65 | struct lttcomm_ust_msg command; |
66 | struct lttcomm_ust_reply *reply; | |
471d1693 | 67 | |
0177d773 | 68 | DBG("Creating UST session for app pid:%d", session->app->pid); |
471d1693 | 69 | |
0177d773 DG |
70 | command.cmd = LTTNG_UST_SESSION; |
71 | command.handle = LTTNG_UST_ROOT_HANDLE; | |
471d1693 | 72 | |
0177d773 DG |
73 | reply = ustcomm_send_command(session->app->sock, &command); |
74 | if (reply == NULL) { | |
471d1693 DG |
75 | goto error; |
76 | } | |
77 | ||
0177d773 DG |
78 | if (reply->ret_code != LTTCOMM_OK) { |
79 | DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code)); | |
471d1693 DG |
80 | goto error; |
81 | } | |
82 | ||
0177d773 DG |
83 | /* Save session handle */ |
84 | session->handle = reply->handle; | |
471d1693 | 85 | |
0177d773 | 86 | return 0; |
5461b305 | 87 | |
471d1693 | 88 | error: |
0177d773 | 89 | return -1; |
471d1693 | 90 | } |