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>
6 * SPDX-License-Identifier: GPL-2.0-only
12 #include "cmd-2-1.hpp"
13 #include "cmd-2-2.hpp"
16 #include <common/common.hpp>
17 #include <common/compat/endian.hpp>
18 #include <common/compat/string.hpp>
19 #include <common/sessiond-comm/relayd.hpp>
21 #include <lttng/constant.h>
24 * cmd_recv_stream_2_2 allocates path_name and channel_name.
26 int cmd_recv_stream_2_2(const struct lttng_buffer_view
*payload
,
28 char **ret_channel_name
,
29 uint64_t *tracefile_size
,
30 uint64_t *tracefile_count
)
33 struct lttcomm_relayd_add_stream_2_2 stream_info
;
34 char *path_name
= nullptr;
35 char *channel_name
= nullptr;
38 if (payload
->size
< sizeof(stream_info
)) {
39 ERR("Unexpected payload size in \"cmd_recv_stream_2_2\": expected >= %zu bytes, got %zu bytes",
45 memcpy(&stream_info
, payload
->data
, sizeof(stream_info
));
47 len
= lttng_strnlen(stream_info
.pathname
, sizeof(stream_info
.pathname
));
48 /* Ensure that NULL-terminated and fits in local filename length. */
49 if (len
== sizeof(stream_info
.pathname
) || len
>= LTTNG_NAME_MAX
) {
51 ERR("Path name too long");
54 path_name
= strdup(stream_info
.pathname
);
56 PERROR("Path name allocation");
60 len
= lttng_strnlen(stream_info
.channel_name
, sizeof(stream_info
.channel_name
));
61 if (len
== sizeof(stream_info
.channel_name
) || len
>= DEFAULT_STREAM_NAME_LEN
) {
63 ERR("Channel name too long");
66 channel_name
= strdup(stream_info
.channel_name
);
69 PERROR("Channel name allocation");
73 *tracefile_size
= be64toh(stream_info
.tracefile_size
);
74 *tracefile_count
= be64toh(stream_info
.tracefile_count
);
75 *ret_path_name
= path_name
;
76 *ret_channel_name
= channel_name
;