Fix: Relay daemon ownership and reference counting
[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 _GNU_SOURCE
21 #define _LGPL_SOURCE
22 #include <assert.h>
23 #include <string.h>
24
25 #include <common/common.h>
26 #include <common/sessiond-comm/relayd.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
43 ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info));
44 if (ret < 0) {
45 ERR("Unable to recv stream version 2.1");
46 goto error;
47 }
48
49 path_name = create_output_path(stream_info.pathname);
50 if (!path_name) {
51 PERROR("Path name allocation");
52 ret = -ENOMEM;
53 goto error;
54 }
55
56 channel_name = strdup(stream_info.channel_name);
57 if (!channel_name) {
58 ret = -errno;
59 PERROR("Path name allocation");
60 goto error;
61 }
62
63 *ret_path_name = path_name;
64 *ret_channel_name = channel_name;
65 return 0;
66 error:
67 free(path_name);
68 free(channel_name);
69 return ret;
70 }
This page took 0.031222 seconds and 5 git commands to generate.