2 * Copyright 2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "PLUGIN-CTF-LTTNG-LIVE-SRC-VIEWER"
33 #include <sys/types.h>
36 #include <babeltrace/compat/socket-internal.h>
37 #include <babeltrace/endian-internal.h>
38 #include <babeltrace/compiler-internal.h>
39 #include <babeltrace/common-internal.h>
40 #include <babeltrace/babeltrace.h>
42 #include "lttng-live-internal.h"
43 #include "viewer-connection.h"
44 #include "lttng-viewer-abi.h"
45 #include "data-stream.h"
48 static ssize_t
lttng_live_recv(struct bt_live_viewer_connection
*viewer_connection
,
49 void *buf
, size_t len
)
52 size_t copied
= 0, to_copy
= len
;
53 struct lttng_live_component
*lttng_live
=
54 viewer_connection
->lttng_live
;
55 BT_SOCKET sock
= viewer_connection
->control_sock
;
58 ret
= bt_socket_recv(sock
, buf
+ copied
, to_copy
, 0);
60 BT_ASSERT(ret
<= to_copy
);
64 if (ret
== BT_SOCKET_ERROR
&& bt_socket_interrupted()) {
65 if (lttng_live_is_canceled(lttng_live
)) {
71 } while (ret
> 0 && to_copy
> 0);
74 /* ret = 0 means orderly shutdown, ret == BT_SOCKET_ERROR is error. */
78 static ssize_t
lttng_live_send(struct bt_live_viewer_connection
*viewer_connection
,
79 const void *buf
, size_t len
)
81 struct lttng_live_component
*lttng_live
=
82 viewer_connection
->lttng_live
;
83 BT_SOCKET sock
= viewer_connection
->control_sock
;
87 ret
= bt_socket_send_nosigpipe(sock
, buf
, len
);
88 if (ret
== BT_SOCKET_ERROR
&& bt_socket_interrupted()) {
89 if (lttng_live_is_canceled(lttng_live
)) {
101 static int parse_url(struct bt_live_viewer_connection
*viewer_connection
)
103 char error_buf
[256] = { 0 };
104 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
106 const char *path
= viewer_connection
->url
->str
;
112 lttng_live_url_parts
= bt_common_parse_lttng_live_url(path
,
113 error_buf
, sizeof(error_buf
));
114 if (!lttng_live_url_parts
.proto
) {
115 BT_LOGW("Invalid LTTng live URL format: %s", error_buf
);
119 viewer_connection
->relay_hostname
=
120 lttng_live_url_parts
.hostname
;
121 lttng_live_url_parts
.hostname
= NULL
;
123 if (lttng_live_url_parts
.port
>= 0) {
124 viewer_connection
->port
= lttng_live_url_parts
.port
;
126 viewer_connection
->port
= LTTNG_DEFAULT_NETWORK_VIEWER_PORT
;
129 viewer_connection
->target_hostname
=
130 lttng_live_url_parts
.target_hostname
;
131 lttng_live_url_parts
.target_hostname
= NULL
;
133 if (lttng_live_url_parts
.session_name
) {
134 viewer_connection
->session_name
=
135 lttng_live_url_parts
.session_name
;
136 lttng_live_url_parts
.session_name
= NULL
;
139 BT_LOGD("Connecting to hostname : %s, port : %d, "
140 "target hostname : %s, session name : %s, "
142 viewer_connection
->relay_hostname
->str
,
143 viewer_connection
->port
,
144 viewer_connection
->target_hostname
== NULL
?
145 "<none>" : viewer_connection
->target_hostname
->str
,
146 viewer_connection
->session_name
== NULL
?
147 "<none>" : viewer_connection
->session_name
->str
,
148 lttng_live_url_parts
.proto
->str
);
152 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
156 static int lttng_live_handshake(struct bt_live_viewer_connection
*viewer_connection
)
158 struct lttng_viewer_cmd cmd
;
159 struct lttng_viewer_connect connect
;
160 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(connect
);
161 char cmd_buf
[cmd_buf_len
];
165 cmd
.cmd
= htobe32(LTTNG_VIEWER_CONNECT
);
166 cmd
.data_size
= htobe64((uint64_t) sizeof(connect
));
167 cmd
.cmd_version
= htobe32(0);
169 connect
.viewer_session_id
= -1ULL; /* will be set on recv */
170 connect
.major
= htobe32(LTTNG_LIVE_MAJOR
);
171 connect
.minor
= htobe32(LTTNG_LIVE_MINOR
);
172 connect
.type
= htobe32(LTTNG_VIEWER_CLIENT_COMMAND
);
175 * Merge the cmd and connection request to prevent a write-write
176 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
177 * second write to be performed quickly in presence of Nagle's algorithm
179 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
180 memcpy(cmd_buf
+ sizeof(cmd
), &connect
, sizeof(connect
));
181 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
182 if (ret_len
== BT_SOCKET_ERROR
) {
183 BT_LOGE("Error sending version: %s", bt_socket_errormsg());
187 BT_ASSERT(ret_len
== cmd_buf_len
);
189 ret_len
= lttng_live_recv(viewer_connection
, &connect
, sizeof(connect
));
191 BT_LOGI("Remote side has closed connection");
194 if (ret_len
== BT_SOCKET_ERROR
) {
195 BT_LOGE("Error receiving version: %s", bt_socket_errormsg());
198 BT_ASSERT(ret_len
== sizeof(connect
));
200 BT_LOGD("Received viewer session ID : %" PRIu64
,
201 (uint64_t) be64toh(connect
.viewer_session_id
));
202 BT_LOGD("Relayd version : %u.%u", be32toh(connect
.major
),
203 be32toh(connect
.minor
));
205 if (LTTNG_LIVE_MAJOR
!= be32toh(connect
.major
)) {
206 BT_LOGE("Incompatible lttng-relayd protocol");
209 /* Use the smallest protocol version implemented. */
210 if (LTTNG_LIVE_MINOR
> be32toh(connect
.minor
)) {
211 viewer_connection
->minor
= be32toh(connect
.minor
);
213 viewer_connection
->minor
= LTTNG_LIVE_MINOR
;
215 viewer_connection
->major
= LTTNG_LIVE_MAJOR
;
220 BT_LOGE("Unable to establish connection");
224 static int lttng_live_connect_viewer(struct bt_live_viewer_connection
*viewer_connection
)
226 struct hostent
*host
;
227 struct sockaddr_in server_addr
;
230 if (parse_url(viewer_connection
)) {
234 host
= gethostbyname(viewer_connection
->relay_hostname
->str
);
236 BT_LOGE("Cannot lookup hostname %s",
237 viewer_connection
->relay_hostname
->str
);
241 if ((viewer_connection
->control_sock
= socket(AF_INET
, SOCK_STREAM
, 0)) == BT_INVALID_SOCKET
) {
242 BT_LOGE("Socket creation failed: %s", bt_socket_errormsg());
246 server_addr
.sin_family
= AF_INET
;
247 server_addr
.sin_port
= htons(viewer_connection
->port
);
248 server_addr
.sin_addr
= *((struct in_addr
*) host
->h_addr
);
249 memset(&(server_addr
.sin_zero
), 0, 8);
251 if (connect(viewer_connection
->control_sock
, (struct sockaddr
*) &server_addr
,
252 sizeof(struct sockaddr
)) == BT_SOCKET_ERROR
) {
253 BT_LOGE("Connection failed: %s", bt_socket_errormsg());
256 if (lttng_live_handshake(viewer_connection
)) {
265 if (viewer_connection
->control_sock
!= BT_INVALID_SOCKET
) {
266 if (bt_socket_close(viewer_connection
->control_sock
) == BT_SOCKET_ERROR
) {
267 BT_LOGE("Close: %s", bt_socket_errormsg());
270 viewer_connection
->control_sock
= BT_INVALID_SOCKET
;
274 static void lttng_live_disconnect_viewer(struct bt_live_viewer_connection
*viewer_connection
)
276 if (viewer_connection
->control_sock
== BT_INVALID_SOCKET
) {
279 if (bt_socket_close(viewer_connection
->control_sock
) == BT_SOCKET_ERROR
) {
280 BT_LOGE("Close: %s", bt_socket_errormsg());
281 viewer_connection
->control_sock
= BT_INVALID_SOCKET
;
285 static void connection_release(bt_object
*obj
)
287 struct bt_live_viewer_connection
*conn
=
288 container_of(obj
, struct bt_live_viewer_connection
, obj
);
290 bt_live_viewer_connection_destroy(conn
);
294 enum bt_value_status
list_update_session(bt_value
*results
,
295 const struct lttng_viewer_session
*session
,
298 enum bt_value_status ret
= BT_VALUE_STATUS_OK
;
299 bt_value
*map
= NULL
;
300 bt_value
*hostname
= NULL
;
301 bt_value
*session_name
= NULL
;
302 bt_value
*btval
= NULL
;
306 len
= bt_value_array_get_size(results
);
308 ret
= BT_VALUE_STATUS_ERROR
;
311 for (i
= 0; i
< len
; i
++) {
312 const char *hostname_str
= NULL
;
313 const char *session_name_str
= NULL
;
315 map
= bt_value_array_get(results
, (size_t) i
);
317 ret
= BT_VALUE_STATUS_ERROR
;
320 hostname
= bt_value_map_get(map
, "target-hostname");
322 ret
= BT_VALUE_STATUS_ERROR
;
325 session_name
= bt_value_map_get(map
, "session-name");
327 ret
= BT_VALUE_STATUS_ERROR
;
330 hostname_str
= bt_value_string_get(hostname
);
331 session_name_str
= bt_value_string_get(session_name
);
333 if (!strcmp(session
->hostname
, hostname_str
)
334 && !strcmp(session
->session_name
,
337 uint32_t streams
= be32toh(session
->streams
);
338 uint32_t clients
= be32toh(session
->clients
);
342 btval
= bt_value_map_get(map
, "stream-count");
344 ret
= BT_VALUE_STATUS_ERROR
;
347 val
= bt_value_integer_get(btval
);
350 ret
= bt_private_integer_bool_set(btval
, val
);
351 if (ret
!= BT_VALUE_STATUS_OK
) {
354 BT_VALUE_PUT_REF_AND_RESET(btval
);
356 btval
= bt_value_map_get(map
, "client-count");
358 ret
= BT_VALUE_STATUS_ERROR
;
361 val
= bt_value_integer_get(btval
);
363 val
= max_t(int64_t, clients
, val
);
364 ret
= bt_private_integer_bool_set(btval
, val
);
365 if (ret
!= BT_VALUE_STATUS_OK
) {
368 BT_VALUE_PUT_REF_AND_RESET(btval
);
371 BT_VALUE_PUT_REF_AND_RESET(hostname
);
372 BT_VALUE_PUT_REF_AND_RESET(session_name
);
373 BT_VALUE_PUT_REF_AND_RESET(map
);
380 BT_VALUE_PUT_REF_AND_RESET(btval
);
381 BT_VALUE_PUT_REF_AND_RESET(hostname
);
382 BT_VALUE_PUT_REF_AND_RESET(session_name
);
383 BT_VALUE_PUT_REF_AND_RESET(map
);
389 enum bt_value_status
list_append_session(bt_value
*results
,
391 const struct lttng_viewer_session
*session
)
393 enum bt_value_status ret
= BT_VALUE_STATUS_OK
;
394 bt_value
*map
= NULL
;
399 * If the session already exists, add the stream count to it,
400 * and do max of client counts.
402 ret
= list_update_session(results
, session
, &found
);
403 if (ret
!= BT_VALUE_STATUS_OK
|| found
) {
407 map
= bt_private_value_map_create();
409 ret
= BT_VALUE_STATUS_ERROR
;
413 if (base_url
->len
< 1) {
414 ret
= BT_VALUE_STATUS_ERROR
;
421 url
= g_string_new(base_url
->str
);
422 g_string_append(url
, "/host/");
423 g_string_append(url
, session
->hostname
);
424 g_string_append_c(url
, '/');
425 g_string_append(url
, session
->session_name
);
427 ret
= bt_private_value_map_insert_string_entry(map
, "url", url
->str
);
428 if (ret
!= BT_VALUE_STATUS_OK
) {
433 * key = "target-hostname",
436 ret
= bt_private_value_map_insert_string_entry(map
, "target-hostname",
438 if (ret
!= BT_VALUE_STATUS_OK
) {
443 * key = "session-name",
446 ret
= bt_private_value_map_insert_string_entry(map
, "session-name",
447 session
->session_name
);
448 if (ret
!= BT_VALUE_STATUS_OK
) {
457 uint32_t live_timer
= be32toh(session
->live_timer
);
459 ret
= bt_private_value_map_insert_integer_entry(map
, "timer-us",
461 if (ret
!= BT_VALUE_STATUS_OK
) {
467 * key = "stream-count",
471 uint32_t streams
= be32toh(session
->streams
);
473 ret
= bt_private_value_map_insert_integer_entry(map
, "stream-count",
475 if (ret
!= BT_VALUE_STATUS_OK
) {
482 * key = "client-count",
486 uint32_t clients
= be32toh(session
->clients
);
488 ret
= bt_private_value_map_insert_integer_entry(map
, "client-count",
490 if (ret
!= BT_VALUE_STATUS_OK
) {
495 ret
= bt_private_value_array_append_element(results
, map
);
498 g_string_free(url
, TRUE
);
500 BT_VALUE_PUT_REF_AND_RESET(map
);
505 * Data structure returned:
516 * key = "target-hostname",
520 * key = "session-name",
528 * key = "stream-count",
532 * key = "client-count",
541 bt_value
*bt_live_viewer_connection_list_sessions(struct bt_live_viewer_connection
*viewer_connection
)
543 bt_value
*results
= NULL
;
544 struct lttng_viewer_cmd cmd
;
545 struct lttng_viewer_list_sessions list
;
546 uint32_t i
, sessions_count
;
549 if (lttng_live_handshake(viewer_connection
)) {
553 results
= bt_private_value_array_create();
555 BT_LOGE("Error creating array");
559 cmd
.cmd
= htobe32(LTTNG_VIEWER_LIST_SESSIONS
);
560 cmd
.data_size
= htobe64((uint64_t) 0);
561 cmd
.cmd_version
= htobe32(0);
563 ret_len
= lttng_live_send(viewer_connection
, &cmd
, sizeof(cmd
));
564 if (ret_len
== BT_SOCKET_ERROR
) {
565 BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
568 BT_ASSERT(ret_len
== sizeof(cmd
));
570 ret_len
= lttng_live_recv(viewer_connection
, &list
, sizeof(list
));
572 BT_LOGI("Remote side has closed connection");
575 if (ret_len
== BT_SOCKET_ERROR
) {
576 BT_LOGE("Error receiving session list: %s", bt_socket_errormsg());
579 BT_ASSERT(ret_len
== sizeof(list
));
581 sessions_count
= be32toh(list
.sessions_count
);
582 for (i
= 0; i
< sessions_count
; i
++) {
583 struct lttng_viewer_session lsession
;
585 ret_len
= lttng_live_recv(viewer_connection
,
586 &lsession
, sizeof(lsession
));
588 BT_LOGI("Remote side has closed connection");
591 if (ret_len
== BT_SOCKET_ERROR
) {
592 BT_LOGE("Error receiving session: %s", bt_socket_errormsg());
595 BT_ASSERT(ret_len
== sizeof(lsession
));
596 lsession
.hostname
[LTTNG_VIEWER_HOST_NAME_MAX
- 1] = '\0';
597 lsession
.session_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
598 if (list_append_session(results
,
599 viewer_connection
->url
, &lsession
)
600 != BT_VALUE_STATUS_OK
) {
606 BT_VALUE_PUT_REF_AND_RESET(results
);
612 int lttng_live_query_session_ids(struct lttng_live_component
*lttng_live
)
614 struct lttng_viewer_cmd cmd
;
615 struct lttng_viewer_list_sessions list
;
616 struct lttng_viewer_session lsession
;
617 uint32_t i
, sessions_count
;
620 struct bt_live_viewer_connection
*viewer_connection
=
621 lttng_live
->viewer_connection
;
623 cmd
.cmd
= htobe32(LTTNG_VIEWER_LIST_SESSIONS
);
624 cmd
.data_size
= htobe64((uint64_t) 0);
625 cmd
.cmd_version
= htobe32(0);
627 ret_len
= lttng_live_send(viewer_connection
, &cmd
, sizeof(cmd
));
628 if (ret_len
== BT_SOCKET_ERROR
) {
629 BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
632 BT_ASSERT(ret_len
== sizeof(cmd
));
634 ret_len
= lttng_live_recv(viewer_connection
, &list
, sizeof(list
));
636 BT_LOGI("Remote side has closed connection");
639 if (ret_len
== BT_SOCKET_ERROR
) {
640 BT_LOGE("Error receiving session list: %s", bt_socket_errormsg());
643 BT_ASSERT(ret_len
== sizeof(list
));
645 sessions_count
= be32toh(list
.sessions_count
);
646 for (i
= 0; i
< sessions_count
; i
++) {
647 ret_len
= lttng_live_recv(viewer_connection
,
648 &lsession
, sizeof(lsession
));
650 BT_LOGI("Remote side has closed connection");
653 if (ret_len
== BT_SOCKET_ERROR
) {
654 BT_LOGE("Error receiving session: %s", bt_socket_errormsg());
657 BT_ASSERT(ret_len
== sizeof(lsession
));
658 lsession
.hostname
[LTTNG_VIEWER_HOST_NAME_MAX
- 1] = '\0';
659 lsession
.session_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
660 session_id
= be64toh(lsession
.id
);
662 BT_LOGD("Adding session %" PRIu64
" hostname: %s session_name: %s",
663 session_id
, lsession
.hostname
, lsession
.session_name
);
665 if ((strncmp(lsession
.session_name
,
666 viewer_connection
->session_name
->str
,
667 LTTNG_VIEWER_NAME_MAX
) == 0) && (strncmp(lsession
.hostname
,
668 viewer_connection
->target_hostname
->str
,
669 LTTNG_VIEWER_HOST_NAME_MAX
) == 0)) {
670 if (lttng_live_add_session(lttng_live
, session_id
,
672 lsession
.session_name
)) {
681 BT_LOGE("Unable to query session ids");
686 int lttng_live_create_viewer_session(struct lttng_live_component
*lttng_live
)
688 struct lttng_viewer_cmd cmd
;
689 struct lttng_viewer_create_session_response resp
;
691 struct bt_live_viewer_connection
*viewer_connection
=
692 lttng_live
->viewer_connection
;
694 cmd
.cmd
= htobe32(LTTNG_VIEWER_CREATE_SESSION
);
695 cmd
.data_size
= htobe64((uint64_t) 0);
696 cmd
.cmd_version
= htobe32(0);
698 ret_len
= lttng_live_send(viewer_connection
, &cmd
, sizeof(cmd
));
699 if (ret_len
== BT_SOCKET_ERROR
) {
700 BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
703 BT_ASSERT(ret_len
== sizeof(cmd
));
705 ret_len
= lttng_live_recv(viewer_connection
, &resp
, sizeof(resp
));
707 BT_LOGI("Remote side has closed connection");
710 if (ret_len
== BT_SOCKET_ERROR
) {
711 BT_LOGE("Error receiving create session reply: %s", bt_socket_errormsg());
714 BT_ASSERT(ret_len
== sizeof(resp
));
716 if (be32toh(resp
.status
) != LTTNG_VIEWER_CREATE_SESSION_OK
) {
717 BT_LOGE("Error creating viewer session");
720 if (lttng_live_query_session_ids(lttng_live
)) {
731 int receive_streams(struct lttng_live_session
*session
,
732 uint32_t stream_count
)
736 struct lttng_live_component
*lttng_live
= session
->lttng_live
;
737 struct bt_live_viewer_connection
*viewer_connection
=
738 lttng_live
->viewer_connection
;
740 BT_LOGD("Getting %" PRIu32
" new streams:", stream_count
);
741 for (i
= 0; i
< stream_count
; i
++) {
742 struct lttng_viewer_stream stream
;
743 struct lttng_live_stream_iterator
*live_stream
;
745 uint64_t ctf_trace_id
;
747 ret_len
= lttng_live_recv(viewer_connection
, &stream
, sizeof(stream
));
749 BT_LOGI("Remote side has closed connection");
752 if (ret_len
== BT_SOCKET_ERROR
) {
753 BT_LOGE("Error receiving stream");
756 BT_ASSERT(ret_len
== sizeof(stream
));
757 stream
.path_name
[LTTNG_VIEWER_PATH_MAX
- 1] = '\0';
758 stream
.channel_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
759 stream_id
= be64toh(stream
.id
);
760 ctf_trace_id
= be64toh(stream
.ctf_trace_id
);
762 if (stream
.metadata_flag
) {
763 BT_LOGD(" metadata stream %" PRIu64
" : %s/%s",
764 stream_id
, stream
.path_name
,
765 stream
.channel_name
);
766 if (lttng_live_metadata_create_stream(session
,
767 ctf_trace_id
, stream_id
,
769 BT_LOGE("Error creating metadata stream");
773 session
->lazy_stream_notif_init
= true;
775 BT_LOGD(" stream %" PRIu64
" : %s/%s",
776 stream_id
, stream
.path_name
,
777 stream
.channel_name
);
778 live_stream
= lttng_live_stream_iterator_create(session
,
779 ctf_trace_id
, stream_id
);
781 BT_LOGE("Error creating streamn");
793 int lttng_live_attach_session(struct lttng_live_session
*session
)
795 struct lttng_viewer_cmd cmd
;
796 struct lttng_viewer_attach_session_request rq
;
797 struct lttng_viewer_attach_session_response rp
;
799 struct lttng_live_component
*lttng_live
= session
->lttng_live
;
800 struct bt_live_viewer_connection
*viewer_connection
=
801 lttng_live
->viewer_connection
;
802 uint64_t session_id
= session
->id
;
803 uint32_t streams_count
;
804 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
805 char cmd_buf
[cmd_buf_len
];
807 if (session
->attached
) {
811 cmd
.cmd
= htobe32(LTTNG_VIEWER_ATTACH_SESSION
);
812 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
813 cmd
.cmd_version
= htobe32(0);
815 memset(&rq
, 0, sizeof(rq
));
816 rq
.session_id
= htobe64(session_id
);
817 // TODO: add cmd line parameter to select seek beginning
818 // rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
819 rq
.seek
= htobe32(LTTNG_VIEWER_SEEK_LAST
);
822 * Merge the cmd and connection request to prevent a write-write
823 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
824 * second write to be performed quickly in presence of Nagle's algorithm.
826 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
827 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
828 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
829 if (ret_len
== BT_SOCKET_ERROR
) {
830 BT_LOGE("Error sending attach request: %s", bt_socket_errormsg());
834 BT_ASSERT(ret_len
== cmd_buf_len
);
835 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
837 BT_LOGI("Remote side has closed connection");
840 if (ret_len
== BT_SOCKET_ERROR
) {
841 BT_LOGE("Error receiving attach response: %s", bt_socket_errormsg());
844 BT_ASSERT(ret_len
== sizeof(rp
));
846 streams_count
= be32toh(rp
.streams_count
);
847 switch(be32toh(rp
.status
)) {
848 case LTTNG_VIEWER_ATTACH_OK
:
850 case LTTNG_VIEWER_ATTACH_UNK
:
851 BT_LOGW("Session id %" PRIu64
" is unknown", session_id
);
853 case LTTNG_VIEWER_ATTACH_ALREADY
:
854 BT_LOGW("There is already a viewer attached to this session");
856 case LTTNG_VIEWER_ATTACH_NOT_LIVE
:
857 BT_LOGW("Not a live session");
859 case LTTNG_VIEWER_ATTACH_SEEK_ERR
:
860 BT_LOGE("Wrong seek parameter");
863 BT_LOGE("Unknown attach return code %u", be32toh(rp
.status
));
867 /* We receive the initial list of streams. */
868 if (receive_streams(session
, streams_count
)) {
872 session
->attached
= true;
873 session
->new_streams_needed
= false;
882 int lttng_live_detach_session(struct lttng_live_session
*session
)
884 struct lttng_viewer_cmd cmd
;
885 struct lttng_viewer_detach_session_request rq
;
886 struct lttng_viewer_detach_session_response rp
;
888 struct lttng_live_component
*lttng_live
= session
->lttng_live
;
889 struct bt_live_viewer_connection
*viewer_connection
=
890 lttng_live
->viewer_connection
;
891 uint64_t session_id
= session
->id
;
892 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
893 char cmd_buf
[cmd_buf_len
];
895 if (!session
->attached
) {
899 cmd
.cmd
= htobe32(LTTNG_VIEWER_DETACH_SESSION
);
900 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
901 cmd
.cmd_version
= htobe32(0);
903 memset(&rq
, 0, sizeof(rq
));
904 rq
.session_id
= htobe64(session_id
);
907 * Merge the cmd and connection request to prevent a write-write
908 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
909 * second write to be performed quickly in presence of Nagle's algorithm.
911 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
912 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
913 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
914 if (ret_len
== BT_SOCKET_ERROR
) {
915 BT_LOGE("Error sending detach request: %s", bt_socket_errormsg());
919 BT_ASSERT(ret_len
== cmd_buf_len
);
920 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
922 BT_LOGI("Remote side has closed connection");
925 if (ret_len
== BT_SOCKET_ERROR
) {
926 BT_LOGE("Error receiving detach response: %s", bt_socket_errormsg());
929 BT_ASSERT(ret_len
== sizeof(rp
));
931 switch(be32toh(rp
.status
)) {
932 case LTTNG_VIEWER_DETACH_SESSION_OK
:
934 case LTTNG_VIEWER_DETACH_SESSION_UNK
:
935 BT_LOGW("Session id %" PRIu64
" is unknown", session_id
);
937 case LTTNG_VIEWER_DETACH_SESSION_ERR
:
938 BT_LOGW("Error detaching session id %" PRIu64
"", session_id
);
941 BT_LOGE("Unknown detach return code %u", be32toh(rp
.status
));
945 session
->attached
= false;
954 ssize_t
lttng_live_get_one_metadata_packet(struct lttng_live_trace
*trace
,
959 struct lttng_viewer_cmd cmd
;
960 struct lttng_viewer_get_metadata rq
;
961 struct lttng_viewer_metadata_packet rp
;
964 struct lttng_live_session
*session
= trace
->session
;
965 struct lttng_live_component
*lttng_live
= session
->lttng_live
;
966 struct lttng_live_metadata
*metadata
= trace
->metadata
;
967 struct bt_live_viewer_connection
*viewer_connection
=
968 lttng_live
->viewer_connection
;
969 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
970 char cmd_buf
[cmd_buf_len
];
972 rq
.stream_id
= htobe64(metadata
->stream_id
);
973 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_METADATA
);
974 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
975 cmd
.cmd_version
= htobe32(0);
978 * Merge the cmd and connection request to prevent a write-write
979 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
980 * second write to be performed quickly in presence of Nagle's algorithm.
982 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
983 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
984 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
985 if (ret_len
== BT_SOCKET_ERROR
) {
986 BT_LOGE("Error sending get_metadata request: %s", bt_socket_errormsg());
990 BT_ASSERT(ret_len
== cmd_buf_len
);
991 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
993 BT_LOGI("Remote side has closed connection");
996 if (ret_len
== BT_SOCKET_ERROR
) {
997 BT_LOGE("Error receiving get_metadata response: %s", bt_socket_errormsg());
1000 BT_ASSERT(ret_len
== sizeof(rp
));
1002 switch (be32toh(rp
.status
)) {
1003 case LTTNG_VIEWER_METADATA_OK
:
1004 BT_LOGD("get_metadata : OK");
1006 case LTTNG_VIEWER_NO_NEW_METADATA
:
1007 BT_LOGD("get_metadata : NO NEW");
1010 case LTTNG_VIEWER_METADATA_ERR
:
1011 BT_LOGD("get_metadata : ERR");
1014 BT_LOGD("get_metadata : UNKNOWN");
1018 len
= be64toh(rp
.len
);
1019 BT_LOGD("Writing %" PRIu64
" bytes to metadata", len
);
1024 data
= zmalloc(len
);
1026 BT_LOGE("relay data zmalloc: %s", strerror(errno
));
1029 ret_len
= lttng_live_recv(viewer_connection
, data
, len
);
1031 BT_LOGI("Remote side has closed connection");
1032 goto error_free_data
;
1034 if (ret_len
== BT_SOCKET_ERROR
) {
1035 BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg());
1036 goto error_free_data
;
1038 BT_ASSERT(ret_len
== len
);
1041 ret_len
= fwrite(data
, 1, len
, fp
);
1042 } while (ret_len
< 0 && errno
== EINTR
);
1044 BT_LOGE("Writing in the metadata fp");
1045 goto error_free_data
;
1047 BT_ASSERT(ret_len
== len
);
1060 * Assign the fields from a lttng_viewer_index to a packet_index.
1063 void lttng_index_to_packet_index(struct lttng_viewer_index
*lindex
,
1064 struct packet_index
*pindex
)
1069 pindex
->offset
= be64toh(lindex
->offset
);
1070 pindex
->packet_size
= be64toh(lindex
->packet_size
);
1071 pindex
->content_size
= be64toh(lindex
->content_size
);
1072 pindex
->ts_cycles
.timestamp_begin
= be64toh(lindex
->timestamp_begin
);
1073 pindex
->ts_cycles
.timestamp_end
= be64toh(lindex
->timestamp_end
);
1074 pindex
->events_discarded
= be64toh(lindex
->events_discarded
);
1078 enum bt_lttng_live_iterator_status
lttng_live_get_next_index(struct lttng_live_component
*lttng_live
,
1079 struct lttng_live_stream_iterator
*stream
,
1080 struct packet_index
*index
)
1082 struct lttng_viewer_cmd cmd
;
1083 struct lttng_viewer_get_next_index rq
;
1085 struct lttng_viewer_index rp
;
1086 uint32_t flags
, status
;
1087 enum bt_lttng_live_iterator_status retstatus
=
1088 BT_LTTNG_LIVE_ITERATOR_STATUS_OK
;
1089 struct bt_live_viewer_connection
*viewer_connection
=
1090 lttng_live
->viewer_connection
;
1091 struct lttng_live_trace
*trace
= stream
->trace
;
1092 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
1093 char cmd_buf
[cmd_buf_len
];
1095 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEXT_INDEX
);
1096 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
1097 cmd
.cmd_version
= htobe32(0);
1100 memset(&rq
, 0, sizeof(rq
));
1101 rq
.stream_id
= htobe64(stream
->viewer_stream_id
);
1104 * Merge the cmd and connection request to prevent a write-write
1105 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1106 * second write to be performed quickly in presence of Nagle's algorithm.
1108 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
1109 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
1110 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
1111 if (ret_len
== BT_SOCKET_ERROR
) {
1112 BT_LOGE("Error sending get_next_index request: %s", bt_socket_errormsg());
1116 BT_ASSERT(ret_len
== cmd_buf_len
);
1117 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
1119 BT_LOGI("Remote side has closed connection");
1122 if (ret_len
== BT_SOCKET_ERROR
) {
1123 BT_LOGE("Error receiving get_next_index response: %s", bt_socket_errormsg());
1126 BT_ASSERT(ret_len
== sizeof(rp
));
1128 flags
= be32toh(rp
.flags
);
1129 status
= be32toh(rp
.status
);
1132 case LTTNG_VIEWER_INDEX_INACTIVE
:
1134 uint64_t ctf_stream_class_id
;
1136 BT_LOGD("get_next_index: inactive");
1137 memset(index
, 0, sizeof(struct packet_index
));
1138 index
->ts_cycles
.timestamp_end
= be64toh(rp
.timestamp_end
);
1139 stream
->current_inactivity_timestamp
= index
->ts_cycles
.timestamp_end
;
1140 ctf_stream_class_id
= be64toh(rp
.stream_id
);
1141 if (stream
->ctf_stream_class_id
!= -1ULL) {
1142 BT_ASSERT(stream
->ctf_stream_class_id
==
1143 ctf_stream_class_id
);
1145 stream
->ctf_stream_class_id
= ctf_stream_class_id
;
1147 stream
->state
= LTTNG_LIVE_STREAM_QUIESCENT
;
1150 case LTTNG_VIEWER_INDEX_OK
:
1152 uint64_t ctf_stream_class_id
;
1154 BT_LOGD("get_next_index: OK");
1155 lttng_index_to_packet_index(&rp
, index
);
1156 ctf_stream_class_id
= be64toh(rp
.stream_id
);
1157 if (stream
->ctf_stream_class_id
!= -1ULL) {
1158 BT_ASSERT(stream
->ctf_stream_class_id
==
1159 ctf_stream_class_id
);
1161 stream
->ctf_stream_class_id
= ctf_stream_class_id
;
1164 stream
->state
= LTTNG_LIVE_STREAM_ACTIVE_DATA
;
1165 stream
->current_packet_end_timestamp
=
1166 index
->ts_cycles
.timestamp_end
;
1168 if (flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
1169 BT_LOGD("get_next_index: new metadata needed");
1170 trace
->new_metadata_needed
= true;
1172 if (flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
1173 BT_LOGD("get_next_index: new streams needed");
1174 lttng_live_need_new_streams(lttng_live
);
1178 case LTTNG_VIEWER_INDEX_RETRY
:
1179 BT_LOGD("get_next_index: retry");
1180 memset(index
, 0, sizeof(struct packet_index
));
1181 retstatus
= BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1182 stream
->state
= LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
;
1184 case LTTNG_VIEWER_INDEX_HUP
:
1185 BT_LOGD("get_next_index: stream hung up");
1186 memset(index
, 0, sizeof(struct packet_index
));
1187 index
->offset
= EOF
;
1188 retstatus
= BT_LTTNG_LIVE_ITERATOR_STATUS_END
;
1189 stream
->state
= LTTNG_LIVE_STREAM_EOF
;
1191 case LTTNG_VIEWER_INDEX_ERR
:
1192 BT_LOGE("get_next_index: error");
1193 memset(index
, 0, sizeof(struct packet_index
));
1194 stream
->state
= LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
;
1197 BT_LOGE("get_next_index: unknown value");
1198 memset(index
, 0, sizeof(struct packet_index
));
1199 stream
->state
= LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
;
1206 if (lttng_live_is_canceled(lttng_live
)) {
1207 retstatus
= BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1209 retstatus
= BT_LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
1215 enum bt_notif_iter_medium_status
lttng_live_get_stream_bytes(struct lttng_live_component
*lttng_live
,
1216 struct lttng_live_stream_iterator
*stream
, uint8_t *buf
, uint64_t offset
,
1217 uint64_t req_len
, uint64_t *recv_len
)
1219 enum bt_notif_iter_medium_status retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_OK
;
1220 struct lttng_viewer_cmd cmd
;
1221 struct lttng_viewer_get_packet rq
;
1222 struct lttng_viewer_trace_packet rp
;
1224 uint32_t flags
, status
;
1225 struct bt_live_viewer_connection
*viewer_connection
=
1226 lttng_live
->viewer_connection
;
1227 struct lttng_live_trace
*trace
= stream
->trace
;
1228 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
1229 char cmd_buf
[cmd_buf_len
];
1231 BT_LOGD("lttng_live_get_stream_bytes: offset=%" PRIu64
", req_len=%" PRIu64
,
1233 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_PACKET
);
1234 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
1235 cmd
.cmd_version
= htobe32(0);
1237 memset(&rq
, 0, sizeof(rq
));
1238 rq
.stream_id
= htobe64(stream
->viewer_stream_id
);
1239 rq
.offset
= htobe64(offset
);
1240 rq
.len
= htobe32(req_len
);
1243 * Merge the cmd and connection request to prevent a write-write
1244 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1245 * second write to be performed quickly in presence of Nagle's algorithm.
1247 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
1248 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
1249 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
1250 if (ret_len
== BT_SOCKET_ERROR
) {
1251 BT_LOGE("Error sending get_data request: %s", bt_socket_errormsg());
1255 BT_ASSERT(ret_len
== cmd_buf_len
);
1256 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
1258 BT_LOGI("Remote side has closed connection");
1261 if (ret_len
== BT_SOCKET_ERROR
) {
1262 BT_LOGE("Error receiving get_data response: %s", bt_socket_errormsg());
1265 if (ret_len
!= sizeof(rp
)) {
1266 BT_LOGE("get_data_packet: expected %zu"
1267 ", received %zd", sizeof(rp
),
1272 flags
= be32toh(rp
.flags
);
1273 status
= be32toh(rp
.status
);
1276 case LTTNG_VIEWER_GET_PACKET_OK
:
1277 req_len
= be32toh(rp
.len
);
1278 BT_LOGD("get_data_packet: Ok, packet size : %" PRIu64
"", req_len
);
1280 case LTTNG_VIEWER_GET_PACKET_RETRY
:
1281 /* Unimplemented by relay daemon */
1282 BT_LOGD("get_data_packet: retry");
1283 retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_AGAIN
;
1285 case LTTNG_VIEWER_GET_PACKET_ERR
:
1286 if (flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
1287 BT_LOGD("get_data_packet: new metadata needed, try again later");
1288 trace
->new_metadata_needed
= true;
1290 if (flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
1291 BT_LOGD("get_data_packet: new streams needed, try again later");
1292 lttng_live_need_new_streams(lttng_live
);
1294 if (flags
& (LTTNG_VIEWER_FLAG_NEW_METADATA
1295 | LTTNG_VIEWER_FLAG_NEW_STREAM
)) {
1296 retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_AGAIN
;
1299 BT_LOGE("get_data_packet: error");
1301 case LTTNG_VIEWER_GET_PACKET_EOF
:
1302 retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_EOF
;
1305 BT_LOGE("get_data_packet: unknown");
1313 ret_len
= lttng_live_recv(viewer_connection
, buf
, req_len
);
1315 BT_LOGI("Remote side has closed connection");
1318 if (ret_len
== BT_SOCKET_ERROR
) {
1319 BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg());
1322 BT_ASSERT(ret_len
== req_len
);
1323 *recv_len
= ret_len
;
1328 if (lttng_live_is_canceled(lttng_live
)) {
1329 retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_AGAIN
;
1331 retstatus
= BT_NOTIF_ITER_MEDIUM_STATUS_ERROR
;
1337 * Request new streams for a session.
1340 enum bt_lttng_live_iterator_status
lttng_live_get_new_streams(
1341 struct lttng_live_session
*session
)
1343 enum bt_lttng_live_iterator_status status
=
1344 BT_LTTNG_LIVE_ITERATOR_STATUS_OK
;
1345 struct lttng_viewer_cmd cmd
;
1346 struct lttng_viewer_new_streams_request rq
;
1347 struct lttng_viewer_new_streams_response rp
;
1349 struct lttng_live_component
*lttng_live
= session
->lttng_live
;
1350 struct bt_live_viewer_connection
*viewer_connection
=
1351 lttng_live
->viewer_connection
;
1352 uint32_t streams_count
;
1353 const size_t cmd_buf_len
= sizeof(cmd
) + sizeof(rq
);
1354 char cmd_buf
[cmd_buf_len
];
1356 if (!session
->new_streams_needed
) {
1357 return BT_LTTNG_LIVE_ITERATOR_STATUS_OK
;
1360 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEW_STREAMS
);
1361 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
1362 cmd
.cmd_version
= htobe32(0);
1364 memset(&rq
, 0, sizeof(rq
));
1365 rq
.session_id
= htobe64(session
->id
);
1368 * Merge the cmd and connection request to prevent a write-write
1369 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1370 * second write to be performed quickly in presence of Nagle's algorithm.
1372 memcpy(cmd_buf
, &cmd
, sizeof(cmd
));
1373 memcpy(cmd_buf
+ sizeof(cmd
), &rq
, sizeof(rq
));
1374 ret_len
= lttng_live_send(viewer_connection
, &cmd_buf
, cmd_buf_len
);
1375 if (ret_len
== BT_SOCKET_ERROR
) {
1376 BT_LOGE("Error sending get_new_streams request: %s", bt_socket_errormsg());
1380 BT_ASSERT(ret_len
== cmd_buf_len
);
1381 ret_len
= lttng_live_recv(viewer_connection
, &rp
, sizeof(rp
));
1383 BT_LOGI("Remote side has closed connection");
1386 if (ret_len
== BT_SOCKET_ERROR
) {
1387 BT_LOGE("Error receiving get_new_streams response");
1390 BT_ASSERT(ret_len
== sizeof(rp
));
1392 streams_count
= be32toh(rp
.streams_count
);
1394 switch(be32toh(rp
.status
)) {
1395 case LTTNG_VIEWER_NEW_STREAMS_OK
:
1396 session
->new_streams_needed
= false;
1398 case LTTNG_VIEWER_NEW_STREAMS_NO_NEW
:
1399 session
->new_streams_needed
= false;
1401 case LTTNG_VIEWER_NEW_STREAMS_HUP
:
1402 session
->new_streams_needed
= false;
1403 session
->closed
= true;
1404 status
= BT_LTTNG_LIVE_ITERATOR_STATUS_END
;
1406 case LTTNG_VIEWER_NEW_STREAMS_ERR
:
1407 BT_LOGE("get_new_streams error");
1410 BT_LOGE("Unknown return code %u", be32toh(rp
.status
));
1414 if (receive_streams(session
, streams_count
)) {
1421 if (lttng_live_is_canceled(lttng_live
)) {
1422 status
= BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1424 status
= BT_LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
1430 struct bt_live_viewer_connection
*
1431 bt_live_viewer_connection_create(const char *url
,
1432 struct lttng_live_component
*lttng_live
)
1434 struct bt_live_viewer_connection
*viewer_connection
;
1436 viewer_connection
= g_new0(struct bt_live_viewer_connection
, 1);
1438 if (bt_socket_init() != 0) {
1442 bt_object_init(&viewer_connection
->obj
, connection_release
);
1443 viewer_connection
->control_sock
= BT_INVALID_SOCKET
;
1444 viewer_connection
->port
= -1;
1445 viewer_connection
->lttng_live
= lttng_live
;
1446 viewer_connection
->url
= g_string_new(url
);
1447 if (!viewer_connection
->url
) {
1451 BT_LOGD("Establishing connection to url \"%s\"...", url
);
1452 if (lttng_live_connect_viewer(viewer_connection
)) {
1455 BT_LOGD("Connection to url \"%s\" is established", url
);
1456 return viewer_connection
;
1459 BT_LOGW("Failure to establish connection to url \"%s\"", url
);
1461 g_free(viewer_connection
);
1466 void bt_live_viewer_connection_destroy(struct bt_live_viewer_connection
*viewer_connection
)
1468 BT_LOGD("Closing connection to url \"%s\"", viewer_connection
->url
->str
);
1469 lttng_live_disconnect_viewer(viewer_connection
);
1470 g_string_free(viewer_connection
->url
, TRUE
);
1471 if (viewer_connection
->relay_hostname
) {
1472 g_string_free(viewer_connection
->relay_hostname
, TRUE
);
1474 if (viewer_connection
->target_hostname
) {
1475 g_string_free(viewer_connection
->target_hostname
, TRUE
);
1477 if (viewer_connection
->session_name
) {
1478 g_string_free(viewer_connection
->session_name
, TRUE
);
1480 g_free(viewer_connection
);