Commit | Line | Data |
---|---|---|
d3e2ba59 JD |
1 | /* |
2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * David Goulet <dgoulet@efficios.com> | |
7591bab1 | 4 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
d3e2ba59 JD |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License, version 2 only, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
6c1c0768 | 20 | #define _LGPL_SOURCE |
d3e2ba59 | 21 | #include <assert.h> |
d3e2ba59 JD |
22 | |
23 | #include <common/common.h> | |
24 | #include <common/sessiond-comm/relayd.h> | |
25 | ||
f263b7fd | 26 | #include <common/compat/endian.h> |
246777db MD |
27 | #include <common/compat/string.h> |
28 | #include <lttng/constant.h> | |
f263b7fd | 29 | |
d3e2ba59 JD |
30 | #include "cmd-generic.h" |
31 | #include "lttng-relayd.h" | |
32 | ||
58eb9381 | 33 | int cmd_create_session_2_4(struct relay_connection *conn, |
7591bab1 MD |
34 | char *session_name, char *hostname, |
35 | uint32_t *live_timer, bool *snapshot) | |
d3e2ba59 JD |
36 | { |
37 | int ret; | |
38 | struct lttcomm_relayd_create_session_2_4 session_info; | |
246777db | 39 | size_t len; |
d3e2ba59 | 40 | |
58eb9381 | 41 | ret = cmd_recv(conn->sock, &session_info, sizeof(session_info)); |
d3e2ba59 JD |
42 | if (ret < 0) { |
43 | ERR("Unable to recv session info version 2.4"); | |
44 | goto error; | |
45 | } | |
246777db MD |
46 | len = lttng_strnlen(session_info.session_name, sizeof(session_info.session_name)); |
47 | /* Ensure that NULL-terminated and fits in local filename length. */ | |
48 | if (len == sizeof(session_info.session_name) || len >= LTTNG_NAME_MAX) { | |
49 | ret = -ENAMETOOLONG; | |
50 | ERR("Session name too long"); | |
51 | goto error; | |
52 | } | |
7591bab1 MD |
53 | strncpy(session_name, session_info.session_name, |
54 | sizeof(session_info.session_name)); | |
246777db MD |
55 | |
56 | len = lttng_strnlen(session_info.hostname, sizeof(session_info.hostname)); | |
57 | if (len == sizeof(session_info.hostname) || len >= LTTNG_HOST_NAME_MAX) { | |
58 | ret = -ENAMETOOLONG; | |
59 | ERR("Session name too long"); | |
60 | goto error; | |
61 | } | |
7591bab1 MD |
62 | strncpy(hostname, session_info.hostname, |
63 | sizeof(session_info.hostname)); | |
64 | *live_timer = be32toh(session_info.live_timer); | |
65 | *snapshot = be32toh(session_info.snapshot); | |
d3e2ba59 JD |
66 | |
67 | ret = 0; | |
68 | ||
69 | error: | |
70 | return ret; | |
71 | } |