2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
7 #include <lttng/session-descriptor-internal.hpp>
8 #include <common/macros.hpp>
9 #include <common/uri.hpp>
10 #include <common/defaults.hpp>
11 #include <common/error.hpp>
16 struct lttng_session_descriptor_network_location
{
17 struct lttng_uri
*control
;
18 struct lttng_uri
*data
;
22 struct lttng_session_descriptor
{
23 enum lttng_session_descriptor_type type
;
25 * If an output type that is not OUTPUT_TYPE_NONE is specified,
26 * it means that an output of that type must be generated at
27 * session-creation time.
29 enum lttng_session_descriptor_output_type output_type
;
32 struct lttng_session_descriptor_network_location network
;
33 struct lttng_uri
*local
;
38 struct lttng_session_descriptor_snapshot
{
39 struct lttng_session_descriptor base
;
41 * Assumes at-most one snapshot output is supported. Uses
42 * the output field of the base class.
46 struct lttng_session_descriptor_live
{
47 struct lttng_session_descriptor base
;
48 unsigned long long live_timer_us
;
51 struct lttng_session_descriptor_comm
{
52 /* enum lttng_session_descriptor_type */
54 /* enum lttng_session_descriptor_output_type */
56 /* Includes trailing null. */
58 /* Name follows, followed by URIs */
62 struct lttng_session_descriptor_live_comm
{
63 struct lttng_session_descriptor_comm base
;
64 /* Live-specific parameters. */
65 uint64_t live_timer_us
;
70 struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
72 struct lttng_uri
*new_uri
= NULL
;
78 new_uri
= zmalloc
<lttng_uri
>();
82 memcpy(new_uri
, uri
, sizeof(*new_uri
));
88 struct lttng_uri
*uri_from_path(const char *path
)
90 struct lttng_uri
*uris
= NULL
;
92 char local_protocol_string
[LTTNG_PATH_MAX
+ sizeof("file://")] =
95 if (strlen(path
) >= LTTNG_PATH_MAX
) {
100 /* Not an absolute path. */
104 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
105 uri_count
= uri_parse(local_protocol_string
, &uris
);
106 if (uri_count
!= 1) {
109 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
121 void network_location_fini(
122 struct lttng_session_descriptor_network_location
*location
)
124 free(location
->control
);
125 free(location
->data
);
128 /* Assumes ownership of control and data. */
130 int network_location_set_from_lttng_uris(
131 struct lttng_session_descriptor_network_location
*location
,
132 struct lttng_uri
*control
, struct lttng_uri
*data
)
136 if (!control
&& !data
) {
140 if (!(control
&& data
)) {
141 /* None or both must be set. */
146 if (control
->stype
!= LTTNG_STREAM_CONTROL
||
147 data
->stype
!= LTTNG_STREAM_DATA
) {
152 free(location
->control
);
153 free(location
->data
);
154 location
->control
= control
;
155 location
->data
= data
;
165 int network_location_set_from_uri_strings(
166 struct lttng_session_descriptor_network_location
*location
,
167 const char *control
, const char *data
)
171 struct lttng_uri
*parsed_uris
= NULL
;
172 struct lttng_uri
*control_uri
= NULL
;
173 struct lttng_uri
*data_uri
= NULL
;
175 uri_count
= uri_parse_str_urls(control
, data
, &parsed_uris
);
176 if (uri_count
!= 2 && uri_count
!= 0) {
182 * uri_parse_str_urls returns a contiguous array of lttng_uris whereas
183 * session descriptors expect individually allocated lttng_uris.
185 if (uri_count
== 2) {
186 control_uri
= zmalloc
<lttng_uri
>();
187 data_uri
= zmalloc
<lttng_uri
>();
188 if (!control_uri
|| !data_uri
) {
192 memcpy(control_uri
, &parsed_uris
[0], sizeof(*control_uri
));
193 memcpy(data_uri
, &parsed_uris
[1], sizeof(*data_uri
));
196 /* Ownership of control and data uris is transferred. */
197 ret
= network_location_set_from_lttng_uris(
210 struct lttng_session_descriptor
*
211 lttng_session_descriptor_create(const char *name
)
213 struct lttng_session_descriptor
*descriptor
;
215 descriptor
= zmalloc
<lttng_session_descriptor
>();
220 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
221 descriptor
->output_type
=
222 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
223 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
228 lttng_session_descriptor_destroy(descriptor
);
232 /* Ownership of uri is transferred. */
234 struct lttng_session_descriptor
*
235 _lttng_session_descriptor_local_create(const char *name
,
236 struct lttng_uri
*uri
)
238 struct lttng_session_descriptor
*descriptor
;
240 descriptor
= lttng_session_descriptor_create(name
);
244 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
245 descriptor
->output_type
=
246 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
248 if (uri
->dtype
!= LTTNG_DST_PATH
) {
251 descriptor
->output
.local
= uri
;
257 lttng_session_descriptor_destroy(descriptor
);
261 struct lttng_session_descriptor
*
262 lttng_session_descriptor_local_create(const char *name
, const char *path
)
264 struct lttng_uri
*uri
= NULL
;
265 struct lttng_session_descriptor
*descriptor
;
268 uri
= uri_from_path(path
);
273 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
279 /* Assumes the ownership of both uris. */
281 struct lttng_session_descriptor
*
282 _lttng_session_descriptor_network_create(const char *name
,
283 struct lttng_uri
*control
, struct lttng_uri
*data
)
286 struct lttng_session_descriptor
*descriptor
;
288 descriptor
= lttng_session_descriptor_create(name
);
293 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
294 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
295 /* Assumes the ownership of both uris. */
296 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
,
305 lttng_session_descriptor_destroy(descriptor
);
311 struct lttng_session_descriptor
*
312 lttng_session_descriptor_network_create(const char *name
,
313 const char *control_url
, const char *data_url
)
316 struct lttng_session_descriptor
*descriptor
;
318 descriptor
= _lttng_session_descriptor_network_create(name
,
324 ret
= network_location_set_from_uri_strings(&descriptor
->output
.network
,
325 control_url
, data_url
);
331 lttng_session_descriptor_destroy(descriptor
);
336 struct lttng_session_descriptor_snapshot
*
337 _lttng_session_descriptor_snapshot_create(const char *name
)
339 struct lttng_session_descriptor_snapshot
*descriptor
;
341 descriptor
= zmalloc
<lttng_session_descriptor_snapshot
>();
346 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
347 descriptor
->base
.output_type
=
348 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
349 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
355 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
359 /* Ownership of control and data is transferred. */
361 struct lttng_session_descriptor_snapshot
*
362 _lttng_session_descriptor_snapshot_network_create(const char *name
,
363 struct lttng_uri
*control
, struct lttng_uri
*data
)
366 struct lttng_session_descriptor_snapshot
*descriptor
;
368 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
373 descriptor
->base
.output_type
=
374 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
375 /* Ownership of control and data is transferred. */
376 ret
= network_location_set_from_lttng_uris(
377 &descriptor
->base
.output
.network
,
388 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
392 struct lttng_session_descriptor
*
393 lttng_session_descriptor_snapshot_create(const char *name
)
395 struct lttng_session_descriptor_snapshot
*descriptor
;
397 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
398 return descriptor
? &descriptor
->base
: NULL
;
401 struct lttng_session_descriptor
*
402 lttng_session_descriptor_snapshot_network_create(const char *name
,
403 const char *control_url
, const char *data_url
)
406 struct lttng_session_descriptor_snapshot
*descriptor
;
408 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
,
414 ret
= network_location_set_from_uri_strings(
415 &descriptor
->base
.output
.network
,
416 control_url
, data_url
);
420 return &descriptor
->base
;
422 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
426 /* Ownership of uri is transferred. */
428 struct lttng_session_descriptor_snapshot
*
429 _lttng_session_descriptor_snapshot_local_create(const char *name
,
430 struct lttng_uri
*uri
)
432 struct lttng_session_descriptor_snapshot
*descriptor
;
434 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
438 descriptor
->base
.output_type
=
439 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
441 if (uri
->dtype
!= LTTNG_DST_PATH
) {
444 descriptor
->base
.output
.local
= uri
;
450 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
454 struct lttng_session_descriptor
*
455 lttng_session_descriptor_snapshot_local_create(const char *name
,
458 struct lttng_uri
*path_uri
= NULL
;
459 struct lttng_session_descriptor_snapshot
*descriptor
;
462 path_uri
= uri_from_path(path
);
467 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
,
469 return descriptor
? &descriptor
->base
: NULL
;
475 struct lttng_session_descriptor_live
*
476 _lttng_session_descriptor_live_create(const char *name
,
477 unsigned long long live_timer_interval_us
)
479 struct lttng_session_descriptor_live
*descriptor
= NULL
;
481 if (live_timer_interval_us
== 0) {
484 descriptor
= zmalloc
<lttng_session_descriptor_live
>();
489 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
490 descriptor
->base
.output_type
=
491 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
492 descriptor
->live_timer_us
= live_timer_interval_us
;
493 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
500 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
504 /* Ownership of control and data is transferred. */
506 struct lttng_session_descriptor_live
*
507 _lttng_session_descriptor_live_network_create(
509 struct lttng_uri
*control
, struct lttng_uri
*data
,
510 unsigned long long live_timer_interval_us
)
513 struct lttng_session_descriptor_live
*descriptor
;
515 descriptor
= _lttng_session_descriptor_live_create(name
,
516 live_timer_interval_us
);
521 descriptor
->base
.output_type
=
522 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
524 /* Ownerwhip of control and data is transferred. */
525 ret
= network_location_set_from_lttng_uris(
526 &descriptor
->base
.output
.network
,
537 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
541 struct lttng_session_descriptor
*
542 lttng_session_descriptor_live_create(
544 unsigned long long live_timer_us
)
546 struct lttng_session_descriptor_live
*descriptor
;
548 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
550 return descriptor
? &descriptor
->base
: NULL
;
553 struct lttng_session_descriptor
*
554 lttng_session_descriptor_live_network_create(
556 const char *control_url
, const char *data_url
,
557 unsigned long long live_timer_us
)
560 struct lttng_session_descriptor_live
*descriptor
;
562 descriptor
= _lttng_session_descriptor_live_network_create(name
,
563 NULL
, NULL
, live_timer_us
);
568 ret
= network_location_set_from_uri_strings(
569 &descriptor
->base
.output
.network
,
570 control_url
, data_url
);
574 return &descriptor
->base
;
576 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
580 void lttng_session_descriptor_destroy(
581 struct lttng_session_descriptor
*descriptor
)
587 switch (descriptor
->output_type
) {
588 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
590 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
591 free(descriptor
->output
.local
);
593 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
594 network_location_fini(&descriptor
->output
.network
);
600 free(descriptor
->name
);
604 ssize_t
lttng_session_descriptor_create_from_buffer(
605 const struct lttng_buffer_view
*payload
,
606 struct lttng_session_descriptor
**descriptor
)
609 ssize_t offset
= 0, ret
;
610 struct lttng_buffer_view current_view
;
611 const char *name
= NULL
;
612 const struct lttng_session_descriptor_comm
*base_header
;
613 size_t max_expected_uri_count
;
614 uint64_t live_timer_us
= 0;
615 struct lttng_uri
*uris
[2] = {};
616 enum lttng_session_descriptor_type type
;
617 enum lttng_session_descriptor_output_type output_type
;
619 current_view
= lttng_buffer_view_from_view(payload
, offset
,
620 sizeof(*base_header
));
621 if (!lttng_buffer_view_is_valid(¤t_view
)) {
626 base_header
= (typeof(base_header
)) current_view
.data
;
627 switch (base_header
->type
) {
628 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
629 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
631 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
633 const struct lttng_session_descriptor_live_comm
*live_header
;
635 current_view
= lttng_buffer_view_from_view(payload
, offset
,
636 sizeof(*live_header
));
637 if (!lttng_buffer_view_is_valid(¤t_view
)) {
642 live_header
= (typeof(live_header
)) current_view
.data
;
643 live_timer_us
= live_header
->live_timer_us
;
650 /* type has been validated. */
651 type
= (lttng_session_descriptor_type
) base_header
->type
;
653 switch (base_header
->output_type
) {
654 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
655 max_expected_uri_count
= 0;
657 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
658 max_expected_uri_count
= 1;
660 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
661 max_expected_uri_count
= 2;
667 /* output_type has been validated. */
668 output_type
= (lttng_session_descriptor_output_type
) base_header
->output_type
;
670 /* Skip after header. */
671 offset
+= current_view
.size
;
672 if (!base_header
->name_len
) {
677 current_view
= lttng_buffer_view_from_view(payload
, offset
,
678 base_header
->name_len
);
679 if (!lttng_buffer_view_is_valid(¤t_view
)) {
684 name
= current_view
.data
;
685 if (base_header
->name_len
== 1 ||
686 name
[base_header
->name_len
- 1] ||
687 strlen(name
) != base_header
->name_len
- 1) {
689 * Check that the name is not NULL, is NULL-terminated, and
690 * does not contain a NULL before the last byte.
696 /* Skip after the name. */
697 offset
+= base_header
->name_len
;
699 if (base_header
->uri_count
> max_expected_uri_count
) {
704 for (i
= 0; i
< base_header
->uri_count
; i
++) {
705 struct lttng_uri
*uri
;
708 current_view
= lttng_buffer_view_from_view(payload
,
709 offset
, sizeof(*uri
));
710 if (!lttng_buffer_view_is_valid(¤t_view
)) {
715 uri
= (typeof(uri
)) current_view
.data
;
716 uris
[i
] = zmalloc
<lttng_uri
>();
721 memcpy(uris
[i
], uri
, sizeof(*uri
));
722 offset
+= sizeof(*uri
);
726 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
727 switch (output_type
) {
728 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
729 *descriptor
= lttng_session_descriptor_create(name
);
731 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
732 *descriptor
= _lttng_session_descriptor_local_create(
735 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
736 *descriptor
= _lttng_session_descriptor_network_create(
737 name
, uris
[0], uris
[1]);
740 /* Already checked. */
744 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
746 struct lttng_session_descriptor_snapshot
*snapshot
;
747 switch (output_type
) {
748 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
749 snapshot
= _lttng_session_descriptor_snapshot_create(
752 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
753 snapshot
= _lttng_session_descriptor_snapshot_local_create(
756 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
757 snapshot
= _lttng_session_descriptor_snapshot_network_create(
758 name
, uris
[0], uris
[1]);
761 /* Already checked. */
764 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
767 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
769 struct lttng_session_descriptor_live
*live
;
771 switch (output_type
) {
772 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
773 live
= _lttng_session_descriptor_live_create(
774 name
, live_timer_us
);
776 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
777 live
= _lttng_session_descriptor_live_network_create(
778 name
, uris
[0], uris
[1],
781 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
785 /* Already checked. */
788 *descriptor
= live
? &live
->base
: NULL
;
792 /* Already checked. */
795 memset(uris
, 0, sizeof(uris
));
808 int lttng_session_descriptor_serialize(
809 const struct lttng_session_descriptor
*descriptor
,
810 struct lttng_dynamic_buffer
*buffer
)
813 /* There are, at most, two URIs to serialize. */
814 struct lttng_uri
*uris
[2] = {};
815 size_t uri_count
= 0;
816 /* The live header is a superset of all headers. */
817 struct lttng_session_descriptor_live_comm header
= {
819 .type
= (uint8_t) descriptor
->type
,
820 .output_type
= (uint8_t) descriptor
->output_type
,
821 .name_len
= (uint32_t) (descriptor
->name
?
822 strlen(descriptor
->name
) + 1 : 0),
828 const void *header_ptr
= NULL
;
831 switch (descriptor
->output_type
) {
832 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
834 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
835 uris
[0] = descriptor
->output
.local
;
837 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
838 uris
[0] = descriptor
->output
.network
.control
;
839 uris
[1] = descriptor
->output
.network
.data
;
845 uri_count
+= !!uris
[0];
846 uri_count
+= !!uris
[1];
848 header
.base
.uri_count
= uri_count
;
849 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
850 const struct lttng_session_descriptor_live
*live
=
851 container_of(descriptor
, typeof(*live
),
854 header
.live_timer_us
= live
->live_timer_us
;
855 header_ptr
= &header
;
856 header_size
= sizeof(header
);
858 header_ptr
= &header
.base
;
859 header_size
= sizeof(header
.base
);
862 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
866 if (header
.base
.name_len
) {
867 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
868 header
.base
.name_len
);
874 for (i
= 0; i
< uri_count
; i
++) {
875 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
876 sizeof(struct lttng_uri
));
885 enum lttng_session_descriptor_type
886 lttng_session_descriptor_get_type(
887 const struct lttng_session_descriptor
*descriptor
)
889 return descriptor
->type
;
892 enum lttng_session_descriptor_output_type
893 lttng_session_descriptor_get_output_type(
894 const struct lttng_session_descriptor
*descriptor
)
896 return descriptor
->output_type
;
899 void lttng_session_descriptor_get_local_output_uri(
900 const struct lttng_session_descriptor
*descriptor
,
901 struct lttng_uri
*local_uri
)
903 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
906 void lttng_session_descriptor_get_network_output_uris(
907 const struct lttng_session_descriptor
*descriptor
,
908 struct lttng_uri
*control
,
909 struct lttng_uri
*data
)
911 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
912 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
916 lttng_session_descriptor_live_get_timer_interval(
917 const struct lttng_session_descriptor
*descriptor
)
919 struct lttng_session_descriptor_live
*live
;
921 live
= container_of(descriptor
, typeof(*live
), base
);
922 return live
->live_timer_us
;
925 enum lttng_session_descriptor_status
926 lttng_session_descriptor_get_session_name(
927 const struct lttng_session_descriptor
*descriptor
,
928 const char **session_name
)
930 enum lttng_session_descriptor_status status
;
932 if (!descriptor
|| !session_name
) {
933 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
937 *session_name
= descriptor
->name
;
938 status
= descriptor
->name
?
939 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
940 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
945 int lttng_session_descriptor_set_session_name(
946 struct lttng_session_descriptor
*descriptor
,
955 if (strlen(name
) >= LTTNG_NAME_MAX
) {
959 new_name
= strdup(name
);
964 free(descriptor
->name
);
965 descriptor
->name
= new_name
;
970 bool lttng_session_descriptor_is_output_destination_initialized(
971 const struct lttng_session_descriptor
*descriptor
)
973 switch (descriptor
->output_type
) {
974 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
976 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
977 return descriptor
->output
.local
;
978 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
979 return descriptor
->output
.network
.control
;
985 bool lttng_session_descriptor_has_output_directory(
986 const struct lttng_session_descriptor
*descriptor
)
988 switch (descriptor
->output_type
) {
989 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
991 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
992 if (descriptor
->output
.local
) {
993 return *descriptor
->output
.local
->dst
.path
;
996 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
997 if (descriptor
->output
.network
.control
) {
998 return *descriptor
->output
.network
.control
->subdir
;
1007 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1008 struct lttng_session_descriptor
*descriptor
,
1009 time_t *session_creation_time
,
1010 const char *absolute_home_path
)
1012 enum lttng_error_code ret_code
= LTTNG_OK
;
1013 struct lttng_uri
*uris
= NULL
;
1015 switch (descriptor
->output_type
) {
1016 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1018 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1022 char local_uri
[LTTNG_PATH_MAX
];
1023 char creation_datetime_suffix
[17] = {};
1025 if (session_creation_time
) {
1026 size_t strftime_ret
;
1027 struct tm
*timeinfo
;
1029 timeinfo
= localtime(session_creation_time
);
1031 ret_code
= LTTNG_ERR_FATAL
;
1034 strftime_ret
= strftime(creation_datetime_suffix
,
1035 sizeof(creation_datetime_suffix
),
1036 "-%Y%m%d-%H%M%S", timeinfo
);
1037 if (strftime_ret
== 0) {
1038 ERR("Failed to format session creation timestamp while setting default local output destination");
1039 ret_code
= LTTNG_ERR_FATAL
;
1043 LTTNG_ASSERT(descriptor
->name
);
1044 ret
= snprintf(local_uri
, sizeof(local_uri
),
1045 "file://%s/%s/%s%s",
1047 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1048 creation_datetime_suffix
);
1049 if (ret
>= sizeof(local_uri
)) {
1050 ERR("Truncation occurred while setting default local output destination");
1051 ret_code
= LTTNG_ERR_SET_URL
;
1053 } else if (ret
< 0) {
1054 PERROR("Failed to format default local output URI");
1055 ret_code
= LTTNG_ERR_SET_URL
;
1059 uri_ret
= uri_parse(local_uri
, &uris
);
1061 ret_code
= LTTNG_ERR_SET_URL
;
1064 free(descriptor
->output
.local
);
1065 descriptor
->output
.local
= &uris
[0];
1069 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1073 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1075 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1077 ret_code
= LTTNG_ERR_SET_URL
;
1081 control
= uri_copy(&uris
[0]);
1082 data
= uri_copy(&uris
[1]);
1083 if (!control
|| !data
) {
1086 ret_code
= LTTNG_ERR_SET_URL
;
1090 /* Ownership of uris is transferred. */
1091 ret
= network_location_set_from_lttng_uris(
1092 &descriptor
->output
.network
,
1096 ret_code
= LTTNG_ERR_SET_URL
;
1110 * Note that only properties that can be populated by the session daemon
1111 * (output destination and name) are assigned.
1113 int lttng_session_descriptor_assign(
1114 struct lttng_session_descriptor
*dst
,
1115 const struct lttng_session_descriptor
*src
)
1119 if (dst
->type
!= src
->type
) {
1123 if (dst
->output_type
!= src
->output_type
) {
1127 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1131 switch (dst
->output_type
) {
1132 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1133 free(dst
->output
.local
);
1134 dst
->output
.local
= uri_copy(src
->output
.local
);
1135 if (!dst
->output
.local
) {
1140 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1142 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1144 control_copy
= uri_copy(dst
->output
.network
.control
);
1145 if (!control_copy
&& dst
->output
.network
.control
) {
1149 data_copy
= uri_copy(dst
->output
.network
.data
);
1150 if (!data_copy
&& dst
->output
.network
.data
) {
1155 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1156 control_copy
, data_copy
);
1159 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: