2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
7 #include <common/defaults.hpp>
8 #include <common/error.hpp>
9 #include <common/macros.hpp>
10 #include <common/uri.hpp>
12 #include <lttng/session-descriptor-internal.hpp>
18 struct lttng_session_descriptor_network_location
{
19 struct lttng_uri
*control
;
20 struct lttng_uri
*data
;
24 struct lttng_session_descriptor
{
25 enum lttng_session_descriptor_type type
;
27 * If an output type that is not OUTPUT_TYPE_NONE is specified,
28 * it means that an output of that type must be generated at
29 * session-creation time.
31 enum lttng_session_descriptor_output_type output_type
;
34 struct lttng_session_descriptor_network_location network
;
35 struct lttng_uri
*local
;
40 struct lttng_session_descriptor_snapshot
{
41 struct lttng_session_descriptor base
;
43 * Assumes at-most one snapshot output is supported. Uses
44 * the output field of the base class.
48 struct lttng_session_descriptor_live
{
49 struct lttng_session_descriptor base
;
50 unsigned long long live_timer_us
;
53 struct lttng_session_descriptor_comm
{
54 /* enum lttng_session_descriptor_type */
56 /* enum lttng_session_descriptor_output_type */
58 /* Includes trailing null. */
60 /* Name follows, followed by URIs */
64 struct lttng_session_descriptor_live_comm
{
65 struct lttng_session_descriptor_comm base
;
66 /* Live-specific parameters. */
67 uint64_t live_timer_us
;
71 static struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
73 struct lttng_uri
*new_uri
= NULL
;
79 new_uri
= zmalloc
<lttng_uri
>();
83 memcpy(new_uri
, uri
, sizeof(*new_uri
));
88 static 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://")] = "file://";
94 if (strlen(path
) >= LTTNG_PATH_MAX
) {
99 /* Not an absolute path. */
103 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
104 uri_count
= uri_parse(local_protocol_string
, &uris
);
105 if (uri_count
!= 1) {
108 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
119 static void network_location_fini(struct lttng_session_descriptor_network_location
*location
)
121 free(location
->control
);
122 free(location
->data
);
125 /* Assumes ownership of control and data. */
127 network_location_set_from_lttng_uris(struct lttng_session_descriptor_network_location
*location
,
128 struct lttng_uri
*control
,
129 struct lttng_uri
*data
)
133 if (!control
&& !data
) {
137 if (!(control
&& data
)) {
138 /* None or both must be set. */
143 if (control
->stype
!= LTTNG_STREAM_CONTROL
|| data
->stype
!= LTTNG_STREAM_DATA
) {
148 free(location
->control
);
149 free(location
->data
);
150 location
->control
= control
;
151 location
->data
= data
;
161 network_location_set_from_uri_strings(struct lttng_session_descriptor_network_location
*location
,
167 struct lttng_uri
*parsed_uris
= NULL
;
168 struct lttng_uri
*control_uri
= NULL
;
169 struct lttng_uri
*data_uri
= NULL
;
171 uri_count
= uri_parse_str_urls(control
, data
, &parsed_uris
);
172 if (uri_count
!= 2 && uri_count
!= 0) {
178 * uri_parse_str_urls returns a contiguous array of lttng_uris whereas
179 * session descriptors expect individually allocated lttng_uris.
181 if (uri_count
== 2) {
182 control_uri
= zmalloc
<lttng_uri
>();
183 data_uri
= zmalloc
<lttng_uri
>();
184 if (!control_uri
|| !data_uri
) {
188 memcpy(control_uri
, &parsed_uris
[0], sizeof(*control_uri
));
189 memcpy(data_uri
, &parsed_uris
[1], sizeof(*data_uri
));
192 /* Ownership of control and data uris is transferred. */
193 ret
= network_location_set_from_lttng_uris(location
, control_uri
, data_uri
);
203 struct lttng_session_descriptor
*lttng_session_descriptor_create(const char *name
)
205 struct lttng_session_descriptor
*descriptor
;
207 descriptor
= zmalloc
<lttng_session_descriptor
>();
212 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
213 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
214 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
219 lttng_session_descriptor_destroy(descriptor
);
223 /* Ownership of uri is transferred. */
224 static struct lttng_session_descriptor
*
225 _lttng_session_descriptor_local_create(const char *name
, struct lttng_uri
*uri
)
227 struct lttng_session_descriptor
*descriptor
;
229 descriptor
= lttng_session_descriptor_create(name
);
233 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
234 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
236 if (uri
->dtype
!= LTTNG_DST_PATH
) {
239 descriptor
->output
.local
= uri
;
245 lttng_session_descriptor_destroy(descriptor
);
249 struct lttng_session_descriptor
*lttng_session_descriptor_local_create(const char *name
,
252 struct lttng_uri
*uri
= NULL
;
253 struct lttng_session_descriptor
*descriptor
;
256 uri
= uri_from_path(path
);
261 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
267 /* Assumes the ownership of both uris. */
268 static struct lttng_session_descriptor
*_lttng_session_descriptor_network_create(
269 const char *name
, struct lttng_uri
*control
, struct lttng_uri
*data
)
272 struct lttng_session_descriptor
*descriptor
;
274 descriptor
= lttng_session_descriptor_create(name
);
279 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
280 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
281 /* Assumes the ownership of both uris. */
282 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
, control
, data
);
290 lttng_session_descriptor_destroy(descriptor
);
296 struct lttng_session_descriptor
*lttng_session_descriptor_network_create(const char *name
,
297 const char *control_url
,
298 const char *data_url
)
301 struct lttng_session_descriptor
*descriptor
;
303 descriptor
= _lttng_session_descriptor_network_create(name
, NULL
, NULL
);
308 ret
= network_location_set_from_uri_strings(
309 &descriptor
->output
.network
, control_url
, data_url
);
315 lttng_session_descriptor_destroy(descriptor
);
319 static struct lttng_session_descriptor_snapshot
*
320 _lttng_session_descriptor_snapshot_create(const char *name
)
322 struct lttng_session_descriptor_snapshot
*descriptor
;
324 descriptor
= zmalloc
<lttng_session_descriptor_snapshot
>();
329 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
330 descriptor
->base
.output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
331 if (lttng_session_descriptor_set_session_name(&descriptor
->base
, name
)) {
336 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
340 /* Ownership of control and data is transferred. */
341 static struct lttng_session_descriptor_snapshot
*_lttng_session_descriptor_snapshot_network_create(
342 const char *name
, struct lttng_uri
*control
, struct lttng_uri
*data
)
345 struct lttng_session_descriptor_snapshot
*descriptor
;
347 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
352 descriptor
->base
.output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
353 /* Ownership of control and data is transferred. */
354 ret
= network_location_set_from_lttng_uris(&descriptor
->base
.output
.network
, control
, data
);
364 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
368 struct lttng_session_descriptor
*lttng_session_descriptor_snapshot_create(const char *name
)
370 struct lttng_session_descriptor_snapshot
*descriptor
;
372 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
373 return descriptor
? &descriptor
->base
: NULL
;
376 struct lttng_session_descriptor
*lttng_session_descriptor_snapshot_network_create(
377 const char *name
, const char *control_url
, const char *data_url
)
380 struct lttng_session_descriptor_snapshot
*descriptor
;
382 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
, NULL
, NULL
);
387 ret
= network_location_set_from_uri_strings(
388 &descriptor
->base
.output
.network
, control_url
, data_url
);
392 return &descriptor
->base
;
394 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
398 /* Ownership of uri is transferred. */
399 static struct lttng_session_descriptor_snapshot
*
400 _lttng_session_descriptor_snapshot_local_create(const char *name
, struct lttng_uri
*uri
)
402 struct lttng_session_descriptor_snapshot
*descriptor
;
404 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
408 descriptor
->base
.output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
410 if (uri
->dtype
!= LTTNG_DST_PATH
) {
413 descriptor
->base
.output
.local
= uri
;
419 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
423 struct lttng_session_descriptor
*lttng_session_descriptor_snapshot_local_create(const char *name
,
426 struct lttng_uri
*path_uri
= NULL
;
427 struct lttng_session_descriptor_snapshot
*descriptor
;
430 path_uri
= uri_from_path(path
);
435 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
, path_uri
);
436 return descriptor
? &descriptor
->base
: NULL
;
441 static struct lttng_session_descriptor_live
*
442 _lttng_session_descriptor_live_create(const char *name
, unsigned long long live_timer_interval_us
)
444 struct lttng_session_descriptor_live
*descriptor
= NULL
;
446 if (live_timer_interval_us
== 0) {
449 descriptor
= zmalloc
<lttng_session_descriptor_live
>();
454 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
455 descriptor
->base
.output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
456 descriptor
->live_timer_us
= live_timer_interval_us
;
457 if (lttng_session_descriptor_set_session_name(&descriptor
->base
, name
)) {
463 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
467 /* Ownership of control and data is transferred. */
468 static struct lttng_session_descriptor_live
*
469 _lttng_session_descriptor_live_network_create(const char *name
,
470 struct lttng_uri
*control
,
471 struct lttng_uri
*data
,
472 unsigned long long live_timer_interval_us
)
475 struct lttng_session_descriptor_live
*descriptor
;
477 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_interval_us
);
482 descriptor
->base
.output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
484 /* Ownerwhip of control and data is transferred. */
485 ret
= network_location_set_from_lttng_uris(&descriptor
->base
.output
.network
, control
, data
);
495 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
499 struct lttng_session_descriptor
*
500 lttng_session_descriptor_live_create(const char *name
, unsigned long long live_timer_us
)
502 struct lttng_session_descriptor_live
*descriptor
;
504 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
506 return descriptor
? &descriptor
->base
: NULL
;
509 struct lttng_session_descriptor
*
510 lttng_session_descriptor_live_network_create(const char *name
,
511 const char *control_url
,
512 const char *data_url
,
513 unsigned long long live_timer_us
)
516 struct lttng_session_descriptor_live
*descriptor
;
518 descriptor
= _lttng_session_descriptor_live_network_create(name
, NULL
, NULL
, live_timer_us
);
523 ret
= network_location_set_from_uri_strings(
524 &descriptor
->base
.output
.network
, control_url
, data_url
);
528 return &descriptor
->base
;
530 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
534 void lttng_session_descriptor_destroy(struct lttng_session_descriptor
*descriptor
)
540 switch (descriptor
->output_type
) {
541 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
543 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
544 free(descriptor
->output
.local
);
546 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
547 network_location_fini(&descriptor
->output
.network
);
553 free(descriptor
->name
);
557 ssize_t
lttng_session_descriptor_create_from_buffer(const struct lttng_buffer_view
*payload
,
558 struct lttng_session_descriptor
**descriptor
)
561 ssize_t offset
= 0, ret
;
562 struct lttng_buffer_view current_view
;
563 const char *name
= NULL
;
564 const struct lttng_session_descriptor_comm
*base_header
;
565 size_t max_expected_uri_count
;
566 uint64_t live_timer_us
= 0;
567 struct lttng_uri
*uris
[2] = {};
568 enum lttng_session_descriptor_type type
;
569 enum lttng_session_descriptor_output_type output_type
;
571 current_view
= lttng_buffer_view_from_view(payload
, offset
, sizeof(*base_header
));
572 if (!lttng_buffer_view_is_valid(¤t_view
)) {
577 base_header
= (typeof(base_header
)) current_view
.data
;
578 switch (base_header
->type
) {
579 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
580 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
582 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
584 const struct lttng_session_descriptor_live_comm
*live_header
;
586 current_view
= lttng_buffer_view_from_view(payload
, offset
, sizeof(*live_header
));
587 if (!lttng_buffer_view_is_valid(¤t_view
)) {
592 live_header
= (typeof(live_header
)) current_view
.data
;
593 live_timer_us
= live_header
->live_timer_us
;
600 /* type has been validated. */
601 type
= (lttng_session_descriptor_type
) base_header
->type
;
603 switch (base_header
->output_type
) {
604 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
605 max_expected_uri_count
= 0;
607 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
608 max_expected_uri_count
= 1;
610 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
611 max_expected_uri_count
= 2;
617 /* output_type has been validated. */
618 output_type
= (lttng_session_descriptor_output_type
) base_header
->output_type
;
620 /* Skip after header. */
621 offset
+= current_view
.size
;
622 if (!base_header
->name_len
) {
627 current_view
= lttng_buffer_view_from_view(payload
, offset
, base_header
->name_len
);
628 if (!lttng_buffer_view_is_valid(¤t_view
)) {
633 name
= current_view
.data
;
634 if (base_header
->name_len
== 1 || name
[base_header
->name_len
- 1] ||
635 strlen(name
) != base_header
->name_len
- 1) {
637 * Check that the name is not NULL, is NULL-terminated, and
638 * does not contain a NULL before the last byte.
644 /* Skip after the name. */
645 offset
+= base_header
->name_len
;
647 if (base_header
->uri_count
> max_expected_uri_count
) {
652 for (i
= 0; i
< base_header
->uri_count
; i
++) {
653 struct lttng_uri
*uri
;
656 current_view
= lttng_buffer_view_from_view(payload
, offset
, sizeof(*uri
));
657 if (!lttng_buffer_view_is_valid(¤t_view
)) {
662 uri
= (typeof(uri
)) current_view
.data
;
663 uris
[i
] = zmalloc
<lttng_uri
>();
668 memcpy(uris
[i
], uri
, sizeof(*uri
));
669 offset
+= sizeof(*uri
);
673 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
674 switch (output_type
) {
675 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
676 *descriptor
= lttng_session_descriptor_create(name
);
678 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
679 *descriptor
= _lttng_session_descriptor_local_create(name
, uris
[0]);
681 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
683 _lttng_session_descriptor_network_create(name
, uris
[0], uris
[1]);
686 /* Already checked. */
690 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
692 struct lttng_session_descriptor_snapshot
*snapshot
;
693 switch (output_type
) {
694 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
695 snapshot
= _lttng_session_descriptor_snapshot_create(name
);
697 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
698 snapshot
= _lttng_session_descriptor_snapshot_local_create(name
, uris
[0]);
700 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
701 snapshot
= _lttng_session_descriptor_snapshot_network_create(
702 name
, uris
[0], uris
[1]);
705 /* Already checked. */
708 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
711 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
713 struct lttng_session_descriptor_live
*live
;
715 switch (output_type
) {
716 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
717 live
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
719 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
720 live
= _lttng_session_descriptor_live_network_create(
721 name
, uris
[0], uris
[1], live_timer_us
);
723 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
727 /* Already checked. */
730 *descriptor
= live
? &live
->base
: NULL
;
734 /* Already checked. */
737 memset(uris
, 0, sizeof(uris
));
750 int lttng_session_descriptor_serialize(const struct lttng_session_descriptor
*descriptor
,
751 struct lttng_dynamic_buffer
*buffer
)
754 /* There are, at most, two URIs to serialize. */
755 struct lttng_uri
*uris
[2] = {};
756 size_t uri_count
= 0;
757 /* The live header is a superset of all headers. */
758 struct lttng_session_descriptor_live_comm header
= {
760 .type
= (uint8_t) descriptor
->type
,
761 .output_type
= (uint8_t) descriptor
->output_type
,
762 .name_len
= (uint32_t) (descriptor
->name
?
763 strlen(descriptor
->name
) + 1 : 0),
769 const void *header_ptr
= NULL
;
772 switch (descriptor
->output_type
) {
773 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
775 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
776 uris
[0] = descriptor
->output
.local
;
778 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
779 uris
[0] = descriptor
->output
.network
.control
;
780 uris
[1] = descriptor
->output
.network
.data
;
786 uri_count
+= !!uris
[0];
787 uri_count
+= !!uris
[1];
789 header
.base
.uri_count
= uri_count
;
790 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
791 const struct lttng_session_descriptor_live
*live
= lttng::utils::container_of(
792 descriptor
, <tng_session_descriptor_live::base
);
794 header
.live_timer_us
= live
->live_timer_us
;
795 header_ptr
= &header
;
796 header_size
= sizeof(header
);
798 header_ptr
= &header
.base
;
799 header_size
= sizeof(header
.base
);
802 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
806 if (header
.base
.name_len
) {
807 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
, header
.base
.name_len
);
813 for (i
= 0; i
< uri_count
; i
++) {
814 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
], sizeof(struct lttng_uri
));
823 enum lttng_session_descriptor_type
824 lttng_session_descriptor_get_type(const struct lttng_session_descriptor
*descriptor
)
826 return descriptor
->type
;
829 enum lttng_session_descriptor_output_type
830 lttng_session_descriptor_get_output_type(const struct lttng_session_descriptor
*descriptor
)
832 return descriptor
->output_type
;
835 void lttng_session_descriptor_get_local_output_uri(
836 const struct lttng_session_descriptor
*descriptor
, struct lttng_uri
*local_uri
)
838 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
841 void lttng_session_descriptor_get_network_output_uris(
842 const struct lttng_session_descriptor
*descriptor
,
843 struct lttng_uri
*control
,
844 struct lttng_uri
*data
)
846 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
847 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
851 lttng_session_descriptor_live_get_timer_interval(const struct lttng_session_descriptor
*descriptor
)
853 struct lttng_session_descriptor_live
*live
;
855 live
= lttng::utils::container_of(descriptor
, <tng_session_descriptor_live::base
);
856 return live
->live_timer_us
;
859 enum lttng_session_descriptor_status
860 lttng_session_descriptor_get_session_name(const struct lttng_session_descriptor
*descriptor
,
861 const char **session_name
)
863 enum lttng_session_descriptor_status status
;
865 if (!descriptor
|| !session_name
) {
866 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
870 *session_name
= descriptor
->name
;
871 status
= descriptor
->name
? LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
872 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
877 int lttng_session_descriptor_set_session_name(struct lttng_session_descriptor
*descriptor
,
886 if (strlen(name
) >= LTTNG_NAME_MAX
) {
890 new_name
= strdup(name
);
895 free(descriptor
->name
);
896 descriptor
->name
= new_name
;
901 bool lttng_session_descriptor_is_output_destination_initialized(
902 const struct lttng_session_descriptor
*descriptor
)
904 switch (descriptor
->output_type
) {
905 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
907 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
908 return descriptor
->output
.local
;
909 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
910 return descriptor
->output
.network
.control
;
916 bool lttng_session_descriptor_has_output_directory(const struct lttng_session_descriptor
*descriptor
)
918 switch (descriptor
->output_type
) {
919 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
921 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
922 if (descriptor
->output
.local
) {
923 return *descriptor
->output
.local
->dst
.path
;
926 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
927 if (descriptor
->output
.network
.control
) {
928 return *descriptor
->output
.network
.control
->subdir
;
937 enum lttng_error_code
938 lttng_session_descriptor_set_default_output(struct lttng_session_descriptor
*descriptor
,
939 time_t *session_creation_time
,
940 const char *absolute_home_path
)
942 enum lttng_error_code ret_code
= LTTNG_OK
;
943 struct lttng_uri
*uris
= NULL
;
945 switch (descriptor
->output_type
) {
946 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
948 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
952 char local_uri
[LTTNG_PATH_MAX
];
953 char creation_datetime_suffix
[17] = {};
955 if (session_creation_time
) {
959 timeinfo
= localtime(session_creation_time
);
961 ret_code
= LTTNG_ERR_FATAL
;
964 strftime_ret
= strftime(creation_datetime_suffix
,
965 sizeof(creation_datetime_suffix
),
968 if (strftime_ret
== 0) {
969 ERR("Failed to format session creation timestamp while setting default local output destination");
970 ret_code
= LTTNG_ERR_FATAL
;
974 LTTNG_ASSERT(descriptor
->name
);
975 ret
= snprintf(local_uri
,
979 DEFAULT_TRACE_DIR_NAME
,
981 creation_datetime_suffix
);
982 if (ret
>= sizeof(local_uri
)) {
983 ERR("Truncation occurred while setting default local output destination");
984 ret_code
= LTTNG_ERR_SET_URL
;
986 } else if (ret
< 0) {
987 PERROR("Failed to format default local output URI");
988 ret_code
= LTTNG_ERR_SET_URL
;
992 uri_ret
= uri_parse(local_uri
, &uris
);
994 ret_code
= LTTNG_ERR_SET_URL
;
997 free(descriptor
->output
.local
);
998 descriptor
->output
.local
= &uris
[0];
1002 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1006 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1008 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1010 ret_code
= LTTNG_ERR_SET_URL
;
1014 control
= uri_copy(&uris
[0]);
1015 data
= uri_copy(&uris
[1]);
1016 if (!control
|| !data
) {
1019 ret_code
= LTTNG_ERR_SET_URL
;
1023 /* Ownership of uris is transferred. */
1024 ret
= network_location_set_from_lttng_uris(
1025 &descriptor
->output
.network
, control
, data
);
1028 ret_code
= LTTNG_ERR_SET_URL
;
1042 * Note that only properties that can be populated by the session daemon
1043 * (output destination and name) are assigned.
1045 int lttng_session_descriptor_assign(struct lttng_session_descriptor
*dst
,
1046 const struct lttng_session_descriptor
*src
)
1050 if (dst
->type
!= src
->type
) {
1054 if (dst
->output_type
!= src
->output_type
) {
1058 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1062 switch (dst
->output_type
) {
1063 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1064 free(dst
->output
.local
);
1065 dst
->output
.local
= uri_copy(src
->output
.local
);
1066 if (!dst
->output
.local
) {
1071 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1073 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1075 control_copy
= uri_copy(dst
->output
.network
.control
);
1076 if (!control_copy
&& dst
->output
.network
.control
) {
1080 data_copy
= uri_copy(dst
->output
.network
.data
);
1081 if (!data_copy
&& dst
->output
.network
.data
) {
1086 ret
= network_location_set_from_lttng_uris(
1087 &dst
->output
.network
, control_copy
, data_copy
);
1090 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: