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
= lttng::utils::container_of(
851 descriptor
, <tng_session_descriptor_live::base
);
853 header
.live_timer_us
= live
->live_timer_us
;
854 header_ptr
= &header
;
855 header_size
= sizeof(header
);
857 header_ptr
= &header
.base
;
858 header_size
= sizeof(header
.base
);
861 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
865 if (header
.base
.name_len
) {
866 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
867 header
.base
.name_len
);
873 for (i
= 0; i
< uri_count
; i
++) {
874 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
875 sizeof(struct lttng_uri
));
884 enum lttng_session_descriptor_type
885 lttng_session_descriptor_get_type(
886 const struct lttng_session_descriptor
*descriptor
)
888 return descriptor
->type
;
891 enum lttng_session_descriptor_output_type
892 lttng_session_descriptor_get_output_type(
893 const struct lttng_session_descriptor
*descriptor
)
895 return descriptor
->output_type
;
898 void lttng_session_descriptor_get_local_output_uri(
899 const struct lttng_session_descriptor
*descriptor
,
900 struct lttng_uri
*local_uri
)
902 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
905 void lttng_session_descriptor_get_network_output_uris(
906 const struct lttng_session_descriptor
*descriptor
,
907 struct lttng_uri
*control
,
908 struct lttng_uri
*data
)
910 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
911 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
915 lttng_session_descriptor_live_get_timer_interval(
916 const struct lttng_session_descriptor
*descriptor
)
918 struct lttng_session_descriptor_live
*live
;
920 live
= lttng::utils::container_of(descriptor
, <tng_session_descriptor_live::base
);
921 return live
->live_timer_us
;
924 enum lttng_session_descriptor_status
925 lttng_session_descriptor_get_session_name(
926 const struct lttng_session_descriptor
*descriptor
,
927 const char **session_name
)
929 enum lttng_session_descriptor_status status
;
931 if (!descriptor
|| !session_name
) {
932 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
936 *session_name
= descriptor
->name
;
937 status
= descriptor
->name
?
938 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
939 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
944 int lttng_session_descriptor_set_session_name(
945 struct lttng_session_descriptor
*descriptor
,
954 if (strlen(name
) >= LTTNG_NAME_MAX
) {
958 new_name
= strdup(name
);
963 free(descriptor
->name
);
964 descriptor
->name
= new_name
;
969 bool lttng_session_descriptor_is_output_destination_initialized(
970 const struct lttng_session_descriptor
*descriptor
)
972 switch (descriptor
->output_type
) {
973 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
975 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
976 return descriptor
->output
.local
;
977 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
978 return descriptor
->output
.network
.control
;
984 bool lttng_session_descriptor_has_output_directory(
985 const struct lttng_session_descriptor
*descriptor
)
987 switch (descriptor
->output_type
) {
988 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
990 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
991 if (descriptor
->output
.local
) {
992 return *descriptor
->output
.local
->dst
.path
;
995 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
996 if (descriptor
->output
.network
.control
) {
997 return *descriptor
->output
.network
.control
->subdir
;
1006 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1007 struct lttng_session_descriptor
*descriptor
,
1008 time_t *session_creation_time
,
1009 const char *absolute_home_path
)
1011 enum lttng_error_code ret_code
= LTTNG_OK
;
1012 struct lttng_uri
*uris
= NULL
;
1014 switch (descriptor
->output_type
) {
1015 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1017 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1021 char local_uri
[LTTNG_PATH_MAX
];
1022 char creation_datetime_suffix
[17] = {};
1024 if (session_creation_time
) {
1025 size_t strftime_ret
;
1026 struct tm
*timeinfo
;
1028 timeinfo
= localtime(session_creation_time
);
1030 ret_code
= LTTNG_ERR_FATAL
;
1033 strftime_ret
= strftime(creation_datetime_suffix
,
1034 sizeof(creation_datetime_suffix
),
1035 "-%Y%m%d-%H%M%S", timeinfo
);
1036 if (strftime_ret
== 0) {
1037 ERR("Failed to format session creation timestamp while setting default local output destination");
1038 ret_code
= LTTNG_ERR_FATAL
;
1042 LTTNG_ASSERT(descriptor
->name
);
1043 ret
= snprintf(local_uri
, sizeof(local_uri
),
1044 "file://%s/%s/%s%s",
1046 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1047 creation_datetime_suffix
);
1048 if (ret
>= sizeof(local_uri
)) {
1049 ERR("Truncation occurred while setting default local output destination");
1050 ret_code
= LTTNG_ERR_SET_URL
;
1052 } else if (ret
< 0) {
1053 PERROR("Failed to format default local output URI");
1054 ret_code
= LTTNG_ERR_SET_URL
;
1058 uri_ret
= uri_parse(local_uri
, &uris
);
1060 ret_code
= LTTNG_ERR_SET_URL
;
1063 free(descriptor
->output
.local
);
1064 descriptor
->output
.local
= &uris
[0];
1068 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1072 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1074 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1076 ret_code
= LTTNG_ERR_SET_URL
;
1080 control
= uri_copy(&uris
[0]);
1081 data
= uri_copy(&uris
[1]);
1082 if (!control
|| !data
) {
1085 ret_code
= LTTNG_ERR_SET_URL
;
1089 /* Ownership of uris is transferred. */
1090 ret
= network_location_set_from_lttng_uris(
1091 &descriptor
->output
.network
,
1095 ret_code
= LTTNG_ERR_SET_URL
;
1109 * Note that only properties that can be populated by the session daemon
1110 * (output destination and name) are assigned.
1112 int lttng_session_descriptor_assign(
1113 struct lttng_session_descriptor
*dst
,
1114 const struct lttng_session_descriptor
*src
)
1118 if (dst
->type
!= src
->type
) {
1122 if (dst
->output_type
!= src
->output_type
) {
1126 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1130 switch (dst
->output_type
) {
1131 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1132 free(dst
->output
.local
);
1133 dst
->output
.local
= uri_copy(src
->output
.local
);
1134 if (!dst
->output
.local
) {
1139 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1141 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1143 control_copy
= uri_copy(dst
->output
.network
.control
);
1144 if (!control_copy
&& dst
->output
.network
.control
) {
1148 data_copy
= uri_copy(dst
->output
.network
.data
);
1149 if (!data_copy
&& dst
->output
.network
.data
) {
1154 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1155 control_copy
, data_copy
);
1158 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: