Commit | Line | Data |
---|---|---|
0f907de1 | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com> |
3 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> | |
4 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
0f907de1 | 5 | * |
ab5be9fa | 6 | * SPDX-License-Identifier: GPL-2.0-only |
0f907de1 | 7 | * |
0f907de1 JD |
8 | */ |
9 | ||
6c1c0768 | 10 | #define _LGPL_SOURCE |
0f907de1 | 11 | |
28ab034a JG |
12 | #include "cmd-2-1.hpp" |
13 | #include "cmd-2-2.hpp" | |
14 | #include "utils.hpp" | |
0f907de1 | 15 | |
28ab034a | 16 | #include <common/common.hpp> |
c9e313bc SM |
17 | #include <common/compat/endian.hpp> |
18 | #include <common/compat/string.hpp> | |
28ab034a | 19 | #include <common/sessiond-comm/relayd.hpp> |
f263b7fd | 20 | |
28ab034a | 21 | #include <lttng/constant.h> |
0f907de1 | 22 | |
7591bab1 MD |
23 | /* |
24 | * cmd_recv_stream_2_2 allocates path_name and channel_name. | |
25 | */ | |
5312a3ed | 26 | int cmd_recv_stream_2_2(const struct lttng_buffer_view *payload, |
28ab034a JG |
27 | char **ret_path_name, |
28 | char **ret_channel_name, | |
29 | uint64_t *tracefile_size, | |
30 | uint64_t *tracefile_count) | |
0f907de1 JD |
31 | { |
32 | int ret; | |
33 | struct lttcomm_relayd_add_stream_2_2 stream_info; | |
cd9adb8b JG |
34 | char *path_name = nullptr; |
35 | char *channel_name = nullptr; | |
246777db | 36 | size_t len; |
0f907de1 | 37 | |
5312a3ed JG |
38 | if (payload->size < sizeof(stream_info)) { |
39 | ERR("Unexpected payload size in \"cmd_recv_stream_2_2\": expected >= %zu bytes, got %zu bytes", | |
28ab034a JG |
40 | sizeof(stream_info), |
41 | payload->size); | |
5312a3ed | 42 | ret = -1; |
0f907de1 JD |
43 | goto error; |
44 | } | |
5312a3ed | 45 | memcpy(&stream_info, payload->data, sizeof(stream_info)); |
0f907de1 | 46 | |
246777db MD |
47 | len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname)); |
48 | /* Ensure that NULL-terminated and fits in local filename length. */ | |
49 | if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) { | |
50 | ret = -ENAMETOOLONG; | |
51 | ERR("Path name too long"); | |
52 | goto error; | |
53 | } | |
348a81dc | 54 | path_name = strdup(stream_info.pathname); |
7591bab1 | 55 | if (!path_name) { |
0f907de1 JD |
56 | PERROR("Path name allocation"); |
57 | ret = -ENOMEM; | |
58 | goto error; | |
59 | } | |
246777db MD |
60 | len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name)); |
61 | if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) { | |
62 | ret = -ENAMETOOLONG; | |
63 | ERR("Channel name too long"); | |
64 | goto error; | |
65 | } | |
7591bab1 MD |
66 | channel_name = strdup(stream_info.channel_name); |
67 | if (!channel_name) { | |
0f907de1 | 68 | ret = -errno; |
246777db | 69 | PERROR("Channel name allocation"); |
0f907de1 JD |
70 | goto error; |
71 | } | |
72 | ||
7591bab1 MD |
73 | *tracefile_size = be64toh(stream_info.tracefile_size); |
74 | *tracefile_count = be64toh(stream_info.tracefile_count); | |
75 | *ret_path_name = path_name; | |
76 | *ret_channel_name = channel_name; | |
77 | return 0; | |
0f907de1 | 78 | error: |
7591bab1 MD |
79 | free(path_name); |
80 | free(channel_name); | |
0f907de1 JD |
81 | return ret; |
82 | } |