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 <common/common.h>
13 #include <common/sessiond-comm/relayd.h>
14 #include <common/compat/string.h>
15 #include <lttng/constant.h>
21 * cmd_recv_stream_2_1 allocates path_name and channel_name.
23 int cmd_recv_stream_2_1(const struct lttng_buffer_view
*payload
,
24 char **ret_path_name
, char **ret_channel_name
)
27 struct lttcomm_relayd_add_stream stream_info
;
28 char *path_name
= NULL
;
29 char *channel_name
= NULL
;
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
);
38 memcpy(&stream_info
, payload
->data
, sizeof(stream_info
));
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
) {
44 ERR("Path name too long");
47 path_name
= strdup(stream_info
.pathname
);
49 PERROR("Path name allocation");
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
) {
56 ERR("Channel name too long");
59 channel_name
= strdup(stream_info
.channel_name
);
62 PERROR("Channel name allocation");
66 *ret_path_name
= path_name
;
67 *ret_channel_name
= channel_name
;