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 | |
c9e313bc SM |
12 | #include <common/common.hpp> |
13 | #include <common/sessiond-comm/relayd.hpp> | |
0f907de1 | 14 | |
c9e313bc SM |
15 | #include <common/compat/endian.hpp> |
16 | #include <common/compat/string.hpp> | |
246777db | 17 | #include <lttng/constant.h> |
f263b7fd | 18 | |
c9e313bc SM |
19 | #include "cmd-2-2.hpp" |
20 | #include "cmd-2-1.hpp" | |
21 | #include "utils.hpp" | |
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, |
7591bab1 MD |
27 | char **ret_path_name, char **ret_channel_name, |
28 | uint64_t *tracefile_size, uint64_t *tracefile_count) | |
0f907de1 JD |
29 | { |
30 | int ret; | |
31 | struct lttcomm_relayd_add_stream_2_2 stream_info; | |
7591bab1 MD |
32 | char *path_name = NULL; |
33 | char *channel_name = NULL; | |
246777db | 34 | size_t len; |
0f907de1 | 35 | |
5312a3ed JG |
36 | if (payload->size < sizeof(stream_info)) { |
37 | ERR("Unexpected payload size in \"cmd_recv_stream_2_2\": expected >= %zu bytes, got %zu bytes", | |
38 | sizeof(stream_info), payload->size); | |
39 | ret = -1; | |
0f907de1 JD |
40 | goto error; |
41 | } | |
5312a3ed | 42 | memcpy(&stream_info, payload->data, sizeof(stream_info)); |
0f907de1 | 43 | |
246777db MD |
44 | len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname)); |
45 | /* Ensure that NULL-terminated and fits in local filename length. */ | |
46 | if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) { | |
47 | ret = -ENAMETOOLONG; | |
48 | ERR("Path name too long"); | |
49 | goto error; | |
50 | } | |
348a81dc | 51 | path_name = strdup(stream_info.pathname); |
7591bab1 | 52 | if (!path_name) { |
0f907de1 JD |
53 | PERROR("Path name allocation"); |
54 | ret = -ENOMEM; | |
55 | goto error; | |
56 | } | |
246777db MD |
57 | len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name)); |
58 | if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) { | |
59 | ret = -ENAMETOOLONG; | |
60 | ERR("Channel name too long"); | |
61 | goto error; | |
62 | } | |
7591bab1 MD |
63 | channel_name = strdup(stream_info.channel_name); |
64 | if (!channel_name) { | |
0f907de1 | 65 | ret = -errno; |
246777db | 66 | PERROR("Channel name allocation"); |
0f907de1 JD |
67 | goto error; |
68 | } | |
69 | ||
7591bab1 MD |
70 | *tracefile_size = be64toh(stream_info.tracefile_size); |
71 | *tracefile_count = be64toh(stream_info.tracefile_count); | |
72 | *ret_path_name = path_name; | |
73 | *ret_channel_name = channel_name; | |
74 | return 0; | |
0f907de1 | 75 | error: |
7591bab1 MD |
76 | free(path_name); |
77 | free(channel_name); | |
0f907de1 JD |
78 | return ret; |
79 | } |