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