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