38381f894daad1662e10fad02550d9b5366ff623
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-1.c
1 /*
2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #define _LGPL_SOURCE
21 #include <assert.h>
22
23 #include <common/common.h>
24 #include <common/sessiond-comm/relayd.h>
25 #include <common/compat/string.h>
26 #include <lttng/constant.h>
27
28 #include "cmd-2-1.h"
29 #include "utils.h"
30
31 /*
32 * cmd_recv_stream_2_1 allocates path_name and channel_name.
33 */
34 int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload,
35 char **ret_path_name, char **ret_channel_name)
36 {
37 int ret;
38 struct lttcomm_relayd_add_stream stream_info;
39 char *path_name = NULL;
40 char *channel_name = NULL;
41 size_t len;
42
43 if (payload->size < sizeof(stream_info)) {
44 ERR("Unexpected payload size in \"cmd_recv_stream_2_1\": expected >= %zu bytes, got %zu bytes",
45 sizeof(stream_info), payload->size);
46 ret = -1;
47 goto error;
48 }
49 memcpy(&stream_info, payload->data, sizeof(stream_info));
50
51 len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname));
52 /* Ensure that NULL-terminated and fits in local filename length. */
53 if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) {
54 ret = -ENAMETOOLONG;
55 ERR("Path name too long");
56 goto error;
57 }
58 path_name = strdup(stream_info.pathname);
59 if (!path_name) {
60 PERROR("Path name allocation");
61 ret = -ENOMEM;
62 goto error;
63 }
64 len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name));
65 if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) {
66 ret = -ENAMETOOLONG;
67 ERR("Channel name too long");
68 goto error;
69 }
70 channel_name = strdup(stream_info.channel_name);
71 if (!channel_name) {
72 ret = -errno;
73 PERROR("Channel name allocation");
74 goto error;
75 }
76
77 *ret_path_name = path_name;
78 *ret_channel_name = channel_name;
79 return 0;
80 error:
81 free(path_name);
82 free(channel_name);
83 return ret;
84 }
This page took 0.031898 seconds and 4 git commands to generate.