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