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