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