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