Commit | Line | Data |
---|---|---|
0f907de1 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> |
0f907de1 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 |
0f907de1 | 21 | #include <assert.h> |
0f907de1 JD |
22 | |
23 | #include <common/common.h> | |
24 | #include <common/sessiond-comm/relayd.h> | |
246777db MD |
25 | #include <common/compat/string.h> |
26 | #include <lttng/constant.h> | |
0f907de1 | 27 | |
0f907de1 JD |
28 | #include "cmd-2-1.h" |
29 | #include "utils.h" | |
30 | ||
7591bab1 MD |
31 | /* |
32 | * cmd_recv_stream_2_1 allocates path_name and channel_name. | |
33 | */ | |
a8cad461 | 34 | int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload, |
4d27e2b4 JR |
35 | char **ret_path_name, char **ret_channel_name, |
36 | struct relay_session *session) | |
0f907de1 JD |
37 | { |
38 | int ret; | |
39 | struct lttcomm_relayd_add_stream stream_info; | |
7591bab1 MD |
40 | char *path_name = NULL; |
41 | char *channel_name = NULL; | |
246777db | 42 | size_t len; |
0f907de1 | 43 | |
a8cad461 JG |
44 | if (payload->size < sizeof(stream_info)) { |
45 | ERR("Unexpected payload size in \"cmd_recv_stream_2_1\": expected >= %zu bytes, got %zu bytes", | |
46 | sizeof(stream_info), payload->size); | |
47 | ret = -1; | |
0f907de1 JD |
48 | goto error; |
49 | } | |
a8cad461 | 50 | memcpy(&stream_info, payload->data, sizeof(stream_info)); |
0f907de1 | 51 | |
246777db MD |
52 | len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname)); |
53 | /* Ensure that NULL-terminated and fits in local filename length. */ | |
54 | if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) { | |
55 | ret = -ENAMETOOLONG; | |
56 | ERR("Path name too long"); | |
57 | goto error; | |
58 | } | |
4d27e2b4 | 59 | path_name = create_output_path(stream_info.pathname, session->session_name); |
7591bab1 | 60 | if (!path_name) { |
0f907de1 JD |
61 | PERROR("Path name allocation"); |
62 | ret = -ENOMEM; | |
63 | goto error; | |
64 | } | |
246777db MD |
65 | len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name)); |
66 | if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) { | |
67 | ret = -ENAMETOOLONG; | |
68 | ERR("Channel name too long"); | |
69 | goto error; | |
70 | } | |
7591bab1 MD |
71 | channel_name = strdup(stream_info.channel_name); |
72 | if (!channel_name) { | |
0f907de1 | 73 | ret = -errno; |
246777db | 74 | PERROR("Channel name allocation"); |
0f907de1 JD |
75 | goto error; |
76 | } | |
0f907de1 | 77 | |
7591bab1 MD |
78 | *ret_path_name = path_name; |
79 | *ret_channel_name = channel_name; | |
80 | return 0; | |
0f907de1 | 81 | error: |
7591bab1 MD |
82 | free(path_name); |
83 | free(channel_name); | |
0f907de1 JD |
84 | return ret; |
85 | } |