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>
15 struct lttng_session_descriptor_network_location
{
16 struct lttng_uri
*control
;
17 struct lttng_uri
*data
;
20 struct lttng_session_descriptor
{
21 enum lttng_session_descriptor_type type
;
23 * If an output type that is not OUTPUT_TYPE_NONE is specified,
24 * it means that an output of that type must be generated at
25 * session-creation time.
27 enum lttng_session_descriptor_output_type output_type
;
30 struct lttng_session_descriptor_network_location network
;
31 struct lttng_uri
*local
;
35 struct lttng_session_descriptor_snapshot
{
36 struct lttng_session_descriptor base
;
38 * Assumes at-most one snapshot output is supported. Uses
39 * the output field of the base class.
43 struct lttng_session_descriptor_live
{
44 struct lttng_session_descriptor base
;
45 unsigned long long live_timer_us
;
48 struct lttng_session_descriptor_comm
{
49 /* enum lttng_session_descriptor_type */
51 /* enum lttng_session_descriptor_output_type */
53 /* Includes trailing null. */
55 /* Name follows, followed by URIs */
59 struct lttng_session_descriptor_live_comm
{
60 struct lttng_session_descriptor_comm base
;
61 /* Live-specific parameters. */
62 uint64_t live_timer_us
;
66 struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
68 struct lttng_uri
*new_uri
= NULL
;
74 new_uri
= (lttng_uri
*) zmalloc(sizeof(*new_uri
));
78 memcpy(new_uri
, uri
, sizeof(*new_uri
));
84 struct lttng_uri
*uri_from_path(const char *path
)
86 struct lttng_uri
*uris
= NULL
;
88 char local_protocol_string
[LTTNG_PATH_MAX
+ sizeof("file://")] =
91 if (strlen(path
) >= LTTNG_PATH_MAX
) {
96 /* Not an absolute path. */
100 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
101 uri_count
= uri_parse(local_protocol_string
, &uris
);
102 if (uri_count
!= 1) {
105 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
117 void network_location_fini(
118 struct lttng_session_descriptor_network_location
*location
)
120 free(location
->control
);
121 free(location
->data
);
124 /* Assumes ownership of control and data. */
126 int network_location_set_from_lttng_uris(
127 struct lttng_session_descriptor_network_location
*location
,
128 struct lttng_uri
*control
, struct lttng_uri
*data
)
132 if (!control
&& !data
) {
136 if (!(control
&& data
)) {
137 /* None or both must be set. */
142 if (control
->stype
!= LTTNG_STREAM_CONTROL
||
143 data
->stype
!= LTTNG_STREAM_DATA
) {
148 free(location
->control
);
149 free(location
->data
);
150 location
->control
= control
;
151 location
->data
= data
;
161 int network_location_set_from_uri_strings(
162 struct lttng_session_descriptor_network_location
*location
,
163 const char *control
, const char *data
)
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
= (lttng_uri
*) zmalloc(sizeof(*control_uri
));
183 data_uri
= (lttng_uri
*) zmalloc(sizeof(*data_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(
206 struct lttng_session_descriptor
*
207 lttng_session_descriptor_create(const char *name
)
209 struct lttng_session_descriptor
*descriptor
;
211 descriptor
= (lttng_session_descriptor
*) zmalloc(sizeof(*descriptor
));
216 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
217 descriptor
->output_type
=
218 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
219 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
224 lttng_session_descriptor_destroy(descriptor
);
228 /* Ownership of uri is transferred. */
230 struct lttng_session_descriptor
*
231 _lttng_session_descriptor_local_create(const char *name
,
232 struct lttng_uri
*uri
)
234 struct lttng_session_descriptor
*descriptor
;
236 descriptor
= lttng_session_descriptor_create(name
);
240 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
241 descriptor
->output_type
=
242 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
244 if (uri
->dtype
!= LTTNG_DST_PATH
) {
247 descriptor
->output
.local
= uri
;
253 lttng_session_descriptor_destroy(descriptor
);
257 struct lttng_session_descriptor
*
258 lttng_session_descriptor_local_create(const char *name
, const char *path
)
260 struct lttng_uri
*uri
= NULL
;
261 struct lttng_session_descriptor
*descriptor
;
264 uri
= uri_from_path(path
);
269 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
275 /* Assumes the ownership of both uris. */
277 struct lttng_session_descriptor
*
278 _lttng_session_descriptor_network_create(const char *name
,
279 struct lttng_uri
*control
, struct lttng_uri
*data
)
282 struct lttng_session_descriptor
*descriptor
;
284 descriptor
= lttng_session_descriptor_create(name
);
289 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
290 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
291 /* Assumes the ownership of both uris. */
292 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
,
301 lttng_session_descriptor_destroy(descriptor
);
307 struct lttng_session_descriptor
*
308 lttng_session_descriptor_network_create(const char *name
,
309 const char *control_url
, const char *data_url
)
312 struct lttng_session_descriptor
*descriptor
;
314 descriptor
= _lttng_session_descriptor_network_create(name
,
320 ret
= network_location_set_from_uri_strings(&descriptor
->output
.network
,
321 control_url
, data_url
);
327 lttng_session_descriptor_destroy(descriptor
);
332 struct lttng_session_descriptor_snapshot
*
333 _lttng_session_descriptor_snapshot_create(const char *name
)
335 struct lttng_session_descriptor_snapshot
*descriptor
;
337 descriptor
= (lttng_session_descriptor_snapshot
*) zmalloc(sizeof(*descriptor
));
342 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
343 descriptor
->base
.output_type
=
344 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
345 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
351 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
355 /* Ownership of control and data is transferred. */
357 struct lttng_session_descriptor_snapshot
*
358 _lttng_session_descriptor_snapshot_network_create(const char *name
,
359 struct lttng_uri
*control
, struct lttng_uri
*data
)
362 struct lttng_session_descriptor_snapshot
*descriptor
;
364 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
369 descriptor
->base
.output_type
=
370 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
371 /* Ownership of control and data is transferred. */
372 ret
= network_location_set_from_lttng_uris(
373 &descriptor
->base
.output
.network
,
384 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
388 struct lttng_session_descriptor
*
389 lttng_session_descriptor_snapshot_create(const char *name
)
391 struct lttng_session_descriptor_snapshot
*descriptor
;
393 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
394 return descriptor
? &descriptor
->base
: NULL
;
397 struct lttng_session_descriptor
*
398 lttng_session_descriptor_snapshot_network_create(const char *name
,
399 const char *control_url
, const char *data_url
)
402 struct lttng_session_descriptor_snapshot
*descriptor
;
404 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
,
410 ret
= network_location_set_from_uri_strings(
411 &descriptor
->base
.output
.network
,
412 control_url
, data_url
);
416 return &descriptor
->base
;
418 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
422 /* Ownership of uri is transferred. */
424 struct lttng_session_descriptor_snapshot
*
425 _lttng_session_descriptor_snapshot_local_create(const char *name
,
426 struct lttng_uri
*uri
)
428 struct lttng_session_descriptor_snapshot
*descriptor
;
430 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
434 descriptor
->base
.output_type
=
435 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
437 if (uri
->dtype
!= LTTNG_DST_PATH
) {
440 descriptor
->base
.output
.local
= uri
;
446 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
450 struct lttng_session_descriptor
*
451 lttng_session_descriptor_snapshot_local_create(const char *name
,
454 struct lttng_uri
*path_uri
= NULL
;
455 struct lttng_session_descriptor_snapshot
*descriptor
;
458 path_uri
= uri_from_path(path
);
463 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
,
465 return descriptor
? &descriptor
->base
: NULL
;
471 struct lttng_session_descriptor_live
*
472 _lttng_session_descriptor_live_create(const char *name
,
473 unsigned long long live_timer_interval_us
)
475 struct lttng_session_descriptor_live
*descriptor
= NULL
;
477 if (live_timer_interval_us
== 0) {
480 descriptor
= (lttng_session_descriptor_live
*) zmalloc(sizeof(*descriptor
));
485 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
486 descriptor
->base
.output_type
=
487 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
488 descriptor
->live_timer_us
= live_timer_interval_us
;
489 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
496 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
500 /* Ownership of control and data is transferred. */
502 struct lttng_session_descriptor_live
*
503 _lttng_session_descriptor_live_network_create(
505 struct lttng_uri
*control
, struct lttng_uri
*data
,
506 unsigned long long live_timer_interval_us
)
509 struct lttng_session_descriptor_live
*descriptor
;
511 descriptor
= _lttng_session_descriptor_live_create(name
,
512 live_timer_interval_us
);
517 descriptor
->base
.output_type
=
518 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
520 /* Ownerwhip of control and data is transferred. */
521 ret
= network_location_set_from_lttng_uris(
522 &descriptor
->base
.output
.network
,
533 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
537 struct lttng_session_descriptor
*
538 lttng_session_descriptor_live_create(
540 unsigned long long live_timer_us
)
542 struct lttng_session_descriptor_live
*descriptor
;
544 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
546 return descriptor
? &descriptor
->base
: NULL
;
549 struct lttng_session_descriptor
*
550 lttng_session_descriptor_live_network_create(
552 const char *control_url
, const char *data_url
,
553 unsigned long long live_timer_us
)
556 struct lttng_session_descriptor_live
*descriptor
;
558 descriptor
= _lttng_session_descriptor_live_network_create(name
,
559 NULL
, NULL
, live_timer_us
);
564 ret
= network_location_set_from_uri_strings(
565 &descriptor
->base
.output
.network
,
566 control_url
, data_url
);
570 return &descriptor
->base
;
572 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
576 void lttng_session_descriptor_destroy(
577 struct lttng_session_descriptor
*descriptor
)
583 switch (descriptor
->output_type
) {
584 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
586 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
587 free(descriptor
->output
.local
);
589 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
590 network_location_fini(&descriptor
->output
.network
);
596 free(descriptor
->name
);
600 ssize_t
lttng_session_descriptor_create_from_buffer(
601 const struct lttng_buffer_view
*payload
,
602 struct lttng_session_descriptor
**descriptor
)
605 ssize_t offset
= 0, ret
;
606 struct lttng_buffer_view current_view
;
607 const char *name
= NULL
;
608 const struct lttng_session_descriptor_comm
*base_header
;
609 size_t max_expected_uri_count
;
610 uint64_t live_timer_us
= 0;
611 struct lttng_uri
*uris
[2] = {};
612 enum lttng_session_descriptor_type type
;
613 enum lttng_session_descriptor_output_type output_type
;
615 current_view
= lttng_buffer_view_from_view(payload
, offset
,
616 sizeof(*base_header
));
617 if (!lttng_buffer_view_is_valid(¤t_view
)) {
622 base_header
= (typeof(base_header
)) current_view
.data
;
623 switch (base_header
->type
) {
624 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
625 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
627 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
629 const struct lttng_session_descriptor_live_comm
*live_header
;
631 current_view
= lttng_buffer_view_from_view(payload
, offset
,
632 sizeof(*live_header
));
633 if (!lttng_buffer_view_is_valid(¤t_view
)) {
638 live_header
= (typeof(live_header
)) current_view
.data
;
639 live_timer_us
= live_header
->live_timer_us
;
646 /* type has been validated. */
647 type
= (lttng_session_descriptor_type
) base_header
->type
;
649 switch (base_header
->output_type
) {
650 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
651 max_expected_uri_count
= 0;
653 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
654 max_expected_uri_count
= 1;
656 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
657 max_expected_uri_count
= 2;
663 /* output_type has been validated. */
664 output_type
= (lttng_session_descriptor_output_type
) base_header
->output_type
;
666 /* Skip after header. */
667 offset
+= current_view
.size
;
668 if (!base_header
->name_len
) {
673 current_view
= lttng_buffer_view_from_view(payload
, offset
,
674 base_header
->name_len
);
675 if (!lttng_buffer_view_is_valid(¤t_view
)) {
680 name
= current_view
.data
;
681 if (base_header
->name_len
== 1 ||
682 name
[base_header
->name_len
- 1] ||
683 strlen(name
) != base_header
->name_len
- 1) {
685 * Check that the name is not NULL, is NULL-terminated, and
686 * does not contain a NULL before the last byte.
692 /* Skip after the name. */
693 offset
+= base_header
->name_len
;
695 if (base_header
->uri_count
> max_expected_uri_count
) {
700 for (i
= 0; i
< base_header
->uri_count
; i
++) {
701 struct lttng_uri
*uri
;
704 current_view
= lttng_buffer_view_from_view(payload
,
705 offset
, sizeof(*uri
));
706 if (!lttng_buffer_view_is_valid(¤t_view
)) {
711 uri
= (typeof(uri
)) current_view
.data
;
712 uris
[i
] = (lttng_uri
*) zmalloc(sizeof(*uri
));
717 memcpy(uris
[i
], uri
, sizeof(*uri
));
718 offset
+= sizeof(*uri
);
722 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
723 switch (output_type
) {
724 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
725 *descriptor
= lttng_session_descriptor_create(name
);
727 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
728 *descriptor
= _lttng_session_descriptor_local_create(
731 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
732 *descriptor
= _lttng_session_descriptor_network_create(
733 name
, uris
[0], uris
[1]);
736 /* Already checked. */
740 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
742 struct lttng_session_descriptor_snapshot
*snapshot
;
743 switch (output_type
) {
744 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
745 snapshot
= _lttng_session_descriptor_snapshot_create(
748 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
749 snapshot
= _lttng_session_descriptor_snapshot_local_create(
752 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
753 snapshot
= _lttng_session_descriptor_snapshot_network_create(
754 name
, uris
[0], uris
[1]);
757 /* Already checked. */
760 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
763 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
765 struct lttng_session_descriptor_live
*live
;
767 switch (output_type
) {
768 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
769 live
= _lttng_session_descriptor_live_create(
770 name
, live_timer_us
);
772 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
773 live
= _lttng_session_descriptor_live_network_create(
774 name
, uris
[0], uris
[1],
777 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
781 /* Already checked. */
784 *descriptor
= live
? &live
->base
: NULL
;
788 /* Already checked. */
791 memset(uris
, 0, sizeof(uris
));
804 int lttng_session_descriptor_serialize(
805 const struct lttng_session_descriptor
*descriptor
,
806 struct lttng_dynamic_buffer
*buffer
)
809 /* There are, at most, two URIs to serialize. */
810 struct lttng_uri
*uris
[2] = {};
811 size_t uri_count
= 0;
812 /* The live header is a superset of all headers. */
813 struct lttng_session_descriptor_live_comm header
= {
815 .type
= (uint8_t) descriptor
->type
,
816 .output_type
= (uint8_t) descriptor
->output_type
,
817 .name_len
= (uint32_t) (descriptor
->name
?
818 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
));
878 enum lttng_session_descriptor_type
879 lttng_session_descriptor_get_type(
880 const struct lttng_session_descriptor
*descriptor
)
882 return descriptor
->type
;
885 enum lttng_session_descriptor_output_type
886 lttng_session_descriptor_get_output_type(
887 const struct lttng_session_descriptor
*descriptor
)
889 return descriptor
->output_type
;
892 void lttng_session_descriptor_get_local_output_uri(
893 const struct lttng_session_descriptor
*descriptor
,
894 struct lttng_uri
*local_uri
)
896 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
899 void lttng_session_descriptor_get_network_output_uris(
900 const struct lttng_session_descriptor
*descriptor
,
901 struct lttng_uri
*control
,
902 struct lttng_uri
*data
)
904 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
905 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
909 lttng_session_descriptor_live_get_timer_interval(
910 const struct lttng_session_descriptor
*descriptor
)
912 struct lttng_session_descriptor_live
*live
;
914 live
= container_of(descriptor
, typeof(*live
), base
);
915 return live
->live_timer_us
;
918 enum lttng_session_descriptor_status
919 lttng_session_descriptor_get_session_name(
920 const struct lttng_session_descriptor
*descriptor
,
921 const char **session_name
)
923 enum lttng_session_descriptor_status status
;
925 if (!descriptor
|| !session_name
) {
926 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
930 *session_name
= descriptor
->name
;
931 status
= descriptor
->name
?
932 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
933 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
938 int lttng_session_descriptor_set_session_name(
939 struct lttng_session_descriptor
*descriptor
,
948 if (strlen(name
) >= LTTNG_NAME_MAX
) {
952 new_name
= strdup(name
);
957 free(descriptor
->name
);
958 descriptor
->name
= new_name
;
963 bool lttng_session_descriptor_is_output_destination_initialized(
964 const struct lttng_session_descriptor
*descriptor
)
966 switch (descriptor
->output_type
) {
967 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
969 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
970 return descriptor
->output
.local
;
971 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
972 return descriptor
->output
.network
.control
;
978 bool lttng_session_descriptor_has_output_directory(
979 const struct lttng_session_descriptor
*descriptor
)
981 switch (descriptor
->output_type
) {
982 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
984 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
985 if (descriptor
->output
.local
) {
986 return *descriptor
->output
.local
->dst
.path
;
989 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
990 if (descriptor
->output
.network
.control
) {
991 return *descriptor
->output
.network
.control
->subdir
;
1000 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1001 struct lttng_session_descriptor
*descriptor
,
1002 time_t *session_creation_time
,
1003 const char *absolute_home_path
)
1005 enum lttng_error_code ret_code
= LTTNG_OK
;
1006 struct lttng_uri
*uris
= NULL
;
1008 switch (descriptor
->output_type
) {
1009 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1011 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1015 char local_uri
[LTTNG_PATH_MAX
];
1016 char creation_datetime_suffix
[17] = {};
1018 if (session_creation_time
) {
1019 size_t strftime_ret
;
1020 struct tm
*timeinfo
;
1022 timeinfo
= localtime(session_creation_time
);
1024 ret_code
= LTTNG_ERR_FATAL
;
1027 strftime_ret
= strftime(creation_datetime_suffix
,
1028 sizeof(creation_datetime_suffix
),
1029 "-%Y%m%d-%H%M%S", timeinfo
);
1030 if (strftime_ret
== 0) {
1031 ERR("Failed to format session creation timestamp while setting default local output destination");
1032 ret_code
= LTTNG_ERR_FATAL
;
1036 LTTNG_ASSERT(descriptor
->name
);
1037 ret
= snprintf(local_uri
, sizeof(local_uri
),
1038 "file://%s/%s/%s%s",
1040 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1041 creation_datetime_suffix
);
1042 if (ret
>= sizeof(local_uri
)) {
1043 ERR("Truncation occurred while setting default local output destination");
1044 ret_code
= LTTNG_ERR_SET_URL
;
1046 } else if (ret
< 0) {
1047 PERROR("Failed to format default local output URI");
1048 ret_code
= LTTNG_ERR_SET_URL
;
1052 uri_ret
= uri_parse(local_uri
, &uris
);
1054 ret_code
= LTTNG_ERR_SET_URL
;
1057 free(descriptor
->output
.local
);
1058 descriptor
->output
.local
= &uris
[0];
1062 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1066 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1068 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1070 ret_code
= LTTNG_ERR_SET_URL
;
1074 control
= uri_copy(&uris
[0]);
1075 data
= uri_copy(&uris
[1]);
1076 if (!control
|| !data
) {
1079 ret_code
= LTTNG_ERR_SET_URL
;
1083 /* Ownership of uris is transferred. */
1084 ret
= network_location_set_from_lttng_uris(
1085 &descriptor
->output
.network
,
1089 ret_code
= LTTNG_ERR_SET_URL
;
1103 * Note that only properties that can be populated by the session daemon
1104 * (output destination and name) are assigned.
1106 int lttng_session_descriptor_assign(
1107 struct lttng_session_descriptor
*dst
,
1108 const struct lttng_session_descriptor
*src
)
1112 if (dst
->type
!= src
->type
) {
1116 if (dst
->output_type
!= src
->output_type
) {
1120 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1124 switch (dst
->output_type
) {
1125 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1126 free(dst
->output
.local
);
1127 dst
->output
.local
= uri_copy(src
->output
.local
);
1128 if (!dst
->output
.local
) {
1133 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1135 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1137 control_copy
= uri_copy(dst
->output
.network
.control
);
1138 if (!control_copy
&& dst
->output
.network
.control
) {
1142 data_copy
= uri_copy(dst
->output
.network
.data
);
1143 if (!data_copy
&& dst
->output
.network
.data
) {
1148 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1149 control_copy
, data_copy
);
1152 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: