2 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
7 #include <lttng/session-descriptor-internal.h>
8 #include <common/macros.h>
9 #include <common/uri.h>
10 #include <common/defaults.h>
11 #include <common/error.h>
16 struct lttng_session_descriptor_network_location
{
17 struct lttng_uri
*control
;
18 struct lttng_uri
*data
;
21 struct lttng_session_descriptor
{
22 enum lttng_session_descriptor_type type
;
24 * If an output type that is not OUTPUT_TYPE_NONE is specified,
25 * it means that an output of that type must be generated at
26 * session-creation time.
28 enum lttng_session_descriptor_output_type output_type
;
31 struct lttng_session_descriptor_network_location network
;
32 struct lttng_uri
*local
;
36 struct lttng_session_descriptor_snapshot
{
37 struct lttng_session_descriptor base
;
39 * Assumes at-most one snapshot output is supported. Uses
40 * the output field of the base class.
44 struct lttng_session_descriptor_live
{
45 struct lttng_session_descriptor base
;
46 unsigned long long live_timer_us
;
49 struct lttng_session_descriptor_comm
{
50 /* enum lttng_session_descriptor_type */
52 /* enum lttng_session_descriptor_output_type */
54 /* Includes trailing null. */
56 /* Name follows, followed by URIs */
60 struct lttng_session_descriptor_live_comm
{
61 struct lttng_session_descriptor_comm base
;
62 /* Live-specific parameters. */
63 uint64_t live_timer_us
;
67 struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
69 struct lttng_uri
*new_uri
= NULL
;
75 new_uri
= zmalloc(sizeof(*new_uri
));
79 memcpy(new_uri
, uri
, sizeof(*new_uri
));
85 struct lttng_uri
*uri_from_path(const char *path
)
87 struct lttng_uri
*uris
= NULL
;
89 char local_protocol_string
[LTTNG_PATH_MAX
+ sizeof("file://")] =
92 if (strlen(path
) >= LTTNG_PATH_MAX
) {
97 /* Not an absolute path. */
101 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
102 uri_count
= uri_parse(local_protocol_string
, &uris
);
103 if (uri_count
!= 1) {
106 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
118 void network_location_fini(
119 struct lttng_session_descriptor_network_location
*location
)
121 free(location
->control
);
122 free(location
->data
);
125 /* Assumes ownership of control and data. */
127 int network_location_set_from_lttng_uris(
128 struct lttng_session_descriptor_network_location
*location
,
129 struct lttng_uri
*control
, 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
||
144 data
->stype
!= LTTNG_STREAM_DATA
) {
149 free(location
->control
);
150 free(location
->data
);
151 location
->control
= control
;
152 location
->data
= data
;
162 int network_location_set_from_uri_strings(
163 struct lttng_session_descriptor_network_location
*location
,
164 const char *control
, const char *data
)
168 struct lttng_uri
*parsed_uris
= NULL
;
169 struct lttng_uri
*control_uri
= NULL
;
170 struct lttng_uri
*data_uri
= NULL
;
172 uri_count
= uri_parse_str_urls(control
, data
, &parsed_uris
);
173 if (uri_count
!= 2 && uri_count
!= 0) {
179 * uri_parse_str_urls returns a contiguous array of lttng_uris whereas
180 * session descriptors expect individually allocated lttng_uris.
182 if (uri_count
== 2) {
183 control_uri
= zmalloc(sizeof(*control_uri
));
184 data_uri
= zmalloc(sizeof(*data_uri
));
185 if (!control_uri
|| !data_uri
) {
189 memcpy(control_uri
, &parsed_uris
[0], sizeof(*control_uri
));
190 memcpy(data_uri
, &parsed_uris
[1], sizeof(*data_uri
));
193 /* Ownership of control and data uris is transferred. */
194 ret
= network_location_set_from_lttng_uris(
207 struct lttng_session_descriptor
*
208 lttng_session_descriptor_create(const char *name
)
210 struct lttng_session_descriptor
*descriptor
;
212 descriptor
= zmalloc(sizeof(*descriptor
));
217 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
218 descriptor
->output_type
=
219 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
220 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
225 lttng_session_descriptor_destroy(descriptor
);
229 /* Ownership of uri is transferred. */
231 struct lttng_session_descriptor
*
232 _lttng_session_descriptor_local_create(const char *name
,
233 struct lttng_uri
*uri
)
235 struct lttng_session_descriptor
*descriptor
;
237 descriptor
= lttng_session_descriptor_create(name
);
241 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
242 descriptor
->output_type
=
243 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
245 if (uri
->dtype
!= LTTNG_DST_PATH
) {
248 descriptor
->output
.local
= uri
;
254 lttng_session_descriptor_destroy(descriptor
);
258 struct lttng_session_descriptor
*
259 lttng_session_descriptor_local_create(const char *name
, const char *path
)
261 struct lttng_uri
*uri
= NULL
;
262 struct lttng_session_descriptor
*descriptor
;
265 uri
= uri_from_path(path
);
270 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
276 /* Assumes the ownership of both uris. */
278 struct lttng_session_descriptor
*
279 _lttng_session_descriptor_network_create(const char *name
,
280 struct lttng_uri
*control
, struct lttng_uri
*data
)
283 struct lttng_session_descriptor
*descriptor
;
285 descriptor
= lttng_session_descriptor_create(name
);
290 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
291 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
292 /* Assumes the ownership of both uris. */
293 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
,
302 lttng_session_descriptor_destroy(descriptor
);
308 struct lttng_session_descriptor
*
309 lttng_session_descriptor_network_create(const char *name
,
310 const char *control_url
, const char *data_url
)
313 struct lttng_session_descriptor
*descriptor
;
315 descriptor
= _lttng_session_descriptor_network_create(name
,
321 ret
= network_location_set_from_uri_strings(&descriptor
->output
.network
,
322 control_url
, data_url
);
328 lttng_session_descriptor_destroy(descriptor
);
333 struct lttng_session_descriptor_snapshot
*
334 _lttng_session_descriptor_snapshot_create(const char *name
)
336 struct lttng_session_descriptor_snapshot
*descriptor
;
338 descriptor
= zmalloc(sizeof(*descriptor
));
343 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
344 descriptor
->base
.output_type
=
345 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
346 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
352 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
356 /* Ownership of control and data is transferred. */
358 struct lttng_session_descriptor_snapshot
*
359 _lttng_session_descriptor_snapshot_network_create(const char *name
,
360 struct lttng_uri
*control
, struct lttng_uri
*data
)
363 struct lttng_session_descriptor_snapshot
*descriptor
;
365 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
370 descriptor
->base
.output_type
=
371 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
372 /* Ownership of control and data is transferred. */
373 ret
= network_location_set_from_lttng_uris(
374 &descriptor
->base
.output
.network
,
385 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
389 struct lttng_session_descriptor
*
390 lttng_session_descriptor_snapshot_create(const char *name
)
392 struct lttng_session_descriptor_snapshot
*descriptor
;
394 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
395 return descriptor
? &descriptor
->base
: NULL
;
398 struct lttng_session_descriptor
*
399 lttng_session_descriptor_snapshot_network_create(const char *name
,
400 const char *control_url
, const char *data_url
)
403 struct lttng_session_descriptor_snapshot
*descriptor
;
405 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
,
411 ret
= network_location_set_from_uri_strings(
412 &descriptor
->base
.output
.network
,
413 control_url
, data_url
);
417 return &descriptor
->base
;
419 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
423 /* Ownership of uri is transferred. */
425 struct lttng_session_descriptor_snapshot
*
426 _lttng_session_descriptor_snapshot_local_create(const char *name
,
427 struct lttng_uri
*uri
)
429 struct lttng_session_descriptor_snapshot
*descriptor
;
431 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
435 descriptor
->base
.output_type
=
436 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
438 if (uri
->dtype
!= LTTNG_DST_PATH
) {
441 descriptor
->base
.output
.local
= uri
;
447 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
451 struct lttng_session_descriptor
*
452 lttng_session_descriptor_snapshot_local_create(const char *name
,
455 struct lttng_uri
*path_uri
= NULL
;
456 struct lttng_session_descriptor_snapshot
*descriptor
;
459 path_uri
= uri_from_path(path
);
464 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
,
466 return descriptor
? &descriptor
->base
: NULL
;
472 struct lttng_session_descriptor_live
*
473 _lttng_session_descriptor_live_create(const char *name
,
474 unsigned long long live_timer_interval_us
)
476 struct lttng_session_descriptor_live
*descriptor
= NULL
;
478 if (live_timer_interval_us
== 0) {
481 descriptor
= zmalloc(sizeof(*descriptor
));
486 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
487 descriptor
->base
.output_type
=
488 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
489 descriptor
->live_timer_us
= live_timer_interval_us
;
490 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
497 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
501 /* Ownership of control and data is transferred. */
503 struct lttng_session_descriptor_live
*
504 _lttng_session_descriptor_live_network_create(
506 struct lttng_uri
*control
, struct lttng_uri
*data
,
507 unsigned long long live_timer_interval_us
)
510 struct lttng_session_descriptor_live
*descriptor
;
512 descriptor
= _lttng_session_descriptor_live_create(name
,
513 live_timer_interval_us
);
518 descriptor
->base
.output_type
=
519 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
521 /* Ownerwhip of control and data is transferred. */
522 ret
= network_location_set_from_lttng_uris(
523 &descriptor
->base
.output
.network
,
534 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
538 struct lttng_session_descriptor
*
539 lttng_session_descriptor_live_create(
541 unsigned long long live_timer_us
)
543 struct lttng_session_descriptor_live
*descriptor
;
545 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
547 return descriptor
? &descriptor
->base
: NULL
;
550 struct lttng_session_descriptor
*
551 lttng_session_descriptor_live_network_create(
553 const char *control_url
, const char *data_url
,
554 unsigned long long live_timer_us
)
557 struct lttng_session_descriptor_live
*descriptor
;
559 descriptor
= _lttng_session_descriptor_live_network_create(name
,
560 NULL
, NULL
, live_timer_us
);
565 ret
= network_location_set_from_uri_strings(
566 &descriptor
->base
.output
.network
,
567 control_url
, data_url
);
571 return &descriptor
->base
;
573 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
577 void lttng_session_descriptor_destroy(
578 struct lttng_session_descriptor
*descriptor
)
584 switch (descriptor
->output_type
) {
585 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
587 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
588 free(descriptor
->output
.local
);
590 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
591 network_location_fini(&descriptor
->output
.network
);
597 free(descriptor
->name
);
602 ssize_t
lttng_session_descriptor_create_from_buffer(
603 const struct lttng_buffer_view
*payload
,
604 struct lttng_session_descriptor
**descriptor
)
607 ssize_t offset
= 0, ret
;
608 struct lttng_buffer_view current_view
;
609 const char *name
= NULL
;
610 const struct lttng_session_descriptor_comm
*base_header
;
611 size_t max_expected_uri_count
;
612 uint64_t live_timer_us
= 0;
613 struct lttng_uri
*uris
[2] = {};
614 enum lttng_session_descriptor_type type
;
615 enum lttng_session_descriptor_output_type output_type
;
617 current_view
= lttng_buffer_view_from_view(payload
, offset
,
618 sizeof(*base_header
));
619 base_header
= (typeof(base_header
)) current_view
.data
;
625 switch (base_header
->type
) {
626 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
627 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
629 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
631 const struct lttng_session_descriptor_live_comm
*live_header
;
633 current_view
= lttng_buffer_view_from_view(payload
, offset
,
634 sizeof(*live_header
));
635 live_header
= (typeof(live_header
)) current_view
.data
;
641 live_timer_us
= live_header
->live_timer_us
;
648 /* type has been validated. */
649 type
= base_header
->type
;
651 switch (base_header
->output_type
) {
652 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
653 max_expected_uri_count
= 0;
655 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
656 max_expected_uri_count
= 1;
658 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
659 max_expected_uri_count
= 2;
665 /* output_type has been validated. */
666 output_type
= base_header
->output_type
;
668 /* Skip after header. */
669 offset
+= current_view
.size
;
670 if (!base_header
->name_len
) {
675 current_view
= lttng_buffer_view_from_view(payload
, offset
,
676 base_header
->name_len
);
677 name
= current_view
.data
;
683 if (base_header
->name_len
== 1 ||
684 name
[base_header
->name_len
- 1] ||
685 strlen(name
) != base_header
->name_len
- 1) {
687 * Check that the name is not NULL, is NULL-terminated, and
688 * does not contain a NULL before the last byte.
694 /* Skip after the name. */
695 offset
+= base_header
->name_len
;
697 if (base_header
->uri_count
> max_expected_uri_count
) {
702 for (i
= 0; i
< base_header
->uri_count
; i
++) {
703 struct lttng_uri
*uri
;
706 current_view
= lttng_buffer_view_from_view(payload
,
707 offset
, sizeof(*uri
));
708 uri
= (typeof(uri
)) current_view
.data
;
713 uris
[i
] = zmalloc(sizeof(*uri
));
718 memcpy(uris
[i
], uri
, sizeof(*uri
));
719 offset
+= sizeof(*uri
);
723 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
724 switch (output_type
) {
725 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
726 *descriptor
= lttng_session_descriptor_create(name
);
728 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
729 *descriptor
= _lttng_session_descriptor_local_create(
732 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
733 *descriptor
= _lttng_session_descriptor_network_create(
734 name
, uris
[0], uris
[1]);
737 /* Already checked. */
741 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
743 struct lttng_session_descriptor_snapshot
*snapshot
;
744 switch (output_type
) {
745 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
746 snapshot
= _lttng_session_descriptor_snapshot_create(
749 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
750 snapshot
= _lttng_session_descriptor_snapshot_local_create(
753 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
754 snapshot
= _lttng_session_descriptor_snapshot_network_create(
755 name
, uris
[0], uris
[1]);
758 /* Already checked. */
761 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
764 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
766 struct lttng_session_descriptor_live
*live
;
768 switch (output_type
) {
769 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
770 live
= _lttng_session_descriptor_live_create(
771 name
, live_timer_us
);
773 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
774 live
= _lttng_session_descriptor_live_network_create(
775 name
, uris
[0], uris
[1],
778 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
782 /* Already checked. */
785 *descriptor
= live
? &live
->base
: NULL
;
789 /* Already checked. */
792 memset(uris
, 0, sizeof(uris
));
806 int lttng_session_descriptor_serialize(
807 const struct lttng_session_descriptor
*descriptor
,
808 struct lttng_dynamic_buffer
*buffer
)
811 /* There are, at most, two URIs to serialize. */
812 struct lttng_uri
*uris
[2] = {};
813 size_t uri_count
= 0;
814 /* The live header is a superset of all headers. */
815 struct lttng_session_descriptor_live_comm header
= {
816 .base
.type
= (uint8_t) descriptor
->type
,
817 .base
.output_type
= (uint8_t) descriptor
->output_type
,
818 .base
.name_len
= descriptor
->name
?
819 strlen(descriptor
->name
) + 1 : 0,
821 const void *header_ptr
= NULL
;
824 switch (descriptor
->output_type
) {
825 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
827 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
828 uris
[0] = descriptor
->output
.local
;
830 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
831 uris
[0] = descriptor
->output
.network
.control
;
832 uris
[1] = descriptor
->output
.network
.data
;
838 uri_count
+= !!uris
[0];
839 uri_count
+= !!uris
[1];
841 header
.base
.uri_count
= uri_count
;
842 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
843 const struct lttng_session_descriptor_live
*live
=
844 container_of(descriptor
, typeof(*live
),
847 header
.live_timer_us
= live
->live_timer_us
;
848 header_ptr
= &header
;
849 header_size
= sizeof(header
);
851 header_ptr
= &header
.base
;
852 header_size
= sizeof(header
.base
);
855 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
859 if (header
.base
.name_len
) {
860 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
861 header
.base
.name_len
);
867 for (i
= 0; i
< uri_count
; i
++) {
868 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
869 sizeof(struct lttng_uri
));
879 enum lttng_session_descriptor_type
880 lttng_session_descriptor_get_type(
881 const struct lttng_session_descriptor
*descriptor
)
883 return descriptor
->type
;
887 enum lttng_session_descriptor_output_type
888 lttng_session_descriptor_get_output_type(
889 const struct lttng_session_descriptor
*descriptor
)
891 return descriptor
->output_type
;
895 void lttng_session_descriptor_get_local_output_uri(
896 const struct lttng_session_descriptor
*descriptor
,
897 struct lttng_uri
*local_uri
)
899 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
903 void lttng_session_descriptor_get_network_output_uris(
904 const struct lttng_session_descriptor
*descriptor
,
905 struct lttng_uri
*control
,
906 struct lttng_uri
*data
)
908 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
909 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
914 lttng_session_descriptor_live_get_timer_interval(
915 const struct lttng_session_descriptor
*descriptor
)
917 struct lttng_session_descriptor_live
*live
;
919 live
= container_of(descriptor
, typeof(*live
), base
);
920 return live
->live_timer_us
;
923 enum lttng_session_descriptor_status
924 lttng_session_descriptor_get_session_name(
925 const struct lttng_session_descriptor
*descriptor
,
926 const char **session_name
)
928 enum lttng_session_descriptor_status status
;
930 if (!descriptor
|| !session_name
) {
931 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
935 *session_name
= descriptor
->name
;
936 status
= descriptor
->name
?
937 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
938 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
;
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
;
986 bool lttng_session_descriptor_has_output_directory(
987 const struct lttng_session_descriptor
*descriptor
)
989 switch (descriptor
->output_type
) {
990 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
992 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
993 if (descriptor
->output
.local
) {
994 return *descriptor
->output
.local
->dst
.path
;
997 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
998 if (descriptor
->output
.network
.control
) {
999 return *descriptor
->output
.network
.control
->subdir
;
1009 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1010 struct lttng_session_descriptor
*descriptor
,
1011 time_t *session_creation_time
,
1012 const char *absolute_home_path
)
1014 enum lttng_error_code ret_code
= LTTNG_OK
;
1015 struct lttng_uri
*uris
= NULL
;
1017 switch (descriptor
->output_type
) {
1018 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1020 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1024 char local_uri
[LTTNG_PATH_MAX
];
1025 char creation_datetime_suffix
[17] = {};
1027 if (session_creation_time
) {
1028 size_t strftime_ret
;
1029 struct tm
*timeinfo
;
1031 timeinfo
= localtime(session_creation_time
);
1033 ret_code
= LTTNG_ERR_FATAL
;
1036 strftime_ret
= strftime(creation_datetime_suffix
,
1037 sizeof(creation_datetime_suffix
),
1038 "-%Y%m%d-%H%M%S", timeinfo
);
1039 if (strftime_ret
== 0) {
1040 ERR("Failed to format session creation timestamp while setting default local output destination");
1041 ret_code
= LTTNG_ERR_FATAL
;
1045 assert(descriptor
->name
);
1046 ret
= snprintf(local_uri
, sizeof(local_uri
),
1047 "file://%s/%s/%s%s",
1049 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1050 creation_datetime_suffix
);
1051 if (ret
>= sizeof(local_uri
)) {
1052 ERR("Truncation occurred while setting default local output destination");
1053 ret_code
= LTTNG_ERR_SET_URL
;
1055 } else if (ret
< 0) {
1056 PERROR("Failed to format default local output URI");
1057 ret_code
= LTTNG_ERR_SET_URL
;
1061 uri_ret
= uri_parse(local_uri
, &uris
);
1063 ret_code
= LTTNG_ERR_SET_URL
;
1066 free(descriptor
->output
.local
);
1067 descriptor
->output
.local
= &uris
[0];
1071 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1075 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1077 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1079 ret_code
= LTTNG_ERR_SET_URL
;
1083 control
= uri_copy(&uris
[0]);
1084 data
= uri_copy(&uris
[1]);
1085 if (!control
|| !data
) {
1088 ret_code
= LTTNG_ERR_SET_URL
;
1092 /* Ownership of uris is transferred. */
1093 ret
= network_location_set_from_lttng_uris(
1094 &descriptor
->output
.network
,
1098 ret_code
= LTTNG_ERR_SET_URL
;
1112 * Note that only properties that can be populated by the session daemon
1113 * (output destination and name) are assigned.
1116 int lttng_session_descriptor_assign(
1117 struct lttng_session_descriptor
*dst
,
1118 const struct lttng_session_descriptor
*src
)
1122 if (dst
->type
!= src
->type
) {
1126 if (dst
->output_type
!= src
->output_type
) {
1130 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1134 switch (dst
->output_type
) {
1135 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1136 free(dst
->output
.local
);
1137 dst
->output
.local
= uri_copy(src
->output
.local
);
1138 if (!dst
->output
.local
) {
1143 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1145 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1147 control_copy
= uri_copy(dst
->output
.network
.control
);
1148 if (!control_copy
&& dst
->output
.network
.control
) {
1152 data_copy
= uri_copy(dst
->output
.network
.data
);
1153 if (!data_copy
&& dst
->output
.network
.data
) {
1158 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1159 control_copy
, data_copy
);
1162 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: