2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <lttng/session-descriptor-internal.h>
19 #include <common/macros.h>
20 #include <common/uri.h>
21 #include <common/defaults.h>
22 #include <common/error.h>
27 struct lttng_session_descriptor_network_location
{
28 struct lttng_uri
*control
;
29 struct lttng_uri
*data
;
32 struct lttng_session_descriptor
{
33 enum lttng_session_descriptor_type type
;
35 * If an output type that is not OUTPUT_TYPE_NONE is specified,
36 * it means that an output of that type must be generated at
37 * session-creation time.
39 enum lttng_session_descriptor_output_type output_type
;
42 struct lttng_session_descriptor_network_location network
;
43 struct lttng_uri
*local
;
47 struct lttng_session_descriptor_snapshot
{
48 struct lttng_session_descriptor base
;
50 * Assumes at-most one snapshot output is supported. Uses
51 * the output field of the base class.
55 struct lttng_session_descriptor_live
{
56 struct lttng_session_descriptor base
;
57 unsigned long long live_timer_us
;
60 struct lttng_session_descriptor_comm
{
61 /* enum lttng_session_descriptor_type */
63 /* enum lttng_session_descriptor_output_type */
65 /* Includes trailing null. */
67 /* Name follows, followed by URIs */
71 struct lttng_session_descriptor_live_comm
{
72 struct lttng_session_descriptor_comm base
;
73 /* Live-specific parameters. */
74 uint64_t live_timer_us
;
78 struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
80 struct lttng_uri
*new_uri
= NULL
;
86 new_uri
= zmalloc(sizeof(*new_uri
));
90 memcpy(new_uri
, uri
, sizeof(*new_uri
));
96 struct lttng_uri
*uri_from_path(const char *path
)
98 struct lttng_uri
*uris
= NULL
;
100 char local_protocol_string
[LTTNG_PATH_MAX
+ sizeof("file://")] =
103 if (strlen(path
) >= LTTNG_PATH_MAX
) {
107 if (path
[0] != '/') {
108 /* Not an absolute path. */
112 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
113 uri_count
= uri_parse(local_protocol_string
, &uris
);
114 if (uri_count
!= 1) {
117 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
129 void network_location_fini(
130 struct lttng_session_descriptor_network_location
*location
)
132 free(location
->control
);
133 free(location
->data
);
136 /* Assumes ownership of control and data. */
138 int network_location_set_from_lttng_uris(
139 struct lttng_session_descriptor_network_location
*location
,
140 struct lttng_uri
*control
, struct lttng_uri
*data
)
144 if (!control
&& !data
) {
148 if (!(control
&& data
)) {
149 /* None or both must be set. */
154 if (control
->stype
!= LTTNG_STREAM_CONTROL
||
155 data
->stype
!= LTTNG_STREAM_DATA
) {
160 free(location
->control
);
161 free(location
->data
);
162 location
->control
= control
;
163 location
->data
= data
;
173 int network_location_set_from_uri_strings(
174 struct lttng_session_descriptor_network_location
*location
,
175 const char *control
, const char *data
)
179 struct lttng_uri
*parsed_uris
= NULL
;
180 struct lttng_uri
*control_uri
= NULL
;
181 struct lttng_uri
*data_uri
= NULL
;
183 uri_count
= uri_parse_str_urls(control
, data
, &parsed_uris
);
184 if (uri_count
!= 2 && uri_count
!= 0) {
190 * uri_parse_str_urls returns a contiguous array of lttng_uris whereas
191 * session descriptors expect individually allocated lttng_uris.
193 if (uri_count
== 2) {
194 control_uri
= zmalloc(sizeof(*control_uri
));
195 data_uri
= zmalloc(sizeof(*data_uri
));
196 if (!control_uri
|| !data_uri
) {
200 memcpy(control_uri
, &parsed_uris
[0], sizeof(*control_uri
));
201 memcpy(data_uri
, &parsed_uris
[1], sizeof(*data_uri
));
204 /* Ownership of control and data uris is transferred. */
205 ret
= network_location_set_from_lttng_uris(
218 struct lttng_session_descriptor
*
219 lttng_session_descriptor_create(const char *name
)
221 struct lttng_session_descriptor
*descriptor
;
223 descriptor
= zmalloc(sizeof(*descriptor
));
228 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
229 descriptor
->output_type
=
230 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
231 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
236 lttng_session_descriptor_destroy(descriptor
);
240 /* Ownership of uri is transferred. */
242 struct lttng_session_descriptor
*
243 _lttng_session_descriptor_local_create(const char *name
,
244 struct lttng_uri
*uri
)
246 struct lttng_session_descriptor
*descriptor
;
248 descriptor
= lttng_session_descriptor_create(name
);
252 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
253 descriptor
->output_type
=
254 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
256 if (uri
->dtype
!= LTTNG_DST_PATH
) {
259 descriptor
->output
.local
= uri
;
265 lttng_session_descriptor_destroy(descriptor
);
269 struct lttng_session_descriptor
*
270 lttng_session_descriptor_local_create(const char *name
, const char *path
)
272 struct lttng_uri
*uri
= NULL
;
273 struct lttng_session_descriptor
*descriptor
;
276 uri
= uri_from_path(path
);
281 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
287 /* Assumes the ownership of both uris. */
289 struct lttng_session_descriptor
*
290 _lttng_session_descriptor_network_create(const char *name
,
291 struct lttng_uri
*control
, struct lttng_uri
*data
)
294 struct lttng_session_descriptor
*descriptor
;
296 descriptor
= lttng_session_descriptor_create(name
);
301 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
302 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
303 /* Assumes the ownership of both uris. */
304 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
,
313 lttng_session_descriptor_destroy(descriptor
);
319 struct lttng_session_descriptor
*
320 lttng_session_descriptor_network_create(const char *name
,
321 const char *control_url
, const char *data_url
)
324 struct lttng_session_descriptor
*descriptor
;
326 descriptor
= _lttng_session_descriptor_network_create(name
,
332 ret
= network_location_set_from_uri_strings(&descriptor
->output
.network
,
333 control_url
, data_url
);
339 lttng_session_descriptor_destroy(descriptor
);
344 struct lttng_session_descriptor_snapshot
*
345 _lttng_session_descriptor_snapshot_create(const char *name
)
347 struct lttng_session_descriptor_snapshot
*descriptor
;
349 descriptor
= zmalloc(sizeof(*descriptor
));
354 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
355 descriptor
->base
.output_type
=
356 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
357 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
363 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
367 /* Ownership of control and data is transferred. */
369 struct lttng_session_descriptor_snapshot
*
370 _lttng_session_descriptor_snapshot_network_create(const char *name
,
371 struct lttng_uri
*control
, struct lttng_uri
*data
)
374 struct lttng_session_descriptor_snapshot
*descriptor
;
376 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
381 descriptor
->base
.output_type
=
382 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
383 /* Ownership of control and data is transferred. */
384 ret
= network_location_set_from_lttng_uris(
385 &descriptor
->base
.output
.network
,
396 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
400 struct lttng_session_descriptor
*
401 lttng_session_descriptor_snapshot_create(const char *name
)
403 struct lttng_session_descriptor_snapshot
*descriptor
;
405 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
406 return descriptor
? &descriptor
->base
: NULL
;
409 struct lttng_session_descriptor
*
410 lttng_session_descriptor_snapshot_network_create(const char *name
,
411 const char *control_url
, const char *data_url
)
414 struct lttng_session_descriptor_snapshot
*descriptor
;
416 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
,
422 ret
= network_location_set_from_uri_strings(
423 &descriptor
->base
.output
.network
,
424 control_url
, data_url
);
428 return &descriptor
->base
;
430 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
434 /* Ownership of uri is transferred. */
436 struct lttng_session_descriptor_snapshot
*
437 _lttng_session_descriptor_snapshot_local_create(const char *name
,
438 struct lttng_uri
*uri
)
440 struct lttng_session_descriptor_snapshot
*descriptor
;
442 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
446 descriptor
->base
.output_type
=
447 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
449 if (uri
->dtype
!= LTTNG_DST_PATH
) {
452 descriptor
->base
.output
.local
= uri
;
458 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
462 struct lttng_session_descriptor
*
463 lttng_session_descriptor_snapshot_local_create(const char *name
,
466 struct lttng_uri
*path_uri
= NULL
;
467 struct lttng_session_descriptor_snapshot
*descriptor
;
470 path_uri
= uri_from_path(path
);
475 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
,
477 return descriptor
? &descriptor
->base
: NULL
;
483 struct lttng_session_descriptor_live
*
484 _lttng_session_descriptor_live_create(const char *name
,
485 unsigned long long live_timer_interval_us
)
487 struct lttng_session_descriptor_live
*descriptor
= NULL
;
489 if (live_timer_interval_us
== 0) {
492 descriptor
= zmalloc(sizeof(*descriptor
));
497 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
498 descriptor
->base
.output_type
=
499 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
500 descriptor
->live_timer_us
= live_timer_interval_us
;
501 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
508 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
512 /* Ownership of control and data is transferred. */
514 struct lttng_session_descriptor_live
*
515 _lttng_session_descriptor_live_network_create(
517 struct lttng_uri
*control
, struct lttng_uri
*data
,
518 unsigned long long live_timer_interval_us
)
521 struct lttng_session_descriptor_live
*descriptor
;
523 descriptor
= _lttng_session_descriptor_live_create(name
,
524 live_timer_interval_us
);
529 descriptor
->base
.output_type
=
530 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
532 /* Ownerwhip of control and data is transferred. */
533 ret
= network_location_set_from_lttng_uris(
534 &descriptor
->base
.output
.network
,
545 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
549 struct lttng_session_descriptor
*
550 lttng_session_descriptor_live_create(
552 unsigned long long live_timer_us
)
554 struct lttng_session_descriptor_live
*descriptor
;
556 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
558 return descriptor
? &descriptor
->base
: NULL
;
561 struct lttng_session_descriptor
*
562 lttng_session_descriptor_live_network_create(
564 const char *control_url
, const char *data_url
,
565 unsigned long long live_timer_us
)
568 struct lttng_session_descriptor_live
*descriptor
;
570 descriptor
= _lttng_session_descriptor_live_network_create(name
,
571 NULL
, NULL
, live_timer_us
);
576 ret
= network_location_set_from_uri_strings(
577 &descriptor
->base
.output
.network
,
578 control_url
, data_url
);
582 return &descriptor
->base
;
584 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
588 void lttng_session_descriptor_destroy(
589 struct lttng_session_descriptor
*descriptor
)
595 switch (descriptor
->output_type
) {
596 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
598 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
599 free(descriptor
->output
.local
);
601 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
602 network_location_fini(&descriptor
->output
.network
);
608 free(descriptor
->name
);
613 ssize_t
lttng_session_descriptor_create_from_buffer(
614 const struct lttng_buffer_view
*payload
,
615 struct lttng_session_descriptor
**descriptor
)
618 ssize_t offset
= 0, ret
;
619 struct lttng_buffer_view current_view
;
620 const char *name
= NULL
;
621 const struct lttng_session_descriptor_comm
*base_header
;
622 size_t max_expected_uri_count
;
623 uint64_t live_timer_us
= 0;
624 struct lttng_uri
*uris
[2] = {};
625 enum lttng_session_descriptor_type type
;
626 enum lttng_session_descriptor_output_type output_type
;
628 current_view
= lttng_buffer_view_from_view(payload
, offset
,
629 sizeof(*base_header
));
630 base_header
= (typeof(base_header
)) current_view
.data
;
636 switch (base_header
->type
) {
637 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
638 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
640 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
642 const struct lttng_session_descriptor_live_comm
*live_header
;
644 current_view
= lttng_buffer_view_from_view(payload
, offset
,
645 sizeof(*live_header
));
646 live_header
= (typeof(live_header
)) current_view
.data
;
652 live_timer_us
= live_header
->live_timer_us
;
659 /* type has been validated. */
660 type
= base_header
->type
;
662 switch (base_header
->output_type
) {
663 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
664 max_expected_uri_count
= 0;
666 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
667 max_expected_uri_count
= 1;
669 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
670 max_expected_uri_count
= 2;
676 /* output_type has been validated. */
677 output_type
= base_header
->output_type
;
679 /* Skip after header. */
680 offset
+= current_view
.size
;
681 if (!base_header
->name_len
) {
686 current_view
= lttng_buffer_view_from_view(payload
, offset
,
687 base_header
->name_len
);
688 name
= current_view
.data
;
694 if (base_header
->name_len
== 1 ||
695 name
[base_header
->name_len
- 1] ||
696 strlen(name
) != base_header
->name_len
- 1) {
698 * Check that the name is not NULL, is NULL-terminated, and
699 * does not contain a NULL before the last byte.
705 /* Skip after the name. */
706 offset
+= base_header
->name_len
;
708 if (base_header
->uri_count
> max_expected_uri_count
) {
713 for (i
= 0; i
< base_header
->uri_count
; i
++) {
714 struct lttng_uri
*uri
;
717 current_view
= lttng_buffer_view_from_view(payload
,
718 offset
, sizeof(*uri
));
719 uri
= (typeof(uri
)) current_view
.data
;
724 uris
[i
] = zmalloc(sizeof(*uri
));
729 memcpy(uris
[i
], uri
, sizeof(*uri
));
730 offset
+= sizeof(*uri
);
734 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
735 switch (output_type
) {
736 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
737 *descriptor
= lttng_session_descriptor_create(name
);
739 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
740 *descriptor
= _lttng_session_descriptor_local_create(
743 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
744 *descriptor
= _lttng_session_descriptor_network_create(
745 name
, uris
[0], uris
[1]);
748 /* Already checked. */
752 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
754 struct lttng_session_descriptor_snapshot
*snapshot
;
755 switch (output_type
) {
756 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
757 snapshot
= _lttng_session_descriptor_snapshot_create(
760 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
761 snapshot
= _lttng_session_descriptor_snapshot_local_create(
764 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
765 snapshot
= _lttng_session_descriptor_snapshot_network_create(
766 name
, uris
[0], uris
[1]);
769 /* Already checked. */
772 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
775 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
777 struct lttng_session_descriptor_live
*live
;
779 switch (output_type
) {
780 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
781 live
= _lttng_session_descriptor_live_create(
782 name
, live_timer_us
);
784 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
785 live
= _lttng_session_descriptor_live_network_create(
786 name
, uris
[0], uris
[1],
789 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
793 /* Already checked. */
796 *descriptor
= live
? &live
->base
: NULL
;
800 /* Already checked. */
803 memset(uris
, 0, sizeof(uris
));
817 int lttng_session_descriptor_serialize(
818 const struct lttng_session_descriptor
*descriptor
,
819 struct lttng_dynamic_buffer
*buffer
)
822 /* There are, at most, two URIs to serialize. */
823 struct lttng_uri
*uris
[2] = {};
824 size_t uri_count
= 0;
825 /* The live header is a superset of all headers. */
826 struct lttng_session_descriptor_live_comm header
= {
827 .base
.type
= (uint8_t) descriptor
->type
,
828 .base
.output_type
= (uint8_t) descriptor
->output_type
,
829 .base
.name_len
= descriptor
->name
?
830 strlen(descriptor
->name
) + 1 : 0,
832 const void *header_ptr
= NULL
;
835 switch (descriptor
->output_type
) {
836 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
838 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
839 uris
[0] = descriptor
->output
.local
;
841 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
842 uris
[0] = descriptor
->output
.network
.control
;
843 uris
[1] = descriptor
->output
.network
.data
;
849 uri_count
+= !!uris
[0];
850 uri_count
+= !!uris
[1];
852 header
.base
.uri_count
= uri_count
;
853 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
854 const struct lttng_session_descriptor_live
*live
=
855 container_of(descriptor
, typeof(*live
),
858 header
.live_timer_us
= live
->live_timer_us
;
859 header_ptr
= &header
;
860 header_size
= sizeof(header
);
862 header_ptr
= &header
.base
;
863 header_size
= sizeof(header
.base
);
866 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
870 if (header
.base
.name_len
) {
871 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
872 header
.base
.name_len
);
878 for (i
= 0; i
< uri_count
; i
++) {
879 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
880 sizeof(struct lttng_uri
));
890 enum lttng_session_descriptor_type
891 lttng_session_descriptor_get_type(
892 const struct lttng_session_descriptor
*descriptor
)
894 return descriptor
->type
;
898 enum lttng_session_descriptor_output_type
899 lttng_session_descriptor_get_output_type(
900 const struct lttng_session_descriptor
*descriptor
)
902 return descriptor
->output_type
;
906 void lttng_session_descriptor_get_local_output_uri(
907 const struct lttng_session_descriptor
*descriptor
,
908 struct lttng_uri
*local_uri
)
910 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
914 void lttng_session_descriptor_get_network_output_uris(
915 const struct lttng_session_descriptor
*descriptor
,
916 struct lttng_uri
*control
,
917 struct lttng_uri
*data
)
919 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
920 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
925 lttng_session_descriptor_live_get_timer_interval(
926 const struct lttng_session_descriptor
*descriptor
)
928 struct lttng_session_descriptor_live
*live
;
930 live
= container_of(descriptor
, typeof(*live
), base
);
931 return live
->live_timer_us
;
934 enum lttng_session_descriptor_status
935 lttng_session_descriptor_get_session_name(
936 const struct lttng_session_descriptor
*descriptor
,
937 const char **session_name
)
939 enum lttng_session_descriptor_status status
;
941 if (!descriptor
|| !session_name
) {
942 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
946 *session_name
= descriptor
->name
;
947 status
= descriptor
->name
?
948 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
949 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
955 int lttng_session_descriptor_set_session_name(
956 struct lttng_session_descriptor
*descriptor
,
965 if (strlen(name
) >= LTTNG_NAME_MAX
) {
969 new_name
= strdup(name
);
974 free(descriptor
->name
);
975 descriptor
->name
= new_name
;
981 bool lttng_session_descriptor_is_output_destination_initialized(
982 const struct lttng_session_descriptor
*descriptor
)
984 switch (descriptor
->output_type
) {
985 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
987 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
988 return descriptor
->output
.local
;
989 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
990 return descriptor
->output
.network
.control
;
997 bool lttng_session_descriptor_has_output_directory(
998 const struct lttng_session_descriptor
*descriptor
)
1000 switch (descriptor
->output_type
) {
1001 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1003 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1004 if (descriptor
->output
.local
) {
1005 return *descriptor
->output
.local
->dst
.path
;
1008 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1009 if (descriptor
->output
.network
.control
) {
1010 return *descriptor
->output
.network
.control
->subdir
;
1020 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1021 struct lttng_session_descriptor
*descriptor
,
1022 time_t *session_creation_time
,
1023 const char *absolute_home_path
)
1025 enum lttng_error_code ret_code
= LTTNG_OK
;
1026 struct lttng_uri
*uris
= NULL
;
1028 switch (descriptor
->output_type
) {
1029 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1031 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1035 char local_uri
[LTTNG_PATH_MAX
];
1036 char creation_datetime_suffix
[17] = {};
1038 if (session_creation_time
) {
1039 size_t strftime_ret
;
1040 struct tm
*timeinfo
;
1042 timeinfo
= localtime(session_creation_time
);
1044 ret_code
= LTTNG_ERR_FATAL
;
1047 strftime_ret
= strftime(creation_datetime_suffix
,
1048 sizeof(creation_datetime_suffix
),
1049 "-%Y%m%d-%H%M%S", timeinfo
);
1050 if (strftime_ret
== 0) {
1051 ERR("Failed to format session creation timestamp while setting default local output destination");
1052 ret_code
= LTTNG_ERR_FATAL
;
1056 assert(descriptor
->name
);
1057 ret
= snprintf(local_uri
, sizeof(local_uri
),
1058 "file://%s/%s/%s%s",
1060 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1061 creation_datetime_suffix
);
1062 if (ret
>= sizeof(local_uri
)) {
1063 ERR("Truncation occurred while setting default local output destination");
1064 ret_code
= LTTNG_ERR_SET_URL
;
1066 } else if (ret
< 0) {
1067 PERROR("Failed to format default local output URI");
1068 ret_code
= LTTNG_ERR_SET_URL
;
1072 uri_ret
= uri_parse(local_uri
, &uris
);
1074 ret_code
= LTTNG_ERR_SET_URL
;
1077 free(descriptor
->output
.local
);
1078 descriptor
->output
.local
= &uris
[0];
1082 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1086 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1088 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1090 ret_code
= LTTNG_ERR_SET_URL
;
1094 control
= uri_copy(&uris
[0]);
1095 data
= uri_copy(&uris
[1]);
1096 if (!control
|| !data
) {
1099 ret_code
= LTTNG_ERR_SET_URL
;
1103 /* Ownership of uris is transferred. */
1104 ret
= network_location_set_from_lttng_uris(
1105 &descriptor
->output
.network
,
1109 ret_code
= LTTNG_ERR_SET_URL
;
1123 * Note that only properties that can be populated by the session daemon
1124 * (output destination and name) are assigned.
1127 int lttng_session_descriptor_assign(
1128 struct lttng_session_descriptor
*dst
,
1129 const struct lttng_session_descriptor
*src
)
1133 if (dst
->type
!= src
->type
) {
1137 if (dst
->output_type
!= src
->output_type
) {
1141 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1145 switch (dst
->output_type
) {
1146 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1147 free(dst
->output
.local
);
1148 dst
->output
.local
= uri_copy(src
->output
.local
);
1149 if (!dst
->output
.local
) {
1154 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1156 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1158 control_copy
= uri_copy(dst
->output
.network
.control
);
1159 if (!control_copy
&& dst
->output
.network
.control
) {
1163 data_copy
= uri_copy(dst
->output
.network
.data
);
1164 if (!data_copy
&& dst
->output
.network
.data
) {
1169 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1170 control_copy
, data_copy
);
1173 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1181 int lttng_session_descriptor_get_base_path(struct lttng_session_descriptor
*dst
,
1182 const char **_base_path
)
1184 switch (dst
->output_type
) {
1185 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1187 if (dst
->output
.network
.control
&&
1188 dst
->output
.network
.control
->subdir
[0]) {
1189 *_base_path
= dst
->output
.network
.control
->subdir
;
1195 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1196 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: