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