Fix: Relay daemon ownership and reference counting
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-2.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 <common/compat/endian.h>
29
30 #include "cmd-generic.h"
31 #include "cmd-2-1.h"
32 #include "utils.h"
33
34 /*
35 * cmd_recv_stream_2_2 allocates path_name and channel_name.
36 */
37 int cmd_recv_stream_2_2(struct relay_connection *conn,
38 char **ret_path_name, char **ret_channel_name,
39 uint64_t *tracefile_size, uint64_t *tracefile_count)
40 {
41 int ret;
42 struct lttcomm_relayd_add_stream_2_2 stream_info;
43 char *path_name = NULL;
44 char *channel_name = NULL;
45
46 ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info));
47 if (ret < 0) {
48 ERR("Unable to recv stream version 2.2");
49 goto error;
50 }
51
52 path_name = create_output_path(stream_info.pathname);
53 if (!path_name) {
54 PERROR("Path name allocation");
55 ret = -ENOMEM;
56 goto error;
57 }
58
59 channel_name = strdup(stream_info.channel_name);
60 if (!channel_name) {
61 ret = -errno;
62 PERROR("Path name allocation");
63 goto error;
64 }
65
66 *tracefile_size = be64toh(stream_info.tracefile_size);
67 *tracefile_count = be64toh(stream_info.tracefile_count);
68 *ret_path_name = path_name;
69 *ret_channel_name = channel_name;
70 return 0;
71 error:
72 free(path_name);
73 free(channel_name);
74 return ret;
75 }
This page took 0.031754 seconds and 5 git commands to generate.