2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <lttng/session-descriptor-internal.h>
19 #include <common/macros.h>
20 #include <common/uri.h>
21 #include <common/defaults.h>
22 #include <common/error.h>
27 struct lttng_session_descriptor_network_location
{
28 struct lttng_uri
*control
;
29 struct lttng_uri
*data
;
32 struct lttng_session_descriptor
{
33 enum lttng_session_descriptor_type type
;
35 * If an output type that is not OUTPUT_TYPE_NONE is specified,
36 * it means that an output of that type must be generated at
37 * session-creation time.
39 enum lttng_session_descriptor_output_type output_type
;
42 struct lttng_session_descriptor_network_location network
;
43 struct lttng_uri
*local
;
47 struct lttng_session_descriptor_snapshot
{
48 struct lttng_session_descriptor base
;
50 * Assumes at-most one snapshot output is supported. Uses
51 * the output field of the base class.
55 struct lttng_session_descriptor_live
{
56 struct lttng_session_descriptor base
;
57 unsigned long long live_timer_us
;
60 struct lttng_session_descriptor_comm
{
61 /* enum lttng_session_descriptor_type */
63 /* enum lttng_session_descriptor_output_type */
65 /* Includes trailing null. */
67 /* Name follows, followed by URIs */
71 struct lttng_session_descriptor_live_comm
{
72 struct lttng_session_descriptor_comm base
;
73 /* Live-specific parameters. */
74 uint64_t live_timer_us
;
78 struct lttng_uri
*uri_copy(const struct lttng_uri
*uri
)
80 struct lttng_uri
*new_uri
= NULL
;
86 new_uri
= zmalloc(sizeof(*new_uri
));
90 memcpy(new_uri
, uri
, sizeof(*new_uri
));
96 struct lttng_uri
*uri_from_path(const char *path
)
98 struct lttng_uri
*uris
= NULL
;
100 char local_protocol_string
[LTTNG_PATH_MAX
+ sizeof("file://")] =
103 if (strlen(path
) >= LTTNG_PATH_MAX
) {
107 if (path
[0] != '/') {
108 /* Not an absolute path. */
112 strncat(local_protocol_string
, path
, LTTNG_PATH_MAX
);
113 uri_count
= uri_parse(local_protocol_string
, &uris
);
114 if (uri_count
!= 1) {
117 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
129 void network_location_fini(
130 struct lttng_session_descriptor_network_location
*location
)
132 free(location
->control
);
133 free(location
->data
);
136 /* Assumes ownership of control and data. */
138 int network_location_set_from_lttng_uris(
139 struct lttng_session_descriptor_network_location
*location
,
140 struct lttng_uri
*control
, struct lttng_uri
*data
)
144 if (!control
&& !data
) {
148 if (!(control
&& data
)) {
149 /* None or both must be set. */
154 if (control
->stype
!= LTTNG_STREAM_CONTROL
||
155 data
->stype
!= LTTNG_STREAM_DATA
) {
160 free(location
->control
);
161 free(location
->data
);
162 location
->control
= control
;
163 location
->data
= data
;
173 int network_location_set_from_uri_strings(
174 struct lttng_session_descriptor_network_location
*location
,
175 const char *control
, const char *data
)
179 struct lttng_uri
*parsed_uris
= NULL
;
180 struct lttng_uri
*control_uri
= NULL
;
181 struct lttng_uri
*data_uri
= NULL
;
183 uri_count
= uri_parse_str_urls(control
, data
, &parsed_uris
);
184 if (uri_count
!= 2 && uri_count
!= 0) {
190 * uri_parse_str_urls returns a contiguous array of lttng_uris whereas
191 * session descriptors expect individually allocated lttng_uris.
193 if (uri_count
== 2) {
194 control_uri
= zmalloc(sizeof(*control_uri
));
195 data_uri
= zmalloc(sizeof(*data_uri
));
196 if (!control_uri
|| !data_uri
) {
200 memcpy(control_uri
, &parsed_uris
[0], sizeof(*control_uri
));
201 memcpy(data_uri
, &parsed_uris
[1], sizeof(*data_uri
));
204 /* Ownership of control and data uris is transferred. */
205 ret
= network_location_set_from_lttng_uris(
218 struct lttng_session_descriptor
*
219 lttng_session_descriptor_create(const char *name
)
221 struct lttng_session_descriptor
*descriptor
;
223 descriptor
= zmalloc(sizeof(*descriptor
));
228 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
229 descriptor
->output_type
=
230 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
231 if (lttng_session_descriptor_set_session_name(descriptor
, name
)) {
236 lttng_session_descriptor_destroy(descriptor
);
240 /* Ownership of uri is transferred. */
242 struct lttng_session_descriptor
*
243 _lttng_session_descriptor_local_create(const char *name
,
244 struct lttng_uri
*uri
)
246 struct lttng_session_descriptor
*descriptor
;
248 descriptor
= lttng_session_descriptor_create(name
);
252 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
253 descriptor
->output_type
=
254 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
256 if (uri
->dtype
!= LTTNG_DST_PATH
) {
259 descriptor
->output
.local
= uri
;
265 lttng_session_descriptor_destroy(descriptor
);
269 struct lttng_session_descriptor
*
270 lttng_session_descriptor_local_create(const char *name
, const char *path
)
272 struct lttng_uri
*uri
= NULL
;
273 struct lttng_session_descriptor
*descriptor
;
276 uri
= uri_from_path(path
);
281 descriptor
= _lttng_session_descriptor_local_create(name
, uri
);
287 /* Assumes the ownership of both uris. */
289 struct lttng_session_descriptor
*
290 _lttng_session_descriptor_network_create(const char *name
,
291 struct lttng_uri
*control
, struct lttng_uri
*data
)
294 struct lttng_session_descriptor
*descriptor
;
296 descriptor
= lttng_session_descriptor_create(name
);
301 descriptor
->type
= LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
;
302 descriptor
->output_type
= LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
303 /* Assumes the ownership of both uris. */
304 ret
= network_location_set_from_lttng_uris(&descriptor
->output
.network
,
313 lttng_session_descriptor_destroy(descriptor
);
319 struct lttng_session_descriptor
*
320 lttng_session_descriptor_network_create(const char *name
,
321 const char *control_url
, const char *data_url
)
324 struct lttng_session_descriptor
*descriptor
;
326 descriptor
= _lttng_session_descriptor_network_create(name
,
332 ret
= network_location_set_from_uri_strings(&descriptor
->output
.network
,
333 control_url
, data_url
);
339 lttng_session_descriptor_destroy(descriptor
);
344 struct lttng_session_descriptor_snapshot
*
345 _lttng_session_descriptor_snapshot_create(const char *name
)
347 struct lttng_session_descriptor_snapshot
*descriptor
;
349 descriptor
= zmalloc(sizeof(*descriptor
));
354 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
;
355 descriptor
->base
.output_type
=
356 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
357 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
363 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
367 /* Ownership of control and data is transferred. */
369 struct lttng_session_descriptor_snapshot
*
370 _lttng_session_descriptor_snapshot_network_create(const char *name
,
371 struct lttng_uri
*control
, struct lttng_uri
*data
)
374 struct lttng_session_descriptor_snapshot
*descriptor
;
376 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
381 descriptor
->base
.output_type
=
382 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
383 /* Ownership of control and data is transferred. */
384 ret
= network_location_set_from_lttng_uris(
385 &descriptor
->base
.output
.network
,
396 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
400 struct lttng_session_descriptor
*
401 lttng_session_descriptor_snapshot_create(const char *name
)
403 struct lttng_session_descriptor_snapshot
*descriptor
;
405 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
406 return descriptor
? &descriptor
->base
: NULL
;
409 struct lttng_session_descriptor
*
410 lttng_session_descriptor_snapshot_network_create(const char *name
,
411 const char *control_url
, const char *data_url
)
414 struct lttng_session_descriptor_snapshot
*descriptor
;
416 descriptor
= _lttng_session_descriptor_snapshot_network_create(name
,
422 ret
= network_location_set_from_uri_strings(
423 &descriptor
->base
.output
.network
,
424 control_url
, data_url
);
428 return &descriptor
->base
;
430 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
434 /* Ownership of uri is transferred. */
436 struct lttng_session_descriptor_snapshot
*
437 _lttng_session_descriptor_snapshot_local_create(const char *name
,
438 struct lttng_uri
*uri
)
440 struct lttng_session_descriptor_snapshot
*descriptor
;
442 descriptor
= _lttng_session_descriptor_snapshot_create(name
);
446 descriptor
->base
.output_type
=
447 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
;
449 if (uri
->dtype
!= LTTNG_DST_PATH
) {
452 descriptor
->base
.output
.local
= uri
;
458 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
462 struct lttng_session_descriptor
*
463 lttng_session_descriptor_snapshot_local_create(const char *name
,
466 struct lttng_uri
*path_uri
= NULL
;
467 struct lttng_session_descriptor_snapshot
*descriptor
;
470 path_uri
= uri_from_path(path
);
475 descriptor
= _lttng_session_descriptor_snapshot_local_create(name
,
477 return descriptor
? &descriptor
->base
: NULL
;
483 struct lttng_session_descriptor_live
*
484 _lttng_session_descriptor_live_create(const char *name
,
485 unsigned long long live_timer_interval_us
)
487 struct lttng_session_descriptor_live
*descriptor
= NULL
;
489 if (live_timer_interval_us
== 0) {
492 descriptor
= zmalloc(sizeof(*descriptor
));
497 descriptor
->base
.type
= LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
;
498 descriptor
->base
.output_type
=
499 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
;
500 descriptor
->live_timer_us
= live_timer_interval_us
;
501 if (lttng_session_descriptor_set_session_name(&descriptor
->base
,
508 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
512 /* Ownership of control and data is transferred. */
514 struct lttng_session_descriptor_live
*
515 _lttng_session_descriptor_live_network_create(
517 struct lttng_uri
*control
, struct lttng_uri
*data
,
518 unsigned long long live_timer_interval_us
)
521 struct lttng_session_descriptor_live
*descriptor
;
523 descriptor
= _lttng_session_descriptor_live_create(name
,
524 live_timer_interval_us
);
525 descriptor
->base
.output_type
=
526 LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
;
528 /* Ownerwhip of control and data is transferred. */
529 ret
= network_location_set_from_lttng_uris(
530 &descriptor
->base
.output
.network
,
541 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
545 struct lttng_session_descriptor
*
546 lttng_session_descriptor_live_create(
548 unsigned long long live_timer_us
)
550 struct lttng_session_descriptor_live
*descriptor
;
552 descriptor
= _lttng_session_descriptor_live_create(name
, live_timer_us
);
554 return descriptor
? &descriptor
->base
: NULL
;
557 struct lttng_session_descriptor
*
558 lttng_session_descriptor_live_network_create(
560 const char *control_url
, const char *data_url
,
561 unsigned long long live_timer_us
)
564 struct lttng_session_descriptor_live
*descriptor
;
566 descriptor
= _lttng_session_descriptor_live_network_create(name
,
567 NULL
, NULL
, live_timer_us
);
572 ret
= network_location_set_from_uri_strings(
573 &descriptor
->base
.output
.network
,
574 control_url
, data_url
);
578 return &descriptor
->base
;
580 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
584 void lttng_session_descriptor_destroy(
585 struct lttng_session_descriptor
*descriptor
)
591 switch (descriptor
->output_type
) {
592 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
594 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
595 free(descriptor
->output
.local
);
597 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
598 network_location_fini(&descriptor
->output
.network
);
604 free(descriptor
->name
);
609 ssize_t
lttng_session_descriptor_create_from_buffer(
610 const struct lttng_buffer_view
*payload
,
611 struct lttng_session_descriptor
**descriptor
)
614 ssize_t offset
= 0, ret
;
615 struct lttng_buffer_view current_view
;
616 const char *name
= NULL
;
617 const struct lttng_session_descriptor_comm
*base_header
;
618 size_t max_expected_uri_count
;
619 uint64_t live_timer_us
= 0;
620 struct lttng_uri
*uris
[2] = {};
621 enum lttng_session_descriptor_type type
;
622 enum lttng_session_descriptor_output_type output_type
;
624 current_view
= lttng_buffer_view_from_view(payload
, offset
,
625 sizeof(*base_header
));
626 base_header
= (typeof(base_header
)) current_view
.data
;
632 switch (base_header
->type
) {
633 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
634 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
636 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
638 const struct lttng_session_descriptor_live_comm
*live_header
;
640 current_view
= lttng_buffer_view_from_view(payload
, offset
,
641 sizeof(*live_header
));
642 live_header
= (typeof(live_header
)) current_view
.data
;
648 live_timer_us
= live_header
->live_timer_us
;
655 /* type has been validated. */
656 type
= base_header
->type
;
658 switch (base_header
->output_type
) {
659 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
660 max_expected_uri_count
= 0;
662 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
663 max_expected_uri_count
= 1;
665 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
666 max_expected_uri_count
= 2;
672 /* output_type has been validated. */
673 output_type
= base_header
->output_type
;
675 /* Skip after header. */
676 offset
+= current_view
.size
;
677 if (!base_header
->name_len
) {
682 current_view
= lttng_buffer_view_from_view(payload
, offset
,
683 base_header
->name_len
);
684 name
= current_view
.data
;
690 if (base_header
->name_len
== 1 ||
691 name
[base_header
->name_len
- 1] ||
692 strlen(name
) != base_header
->name_len
- 1) {
694 * Check that the name is not NULL, is NULL-terminated, and
695 * does not contain a NULL before the last byte.
701 /* Skip after the name. */
702 offset
+= base_header
->name_len
;
704 if (base_header
->uri_count
> max_expected_uri_count
) {
709 for (i
= 0; i
< base_header
->uri_count
; i
++) {
710 struct lttng_uri
*uri
;
713 current_view
= lttng_buffer_view_from_view(payload
,
714 offset
, sizeof(*uri
));
715 uri
= (typeof(uri
)) current_view
.data
;
720 uris
[i
] = zmalloc(sizeof(*uri
));
725 memcpy(uris
[i
], uri
, sizeof(*uri
));
726 offset
+= sizeof(*uri
);
730 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
731 switch (output_type
) {
732 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
733 *descriptor
= lttng_session_descriptor_create(name
);
735 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
736 *descriptor
= _lttng_session_descriptor_local_create(
739 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
740 *descriptor
= _lttng_session_descriptor_network_create(
741 name
, uris
[0], uris
[1]);
744 /* Already checked. */
748 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
750 struct lttng_session_descriptor_snapshot
*snapshot
;
751 switch (output_type
) {
752 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
753 snapshot
= _lttng_session_descriptor_snapshot_create(
756 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
757 snapshot
= _lttng_session_descriptor_snapshot_local_create(
760 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
761 snapshot
= _lttng_session_descriptor_snapshot_network_create(
762 name
, uris
[0], uris
[1]);
765 /* Already checked. */
768 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
771 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
773 struct lttng_session_descriptor_live
*live
;
775 switch (output_type
) {
776 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
777 live
= _lttng_session_descriptor_live_create(
778 name
, live_timer_us
);
780 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
781 live
= _lttng_session_descriptor_live_network_create(
782 name
, uris
[0], uris
[1],
785 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
789 /* Already checked. */
792 *descriptor
= live
? &live
->base
: NULL
;
796 /* Already checked. */
799 memset(uris
, 0, sizeof(uris
));
813 int lttng_session_descriptor_serialize(
814 const struct lttng_session_descriptor
*descriptor
,
815 struct lttng_dynamic_buffer
*buffer
)
818 /* There are, at most, two URIs to serialize. */
819 struct lttng_uri
*uris
[2] = {};
820 size_t uri_count
= 0;
821 /* The live header is a superset of all headers. */
822 struct lttng_session_descriptor_live_comm header
= {
823 .base
.type
= (uint8_t) descriptor
->type
,
824 .base
.output_type
= (uint8_t) descriptor
->output_type
,
825 .base
.name_len
= descriptor
->name
?
826 strlen(descriptor
->name
) + 1 : 0,
828 const void *header_ptr
= NULL
;
831 switch (descriptor
->output_type
) {
832 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
834 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
835 uris
[0] = descriptor
->output
.local
;
837 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
838 uris
[0] = descriptor
->output
.network
.control
;
839 uris
[1] = descriptor
->output
.network
.data
;
845 uri_count
+= !!uris
[0];
846 uri_count
+= !!uris
[1];
848 header
.base
.uri_count
= uri_count
;
849 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
850 const struct lttng_session_descriptor_live
*live
=
851 container_of(descriptor
, typeof(*live
),
854 header
.live_timer_us
= live
->live_timer_us
;
855 header_ptr
= &header
;
856 header_size
= sizeof(header
);
858 header_ptr
= &header
.base
;
859 header_size
= sizeof(header
.base
);
862 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
866 if (header
.base
.name_len
) {
867 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
868 header
.base
.name_len
);
874 for (i
= 0; i
< uri_count
; i
++) {
875 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
876 sizeof(struct lttng_uri
));
886 enum lttng_session_descriptor_type
887 lttng_session_descriptor_get_type(
888 const struct lttng_session_descriptor
*descriptor
)
890 return descriptor
->type
;
894 enum lttng_session_descriptor_output_type
895 lttng_session_descriptor_get_output_type(
896 const struct lttng_session_descriptor
*descriptor
)
898 return descriptor
->output_type
;
902 void lttng_session_descriptor_get_local_output_uri(
903 const struct lttng_session_descriptor
*descriptor
,
904 struct lttng_uri
*local_uri
)
906 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
910 void lttng_session_descriptor_get_network_output_uris(
911 const struct lttng_session_descriptor
*descriptor
,
912 struct lttng_uri
*control
,
913 struct lttng_uri
*data
)
915 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
916 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
921 lttng_session_descriptor_live_get_timer_interval(
922 const struct lttng_session_descriptor
*descriptor
)
924 struct lttng_session_descriptor_live
*live
;
926 live
= container_of(descriptor
, typeof(*live
), base
);
927 return live
->live_timer_us
;
930 enum lttng_session_descriptor_status
931 lttng_session_descriptor_get_session_name(
932 const struct lttng_session_descriptor
*descriptor
,
933 const char **session_name
)
935 enum lttng_session_descriptor_status status
;
937 if (!descriptor
|| !session_name
) {
938 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
942 *session_name
= descriptor
->name
;
943 status
= descriptor
->name
?
944 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
945 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
951 int lttng_session_descriptor_set_session_name(
952 struct lttng_session_descriptor
*descriptor
,
961 if (strlen(name
) >= LTTNG_NAME_MAX
) {
965 new_name
= strdup(name
);
970 free(descriptor
->name
);
971 descriptor
->name
= new_name
;
977 bool lttng_session_descriptor_is_output_destination_initialized(
978 const struct lttng_session_descriptor
*descriptor
)
980 switch (descriptor
->output_type
) {
981 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
983 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
984 return descriptor
->output
.local
;
985 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
986 return descriptor
->output
.network
.control
;
993 bool lttng_session_descriptor_has_output_directory(
994 const struct lttng_session_descriptor
*descriptor
)
996 switch (descriptor
->output_type
) {
997 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
999 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1000 if (descriptor
->output
.local
) {
1001 return *descriptor
->output
.local
->dst
.path
;
1004 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1005 if (descriptor
->output
.network
.control
) {
1006 return *descriptor
->output
.network
.control
->subdir
;
1016 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1017 struct lttng_session_descriptor
*descriptor
,
1018 time_t *session_creation_time
,
1019 const char *absolute_home_path
)
1021 enum lttng_error_code ret_code
= LTTNG_OK
;
1022 struct lttng_uri
*uris
= NULL
;
1024 switch (descriptor
->output_type
) {
1025 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1027 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1031 char local_uri
[LTTNG_PATH_MAX
];
1032 char creation_datetime_suffix
[17] = {};
1034 if (session_creation_time
) {
1035 size_t strftime_ret
;
1036 struct tm
*timeinfo
;
1038 timeinfo
= localtime(session_creation_time
);
1040 ret_code
= LTTNG_ERR_FATAL
;
1043 strftime_ret
= strftime(creation_datetime_suffix
,
1044 sizeof(creation_datetime_suffix
),
1045 "-%Y%m%d-%H%M%S", timeinfo
);
1046 if (strftime_ret
== 0) {
1047 ERR("Failed to format session creation timestamp while setting default local output destination");
1048 ret_code
= LTTNG_ERR_FATAL
;
1052 assert(descriptor
->name
);
1053 ret
= snprintf(local_uri
, sizeof(local_uri
),
1054 "file://%s/%s/%s%s",
1056 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1057 creation_datetime_suffix
);
1058 if (ret
>= sizeof(local_uri
)) {
1059 ERR("Truncation occurred while setting default local output destination");
1060 ret_code
= LTTNG_ERR_SET_URL
;
1062 } else if (ret
< 0) {
1063 PERROR("Failed to format default local output URI");
1064 ret_code
= LTTNG_ERR_SET_URL
;
1068 uri_ret
= uri_parse(local_uri
, &uris
);
1070 ret_code
= LTTNG_ERR_SET_URL
;
1073 free(descriptor
->output
.local
);
1074 descriptor
->output
.local
= &uris
[0];
1078 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1082 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1084 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1086 ret_code
= LTTNG_ERR_SET_URL
;
1090 control
= uri_copy(&uris
[0]);
1091 data
= uri_copy(&uris
[1]);
1092 if (!control
|| !data
) {
1095 ret_code
= LTTNG_ERR_SET_URL
;
1099 /* Ownership of uris is transferred. */
1100 ret
= network_location_set_from_lttng_uris(
1101 &descriptor
->output
.network
,
1105 ret_code
= LTTNG_ERR_SET_URL
;
1119 * Note that only properties that can be populated by the session daemon
1120 * (output destination and name) are assigned.
1123 int lttng_session_descriptor_assign(
1124 struct lttng_session_descriptor
*dst
,
1125 const struct lttng_session_descriptor
*src
)
1129 if (dst
->type
!= src
->type
) {
1133 if (dst
->output_type
!= src
->output_type
) {
1137 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1141 switch (dst
->output_type
) {
1142 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1143 free(dst
->output
.local
);
1144 dst
->output
.local
= uri_copy(src
->output
.local
);
1145 if (!dst
->output
.local
) {
1150 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1152 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1154 control_copy
= uri_copy(dst
->output
.network
.control
);
1155 if (!control_copy
&& dst
->output
.network
.control
) {
1159 data_copy
= uri_copy(dst
->output
.network
.data
);
1160 if (!data_copy
&& dst
->output
.network
.data
) {
1165 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1166 control_copy
, data_copy
);
1169 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1177 int lttng_session_descriptor_get_base_path(struct lttng_session_descriptor
*dst
,
1178 const char **_base_path
)
1180 switch (dst
->output_type
) {
1181 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1183 if (dst
->output
.network
.control
&&
1184 dst
->output
.network
.control
->subdir
[0]) {
1185 *_base_path
= dst
->output
.network
.control
->subdir
;
1191 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1192 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: