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
);
557 return descriptor
? &descriptor
->base
: NULL
;
559 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
563 struct lttng_session_descriptor
*
564 lttng_session_descriptor_live_network_create(
566 const char *control_url
, const char *data_url
,
567 unsigned long long live_timer_us
)
570 struct lttng_session_descriptor_live
*descriptor
;
572 descriptor
= _lttng_session_descriptor_live_network_create(name
,
573 NULL
, NULL
, live_timer_us
);
578 ret
= network_location_set_from_uri_strings(
579 &descriptor
->base
.output
.network
,
580 control_url
, data_url
);
584 return &descriptor
->base
;
586 lttng_session_descriptor_destroy(descriptor
? &descriptor
->base
: NULL
);
590 void lttng_session_descriptor_destroy(
591 struct lttng_session_descriptor
*descriptor
)
597 switch (descriptor
->output_type
) {
598 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
600 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
601 free(descriptor
->output
.local
);
603 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
604 network_location_fini(&descriptor
->output
.network
);
610 free(descriptor
->name
);
615 ssize_t
lttng_session_descriptor_create_from_buffer(
616 const struct lttng_buffer_view
*payload
,
617 struct lttng_session_descriptor
**descriptor
)
620 ssize_t offset
= 0, ret
;
621 struct lttng_buffer_view current_view
;
622 const char *name
= NULL
;
623 const struct lttng_session_descriptor_comm
*base_header
;
624 size_t max_expected_uri_count
;
625 uint64_t live_timer_us
= 0;
626 struct lttng_uri
*uris
[2] = {};
627 enum lttng_session_descriptor_type type
;
628 enum lttng_session_descriptor_output_type output_type
;
630 current_view
= lttng_buffer_view_from_view(payload
, offset
,
631 sizeof(*base_header
));
632 base_header
= (typeof(base_header
)) current_view
.data
;
638 switch (base_header
->type
) {
639 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
640 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
642 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
644 const struct lttng_session_descriptor_live_comm
*live_header
;
646 current_view
= lttng_buffer_view_from_view(payload
, offset
,
647 sizeof(*live_header
));
648 live_header
= (typeof(live_header
)) current_view
.data
;
654 live_timer_us
= live_header
->live_timer_us
;
661 /* type has been validated. */
662 type
= base_header
->type
;
664 switch (base_header
->output_type
) {
665 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
666 max_expected_uri_count
= 0;
668 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
669 max_expected_uri_count
= 1;
671 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
672 max_expected_uri_count
= 2;
678 /* output_type has been validated. */
679 output_type
= base_header
->output_type
;
681 /* Skip after header. */
682 offset
+= current_view
.size
;
683 if (!base_header
->name_len
) {
688 current_view
= lttng_buffer_view_from_view(payload
, offset
,
689 base_header
->name_len
);
690 name
= current_view
.data
;
696 if (base_header
->name_len
== 1 ||
697 name
[base_header
->name_len
- 1] ||
698 strlen(name
) != base_header
->name_len
- 1) {
700 * Check that the name is not NULL, is NULL-terminated, and
701 * does not contain a NULL before the last byte.
707 /* Skip after the name. */
708 offset
+= base_header
->name_len
;
710 if (base_header
->uri_count
> max_expected_uri_count
) {
715 for (i
= 0; i
< base_header
->uri_count
; i
++) {
716 struct lttng_uri
*uri
;
719 current_view
= lttng_buffer_view_from_view(payload
,
720 offset
, sizeof(*uri
));
721 uri
= (typeof(uri
)) current_view
.data
;
726 uris
[i
] = zmalloc(sizeof(*uri
));
731 memcpy(uris
[i
], uri
, sizeof(*uri
));
732 offset
+= sizeof(*uri
);
736 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
737 switch (output_type
) {
738 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
739 *descriptor
= lttng_session_descriptor_create(name
);
741 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
742 *descriptor
= _lttng_session_descriptor_local_create(
745 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
746 *descriptor
= _lttng_session_descriptor_network_create(
747 name
, uris
[0], uris
[1]);
750 /* Already checked. */
754 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
756 struct lttng_session_descriptor_snapshot
*snapshot
;
757 switch (output_type
) {
758 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
759 snapshot
= _lttng_session_descriptor_snapshot_create(
762 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
763 snapshot
= _lttng_session_descriptor_snapshot_local_create(
766 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
767 snapshot
= _lttng_session_descriptor_snapshot_network_create(
768 name
, uris
[0], uris
[1]);
771 /* Already checked. */
774 *descriptor
= snapshot
? &snapshot
->base
: NULL
;
777 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
779 struct lttng_session_descriptor_live
*live
;
781 switch (output_type
) {
782 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
783 live
= _lttng_session_descriptor_live_create(
784 name
, live_timer_us
);
786 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
787 live
= _lttng_session_descriptor_live_network_create(
788 name
, uris
[0], uris
[1],
791 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
795 /* Already checked. */
798 *descriptor
= live
? &live
->base
: NULL
;
802 /* Already checked. */
805 memset(uris
, 0, sizeof(uris
));
819 int lttng_session_descriptor_serialize(
820 const struct lttng_session_descriptor
*descriptor
,
821 struct lttng_dynamic_buffer
*buffer
)
824 /* There are, at most, two URIs to serialize. */
825 struct lttng_uri
*uris
[2] = {};
826 size_t uri_count
= 0;
827 /* The live header is a superset of all headers. */
828 struct lttng_session_descriptor_live_comm header
= {
829 .base
.type
= (uint8_t) descriptor
->type
,
830 .base
.output_type
= (uint8_t) descriptor
->output_type
,
831 .base
.name_len
= descriptor
->name
?
832 strlen(descriptor
->name
) + 1 : 0,
834 const void *header_ptr
= NULL
;
837 switch (descriptor
->output_type
) {
838 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
840 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
841 uris
[0] = descriptor
->output
.local
;
843 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
844 uris
[0] = descriptor
->output
.network
.control
;
845 uris
[1] = descriptor
->output
.network
.data
;
851 uri_count
+= !!uris
[0];
852 uri_count
+= !!uris
[1];
854 header
.base
.uri_count
= uri_count
;
855 if (descriptor
->type
== LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
) {
856 const struct lttng_session_descriptor_live
*live
=
857 container_of(descriptor
, typeof(*live
),
860 header
.live_timer_us
= live
->live_timer_us
;
861 header_ptr
= &header
;
862 header_size
= sizeof(header
);
864 header_ptr
= &header
.base
;
865 header_size
= sizeof(header
.base
);
868 ret
= lttng_dynamic_buffer_append(buffer
, header_ptr
, header_size
);
872 if (header
.base
.name_len
) {
873 ret
= lttng_dynamic_buffer_append(buffer
, descriptor
->name
,
874 header
.base
.name_len
);
880 for (i
= 0; i
< uri_count
; i
++) {
881 ret
= lttng_dynamic_buffer_append(buffer
, uris
[i
],
882 sizeof(struct lttng_uri
));
892 enum lttng_session_descriptor_type
893 lttng_session_descriptor_get_type(
894 const struct lttng_session_descriptor
*descriptor
)
896 return descriptor
->type
;
900 enum lttng_session_descriptor_output_type
901 lttng_session_descriptor_get_output_type(
902 const struct lttng_session_descriptor
*descriptor
)
904 return descriptor
->output_type
;
908 void lttng_session_descriptor_get_local_output_uri(
909 const struct lttng_session_descriptor
*descriptor
,
910 struct lttng_uri
*local_uri
)
912 memcpy(local_uri
, descriptor
->output
.local
, sizeof(*local_uri
));
916 void lttng_session_descriptor_get_network_output_uris(
917 const struct lttng_session_descriptor
*descriptor
,
918 struct lttng_uri
*control
,
919 struct lttng_uri
*data
)
921 memcpy(control
, descriptor
->output
.network
.control
, sizeof(*control
));
922 memcpy(data
, descriptor
->output
.network
.data
, sizeof(*data
));
927 lttng_session_descriptor_live_get_timer_interval(
928 const struct lttng_session_descriptor
*descriptor
)
930 struct lttng_session_descriptor_live
*live
;
932 live
= container_of(descriptor
, typeof(*live
), base
);
933 return live
->live_timer_us
;
936 enum lttng_session_descriptor_status
937 lttng_session_descriptor_get_session_name(
938 const struct lttng_session_descriptor
*descriptor
,
939 const char **session_name
)
941 enum lttng_session_descriptor_status status
;
943 if (!descriptor
|| !session_name
) {
944 status
= LTTNG_SESSION_DESCRIPTOR_STATUS_INVALID
;
948 *session_name
= descriptor
->name
;
949 status
= descriptor
->name
?
950 LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
951 LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
;
957 int lttng_session_descriptor_set_session_name(
958 struct lttng_session_descriptor
*descriptor
,
967 if (strlen(name
) >= LTTNG_NAME_MAX
) {
971 new_name
= strdup(name
);
976 free(descriptor
->name
);
977 descriptor
->name
= new_name
;
983 bool lttng_session_descriptor_is_output_destination_initialized(
984 const struct lttng_session_descriptor
*descriptor
)
986 switch (descriptor
->output_type
) {
987 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
989 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
990 return descriptor
->output
.local
;
991 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
992 return descriptor
->output
.network
.control
;
999 bool lttng_session_descriptor_has_output_directory(
1000 const struct lttng_session_descriptor
*descriptor
)
1002 switch (descriptor
->output_type
) {
1003 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1005 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1006 if (descriptor
->output
.local
) {
1007 return *descriptor
->output
.local
->dst
.path
;
1010 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1011 if (descriptor
->output
.network
.control
) {
1012 return *descriptor
->output
.network
.control
->subdir
;
1022 enum lttng_error_code
lttng_session_descriptor_set_default_output(
1023 struct lttng_session_descriptor
*descriptor
,
1024 time_t *session_creation_time
,
1025 const char *absolute_home_path
)
1027 enum lttng_error_code ret_code
= LTTNG_OK
;
1028 struct lttng_uri
*uris
= NULL
;
1030 switch (descriptor
->output_type
) {
1031 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
1033 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1037 char local_uri
[LTTNG_PATH_MAX
];
1038 char creation_datetime_suffix
[17] = {};
1040 if (session_creation_time
) {
1041 size_t strftime_ret
;
1042 struct tm
*timeinfo
;
1044 timeinfo
= localtime(session_creation_time
);
1046 ret_code
= LTTNG_ERR_FATAL
;
1049 strftime_ret
= strftime(creation_datetime_suffix
,
1050 sizeof(creation_datetime_suffix
),
1051 "-%Y%m%d-%H%M%S", timeinfo
);
1052 if (strftime_ret
== 0) {
1053 ERR("Failed to format session creation timestamp while setting default local output destination");
1054 ret_code
= LTTNG_ERR_FATAL
;
1058 assert(descriptor
->name
);
1059 ret
= snprintf(local_uri
, sizeof(local_uri
),
1060 "file://%s/%s/%s%s",
1062 DEFAULT_TRACE_DIR_NAME
, descriptor
->name
,
1063 creation_datetime_suffix
);
1064 if (ret
>= sizeof(local_uri
)) {
1065 ERR("Truncation occurred while setting default local output destination");
1066 ret_code
= LTTNG_ERR_SET_URL
;
1068 } else if (ret
< 0) {
1069 PERROR("Failed to format default local output URI");
1070 ret_code
= LTTNG_ERR_SET_URL
;
1074 uri_ret
= uri_parse(local_uri
, &uris
);
1076 ret_code
= LTTNG_ERR_SET_URL
;
1079 free(descriptor
->output
.local
);
1080 descriptor
->output
.local
= &uris
[0];
1084 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1088 struct lttng_uri
*control
= NULL
, *data
= NULL
;
1090 uri_ret
= uri_parse_str_urls("net://127.0.0.1", NULL
, &uris
);
1092 ret_code
= LTTNG_ERR_SET_URL
;
1096 control
= uri_copy(&uris
[0]);
1097 data
= uri_copy(&uris
[1]);
1098 if (!control
|| !data
) {
1101 ret_code
= LTTNG_ERR_SET_URL
;
1105 /* Ownership of uris is transferred. */
1106 ret
= network_location_set_from_lttng_uris(
1107 &descriptor
->output
.network
,
1111 ret_code
= LTTNG_ERR_SET_URL
;
1125 * Note that only properties that can be populated by the session daemon
1126 * (output destination and name) are assigned.
1129 int lttng_session_descriptor_assign(
1130 struct lttng_session_descriptor
*dst
,
1131 const struct lttng_session_descriptor
*src
)
1135 if (dst
->type
!= src
->type
) {
1139 if (dst
->output_type
!= src
->output_type
) {
1143 ret
= lttng_session_descriptor_set_session_name(dst
, src
->name
);
1147 switch (dst
->output_type
) {
1148 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
1149 free(dst
->output
.local
);
1150 dst
->output
.local
= uri_copy(src
->output
.local
);
1151 if (!dst
->output
.local
) {
1156 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
1158 struct lttng_uri
*control_copy
= NULL
, *data_copy
= NULL
;
1160 control_copy
= uri_copy(dst
->output
.network
.control
);
1161 if (!control_copy
&& dst
->output
.network
.control
) {
1165 data_copy
= uri_copy(dst
->output
.network
.data
);
1166 if (!data_copy
&& dst
->output
.network
.data
) {
1171 ret
= network_location_set_from_lttng_uris(&dst
->output
.network
,
1172 control_copy
, data_copy
);
1175 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
: