080dc173fc8361b117b4d335c3c2895bd075342f
[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-generic.h"
29 #include "cmd-2-1.h"
30 #include "utils.h"
31
32 /*
33 * cmd_recv_stream_2_1 allocates path_name and channel_name.
34 */
35 int cmd_recv_stream_2_1(struct relay_connection *conn,
36 char **ret_path_name, char **ret_channel_name)
37 {
38 int ret;
39 struct lttcomm_relayd_add_stream stream_info;
40 char *path_name = NULL;
41 char *channel_name = NULL;
42 size_t len;
43
44 ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info));
45 if (ret < 0) {
46 ERR("Unable to recv stream version 2.1");
47 goto error;
48 }
49
50 len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname));
51 /* Ensure that NULL-terminated and fits in local filename length. */
52 if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) {
53 ret = -ENAMETOOLONG;
54 ERR("Path name too long");
55 goto error;
56 }
57 path_name = create_output_path(stream_info.pathname);
58 if (!path_name) {
59 PERROR("Path name allocation");
60 ret = -ENOMEM;
61 goto error;
62 }
63 len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name));
64 if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) {
65 ret = -ENAMETOOLONG;
66 ERR("Channel name too long");
67 goto error;
68 }
69 channel_name = strdup(stream_info.channel_name);
70 if (!channel_name) {
71 ret = -errno;
72 PERROR("Channel name allocation");
73 goto error;
74 }
75
76 *ret_path_name = path_name;
77 *ret_channel_name = channel_name;
78 return 0;
79 error:
80 free(path_name);
81 free(channel_name);
82 return ret;
83 }
This page took 0.029542 seconds and 3 git commands to generate.