Commit | Line | Data |
---|---|---|
0f907de1 JD |
1 | /* |
2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * David Goulet <dgoulet@efficios.com> | |
7591bab1 | 4 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
0f907de1 JD |
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 | ||
6c1c0768 | 20 | #define _LGPL_SOURCE |
0f907de1 | 21 | #include <assert.h> |
0f907de1 JD |
22 | |
23 | #include <common/common.h> | |
24 | #include <common/sessiond-comm/relayd.h> | |
246777db MD |
25 | #include <common/compat/string.h> |
26 | #include <lttng/constant.h> | |
0f907de1 JD |
27 | |
28 | #include "cmd-generic.h" | |
29 | #include "cmd-2-1.h" | |
30 | #include "utils.h" | |
31 | ||
7591bab1 MD |
32 | /* |
33 | * cmd_recv_stream_2_1 allocates path_name and channel_name. | |
34 | */ | |
58eb9381 | 35 | int cmd_recv_stream_2_1(struct relay_connection *conn, |
7591bab1 | 36 | char **ret_path_name, char **ret_channel_name) |
0f907de1 JD |
37 | { |
38 | int ret; | |
39 | struct lttcomm_relayd_add_stream stream_info; | |
7591bab1 MD |
40 | char *path_name = NULL; |
41 | char *channel_name = NULL; | |
246777db | 42 | size_t len; |
0f907de1 | 43 | |
58eb9381 | 44 | ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info)); |
0f907de1 JD |
45 | if (ret < 0) { |
46 | ERR("Unable to recv stream version 2.1"); | |
47 | goto error; | |
48 | } | |
49 | ||
246777db MD |
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 | } | |
7591bab1 MD |
57 | path_name = create_output_path(stream_info.pathname); |
58 | if (!path_name) { | |
0f907de1 JD |
59 | PERROR("Path name allocation"); |
60 | ret = -ENOMEM; | |
61 | goto error; | |
62 | } | |
246777db MD |
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 | } | |
7591bab1 MD |
69 | channel_name = strdup(stream_info.channel_name); |
70 | if (!channel_name) { | |
0f907de1 | 71 | ret = -errno; |
246777db | 72 | PERROR("Channel name allocation"); |
0f907de1 JD |
73 | goto error; |
74 | } | |
0f907de1 | 75 | |
7591bab1 MD |
76 | *ret_path_name = path_name; |
77 | *ret_channel_name = channel_name; | |
78 | return 0; | |
0f907de1 | 79 | error: |
7591bab1 MD |
80 | free(path_name); |
81 | free(channel_name); | |
0f907de1 JD |
82 | return ret; |
83 | } |