src.ctf.lttng-live: make component class handle interruptions
[babeltrace.git] / src / plugins / ctf / lttng-live / viewer-connection.c
1 /*
2 * Copyright 2019 - Francis Deslauriers <francis.deslauriers@efficios.com>
3 * Copyright 2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #define BT_COMP_LOG_SELF_COMP (viewer_connection->self_comp)
25 #define BT_LOG_OUTPUT_LEVEL (viewer_connection->log_level)
26 #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"
27 #include "logging/comp-logging.h"
28
29 #include <fcntl.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36
37 #include <glib.h>
38
39 #include "compat/socket.h"
40 #include "compat/endian.h"
41 #include "compat/compiler.h"
42 #include "common/common.h"
43 #include <babeltrace2/babeltrace.h>
44
45 #include "lttng-live.h"
46 #include "viewer-connection.h"
47 #include "lttng-viewer-abi.h"
48 #include "data-stream.h"
49 #include "metadata.h"
50
51 #define viewer_handle_send_recv_status(_self_comp, _self_comp_class, \
52 _status, _action, _msg_str) \
53 do { \
54 switch (_status) { \
55 case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED: \
56 break; \
57 case LTTNG_LIVE_VIEWER_STATUS_ERROR: \
58 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp, \
59 _self_comp_class, "Error " _action " " _msg_str); \
60 break; \
61 default: \
62 bt_common_abort(); \
63 } \
64 } while (0)
65
66 #define viewer_handle_send_status(_self_comp, _self_comp_class, _status, _msg_str) \
67 viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, \
68 "sending", _msg_str)
69
70 #define viewer_handle_recv_status(_self_comp, _self_comp_class, _status, _msg_str) \
71 viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, \
72 "receiving", _msg_str)
73
74 #define LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(_self_comp, \
75 _self_comp_class, _msg, _fmt, ...) \
76 do { \
77 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp, _self_comp_class, \
78 _msg ": %s" _fmt, bt_socket_errormsg(), ##__VA_ARGS__); \
79 } while (0)
80
81 static inline
82 enum lttng_live_iterator_status viewer_status_to_live_iterator_status(
83 enum lttng_live_viewer_status viewer_status)
84 {
85 switch (viewer_status) {
86 case LTTNG_LIVE_VIEWER_STATUS_OK:
87 return LTTNG_LIVE_ITERATOR_STATUS_OK;
88 case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED:
89 return LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
90 case LTTNG_LIVE_VIEWER_STATUS_ERROR:
91 return LTTNG_LIVE_ITERATOR_STATUS_ERROR;
92 default:
93 bt_common_abort();
94 }
95 }
96
97 static inline
98 enum ctf_msg_iter_medium_status viewer_status_to_ctf_msg_iter_medium_status(
99 enum lttng_live_viewer_status viewer_status)
100 {
101 switch (viewer_status) {
102 case LTTNG_LIVE_VIEWER_STATUS_OK:
103 return CTF_MSG_ITER_MEDIUM_STATUS_OK;
104 case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED:
105 return CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
106 case LTTNG_LIVE_VIEWER_STATUS_ERROR:
107 return CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
108 default:
109 bt_common_abort();
110 }
111 }
112
113 /*
114 * This function receives a message from the Relay daemon.
115 * If it received the entire message, it returns _OK,
116 * If it's interrupted, it returns _INTERRUPTED,
117 * otherwise, it returns _ERROR.
118 */
119 static
120 enum lttng_live_viewer_status lttng_live_recv(
121 struct live_viewer_connection *viewer_connection,
122 void *buf, size_t len)
123 {
124 ssize_t received;
125 bt_self_component_class *self_comp_class =
126 viewer_connection->self_comp_class;
127 bt_self_component *self_comp =
128 viewer_connection->self_comp;
129 size_t total_received = 0, to_receive = len;
130 struct lttng_live_msg_iter *lttng_live_msg_iter =
131 viewer_connection->lttng_live_msg_iter;
132 enum lttng_live_viewer_status status;
133 BT_SOCKET sock = viewer_connection->control_sock;
134
135 /*
136 * Receive a message from the Relay.
137 */
138 do {
139 received = bt_socket_recv(sock, buf + total_received, to_receive, 0);
140 if (received == BT_SOCKET_ERROR) {
141 if (bt_socket_interrupted()) {
142 if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) {
143 /*
144 * This interruption was due to a
145 * SIGINT and the graph is being torn
146 * down.
147 */
148 status = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED;
149 lttng_live_msg_iter->was_interrupted = true;
150 goto end;
151 } else {
152 /*
153 * A signal was received, but the graph
154 * is not being torn down. Carry on.
155 */
156 continue;
157 }
158 } else {
159 /*
160 * For any other types of socket error, returng
161 * an error.
162 */
163 LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(
164 self_comp, self_comp_class,
165 "Error receiving from Relay", ".");
166 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
167 goto end;
168 }
169 } else if (received == 0) {
170 /*
171 * The recv() call returned 0. This means the
172 * connection was orderly shutdown from the other peer.
173 * If that happens when we are trying to receive
174 * a message from it, it means something when wrong.
175 */
176 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
177 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
178 self_comp_class, "Remote side has closed connection");
179 goto end;
180 }
181
182 BT_ASSERT(received <= to_receive);
183 total_received += received;
184 to_receive -= received;
185
186 } while (to_receive > 0);
187
188 BT_ASSERT(total_received == len);
189 status = LTTNG_LIVE_VIEWER_STATUS_OK;
190
191 end:
192 return status;
193 }
194
195 /*
196 * This function sends a message to the Relay daemon.
197 * If it send the message, it returns _OK,
198 * If it's interrupted, it returns _INTERRUPTED,
199 * otherwise, it returns _ERROR.
200 */
201 static
202 enum lttng_live_viewer_status lttng_live_send(
203 struct live_viewer_connection *viewer_connection,
204 const void *buf, size_t len)
205 {
206 enum lttng_live_viewer_status status;
207 bt_self_component_class *self_comp_class =
208 viewer_connection->self_comp_class;
209 bt_self_component *self_comp =
210 viewer_connection->self_comp;
211 struct lttng_live_msg_iter *lttng_live_msg_iter =
212 viewer_connection->lttng_live_msg_iter;
213 BT_SOCKET sock = viewer_connection->control_sock;
214 size_t to_send = len;
215 ssize_t total_sent = 0;
216
217 do {
218 ssize_t sent = bt_socket_send_nosigpipe(sock, buf + total_sent,
219 to_send);
220 if (sent == BT_SOCKET_ERROR) {
221 if (bt_socket_interrupted()) {
222 if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) {
223 /*
224 * This interruption was a SIGINT and
225 * the graph is being teared down.
226 */
227 status = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED;
228 lttng_live_msg_iter->was_interrupted = true;
229 goto end;
230 } else {
231 /*
232 * A signal was received, but the graph
233 * is not being teared down. Carry on.
234 */
235 continue;
236 }
237 } else {
238 /*
239 * The send() call returned an error.
240 */
241 LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(
242 self_comp, self_comp_class,
243 "Error sending to Relay", ".");
244 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
245 goto end;
246 }
247 }
248
249 BT_ASSERT(sent <= to_send);
250 total_sent += sent;
251 to_send -= sent;
252
253 } while (to_send > 0);
254
255 BT_ASSERT(total_sent == len);
256 status = LTTNG_LIVE_VIEWER_STATUS_OK;
257
258 end:
259 return status;
260 }
261
262 static
263 int parse_url(struct live_viewer_connection *viewer_connection)
264 {
265 char error_buf[256] = { 0 };
266 bt_self_component *self_comp = viewer_connection->self_comp;
267 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
268 struct bt_common_lttng_live_url_parts lttng_live_url_parts = { 0 };
269 int ret = -1;
270 const char *path = viewer_connection->url->str;
271
272 if (!path) {
273 goto end;
274 }
275
276 lttng_live_url_parts = bt_common_parse_lttng_live_url(path, error_buf,
277 sizeof(error_buf));
278 if (!lttng_live_url_parts.proto) {
279 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
280 self_comp_class,"Invalid LTTng live URL format: %s",
281 error_buf);
282 goto end;
283 }
284
285 viewer_connection->relay_hostname = lttng_live_url_parts.hostname;
286 lttng_live_url_parts.hostname = NULL;
287
288 if (lttng_live_url_parts.port >= 0) {
289 viewer_connection->port = lttng_live_url_parts.port;
290 } else {
291 viewer_connection->port = LTTNG_DEFAULT_NETWORK_VIEWER_PORT;
292 }
293
294 viewer_connection->target_hostname = lttng_live_url_parts.target_hostname;
295 lttng_live_url_parts.target_hostname = NULL;
296
297 if (lttng_live_url_parts.session_name) {
298 viewer_connection->session_name = lttng_live_url_parts.session_name;
299 lttng_live_url_parts.session_name = NULL;
300 }
301
302 BT_COMP_LOGI("Connecting to hostname : %s, port : %d, "
303 "target hostname : %s, session name : %s, proto : %s",
304 viewer_connection->relay_hostname->str,
305 viewer_connection->port,
306 !viewer_connection->target_hostname ?
307 "<none>" : viewer_connection->target_hostname->str,
308 !viewer_connection->session_name ?
309 "<none>" : viewer_connection->session_name->str,
310 lttng_live_url_parts.proto->str);
311 ret = 0;
312
313 end:
314 bt_common_destroy_lttng_live_url_parts(&lttng_live_url_parts);
315 return ret;
316 }
317
318 static
319 enum lttng_live_viewer_status lttng_live_handshake(
320 struct live_viewer_connection *viewer_connection)
321 {
322 struct lttng_viewer_cmd cmd;
323 struct lttng_viewer_connect connect;
324 enum lttng_live_viewer_status status;
325 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
326 bt_self_component *self_comp = viewer_connection->self_comp;
327 const size_t cmd_buf_len = sizeof(cmd) + sizeof(connect);
328 char cmd_buf[cmd_buf_len];
329
330 cmd.cmd = htobe32(LTTNG_VIEWER_CONNECT);
331 cmd.data_size = htobe64((uint64_t) sizeof(connect));
332 cmd.cmd_version = htobe32(0);
333
334 connect.viewer_session_id = -1ULL; /* will be set on recv */
335 connect.major = htobe32(LTTNG_LIVE_MAJOR);
336 connect.minor = htobe32(LTTNG_LIVE_MINOR);
337 connect.type = htobe32(LTTNG_VIEWER_CLIENT_COMMAND);
338
339 /*
340 * Merge the cmd and connection request to prevent a write-write
341 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
342 * second write to be performed quickly in presence of Nagle's algorithm
343 */
344 memcpy(cmd_buf, &cmd, sizeof(cmd));
345 memcpy(cmd_buf + sizeof(cmd), &connect, sizeof(connect));
346
347 status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
348 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
349 viewer_handle_send_status(self_comp, self_comp_class,
350 status, "viewer connect command");
351 goto end;
352 }
353
354 status = lttng_live_recv(viewer_connection, &connect, sizeof(connect));
355 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
356 viewer_handle_recv_status(self_comp, self_comp_class,
357 status, "viewer connect reply");
358 goto end;
359 }
360
361 BT_COMP_LOGI("Received viewer session ID : %" PRIu64,
362 (uint64_t) be64toh(connect.viewer_session_id));
363 BT_COMP_LOGI("Relayd version : %u.%u", be32toh(connect.major),
364 be32toh(connect.minor));
365
366 if (LTTNG_LIVE_MAJOR != be32toh(connect.major)) {
367 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
368 self_comp_class, "Incompatible lttng-relayd protocol");
369 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
370 goto end;
371 }
372 /* Use the smallest protocol version implemented. */
373 if (LTTNG_LIVE_MINOR > be32toh(connect.minor)) {
374 viewer_connection->minor = be32toh(connect.minor);
375 } else {
376 viewer_connection->minor = LTTNG_LIVE_MINOR;
377 }
378 viewer_connection->major = LTTNG_LIVE_MAJOR;
379
380 status = LTTNG_LIVE_VIEWER_STATUS_OK;
381
382 goto end;
383
384 end:
385 return status;
386 }
387
388 static
389 enum lttng_live_viewer_status lttng_live_connect_viewer(
390 struct live_viewer_connection *viewer_connection)
391 {
392 struct hostent *host;
393 struct sockaddr_in server_addr;
394 enum lttng_live_viewer_status status;
395 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
396 bt_self_component *self_comp = viewer_connection->self_comp;
397
398 if (parse_url(viewer_connection)) {
399 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
400 self_comp_class, "Failed to parse URL");
401 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
402 goto error;
403 }
404
405 host = gethostbyname(viewer_connection->relay_hostname->str);
406 if (!host) {
407 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
408 self_comp_class, "Cannot lookup hostname: hostname=\"%s\"",
409 viewer_connection->relay_hostname->str);
410 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
411 goto error;
412 }
413
414 if ((viewer_connection->control_sock = socket(AF_INET, SOCK_STREAM, 0)) == BT_INVALID_SOCKET) {
415 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
416 self_comp_class, "Socket creation failed: %s", bt_socket_errormsg());
417 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
418 goto error;
419 }
420
421 server_addr.sin_family = AF_INET;
422 server_addr.sin_port = htons(viewer_connection->port);
423 server_addr.sin_addr = *((struct in_addr *) host->h_addr);
424 memset(&(server_addr.sin_zero), 0, 8);
425
426 if (connect(viewer_connection->control_sock, (struct sockaddr *) &server_addr,
427 sizeof(struct sockaddr)) == BT_SOCKET_ERROR) {
428 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
429 self_comp_class, "Connection failed: %s",
430 bt_socket_errormsg());
431 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
432 goto error;
433 }
434
435 status = lttng_live_handshake(viewer_connection);
436
437 /*
438 * Only print error and append cause in case of error. not in case of
439 * interruption.
440 */
441 if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
442 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
443 self_comp_class, "Viewer handshake failed");
444 goto error;
445 } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
446 goto end;
447 }
448
449 goto end;
450
451 error:
452 if (viewer_connection->control_sock != BT_INVALID_SOCKET) {
453 if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
454 BT_COMP_OR_COMP_CLASS_LOGE(self_comp, self_comp_class,
455 "Error closing socket: %s", bt_socket_errormsg());
456 }
457 }
458 viewer_connection->control_sock = BT_INVALID_SOCKET;
459 end:
460 return status;
461 }
462
463 static
464 void lttng_live_disconnect_viewer(
465 struct live_viewer_connection *viewer_connection)
466 {
467 if (viewer_connection->control_sock == BT_INVALID_SOCKET) {
468 return;
469 }
470 if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
471 BT_COMP_LOGE("Error closing socket: %s",
472 bt_socket_errormsg());
473 viewer_connection->control_sock = BT_INVALID_SOCKET;
474 }
475 }
476
477 static
478 int list_update_session(bt_value *results,
479 const struct lttng_viewer_session *session,
480 bool *_found, struct live_viewer_connection *viewer_connection)
481 {
482 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
483 bt_self_component *self_comp = viewer_connection->self_comp;
484 int ret = 0;
485 uint64_t i, len;
486 bt_value *map = NULL;
487 bt_value *hostname = NULL;
488 bt_value *session_name = NULL;
489 bt_value *btval = NULL;
490 bool found = false;
491
492 len = bt_value_array_get_length(results);
493 for (i = 0; i < len; i++) {
494 const char *hostname_str = NULL;
495 const char *session_name_str = NULL;
496
497 map = bt_value_array_borrow_element_by_index(results, i);
498 hostname = bt_value_map_borrow_entry_value(map, "target-hostname");
499 if (!hostname) {
500 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
501 self_comp_class,
502 "Error borrowing \"target-hostname\" entry.");
503 ret = -1;
504 goto end;
505 }
506 session_name = bt_value_map_borrow_entry_value(map, "session-name");
507 if (!session_name) {
508 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
509 self_comp_class,
510 "Error borrowing \"session-name\" entry.");
511 ret = -1;
512 goto end;
513 }
514 hostname_str = bt_value_string_get(hostname);
515 session_name_str = bt_value_string_get(session_name);
516
517 if (strcmp(session->hostname, hostname_str) == 0
518 && strcmp(session->session_name, session_name_str) == 0) {
519 int64_t val;
520 uint32_t streams = be32toh(session->streams);
521 uint32_t clients = be32toh(session->clients);
522
523 found = true;
524
525 btval = bt_value_map_borrow_entry_value(map, "stream-count");
526 if (!btval) {
527 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
528 self_comp, self_comp_class,
529 "Error borrowing \"stream-count\" entry.");
530 ret = -1;
531 goto end;
532 }
533 val = bt_value_integer_unsigned_get(btval);
534 /* sum */
535 val += streams;
536 bt_value_integer_unsigned_set(btval, val);
537
538 btval = bt_value_map_borrow_entry_value(map, "client-count");
539 if (!btval) {
540 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
541 self_comp, self_comp_class,
542 "Error borrowing \"client-count\" entry.");
543 ret = -1;
544 goto end;
545 }
546 val = bt_value_integer_unsigned_get(btval);
547 /* max */
548 val = bt_max_t(int64_t, clients, val);
549 bt_value_integer_unsigned_set(btval, val);
550 }
551
552 if (found) {
553 break;
554 }
555 }
556 end:
557 *_found = found;
558 return ret;
559 }
560
561 static
562 int list_append_session(bt_value *results,
563 GString *base_url,
564 const struct lttng_viewer_session *session,
565 struct live_viewer_connection *viewer_connection)
566 {
567 int ret = 0;
568 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
569 bt_value_map_insert_entry_status insert_status;
570 bt_value_array_append_element_status append_status;
571 bt_value *map = NULL;
572 GString *url = NULL;
573 bool found = false;
574
575 /*
576 * If the session already exists, add the stream count to it,
577 * and do max of client counts.
578 */
579 ret = list_update_session(results, session, &found, viewer_connection);
580 if (ret || found) {
581 goto end;
582 }
583
584 map = bt_value_map_create();
585 if (!map) {
586 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
587 "Error creating map value.");
588 ret = -1;
589 goto end;
590 }
591
592 if (base_url->len < 1) {
593 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
594 "Error: base_url length smaller than 1.");
595 ret = -1;
596 goto end;
597 }
598 /*
599 * key = "url",
600 * value = <string>,
601 */
602 url = g_string_new(base_url->str);
603 g_string_append(url, "/host/");
604 g_string_append(url, session->hostname);
605 g_string_append_c(url, '/');
606 g_string_append(url, session->session_name);
607
608 insert_status = bt_value_map_insert_string_entry(map, "url", url->str);
609 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
610 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
611 "Error inserting \"url\" entry.");
612 ret = -1;
613 goto end;
614 }
615
616 /*
617 * key = "target-hostname",
618 * value = <string>,
619 */
620 insert_status = bt_value_map_insert_string_entry(map, "target-hostname",
621 session->hostname);
622 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
623 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
624 "Error inserting \"target-hostname\" entry.");
625 ret = -1;
626 goto end;
627 }
628
629 /*
630 * key = "session-name",
631 * value = <string>,
632 */
633 insert_status = bt_value_map_insert_string_entry(map, "session-name",
634 session->session_name);
635 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
636 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
637 "Error inserting \"session-name\" entry.");
638 ret = -1;
639 goto end;
640 }
641
642 /*
643 * key = "timer-us",
644 * value = <integer>,
645 */
646 {
647 uint32_t live_timer = be32toh(session->live_timer);
648
649 insert_status = bt_value_map_insert_unsigned_integer_entry(
650 map, "timer-us", live_timer);
651 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
652 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
653 "Error inserting \"timer-us\" entry.");
654 ret = -1;
655 goto end;
656 }
657 }
658
659 /*
660 * key = "stream-count",
661 * value = <integer>,
662 */
663 {
664 uint32_t streams = be32toh(session->streams);
665
666 insert_status = bt_value_map_insert_unsigned_integer_entry(map,
667 "stream-count", streams);
668 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
669 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
670 "Error inserting \"stream-count\" entry.");
671 ret = -1;
672 goto end;
673 }
674 }
675
676 /*
677 * key = "client-count",
678 * value = <integer>,
679 */
680 {
681 uint32_t clients = be32toh(session->clients);
682
683 insert_status = bt_value_map_insert_unsigned_integer_entry(map,
684 "client-count", clients);
685 if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
686 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
687 "Error inserting \"client-count\" entry.");
688 ret = -1;
689 goto end;
690 }
691 }
692
693 append_status = bt_value_array_append_element(results, map);
694 if (append_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) {
695 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
696 "Error appending map to results.");
697 ret = -1;
698 }
699
700 end:
701 if (url) {
702 g_string_free(url, true);
703 }
704 BT_VALUE_PUT_REF_AND_RESET(map);
705 return ret;
706 }
707
708 /*
709 * Data structure returned:
710 *
711 * {
712 * <array> = {
713 * [n] = {
714 * <map> = {
715 * {
716 * key = "url",
717 * value = <string>,
718 * },
719 * {
720 * key = "target-hostname",
721 * value = <string>,
722 * },
723 * {
724 * key = "session-name",
725 * value = <string>,
726 * },
727 * {
728 * key = "timer-us",
729 * value = <integer>,
730 * },
731 * {
732 * key = "stream-count",
733 * value = <integer>,
734 * },
735 * {
736 * key = "client-count",
737 * value = <integer>,
738 * },
739 * },
740 * }
741 * }
742 */
743
744 BT_HIDDEN
745 bt_component_class_query_method_status live_viewer_connection_list_sessions(
746 struct live_viewer_connection *viewer_connection,
747 const bt_value **user_result)
748 {
749 bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
750 bt_component_class_query_method_status status =
751 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
752 bt_value *result = NULL;
753 enum lttng_live_viewer_status viewer_status;
754 struct lttng_viewer_cmd cmd;
755 struct lttng_viewer_list_sessions list;
756 uint32_t i, sessions_count;
757
758 result = bt_value_array_create();
759 if (!result) {
760 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
761 "Error creating array");
762 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR;
763 goto error;
764 }
765
766 cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS);
767 cmd.data_size = htobe64((uint64_t) 0);
768 cmd.cmd_version = htobe32(0);
769
770 viewer_status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
771 if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
772 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
773 "Error sending list sessions command");
774 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
775 goto error;
776 } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
777 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN;
778 goto error;
779 }
780
781 viewer_status = lttng_live_recv(viewer_connection, &list, sizeof(list));
782 if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
783 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
784 "Error receiving session list");
785 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
786 goto error;
787 } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
788 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN;
789 goto error;
790 }
791
792 sessions_count = be32toh(list.sessions_count);
793 for (i = 0; i < sessions_count; i++) {
794 struct lttng_viewer_session lsession;
795
796 viewer_status = lttng_live_recv(viewer_connection, &lsession,
797 sizeof(lsession));
798 if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
799 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
800 "Error receiving session:");
801 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
802 goto error;
803 } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
804 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN;
805 goto error;
806 }
807
808 lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0';
809 lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0';
810 if (list_append_session(result, viewer_connection->url,
811 &lsession, viewer_connection)) {
812 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
813 "Error appending session");
814 status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
815 goto error;
816 }
817 }
818
819 *user_result = result;
820 goto end;
821 error:
822 BT_VALUE_PUT_REF_AND_RESET(result);
823 end:
824 return status;
825 }
826
827 static
828 enum lttng_live_viewer_status lttng_live_query_session_ids(
829 struct lttng_live_msg_iter *lttng_live_msg_iter)
830 {
831 struct lttng_viewer_cmd cmd;
832 struct lttng_viewer_list_sessions list;
833 struct lttng_viewer_session lsession;
834 uint32_t i, sessions_count;
835 uint64_t session_id;
836 enum lttng_live_viewer_status status;
837 struct live_viewer_connection *viewer_connection =
838 lttng_live_msg_iter->viewer_connection;
839 bt_self_component *self_comp = viewer_connection->self_comp;
840 bt_self_component_class *self_comp_class =
841 viewer_connection->self_comp_class;
842
843 cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS);
844 cmd.data_size = htobe64((uint64_t) 0);
845 cmd.cmd_version = htobe32(0);
846
847 status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
848 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
849 viewer_handle_send_status(self_comp, self_comp_class,
850 status, "list sessions command");
851 goto end;
852 }
853
854 status = lttng_live_recv(viewer_connection, &list, sizeof(list));
855 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
856 viewer_handle_recv_status(self_comp, self_comp_class,
857 status, "session list reply");
858 goto end;
859 }
860
861 sessions_count = be32toh(list.sessions_count);
862 for (i = 0; i < sessions_count; i++) {
863 status = lttng_live_recv(viewer_connection, &lsession,
864 sizeof(lsession));
865 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
866 viewer_handle_recv_status(self_comp, self_comp_class,
867 status, "session reply");
868 goto end;
869 }
870 lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0';
871 lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0';
872 session_id = be64toh(lsession.id);
873
874 BT_COMP_LOGI("Adding session %" PRIu64 " hostname: %s session_name: %s",
875 session_id, lsession.hostname, lsession.session_name);
876
877 if ((strncmp(lsession.session_name,
878 viewer_connection->session_name->str,
879 LTTNG_VIEWER_NAME_MAX) == 0) && (strncmp(lsession.hostname,
880 viewer_connection->target_hostname->str,
881 LTTNG_VIEWER_HOST_NAME_MAX) == 0)) {
882 if (lttng_live_add_session(lttng_live_msg_iter, session_id,
883 lsession.hostname,
884 lsession.session_name)) {
885 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
886 "Failed to add live session");
887 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
888 goto end;
889 }
890 }
891 }
892
893 status = LTTNG_LIVE_VIEWER_STATUS_OK;
894
895 end:
896 return status;
897 }
898
899 BT_HIDDEN
900 enum lttng_live_viewer_status lttng_live_create_viewer_session(
901 struct lttng_live_msg_iter *lttng_live_msg_iter)
902 {
903 struct lttng_viewer_cmd cmd;
904 struct lttng_viewer_create_session_response resp;
905 enum lttng_live_viewer_status status;
906 struct live_viewer_connection *viewer_connection =
907 lttng_live_msg_iter->viewer_connection;
908 bt_self_component *self_comp = viewer_connection->self_comp;
909 bt_self_component_class *self_comp_class =
910 viewer_connection->self_comp_class;
911
912 cmd.cmd = htobe32(LTTNG_VIEWER_CREATE_SESSION);
913 cmd.data_size = htobe64((uint64_t) 0);
914 cmd.cmd_version = htobe32(0);
915
916 status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
917 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
918 viewer_handle_send_status(self_comp, self_comp_class,
919 status, "create session command");
920 goto end;
921 }
922
923 status = lttng_live_recv(viewer_connection, &resp, sizeof(resp));
924 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
925 viewer_handle_recv_status(self_comp, self_comp_class,
926 status, "create session reply");
927 goto end;
928 }
929
930 if (be32toh(resp.status) != LTTNG_VIEWER_CREATE_SESSION_OK) {
931 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
932 "Error creating viewer session");
933 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
934 goto end;
935 }
936
937 status = lttng_live_query_session_ids(lttng_live_msg_iter);
938 if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
939 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
940 "Failed to query live viewer session ids");
941 goto end;
942 } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
943 goto end;
944 }
945
946 end:
947 return status;
948 }
949
950 static
951 enum lttng_live_viewer_status receive_streams(struct lttng_live_session *session,
952 uint32_t stream_count,
953 bt_self_message_iterator *self_msg_iter)
954 {
955 uint32_t i;
956 struct lttng_live_msg_iter *lttng_live_msg_iter =
957 session->lttng_live_msg_iter;
958 enum lttng_live_viewer_status status;
959 struct live_viewer_connection *viewer_connection =
960 lttng_live_msg_iter->viewer_connection;
961 bt_self_component *self_comp = viewer_connection->self_comp;
962
963 BT_COMP_LOGI("Getting %" PRIu32 " new streams:", stream_count);
964 for (i = 0; i < stream_count; i++) {
965 struct lttng_viewer_stream stream;
966 struct lttng_live_stream_iterator *live_stream;
967 uint64_t stream_id;
968 uint64_t ctf_trace_id;
969
970 status = lttng_live_recv(viewer_connection, &stream,
971 sizeof(stream));
972 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
973 viewer_handle_recv_status(self_comp, NULL,
974 status, "stream reply");
975 goto end;
976 }
977 stream.path_name[LTTNG_VIEWER_PATH_MAX - 1] = '\0';
978 stream.channel_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0';
979 stream_id = be64toh(stream.id);
980 ctf_trace_id = be64toh(stream.ctf_trace_id);
981
982 if (stream.metadata_flag) {
983 BT_COMP_LOGI(" metadata stream %" PRIu64 " : %s/%s",
984 stream_id, stream.path_name, stream.channel_name);
985 if (lttng_live_metadata_create_stream(session,
986 ctf_trace_id, stream_id,
987 stream.path_name)) {
988 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
989 "Error creating metadata stream");
990 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
991 goto end;
992 }
993 session->lazy_stream_msg_init = true;
994 } else {
995 BT_COMP_LOGI(" stream %" PRIu64 " : %s/%s",
996 stream_id, stream.path_name, stream.channel_name);
997 live_stream = lttng_live_stream_iterator_create(session,
998 ctf_trace_id, stream_id, self_msg_iter);
999 if (!live_stream) {
1000 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1001 "Error creating stream");
1002 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1003 goto end;
1004 }
1005 }
1006 }
1007 status = LTTNG_LIVE_VIEWER_STATUS_OK;
1008
1009 end:
1010 return status;
1011 }
1012
1013 BT_HIDDEN
1014 enum lttng_live_viewer_status lttng_live_attach_session(
1015 struct lttng_live_session *session,
1016 bt_self_message_iterator *self_msg_iter)
1017 {
1018 struct lttng_viewer_cmd cmd;
1019 enum lttng_live_viewer_status status;
1020 struct lttng_viewer_attach_session_request rq;
1021 struct lttng_viewer_attach_session_response rp;
1022 struct lttng_live_msg_iter *lttng_live_msg_iter =
1023 session->lttng_live_msg_iter;
1024 struct live_viewer_connection *viewer_connection =
1025 lttng_live_msg_iter->viewer_connection;
1026 bt_self_component *self_comp = viewer_connection->self_comp;
1027 uint64_t session_id = session->id;
1028 uint32_t streams_count;
1029 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1030 char cmd_buf[cmd_buf_len];
1031
1032 cmd.cmd = htobe32(LTTNG_VIEWER_ATTACH_SESSION);
1033 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1034 cmd.cmd_version = htobe32(0);
1035
1036 memset(&rq, 0, sizeof(rq));
1037 rq.session_id = htobe64(session_id);
1038 // TODO: add cmd line parameter to select seek beginning
1039 // rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
1040 rq.seek = htobe32(LTTNG_VIEWER_SEEK_LAST);
1041
1042 /*
1043 * Merge the cmd and connection request to prevent a write-write
1044 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1045 * second write to be performed quickly in presence of Nagle's algorithm.
1046 */
1047 memcpy(cmd_buf, &cmd, sizeof(cmd));
1048 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1049 status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1050 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1051 viewer_handle_send_status(self_comp, NULL,
1052 status, "attach session command");
1053 goto end;
1054 }
1055
1056 status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1057 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1058 viewer_handle_recv_status(self_comp, NULL,
1059 status, "attach session reply");
1060 goto end;
1061 }
1062
1063 streams_count = be32toh(rp.streams_count);
1064 switch(be32toh(rp.status)) {
1065 case LTTNG_VIEWER_ATTACH_OK:
1066 break;
1067 case LTTNG_VIEWER_ATTACH_UNK:
1068 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1069 "Session id %" PRIu64 " is unknown", session_id);
1070 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1071 goto end;
1072 case LTTNG_VIEWER_ATTACH_ALREADY:
1073 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1074 "There is already a viewer attached to this session");
1075 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1076 goto end;
1077 case LTTNG_VIEWER_ATTACH_NOT_LIVE:
1078 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Not a live session");
1079 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1080 goto end;
1081 case LTTNG_VIEWER_ATTACH_SEEK_ERR:
1082 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Wrong seek parameter");
1083 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1084 goto end;
1085 default:
1086 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1087 "Unknown attach return code %u", be32toh(rp.status));
1088 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1089 goto end;
1090 }
1091
1092 /* We receive the initial list of streams. */
1093 status = receive_streams(session, streams_count, self_msg_iter);
1094 switch (status) {
1095 case LTTNG_LIVE_VIEWER_STATUS_OK:
1096 break;
1097 case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED:
1098 goto end;
1099 case LTTNG_LIVE_VIEWER_STATUS_ERROR:
1100 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams");
1101 goto end;
1102 default:
1103 bt_common_abort();
1104 }
1105
1106 session->attached = true;
1107 session->new_streams_needed = false;
1108
1109 end:
1110 return status;
1111 }
1112
1113 BT_HIDDEN
1114 enum lttng_live_viewer_status lttng_live_detach_session(
1115 struct lttng_live_session *session)
1116 {
1117 struct lttng_viewer_cmd cmd;
1118 enum lttng_live_viewer_status status;
1119 struct lttng_viewer_detach_session_request rq;
1120 struct lttng_viewer_detach_session_response rp;
1121 struct lttng_live_msg_iter *lttng_live_msg_iter =
1122 session->lttng_live_msg_iter;
1123 bt_self_component *self_comp = session->self_comp;
1124 struct live_viewer_connection *viewer_connection =
1125 lttng_live_msg_iter->viewer_connection;
1126 uint64_t session_id = session->id;
1127 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1128 char cmd_buf[cmd_buf_len];
1129
1130 if (!session->attached) {
1131 return 0;
1132 }
1133
1134 cmd.cmd = htobe32(LTTNG_VIEWER_DETACH_SESSION);
1135 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1136 cmd.cmd_version = htobe32(0);
1137
1138 memset(&rq, 0, sizeof(rq));
1139 rq.session_id = htobe64(session_id);
1140
1141 /*
1142 * Merge the cmd and connection request to prevent a write-write
1143 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1144 * second write to be performed quickly in presence of Nagle's algorithm.
1145 */
1146 memcpy(cmd_buf, &cmd, sizeof(cmd));
1147 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1148 status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1149 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1150 viewer_handle_send_status(self_comp, NULL,
1151 status, "detach session command");
1152 goto end;
1153 }
1154
1155 status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1156 if (status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1157 viewer_handle_recv_status(self_comp, NULL,
1158 status, "detach session reply");
1159 goto end;
1160 }
1161
1162 switch(be32toh(rp.status)) {
1163 case LTTNG_VIEWER_DETACH_SESSION_OK:
1164 break;
1165 case LTTNG_VIEWER_DETACH_SESSION_UNK:
1166 BT_COMP_LOGW("Session id %" PRIu64 " is unknown", session_id);
1167 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1168 goto end;
1169 case LTTNG_VIEWER_DETACH_SESSION_ERR:
1170 BT_COMP_LOGW("Error detaching session id %" PRIu64 "", session_id);
1171 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1172 goto end;
1173 default:
1174 BT_COMP_LOGE("Unknown detach return code %u", be32toh(rp.status));
1175 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1176 goto end;
1177 }
1178
1179 session->attached = false;
1180
1181 status = LTTNG_LIVE_VIEWER_STATUS_OK;
1182
1183 end:
1184 return status;
1185 }
1186
1187 BT_HIDDEN
1188 enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet(
1189 struct lttng_live_trace *trace, FILE *fp, size_t *reply_len)
1190 {
1191 uint64_t len = 0;
1192 enum lttng_live_get_one_metadata_status status;
1193 enum lttng_live_viewer_status viewer_status;
1194 struct lttng_viewer_cmd cmd;
1195 struct lttng_viewer_get_metadata rq;
1196 struct lttng_viewer_metadata_packet rp;
1197 char *data = NULL;
1198 ssize_t ret_len;
1199 struct lttng_live_session *session = trace->session;
1200 struct lttng_live_msg_iter *lttng_live_msg_iter =
1201 session->lttng_live_msg_iter;
1202 struct lttng_live_metadata *metadata = trace->metadata;
1203 struct live_viewer_connection *viewer_connection =
1204 lttng_live_msg_iter->viewer_connection;
1205 bt_self_component *self_comp = viewer_connection->self_comp;
1206 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1207 char cmd_buf[cmd_buf_len];
1208
1209 rq.stream_id = htobe64(metadata->stream_id);
1210 cmd.cmd = htobe32(LTTNG_VIEWER_GET_METADATA);
1211 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1212 cmd.cmd_version = htobe32(0);
1213
1214 /*
1215 * Merge the cmd and connection request to prevent a write-write
1216 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1217 * second write to be performed quickly in presence of Nagle's algorithm.
1218 */
1219 memcpy(cmd_buf, &cmd, sizeof(cmd));
1220 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1221 viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1222 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1223 viewer_handle_send_status(self_comp, NULL,
1224 viewer_status, "get metadata command");
1225 status = (enum lttng_live_get_one_metadata_status) viewer_status;
1226 goto end;
1227 }
1228
1229 viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1230 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1231 viewer_handle_recv_status(self_comp, NULL,
1232 viewer_status, "get metadata reply");
1233 status = (enum lttng_live_get_one_metadata_status) viewer_status;
1234 goto end;
1235 }
1236
1237 switch (be32toh(rp.status)) {
1238 case LTTNG_VIEWER_METADATA_OK:
1239 BT_COMP_LOGD("Received get_metadata response: ok");
1240 break;
1241 case LTTNG_VIEWER_NO_NEW_METADATA:
1242 BT_COMP_LOGD("Received get_metadata response: no new");
1243 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_END;
1244 goto end;
1245 case LTTNG_VIEWER_METADATA_ERR:
1246 /*
1247 * The Relayd cannot find this stream id. Maybe its
1248 * gone already. This can happen in short lived UST app
1249 * in a per-pid session.
1250 */
1251 BT_COMP_LOGD("Received get_metadata response: error");
1252 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED;
1253 goto end;
1254 default:
1255 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1256 "Received get_metadata response: unknown");
1257 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR;
1258 goto error;
1259 }
1260
1261 len = be64toh(rp.len);
1262 BT_COMP_LOGD("Writing %" PRIu64" bytes to metadata", len);
1263 if (len <= 0) {
1264 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1265 "Erroneous response length");
1266 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR;
1267 goto error;
1268 }
1269
1270 data = calloc(1, len);
1271 if (!data) {
1272 BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp,
1273 "Failed to allocate data buffer", ".");
1274 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR;
1275 goto error;
1276 }
1277
1278 viewer_status = lttng_live_recv(viewer_connection, data, len);
1279 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1280 viewer_handle_recv_status(self_comp, NULL,
1281 viewer_status, "get metadata packet");
1282 status = (enum lttng_live_get_one_metadata_status) viewer_status;
1283 goto error;
1284 }
1285
1286 /*
1287 * Write the metadata to the file handle.
1288 */
1289 do {
1290 ret_len = fwrite(data, 1, len, fp);
1291 } while (ret_len < 0 && errno == EINTR);
1292 if (ret_len < 0) {
1293 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1294 "Writing in the metadata file stream");
1295 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR;
1296 goto error;
1297 }
1298 BT_ASSERT(ret_len == len);
1299 *reply_len = len;
1300 status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK;
1301
1302 error:
1303 free(data);
1304
1305 end:
1306 return status;
1307 }
1308
1309 /*
1310 * Assign the fields from a lttng_viewer_index to a packet_index.
1311 */
1312 static
1313 void lttng_index_to_packet_index(struct lttng_viewer_index *lindex,
1314 struct packet_index *pindex)
1315 {
1316 BT_ASSERT(lindex);
1317 BT_ASSERT(pindex);
1318
1319 pindex->offset = be64toh(lindex->offset);
1320 pindex->packet_size = be64toh(lindex->packet_size);
1321 pindex->content_size = be64toh(lindex->content_size);
1322 pindex->ts_cycles.timestamp_begin = be64toh(lindex->timestamp_begin);
1323 pindex->ts_cycles.timestamp_end = be64toh(lindex->timestamp_end);
1324 pindex->events_discarded = be64toh(lindex->events_discarded);
1325 }
1326
1327 BT_HIDDEN
1328 enum lttng_live_iterator_status lttng_live_get_next_index(
1329 struct lttng_live_msg_iter *lttng_live_msg_iter,
1330 struct lttng_live_stream_iterator *stream,
1331 struct packet_index *index)
1332 {
1333 struct lttng_viewer_cmd cmd;
1334 struct lttng_viewer_get_next_index rq;
1335 enum lttng_live_viewer_status viewer_status;
1336 struct lttng_viewer_index rp;
1337 enum lttng_live_iterator_status status;
1338 struct live_viewer_connection *viewer_connection =
1339 lttng_live_msg_iter->viewer_connection;
1340 bt_self_component *self_comp = viewer_connection->self_comp;
1341 struct lttng_live_trace *trace = stream->trace;
1342 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1343 char cmd_buf[cmd_buf_len];
1344 uint32_t flags, rp_status;
1345
1346 cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEXT_INDEX);
1347 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1348 cmd.cmd_version = htobe32(0);
1349
1350
1351 memset(&rq, 0, sizeof(rq));
1352 rq.stream_id = htobe64(stream->viewer_stream_id);
1353
1354 /*
1355 * Merge the cmd and connection request to prevent a write-write
1356 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1357 * second write to be performed quickly in presence of Nagle's algorithm.
1358 */
1359 memcpy(cmd_buf, &cmd, sizeof(cmd));
1360 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1361 viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1362 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1363 viewer_handle_send_status(self_comp, NULL,
1364 viewer_status, "get next index command");
1365 goto error;
1366 }
1367
1368 viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1369 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1370 viewer_handle_recv_status(self_comp, NULL,
1371 viewer_status, "get next index reply");
1372 goto error;
1373 }
1374
1375 flags = be32toh(rp.flags);
1376 rp_status = be32toh(rp.status);
1377
1378 switch (rp_status) {
1379 case LTTNG_VIEWER_INDEX_INACTIVE:
1380 {
1381 uint64_t ctf_stream_class_id;
1382
1383 BT_COMP_LOGD("Received get_next_index response: inactive");
1384 memset(index, 0, sizeof(struct packet_index));
1385 index->ts_cycles.timestamp_end = be64toh(rp.timestamp_end);
1386 stream->current_inactivity_ts = index->ts_cycles.timestamp_end;
1387 ctf_stream_class_id = be64toh(rp.stream_id);
1388 if (stream->ctf_stream_class_id != -1ULL) {
1389 BT_ASSERT(stream->ctf_stream_class_id ==
1390 ctf_stream_class_id);
1391 } else {
1392 stream->ctf_stream_class_id = ctf_stream_class_id;
1393 }
1394 stream->state = LTTNG_LIVE_STREAM_QUIESCENT;
1395 status = LTTNG_LIVE_ITERATOR_STATUS_OK;
1396 break;
1397 }
1398 case LTTNG_VIEWER_INDEX_OK:
1399 {
1400 uint64_t ctf_stream_class_id;
1401
1402 BT_COMP_LOGD("Received get_next_index response: OK");
1403 lttng_index_to_packet_index(&rp, index);
1404 ctf_stream_class_id = be64toh(rp.stream_id);
1405 if (stream->ctf_stream_class_id != -1ULL) {
1406 BT_ASSERT(stream->ctf_stream_class_id ==
1407 ctf_stream_class_id);
1408 } else {
1409 stream->ctf_stream_class_id = ctf_stream_class_id;
1410 }
1411
1412 stream->state = LTTNG_LIVE_STREAM_ACTIVE_DATA;
1413
1414 if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
1415 BT_COMP_LOGD("Received get_next_index response: new metadata needed");
1416 trace->new_metadata_needed = true;
1417 }
1418 if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) {
1419 BT_COMP_LOGD("Received get_next_index response: new streams needed");
1420 lttng_live_need_new_streams(lttng_live_msg_iter);
1421 }
1422 status = LTTNG_LIVE_ITERATOR_STATUS_OK;
1423 break;
1424 }
1425 case LTTNG_VIEWER_INDEX_RETRY:
1426 BT_COMP_LOGD("Received get_next_index response: retry");
1427 memset(index, 0, sizeof(struct packet_index));
1428 stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA;
1429 status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
1430 goto end;
1431 case LTTNG_VIEWER_INDEX_HUP:
1432 BT_COMP_LOGD("Received get_next_index response: stream hung up");
1433 memset(index, 0, sizeof(struct packet_index));
1434 index->offset = EOF;
1435 stream->state = LTTNG_LIVE_STREAM_EOF;
1436 stream->has_stream_hung_up = true;
1437 status = LTTNG_LIVE_ITERATOR_STATUS_END;
1438 break;
1439 case LTTNG_VIEWER_INDEX_ERR:
1440 BT_COMP_LOGD("Received get_next_index response: error");
1441 memset(index, 0, sizeof(struct packet_index));
1442 stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA;
1443 status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
1444 goto end;
1445 default:
1446 BT_COMP_LOGD("Received get_next_index response: unknown value");
1447 memset(index, 0, sizeof(struct packet_index));
1448 stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA;
1449 status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
1450 goto end;
1451 }
1452 goto end;
1453
1454 error:
1455 status = viewer_status_to_live_iterator_status(viewer_status);
1456 end:
1457 return status;
1458 }
1459
1460 BT_HIDDEN
1461 enum ctf_msg_iter_medium_status lttng_live_get_stream_bytes(
1462 struct lttng_live_msg_iter *lttng_live_msg_iter,
1463 struct lttng_live_stream_iterator *stream, uint8_t *buf,
1464 uint64_t offset, uint64_t req_len, uint64_t *recv_len)
1465 {
1466 enum ctf_msg_iter_medium_status status;
1467 enum lttng_live_viewer_status viewer_status;
1468 struct lttng_viewer_trace_packet rp;
1469 struct lttng_viewer_cmd cmd;
1470 struct lttng_viewer_get_packet rq;
1471 struct live_viewer_connection *viewer_connection =
1472 lttng_live_msg_iter->viewer_connection;
1473 bt_self_component *self_comp = viewer_connection->self_comp;
1474 struct lttng_live_trace *trace = stream->trace;
1475 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1476 char cmd_buf[cmd_buf_len];
1477 uint32_t flags, rp_status;
1478
1479 BT_COMP_LOGD("lttng_live_get_stream_bytes: offset=%" PRIu64 ", req_len=%" PRIu64,
1480 offset, req_len);
1481 cmd.cmd = htobe32(LTTNG_VIEWER_GET_PACKET);
1482 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1483 cmd.cmd_version = htobe32(0);
1484
1485 memset(&rq, 0, sizeof(rq));
1486 rq.stream_id = htobe64(stream->viewer_stream_id);
1487 rq.offset = htobe64(offset);
1488 rq.len = htobe32(req_len);
1489
1490 /*
1491 * Merge the cmd and connection request to prevent a write-write
1492 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1493 * second write to be performed quickly in presence of Nagle's algorithm.
1494 */
1495 memcpy(cmd_buf, &cmd, sizeof(cmd));
1496 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1497 viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1498 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1499 viewer_handle_send_status(self_comp, NULL,
1500 viewer_status, "get data packet command");
1501 goto error;
1502 }
1503
1504 viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1505 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1506 viewer_handle_recv_status(self_comp, NULL,
1507 viewer_status, "get data packet reply");
1508 goto error;
1509 }
1510
1511 flags = be32toh(rp.flags);
1512 rp_status = be32toh(rp.status);
1513
1514 switch (rp_status) {
1515 case LTTNG_VIEWER_GET_PACKET_OK:
1516 req_len = be32toh(rp.len);
1517 BT_COMP_LOGD("Received get_data_packet response: Ok, "
1518 "packet size : %" PRIu64 "", req_len);
1519 status = CTF_MSG_ITER_MEDIUM_STATUS_OK;
1520 break;
1521 case LTTNG_VIEWER_GET_PACKET_RETRY:
1522 /* Unimplemented by relay daemon */
1523 BT_COMP_LOGD("Received get_data_packet response: retry");
1524 status = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
1525 goto end;
1526 case LTTNG_VIEWER_GET_PACKET_ERR:
1527 if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
1528 BT_COMP_LOGD("get_data_packet: new metadata needed, try again later");
1529 trace->new_metadata_needed = true;
1530 }
1531 if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) {
1532 BT_COMP_LOGD("get_data_packet: new streams needed, try again later");
1533 lttng_live_need_new_streams(lttng_live_msg_iter);
1534 }
1535 if (flags & (LTTNG_VIEWER_FLAG_NEW_METADATA
1536 | LTTNG_VIEWER_FLAG_NEW_STREAM)) {
1537 status = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
1538 goto end;
1539 }
1540 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1541 "Received get_data_packet response: error");
1542 status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
1543 goto end;
1544 case LTTNG_VIEWER_GET_PACKET_EOF:
1545 status = CTF_MSG_ITER_MEDIUM_STATUS_EOF;
1546 goto end;
1547 default:
1548 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1549 "Received get_data_packet response: unknown");
1550 status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
1551 goto error;
1552 }
1553
1554 if (req_len == 0) {
1555 status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
1556 goto error;
1557 }
1558
1559 viewer_status = lttng_live_recv(viewer_connection, buf, req_len);
1560 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1561 viewer_handle_recv_status(self_comp, NULL,
1562 viewer_status, "get data packet");
1563 goto error;
1564 }
1565 *recv_len = req_len;
1566
1567 status = CTF_MSG_ITER_MEDIUM_STATUS_OK;
1568 goto end;
1569 error:
1570
1571 status = viewer_status_to_ctf_msg_iter_medium_status(viewer_status);
1572 end:
1573 return status;
1574 }
1575
1576 /*
1577 * Request new streams for a session.
1578 */
1579 BT_HIDDEN
1580 enum lttng_live_iterator_status lttng_live_get_new_streams(
1581 struct lttng_live_session *session,
1582 bt_self_message_iterator *self_msg_iter)
1583 {
1584 enum lttng_live_iterator_status status =
1585 LTTNG_LIVE_ITERATOR_STATUS_OK;
1586 struct lttng_viewer_cmd cmd;
1587 struct lttng_viewer_new_streams_request rq;
1588 struct lttng_viewer_new_streams_response rp;
1589 struct lttng_live_msg_iter *lttng_live_msg_iter =
1590 session->lttng_live_msg_iter;
1591 enum lttng_live_viewer_status viewer_status;
1592 struct live_viewer_connection *viewer_connection =
1593 lttng_live_msg_iter->viewer_connection;
1594 bt_self_component *self_comp = viewer_connection->self_comp;
1595 uint32_t streams_count;
1596 const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq);
1597 char cmd_buf[cmd_buf_len];
1598
1599 if (!session->new_streams_needed) {
1600 status = LTTNG_LIVE_ITERATOR_STATUS_OK;
1601 goto end;
1602 }
1603
1604 cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEW_STREAMS);
1605 cmd.data_size = htobe64((uint64_t) sizeof(rq));
1606 cmd.cmd_version = htobe32(0);
1607
1608 memset(&rq, 0, sizeof(rq));
1609 rq.session_id = htobe64(session->id);
1610
1611 /*
1612 * Merge the cmd and connection request to prevent a write-write
1613 * sequence on the TCP socket. Otherwise, a delayed ACK will prevent the
1614 * second write to be performed quickly in presence of Nagle's algorithm.
1615 */
1616 memcpy(cmd_buf, &cmd, sizeof(cmd));
1617 memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq));
1618 viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len);
1619 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1620 viewer_handle_send_status(self_comp, NULL,
1621 viewer_status, "get new streams command");
1622 status = viewer_status_to_live_iterator_status(viewer_status);
1623 goto end;
1624 }
1625
1626 viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp));
1627 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1628 viewer_handle_recv_status(self_comp, NULL,
1629 viewer_status, "get new streams reply");
1630 status = viewer_status_to_live_iterator_status(viewer_status);
1631 goto end;
1632 }
1633
1634 streams_count = be32toh(rp.streams_count);
1635
1636 switch(be32toh(rp.status)) {
1637 case LTTNG_VIEWER_NEW_STREAMS_OK:
1638 session->new_streams_needed = false;
1639 break;
1640 case LTTNG_VIEWER_NEW_STREAMS_NO_NEW:
1641 session->new_streams_needed = false;
1642 goto end;
1643 case LTTNG_VIEWER_NEW_STREAMS_HUP:
1644 session->new_streams_needed = false;
1645 session->closed = true;
1646 status = LTTNG_LIVE_ITERATOR_STATUS_END;
1647 goto end;
1648 case LTTNG_VIEWER_NEW_STREAMS_ERR:
1649 BT_COMP_LOGD("Received get_new_streams response: error");
1650 status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
1651 goto end;
1652 default:
1653 BT_COMP_LOGE_APPEND_CAUSE(self_comp,
1654 "Received get_new_streams response: Unknown:"
1655 "return code %u", be32toh(rp.status));
1656 status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
1657 goto end;
1658 }
1659
1660 viewer_status = receive_streams(session, streams_count, self_msg_iter);
1661 if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
1662 viewer_handle_recv_status(self_comp, NULL,
1663 viewer_status, "new streams");
1664 status = viewer_status_to_live_iterator_status(viewer_status);
1665 goto end;
1666 }
1667
1668 status = LTTNG_LIVE_ITERATOR_STATUS_OK;
1669 end:
1670 return status;
1671 }
1672
1673 BT_HIDDEN
1674 enum lttng_live_viewer_status live_viewer_connection_create(
1675 bt_self_component *self_comp,
1676 bt_self_component_class *self_comp_class,
1677 bt_logging_level log_level,
1678 const char *url, bool in_query,
1679 struct lttng_live_msg_iter *lttng_live_msg_iter,
1680 struct live_viewer_connection **viewer)
1681 {
1682 struct live_viewer_connection *viewer_connection;
1683 enum lttng_live_viewer_status status;
1684
1685 viewer_connection = g_new0(struct live_viewer_connection, 1);
1686
1687 if (bt_socket_init(log_level) != 0) {
1688 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
1689 self_comp_class, "Failed to init socket");
1690 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1691 goto error;
1692 }
1693
1694 viewer_connection->log_level = log_level;
1695
1696 viewer_connection->self_comp = self_comp;
1697 viewer_connection->self_comp_class = self_comp_class;
1698
1699 viewer_connection->control_sock = BT_INVALID_SOCKET;
1700 viewer_connection->port = -1;
1701 viewer_connection->in_query = in_query;
1702 viewer_connection->lttng_live_msg_iter = lttng_live_msg_iter;
1703 viewer_connection->url = g_string_new(url);
1704 if (!viewer_connection->url) {
1705 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
1706 self_comp_class, "Failed to allocate URL buffer");
1707 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
1708 goto error;
1709 }
1710
1711 BT_COMP_LOGI("Establishing connection to url \"%s\"...", url);
1712 status = lttng_live_connect_viewer(viewer_connection);
1713 /*
1714 * Only print error and append cause in case of error. not in case of
1715 * interruption.
1716 */
1717 if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
1718 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp,
1719 self_comp_class, "Failed to establish connection: "
1720 "url=\"%s\"", url);
1721 goto error;
1722 } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) {
1723 goto error;
1724 }
1725 BT_COMP_LOGI("Connection to url \"%s\" is established", url);
1726
1727 *viewer = viewer_connection;
1728 status = LTTNG_LIVE_VIEWER_STATUS_OK;
1729 goto end;
1730
1731 error:
1732 if (viewer_connection) {
1733 live_viewer_connection_destroy(viewer_connection);
1734 }
1735 end:
1736 return status;
1737 }
1738
1739 BT_HIDDEN
1740 void live_viewer_connection_destroy(
1741 struct live_viewer_connection *viewer_connection)
1742 {
1743 BT_COMP_LOGI("Closing connection to url \"%s\"", viewer_connection->url->str);
1744
1745 if (!viewer_connection) {
1746 goto end;
1747 }
1748
1749 lttng_live_disconnect_viewer(viewer_connection);
1750
1751 if (viewer_connection->url) {
1752 g_string_free(viewer_connection->url, true);
1753 }
1754
1755 if (viewer_connection->relay_hostname) {
1756 g_string_free(viewer_connection->relay_hostname, true);
1757 }
1758
1759 if (viewer_connection->target_hostname) {
1760 g_string_free(viewer_connection->target_hostname, true);
1761 }
1762
1763 if (viewer_connection->session_name) {
1764 g_string_free(viewer_connection->session_name, true);
1765 }
1766
1767 g_free(viewer_connection);
1768
1769 bt_socket_fini();
1770
1771 end:
1772 return;
1773 }
This page took 0.084077 seconds and 4 git commands to generate.