2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program 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 General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
31 #include <common/defaults.h>
32 #include <common/error.h>
33 #include <common/macros.h>
34 #include <common/utils.h>
35 #include <common/compat/getenv.h>
36 #include <lttng/lttng-error.h>
37 #include <libxml/parser.h>
38 #include <libxml/valid.h>
39 #include <libxml/xmlschemas.h>
40 #include <libxml/tree.h>
41 #include <lttng/lttng.h>
42 #include <lttng/snapshot.h>
44 #include "session-config.h"
45 #include "config-internal.h"
47 struct handler_filter_args
{
49 config_entry_handler_cb handler
;
53 struct session_config_validation_ctx
{
54 xmlSchemaParserCtxtPtr parser_ctx
;
56 xmlSchemaValidCtxtPtr schema_validation_ctx
;
59 const char * const config_str_yes
= "yes";
60 const char * const config_str_true
= "true";
61 const char * const config_str_on
= "on";
62 const char * const config_str_no
= "no";
63 const char * const config_str_false
= "false";
64 const char * const config_str_off
= "off";
65 const char * const config_xml_encoding
= "UTF-8";
66 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
67 const char * const config_xml_indent_string
= "\t";
68 const char * const config_xml_true
= "true";
69 const char * const config_xml_false
= "false";
71 const char * const config_element_channel
= "channel";
72 const char * const config_element_channels
= "channels";
73 const char * const config_element_domain
= "domain";
74 const char * const config_element_domains
= "domains";
75 const char * const config_element_event
= "event";
76 const char * const config_element_events
= "events";
77 const char * const config_element_context
= "context";
78 const char * const config_element_contexts
= "contexts";
79 const char * const config_element_attributes
= "attributes";
80 const char * const config_element_exclusion
= "exclusion";
81 const char * const config_element_exclusions
= "exclusions";
82 const char * const config_element_function_attributes
= "function_attributes";
83 const char * const config_element_probe_attributes
= "probe_attributes";
84 const char * const config_element_symbol_name
= "symbol_name";
85 const char * const config_element_address
= "address";
86 const char * const config_element_offset
= "offset";
87 const char * const config_element_name
= "name";
88 const char * const config_element_enabled
= "enabled";
89 const char * const config_element_overwrite_mode
= "overwrite_mode";
90 const char * const config_element_subbuf_size
= "subbuffer_size";
91 const char * const config_element_num_subbuf
= "subbuffer_count";
92 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
93 const char * const config_element_read_timer_interval
= "read_timer_interval";
94 const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
95 const char * const config_element_output
= "output";
96 const char * const config_element_output_type
= "output_type";
97 const char * const config_element_tracefile_size
= "tracefile_size";
98 const char * const config_element_tracefile_count
= "tracefile_count";
99 const char * const config_element_live_timer_interval
= "live_timer_interval";
100 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
101 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
102 const char * const config_element_type
= "type";
103 const char * const config_element_buffer_type
= "buffer_type";
104 const char * const config_element_session
= "session";
105 const char * const config_element_sessions
= "sessions";
106 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
107 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
108 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
109 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
110 const char * const config_element_config
= "config";
111 const char * const config_element_started
= "started";
112 const char * const config_element_snapshot_mode
= "snapshot_mode";
113 const char * const config_element_loglevel
= "loglevel";
114 const char * const config_element_loglevel_type
= "loglevel_type";
115 const char * const config_element_filter
= "filter";
116 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
117 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
118 const char * const config_element_consumer_output
= "consumer_output";
119 const char * const config_element_destination
= "destination";
120 const char * const config_element_path
= "path";
121 const char * const config_element_net_output
= "net_output";
122 const char * const config_element_control_uri
= "control_uri";
123 const char * const config_element_data_uri
= "data_uri";
124 const char * const config_element_max_size
= "max_size";
125 const char * const config_element_pid
= "pid";
126 const char * const config_element_pids
= "pids";
127 const char * const config_element_shared_memory_path
= "shared_memory_path";
128 const char * const config_element_pid_tracker
= "pid_tracker";
129 const char * const config_element_trackers
= "trackers";
130 const char * const config_element_targets
= "targets";
131 const char * const config_element_target_pid
= "pid_target";
133 const char * const config_domain_type_kernel
= "KERNEL";
134 const char * const config_domain_type_ust
= "UST";
135 const char * const config_domain_type_jul
= "JUL";
136 const char * const config_domain_type_log4j
= "LOG4J";
137 const char * const config_domain_type_python
= "PYTHON";
139 const char * const config_buffer_type_per_pid
= "PER_PID";
140 const char * const config_buffer_type_per_uid
= "PER_UID";
141 const char * const config_buffer_type_global
= "GLOBAL";
143 const char * const config_overwrite_mode_discard
= "DISCARD";
144 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
146 const char * const config_output_type_splice
= "SPLICE";
147 const char * const config_output_type_mmap
= "MMAP";
149 const char * const config_loglevel_type_all
= "ALL";
150 const char * const config_loglevel_type_range
= "RANGE";
151 const char * const config_loglevel_type_single
= "SINGLE";
153 const char * const config_event_type_all
= "ALL";
154 const char * const config_event_type_tracepoint
= "TRACEPOINT";
155 const char * const config_event_type_probe
= "PROBE";
156 const char * const config_event_type_function
= "FUNCTION";
157 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
158 const char * const config_event_type_noop
= "NOOP";
159 const char * const config_event_type_syscall
= "SYSCALL";
160 const char * const config_event_type_kprobe
= "KPROBE";
161 const char * const config_event_type_kretprobe
= "KRETPROBE";
163 const char * const config_event_context_pid
= "PID";
164 const char * const config_event_context_procname
= "PROCNAME";
165 const char * const config_event_context_prio
= "PRIO";
166 const char * const config_event_context_nice
= "NICE";
167 const char * const config_event_context_vpid
= "VPID";
168 const char * const config_event_context_tid
= "TID";
169 const char * const config_event_context_vtid
= "VTID";
170 const char * const config_event_context_ppid
= "PPID";
171 const char * const config_event_context_vppid
= "VPPID";
172 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
173 const char * const config_event_context_hostname
= "HOSTNAME";
174 const char * const config_event_context_ip
= "IP";
175 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
176 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
177 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
178 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
179 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
180 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
182 /* Deprecated symbols */
183 const char * const config_element_perf
;
185 enum process_event_node_phase
{
190 struct consumer_output
{
197 static int config_entry_handler_filter(struct handler_filter_args
*args
,
198 const char *section
, const char *name
, const char *value
)
201 struct config_entry entry
= { section
, name
, value
};
205 if (!section
|| !name
|| !value
) {
211 if (strcmp(args
->section
, section
)) {
216 ret
= args
->handler(&entry
, args
->user_data
);
222 int config_get_section_entries(const char *override_path
, const char *section
,
223 config_entry_handler_cb handler
, void *user_data
)
227 FILE *config_file
= NULL
;
228 struct handler_filter_args filter
= { section
, handler
, user_data
};
230 /* First, try system-wide conf. file. */
231 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
233 config_file
= fopen(path
, "r");
235 DBG("Loading daemon conf file at %s", path
);
237 * Return value is not very important here since error or not, we
238 * continue and try the next possible conf. file.
240 (void) ini_parse_file(config_file
,
241 (ini_entry_handler
) config_entry_handler_filter
,
246 /* Second is the user local configuration. */
247 path
= utils_get_home_dir();
249 char fullpath
[PATH_MAX
];
251 ret
= snprintf(fullpath
, sizeof(fullpath
),
252 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
254 PERROR("snprintf user conf. path");
258 config_file
= fopen(fullpath
, "r");
260 DBG("Loading daemon user conf file at %s", path
);
262 * Return value is not very important here since error or not, we
263 * continue and try the next possible conf. file.
265 (void) ini_parse_file(config_file
,
266 (ini_entry_handler
) config_entry_handler_filter
,
272 /* Final path is the one that the user might have provided. */
274 config_file
= fopen(override_path
, "r");
276 DBG("Loading daemon command line conf file at %s", override_path
);
277 (void) ini_parse_file(config_file
,
278 (ini_entry_handler
) config_entry_handler_filter
,
282 ERR("Failed to open daemon configuration file at %s",
289 /* Everything went well. */
297 int config_parse_value(const char *value
)
300 char *endptr
, *lower_str
;
310 v
= strtoul(value
, &endptr
, 10);
311 if (endptr
!= value
) {
316 lower_str
= zmalloc(len
+ 1);
323 for (i
= 0; i
< len
; i
++) {
324 lower_str
[i
] = tolower(value
[i
]);
327 if (!strcmp(lower_str
, config_str_yes
) ||
328 !strcmp(lower_str
, config_str_true
) ||
329 !strcmp(lower_str
, config_str_on
)) {
331 } else if (!strcmp(lower_str
, config_str_no
) ||
332 !strcmp(lower_str
, config_str_false
) ||
333 !strcmp(lower_str
, config_str_off
)) {
345 * Returns a xmlChar string which must be released using xmlFree().
347 static xmlChar
*encode_string(const char *in_str
)
349 xmlChar
*out_str
= NULL
;
350 xmlCharEncodingHandlerPtr handler
;
351 int out_len
, ret
, in_len
;
355 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
357 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
361 in_len
= strlen(in_str
);
363 * Add 1 byte for the NULL terminted character. The factor 4 here is
364 * used because UTF-8 characters can take up to 4 bytes.
366 out_len
= (in_len
* 4) + 1;
367 out_str
= xmlMalloc(out_len
);
372 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
379 /* out_len is now the size of out_str */
380 out_str
[out_len
] = '\0';
386 struct config_writer
*config_writer_create(int fd_output
, int indent
)
389 struct config_writer
*writer
;
390 xmlOutputBufferPtr buffer
;
392 writer
= zmalloc(sizeof(struct config_writer
));
394 PERROR("zmalloc config_writer_create");
398 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
403 writer
->writer
= xmlNewTextWriter(buffer
);
404 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
405 config_xml_encoding
, NULL
);
410 ret
= xmlTextWriterSetIndentString(writer
->writer
,
411 BAD_CAST config_xml_indent_string
);
416 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
424 config_writer_destroy(writer
);
429 int config_writer_destroy(struct config_writer
*writer
)
438 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
439 WARN("Could not close XML document");
443 if (writer
->writer
) {
444 xmlFreeTextWriter(writer
->writer
);
453 int config_writer_open_element(struct config_writer
*writer
,
454 const char *element_name
)
457 xmlChar
*encoded_element_name
;
459 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
464 encoded_element_name
= encode_string(element_name
);
465 if (!encoded_element_name
) {
470 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
471 xmlFree(encoded_element_name
);
473 return ret
>= 0 ? 0 : ret
;
477 int config_writer_write_attribute(struct config_writer
*writer
,
478 const char *name
, const char *value
)
481 xmlChar
*encoded_name
= NULL
;
482 xmlChar
*encoded_value
= NULL
;
484 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
489 encoded_name
= encode_string(name
);
495 encoded_value
= encode_string(value
);
496 if (!encoded_value
) {
501 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
504 xmlFree(encoded_name
);
505 xmlFree(encoded_value
);
506 return ret
>= 0 ? 0 : ret
;
510 int config_writer_close_element(struct config_writer
*writer
)
514 if (!writer
|| !writer
->writer
) {
519 ret
= xmlTextWriterEndElement(writer
->writer
);
521 return ret
>= 0 ? 0 : ret
;
525 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
526 const char *element_name
, uint64_t value
)
529 xmlChar
*encoded_element_name
;
531 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
536 encoded_element_name
= encode_string(element_name
);
537 if (!encoded_element_name
) {
542 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
543 encoded_element_name
, "%" PRIu64
, value
);
544 xmlFree(encoded_element_name
);
546 return ret
>= 0 ? 0 : ret
;
550 int config_writer_write_element_signed_int(struct config_writer
*writer
,
551 const char *element_name
, int64_t value
)
554 xmlChar
*encoded_element_name
;
556 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
561 encoded_element_name
= encode_string(element_name
);
562 if (!encoded_element_name
) {
567 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
568 encoded_element_name
, "%" PRIi64
, value
);
569 xmlFree(encoded_element_name
);
571 return ret
>= 0 ? 0 : ret
;
575 int config_writer_write_element_bool(struct config_writer
*writer
,
576 const char *element_name
, int value
)
578 return config_writer_write_element_string(writer
, element_name
,
579 value
? config_xml_true
: config_xml_false
);
583 int config_writer_write_element_string(struct config_writer
*writer
,
584 const char *element_name
, const char *value
)
587 xmlChar
*encoded_element_name
= NULL
;
588 xmlChar
*encoded_value
= NULL
;
590 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
596 encoded_element_name
= encode_string(element_name
);
597 if (!encoded_element_name
) {
602 encoded_value
= encode_string(value
);
603 if (!encoded_value
) {
608 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
611 xmlFree(encoded_element_name
);
612 xmlFree(encoded_value
);
613 return ret
>= 0 ? 0 : ret
;
617 void xml_error_handler(void *ctx
, const char *format
, ...)
623 va_start(args
, format
);
624 ret
= vasprintf(&errMsg
, format
, args
);
627 ERR("String allocation failed in xml error handler");
631 fprintf(stderr
, "XML Error: %s", errMsg
);
636 void fini_session_config_validation_ctx(
637 struct session_config_validation_ctx
*ctx
)
639 if (ctx
->parser_ctx
) {
640 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
644 xmlSchemaFree(ctx
->schema
);
647 if (ctx
->schema_validation_ctx
) {
648 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
651 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
655 char *get_session_config_xsd_path()
658 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
659 size_t base_path_len
;
663 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
666 base_path_len
= strlen(base_path
);
667 max_path_len
= base_path_len
+
668 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
669 xsd_path
= zmalloc(max_path_len
);
674 strncpy(xsd_path
, base_path
, max_path_len
);
675 if (xsd_path
[base_path_len
- 1] != '/') {
676 xsd_path
[base_path_len
++] = '/';
679 strncpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
,
680 max_path_len
- base_path_len
);
686 int init_session_config_validation_ctx(
687 struct session_config_validation_ctx
*ctx
)
690 char *xsd_path
= get_session_config_xsd_path();
693 ret
= -LTTNG_ERR_NOMEM
;
697 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
698 if (!ctx
->parser_ctx
) {
699 ERR("XSD parser context creation failed");
700 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
703 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
704 xml_error_handler
, NULL
);
706 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
708 ERR("XSD parsing failed");
709 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
713 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
714 if (!ctx
->schema_validation_ctx
) {
715 ERR("XSD validation context creation failed");
716 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
720 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
721 xml_error_handler
, NULL
);
726 fini_session_config_validation_ctx(ctx
);
734 int parse_uint(xmlChar
*str
, uint64_t *val
)
744 *val
= strtoull((const char *) str
, &endptr
, 10);
745 if (!endptr
|| *endptr
) {
756 int parse_int(xmlChar
*str
, int64_t *val
)
766 *val
= strtoll((const char *) str
, &endptr
, 10);
767 if (!endptr
|| *endptr
) {
778 int parse_bool(xmlChar
*str
, int *val
)
787 if (!strcmp((const char *) str
, config_xml_true
)) {
789 } else if (!strcmp((const char *) str
, config_xml_false
)) {
792 WARN("Invalid boolean value encoutered (%s).",
801 int get_domain_type(xmlChar
*domain
)
809 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
810 ret
= LTTNG_DOMAIN_KERNEL
;
811 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
812 ret
= LTTNG_DOMAIN_UST
;
813 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
814 ret
= LTTNG_DOMAIN_JUL
;
815 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
816 ret
= LTTNG_DOMAIN_LOG4J
;
817 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
818 ret
= LTTNG_DOMAIN_PYTHON
;
829 int get_buffer_type(xmlChar
*buffer_type
)
837 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
838 ret
= LTTNG_BUFFER_GLOBAL
;
839 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
840 ret
= LTTNG_BUFFER_PER_UID
;
841 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
842 ret
= LTTNG_BUFFER_PER_PID
;
853 int get_overwrite_mode(xmlChar
*overwrite_mode
)
857 if (!overwrite_mode
) {
861 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
863 } else if (!strcmp((char *) overwrite_mode
,
864 config_overwrite_mode_discard
)) {
876 int get_output_type(xmlChar
*output_type
)
884 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
885 ret
= LTTNG_EVENT_MMAP
;
886 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
887 ret
= LTTNG_EVENT_SPLICE
;
898 int get_event_type(xmlChar
*event_type
)
906 if (!strcmp((char *) event_type
, config_event_type_all
)) {
907 ret
= LTTNG_EVENT_ALL
;
908 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
909 ret
= LTTNG_EVENT_TRACEPOINT
;
910 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
911 ret
= LTTNG_EVENT_PROBE
;
912 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
913 ret
= LTTNG_EVENT_FUNCTION
;
914 } else if (!strcmp((char *) event_type
,
915 config_event_type_function_entry
)) {
916 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
917 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
918 ret
= LTTNG_EVENT_NOOP
;
919 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
920 ret
= LTTNG_EVENT_SYSCALL
;
931 int get_loglevel_type(xmlChar
*loglevel_type
)
935 if (!loglevel_type
) {
939 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
940 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
941 } else if (!strcmp((char *) loglevel_type
,
942 config_loglevel_type_range
)) {
943 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
944 } else if (!strcmp((char *) loglevel_type
,
945 config_loglevel_type_single
)) {
946 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
957 * Return the context type or -1 on error.
960 int get_context_type(xmlChar
*context_type
)
968 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
969 ret
= LTTNG_EVENT_CONTEXT_PID
;
970 } else if (!strcmp((char *) context_type
,
971 config_event_context_procname
)) {
972 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
973 } else if (!strcmp((char *) context_type
,
974 config_event_context_prio
)) {
975 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
976 } else if (!strcmp((char *) context_type
,
977 config_event_context_nice
)) {
978 ret
= LTTNG_EVENT_CONTEXT_NICE
;
979 } else if (!strcmp((char *) context_type
,
980 config_event_context_vpid
)) {
981 ret
= LTTNG_EVENT_CONTEXT_VPID
;
982 } else if (!strcmp((char *) context_type
,
983 config_event_context_tid
)) {
984 ret
= LTTNG_EVENT_CONTEXT_TID
;
985 } else if (!strcmp((char *) context_type
,
986 config_event_context_vtid
)) {
987 ret
= LTTNG_EVENT_CONTEXT_VTID
;
988 } else if (!strcmp((char *) context_type
,
989 config_event_context_ppid
)) {
990 ret
= LTTNG_EVENT_CONTEXT_PPID
;
991 } else if (!strcmp((char *) context_type
,
992 config_event_context_vppid
)) {
993 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
994 } else if (!strcmp((char *) context_type
,
995 config_event_context_pthread_id
)) {
996 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
997 } else if (!strcmp((char *) context_type
,
998 config_event_context_hostname
)) {
999 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1000 } else if (!strcmp((char *) context_type
,
1001 config_event_context_ip
)) {
1002 ret
= LTTNG_EVENT_CONTEXT_IP
;
1003 } else if (!strcmp((char *) context_type
,
1004 config_event_context_interruptible
)) {
1005 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1006 } else if (!strcmp((char *) context_type
,
1007 config_event_context_preemptible
)) {
1008 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1009 } else if (!strcmp((char *) context_type
,
1010 config_event_context_need_reschedule
)) {
1011 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1012 } else if (!strcmp((char *) context_type
,
1013 config_event_context_migratable
)) {
1014 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1025 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1030 for (node
= xmlFirstElementChild(domain_node
); node
;
1031 node
= xmlNextElementSibling(node
)) {
1032 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1034 xmlChar
*node_content
= xmlNodeGetContent(node
);
1035 if (!node_content
) {
1036 ret
= -LTTNG_ERR_NOMEM
;
1040 ret
= get_domain_type(node_content
);
1043 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1048 } else if (!strcmp((const char *) node
->name
,
1049 config_element_buffer_type
)) {
1051 xmlChar
*node_content
= xmlNodeGetContent(node
);
1052 if (!node_content
) {
1053 ret
= -LTTNG_ERR_NOMEM
;
1057 ret
= get_buffer_type(node_content
);
1060 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1064 domain
->buf_type
= ret
;
1073 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1078 for (node
= xmlFirstElementChild(net_output_node
); node
;
1079 node
= xmlNextElementSibling(node
)) {
1080 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1082 *control_uri
= (char *) xmlNodeGetContent(node
);
1083 if (!*control_uri
) {
1088 *data_uri
= (char *) xmlNodeGetContent(node
);
1095 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1099 int process_consumer_output(xmlNodePtr consumer_output_node
,
1100 struct consumer_output
*output
)
1107 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1108 node
= xmlNextElementSibling(node
)) {
1109 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1110 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1114 ret
= -LTTNG_ERR_NOMEM
;
1118 ret
= parse_bool(enabled_str
, &output
->enabled
);
1124 xmlNodePtr output_type_node
;
1127 output_type_node
= xmlFirstElementChild(node
);
1128 if (!output_type_node
) {
1129 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1133 if (!strcmp((const char *) output_type_node
->name
,
1134 config_element_path
)) {
1136 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1137 if (!output
->path
) {
1138 ret
= -LTTNG_ERR_NOMEM
;
1143 ret
= get_net_output_uris(output_type_node
,
1144 &output
->control_uri
, &output
->data_uri
);
1156 free(output
->control_uri
);
1157 free(output
->data_uri
);
1158 memset(output
, 0, sizeof(struct consumer_output
));
1164 int create_session_net_output(const char *name
, const char *control_uri
,
1165 const char *data_uri
)
1168 struct lttng_handle
*handle
;
1169 const char *uri
= NULL
;
1173 handle
= lttng_create_handle(name
, NULL
);
1175 ret
= -LTTNG_ERR_NOMEM
;
1179 if (!control_uri
|| !data_uri
) {
1180 uri
= control_uri
? control_uri
: data_uri
;
1185 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1186 lttng_destroy_handle(handle
);
1192 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1193 const struct config_load_session_override_attr
*overrides
)
1196 xmlNodePtr node
= NULL
;
1197 xmlNodePtr snapshot_output_list_node
;
1198 xmlNodePtr snapshot_output_node
;
1200 assert(session_name
);
1202 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1211 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1213 /* Parse and create snapshot outputs */
1215 for (snapshot_output_node
=
1216 xmlFirstElementChild(snapshot_output_list_node
);
1217 snapshot_output_node
; snapshot_output_node
=
1218 xmlNextElementSibling(snapshot_output_node
)) {
1220 uint64_t max_size
= UINT64_MAX
;
1221 struct consumer_output output
= { 0 };
1222 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1223 const char *control_uri
= NULL
;
1224 const char *data_uri
= NULL
;
1225 const char *path
= NULL
;
1227 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1228 node
= xmlNextElementSibling(node
)) {
1229 if (!strcmp((const char *) node
->name
,
1230 config_element_name
)) {
1232 name
= (char *) xmlNodeGetContent(node
);
1234 ret
= -LTTNG_ERR_NOMEM
;
1235 goto error_snapshot_output
;
1237 } else if (!strcmp((const char *) node
->name
,
1238 config_element_max_size
)) {
1239 xmlChar
*content
= xmlNodeGetContent(node
);
1243 ret
= -LTTNG_ERR_NOMEM
;
1244 goto error_snapshot_output
;
1246 ret
= parse_uint(content
, &max_size
);
1249 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1250 goto error_snapshot_output
;
1253 /* consumer_output */
1254 ret
= process_consumer_output(node
, &output
);
1256 goto error_snapshot_output
;
1261 control_uri
= output
.control_uri
;
1262 data_uri
= output
.data_uri
;
1266 if (overrides
->path_url
) {
1267 path
= overrides
->path_url
;
1268 /* Control/data_uri are null */
1272 if (overrides
->ctrl_url
) {
1273 control_uri
= overrides
->ctrl_url
;
1277 if (overrides
->data_url
) {
1278 data_uri
= overrides
->data_url
;
1285 snapshot_output
= lttng_snapshot_output_create();
1286 if (!snapshot_output
) {
1287 ret
= -LTTNG_ERR_NOMEM
;
1288 goto error_snapshot_output
;
1291 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1293 goto error_snapshot_output
;
1296 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1298 goto error_snapshot_output
;
1302 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1305 goto error_snapshot_output
;
1309 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1312 goto error_snapshot_output
;
1317 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1320 goto error_snapshot_output
;
1325 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1326 error_snapshot_output
:
1329 free(output
.control_uri
);
1330 free(output
.data_uri
);
1331 lttng_snapshot_output_destroy(snapshot_output
);
1341 int create_session(const char *name
,
1342 struct lttng_domain
*kernel_domain
,
1343 struct lttng_domain
*ust_domain
,
1344 struct lttng_domain
*jul_domain
,
1345 struct lttng_domain
*log4j_domain
,
1346 xmlNodePtr output_node
,
1347 uint64_t live_timer_interval
,
1348 const struct config_load_session_override_attr
*overrides
)
1351 struct consumer_output output
= { 0 };
1352 xmlNodePtr consumer_output_node
;
1353 const char *control_uri
= NULL
;
1354 const char *data_uri
= NULL
;
1355 const char *path
= NULL
;
1360 consumer_output_node
= xmlFirstElementChild(output_node
);
1361 if (!consumer_output_node
) {
1362 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1366 if (strcmp((const char *) consumer_output_node
->name
,
1367 config_element_consumer_output
)) {
1368 WARN("Invalid output type, expected %s node",
1369 config_element_consumer_output
);
1370 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1374 ret
= process_consumer_output(consumer_output_node
, &output
);
1380 control_uri
= output
.control_uri
;
1381 data_uri
= output
.data_uri
;
1384 /* Check for override and apply them */
1386 if (overrides
->path_url
) {
1387 path
= overrides
->path_url
;
1388 /* control/data_uri are null */;
1392 if (overrides
->ctrl_url
) {
1393 control_uri
= overrides
->ctrl_url
;
1397 if (overrides
->data_url
) {
1398 data_uri
= overrides
->data_url
;
1406 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1407 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1411 if (control_uri
|| data_uri
) {
1412 /* network destination */
1413 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1415 * URLs are provided for sure since the test above make sure that
1416 * with a live timer the data and control URIs are provided. So,
1417 * NULL is passed here and will be set right after.
1419 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1421 ret
= lttng_create_session(name
, NULL
);
1427 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1433 /* either local output or no output */
1434 ret
= lttng_create_session(name
, path
);
1441 free(output
.control_uri
);
1442 free(output
.data_uri
);
1446 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1447 struct lttng_event_probe_attr
*attr
)
1451 assert(probe_attribute_node
);
1454 if (!strcmp((const char *) probe_attribute_node
->name
,
1455 config_element_address
)) {
1460 content
= xmlNodeGetContent(probe_attribute_node
);
1462 ret
= -LTTNG_ERR_NOMEM
;
1466 ret
= parse_uint(content
, &addr
);
1469 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1474 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1475 config_element_offset
)) {
1477 uint64_t offset
= 0;
1480 content
= xmlNodeGetContent(probe_attribute_node
);
1482 ret
= -LTTNG_ERR_NOMEM
;
1486 ret
= parse_uint(content
, &offset
);
1489 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1493 attr
->offset
= offset
;
1494 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1495 config_element_symbol_name
)) {
1500 content
= xmlNodeGetContent(probe_attribute_node
);
1502 ret
= -LTTNG_ERR_NOMEM
;
1506 name_len
= strlen((char *) content
);
1507 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1508 WARN("symbol_name too long.");
1509 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1514 strncpy(attr
->symbol_name
, (const char *) content
, name_len
);
1523 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1524 const char *channel_name
, const enum process_event_node_phase phase
)
1528 struct lttng_event event
;
1529 char **exclusions
= NULL
;
1530 unsigned long exclusion_count
= 0;
1531 char *filter_expression
= NULL
;
1535 assert(channel_name
);
1537 memset(&event
, 0, sizeof(event
));
1539 /* Initialize default log level which varies by domain */
1540 switch (handle
->domain
.type
)
1542 case LTTNG_DOMAIN_JUL
:
1543 event
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1545 case LTTNG_DOMAIN_LOG4J
:
1546 event
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1548 case LTTNG_DOMAIN_PYTHON
:
1549 event
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1551 case LTTNG_DOMAIN_UST
:
1552 case LTTNG_DOMAIN_KERNEL
:
1553 event
.loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1559 for (node
= xmlFirstElementChild(event_node
); node
;
1560 node
= xmlNextElementSibling(node
)) {
1561 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1566 content
= xmlNodeGetContent(node
);
1568 ret
= -LTTNG_ERR_NOMEM
;
1572 name_len
= strlen((char *) content
);
1573 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1574 WARN("Channel name too long.");
1575 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1580 strncpy(event
.name
, (const char *) content
, name_len
);
1582 } else if (!strcmp((const char *) node
->name
,
1583 config_element_enabled
)) {
1584 xmlChar
*content
= xmlNodeGetContent(node
);
1588 ret
= -LTTNG_ERR_NOMEM
;
1592 ret
= parse_bool(content
, &event
.enabled
);
1595 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1598 } else if (!strcmp((const char *) node
->name
,
1599 config_element_type
)) {
1600 xmlChar
*content
= xmlNodeGetContent(node
);
1604 ret
= -LTTNG_ERR_NOMEM
;
1608 ret
= get_event_type(content
);
1611 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1616 } else if (!strcmp((const char *) node
->name
,
1617 config_element_loglevel_type
)) {
1618 xmlChar
*content
= xmlNodeGetContent(node
);
1622 ret
= -LTTNG_ERR_NOMEM
;
1626 ret
= get_loglevel_type(content
);
1629 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1633 event
.loglevel_type
= ret
;
1634 } else if (!strcmp((const char *) node
->name
,
1635 config_element_loglevel
)) {
1637 int64_t loglevel
= 0;
1640 content
= xmlNodeGetContent(node
);
1642 ret
= -LTTNG_ERR_NOMEM
;
1646 ret
= parse_int(content
, &loglevel
);
1649 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1653 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1654 WARN("loglevel out of range.");
1655 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1659 event
.loglevel
= loglevel
;
1660 } else if (!strcmp((const char *) node
->name
,
1661 config_element_filter
)) {
1663 xmlNodeGetContent(node
);
1667 ret
= -LTTNG_ERR_NOMEM
;
1671 free(filter_expression
);
1672 filter_expression
= strdup((char *) content
);
1674 if (!filter_expression
) {
1675 ret
= -LTTNG_ERR_NOMEM
;
1678 } else if (!strcmp((const char *) node
->name
,
1679 config_element_exclusions
)) {
1680 xmlNodePtr exclusion_node
;
1681 int exclusion_index
= 0;
1686 * Exclusions has already been initialized,
1689 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1693 exclusion_count
= xmlChildElementCount(node
);
1694 if (!exclusion_count
) {
1698 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1700 exclusion_count
= 0;
1701 ret
= -LTTNG_ERR_NOMEM
;
1705 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1706 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1708 xmlNodeGetContent(exclusion_node
);
1711 ret
= -LTTNG_ERR_NOMEM
;
1715 exclusions
[exclusion_index
] = strdup((const char *) content
);
1717 if (!exclusions
[exclusion_index
]) {
1718 ret
= -LTTNG_ERR_NOMEM
;
1724 event
.exclusion
= 1;
1725 } else if (!strcmp((const char *) node
->name
,
1726 config_element_attributes
)) {
1727 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1730 if (!attribute_node
) {
1731 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1735 if (!strcmp((const char *) node
->name
,
1736 config_element_probe_attributes
)) {
1737 xmlNodePtr probe_attribute_node
;
1739 /* probe_attributes */
1740 for (probe_attribute_node
=
1741 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1742 probe_attribute_node
= xmlNextElementSibling(
1743 probe_attribute_node
)) {
1745 ret
= process_probe_attribute_node(probe_attribute_node
,
1754 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1756 /* function_attributes */
1757 content
= xmlNodeGetContent(symbol_node
);
1759 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1763 sym_len
= strlen((char *) content
);
1764 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1765 WARN("Function name too long.");
1766 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1771 strncpy(event
.attr
.ftrace
.symbol_name
, (char *) content
,
1778 if ((event
.enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1779 ret
= lttng_enable_event_with_exclusions(handle
, &event
, channel_name
,
1780 filter_expression
, exclusion_count
, exclusions
);
1782 WARN("Enabling event (name:%s) on load failed.", event
.name
);
1783 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1788 for (i
= 0; i
< exclusion_count
; i
++) {
1789 free(exclusions
[i
]);
1793 free(filter_expression
);
1798 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
1799 const char *channel_name
)
1802 struct lttng_event event
;
1805 assert(events_node
);
1807 assert(channel_name
);
1809 for (node
= xmlFirstElementChild(events_node
); node
;
1810 node
= xmlNextElementSibling(node
)) {
1811 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
1818 * Disable all events to enable only the necessary events.
1819 * Limitations regarding lttng_disable_events and tuple descriptor
1820 * force this approach.
1822 memset(&event
, 0, sizeof(event
));
1823 event
.loglevel
= -1;
1824 event
.type
= LTTNG_EVENT_ALL
;
1825 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
1830 for (node
= xmlFirstElementChild(events_node
); node
;
1831 node
= xmlNextElementSibling(node
)) {
1832 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
1843 int process_channel_attr_node(xmlNodePtr attr_node
,
1844 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
1845 xmlNodePtr
*events_node
)
1851 assert(contexts_node
);
1852 assert(events_node
);
1854 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
1859 content
= xmlNodeGetContent(attr_node
);
1861 ret
= -LTTNG_ERR_NOMEM
;
1865 name_len
= strlen((char *) content
);
1866 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1867 WARN("Channel name too long.");
1868 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1873 strncpy(channel
->name
, (const char *) content
, name_len
);
1875 } else if (!strcmp((const char *) attr_node
->name
,
1876 config_element_enabled
)) {
1881 content
= xmlNodeGetContent(attr_node
);
1883 ret
= -LTTNG_ERR_NOMEM
;
1887 ret
= parse_bool(content
, &enabled
);
1890 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1894 channel
->enabled
= enabled
;
1895 } else if (!strcmp((const char *) attr_node
->name
,
1896 config_element_overwrite_mode
)) {
1899 /* overwrite_mode */
1900 content
= xmlNodeGetContent(attr_node
);
1902 ret
= -LTTNG_ERR_NOMEM
;
1906 ret
= get_overwrite_mode(content
);
1909 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1913 channel
->attr
.overwrite
= ret
;
1914 } else if (!strcmp((const char *) attr_node
->name
,
1915 config_element_subbuf_size
)) {
1918 /* subbuffer_size */
1919 content
= xmlNodeGetContent(attr_node
);
1921 ret
= -LTTNG_ERR_NOMEM
;
1925 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
1928 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1931 } else if (!strcmp((const char *) attr_node
->name
,
1932 config_element_num_subbuf
)) {
1935 /* subbuffer_count */
1936 content
= xmlNodeGetContent(attr_node
);
1938 ret
= -LTTNG_ERR_NOMEM
;
1942 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
1945 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1948 } else if (!strcmp((const char *) attr_node
->name
,
1949 config_element_switch_timer_interval
)) {
1951 uint64_t switch_timer_interval
= 0;
1953 /* switch_timer_interval */
1954 content
= xmlNodeGetContent(attr_node
);
1956 ret
= -LTTNG_ERR_NOMEM
;
1960 ret
= parse_uint(content
, &switch_timer_interval
);
1963 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1967 if (switch_timer_interval
> UINT_MAX
) {
1968 WARN("switch_timer_interval out of range.");
1969 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1973 channel
->attr
.switch_timer_interval
=
1974 switch_timer_interval
;
1975 } else if (!strcmp((const char *) attr_node
->name
,
1976 config_element_read_timer_interval
)) {
1978 uint64_t read_timer_interval
= 0;
1980 /* read_timer_interval */
1981 content
= xmlNodeGetContent(attr_node
);
1983 ret
= -LTTNG_ERR_NOMEM
;
1987 ret
= parse_uint(content
, &read_timer_interval
);
1990 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1994 if (read_timer_interval
> UINT_MAX
) {
1995 WARN("read_timer_interval out of range.");
1996 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2000 channel
->attr
.read_timer_interval
=
2001 read_timer_interval
;
2002 } else if (!strcmp((const char *) attr_node
->name
,
2003 config_element_output_type
)) {
2007 content
= xmlNodeGetContent(attr_node
);
2009 ret
= -LTTNG_ERR_NOMEM
;
2013 ret
= get_output_type(content
);
2016 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2020 channel
->attr
.output
= ret
;
2021 } else if (!strcmp((const char *) attr_node
->name
,
2022 config_element_tracefile_size
)) {
2025 /* tracefile_size */
2026 content
= xmlNodeGetContent(attr_node
);
2028 ret
= -LTTNG_ERR_NOMEM
;
2032 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2035 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2038 } else if (!strcmp((const char *) attr_node
->name
,
2039 config_element_tracefile_count
)) {
2042 /* tracefile_count */
2043 content
= xmlNodeGetContent(attr_node
);
2045 ret
= -LTTNG_ERR_NOMEM
;
2049 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2052 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2055 } else if (!strcmp((const char *) attr_node
->name
,
2056 config_element_live_timer_interval
)) {
2058 uint64_t live_timer_interval
= 0;
2060 /* live_timer_interval */
2061 content
= xmlNodeGetContent(attr_node
);
2063 ret
= -LTTNG_ERR_NOMEM
;
2067 ret
= parse_uint(content
, &live_timer_interval
);
2070 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2074 if (live_timer_interval
> UINT_MAX
) {
2075 WARN("live_timer_interval out of range.");
2076 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2080 channel
->attr
.live_timer_interval
=
2081 live_timer_interval
;
2082 } else if (!strcmp((const char *) attr_node
->name
,
2083 config_element_events
)) {
2085 *events_node
= attr_node
;
2088 *contexts_node
= attr_node
;
2096 int process_context_node(xmlNodePtr context_node
,
2097 struct lttng_handle
*handle
, const char *channel_name
)
2100 struct lttng_event_context context
;
2101 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2104 assert(channel_name
);
2106 if (!context_child_node
) {
2107 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2111 memset(&context
, 0, sizeof(context
));
2113 if (!strcmp((const char *) context_child_node
->name
,
2114 config_element_type
)) {
2116 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2119 ret
= -LTTNG_ERR_NOMEM
;
2123 ret
= get_context_type(content
);
2126 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2131 } else if (!strcmp((const char *) context_child_node
->name
,
2132 config_element_context_perf
)) {
2134 xmlNodePtr perf_attr_node
;
2136 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2137 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2138 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2139 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2140 perf_attr_node
; perf_attr_node
=
2141 xmlNextElementSibling(perf_attr_node
)) {
2142 if (!strcmp((const char *) perf_attr_node
->name
,
2143 config_element_type
)) {
2148 content
= xmlNodeGetContent(perf_attr_node
);
2150 ret
= -LTTNG_ERR_NOMEM
;
2154 ret
= parse_uint(content
, &type
);
2157 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2161 if (type
> UINT32_MAX
) {
2162 WARN("perf context type out of range.");
2163 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2167 context
.u
.perf_counter
.type
= type
;
2168 } else if (!strcmp((const char *) perf_attr_node
->name
,
2169 config_element_config
)) {
2171 uint64_t config
= 0;
2174 content
= xmlNodeGetContent(perf_attr_node
);
2176 ret
= -LTTNG_ERR_NOMEM
;
2180 ret
= parse_uint(content
, &config
);
2183 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2187 context
.u
.perf_counter
.config
= config
;
2188 } else if (!strcmp((const char *) perf_attr_node
->name
,
2189 config_element_name
)) {
2194 content
= xmlNodeGetContent(perf_attr_node
);
2196 ret
= -LTTNG_ERR_NOMEM
;
2200 name_len
= strlen((char *) content
);
2201 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2202 WARN("perf context name too long.");
2203 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2208 strncpy(context
.u
.perf_counter
.name
, (const char *) content
,
2213 } else if (!strcmp((const char *) context_child_node
->name
,
2214 config_element_context_app
)) {
2215 /* application context */
2216 xmlNodePtr app_ctx_node
;
2218 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2219 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2220 app_ctx_node
; app_ctx_node
=
2221 xmlNextElementSibling(app_ctx_node
)) {
2223 char **target
= strcmp(
2224 (const char *) app_ctx_node
->name
,
2225 config_element_context_app_provider_name
) == 0 ?
2226 &context
.u
.app_ctx
.provider_name
:
2227 &context
.u
.app_ctx
.ctx_name
;
2229 content
= xmlNodeGetContent(app_ctx_node
);
2231 ret
= -LTTNG_ERR_NOMEM
;
2235 *target
= (char *) content
;
2238 /* Unrecognized context type */
2239 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2243 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2244 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2245 free(context
.u
.app_ctx
.provider_name
);
2246 free(context
.u
.app_ctx
.ctx_name
);
2253 int process_contexts_node(xmlNodePtr contexts_node
,
2254 struct lttng_handle
*handle
, const char *channel_name
)
2257 xmlNodePtr context_node
;
2259 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2260 context_node
= xmlNextElementSibling(context_node
)) {
2261 ret
= process_context_node(context_node
, handle
, channel_name
);
2271 int process_pid_tracker_node(xmlNodePtr pid_tracker_node
,
2272 struct lttng_handle
*handle
)
2275 xmlNodePtr targets_node
= NULL
;
2279 assert(pid_tracker_node
);
2280 /* get the targets node */
2281 for (node
= xmlFirstElementChild(pid_tracker_node
); node
;
2282 node
= xmlNextElementSibling(node
)) {
2283 if (!strcmp((const char *) node
->name
,
2284 config_element_targets
)) {
2285 targets_node
= node
;
2290 if (!targets_node
) {
2291 ret
= LTTNG_ERR_INVALID
;
2295 /* Go through all pid_target node */
2296 child
= xmlChildElementCount(targets_node
);
2298 /* The session is explicitly set to target nothing. */
2299 ret
= lttng_untrack_pid(handle
, -1);
2304 for (node
= xmlFirstElementChild(targets_node
); node
;
2305 node
= xmlNextElementSibling(node
)) {
2306 xmlNodePtr pid_target_node
= node
;
2308 /* get pid node and track it */
2309 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2310 node
= xmlNextElementSibling(node
)) {
2311 if (!strcmp((const char *) node
->name
,
2312 config_element_pid
)) {
2314 xmlChar
*content
= NULL
;
2316 content
= xmlNodeGetContent(node
);
2318 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2322 ret
= parse_int(content
, &pid
);
2325 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2329 ret
= lttng_track_pid(handle
, (int) pid
);
2335 node
= pid_target_node
;
2344 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2347 struct lttng_domain domain
= { 0 };
2348 struct lttng_handle
*handle
= NULL
;
2349 xmlNodePtr channels_node
= NULL
;
2350 xmlNodePtr trackers_node
= NULL
;
2351 xmlNodePtr pid_tracker_node
= NULL
;
2354 assert(session_name
);
2356 ret
= init_domain(domain_node
, &domain
);
2361 handle
= lttng_create_handle(session_name
, &domain
);
2363 ret
= -LTTNG_ERR_NOMEM
;
2367 /* get the channels node */
2368 for (node
= xmlFirstElementChild(domain_node
); node
;
2369 node
= xmlNextElementSibling(node
)) {
2370 if (!strcmp((const char *) node
->name
,
2371 config_element_channels
)) {
2372 channels_node
= node
;
2377 if (!channels_node
) {
2381 /* create all channels */
2382 for (node
= xmlFirstElementChild(channels_node
); node
;
2383 node
= xmlNextElementSibling(node
)) {
2384 struct lttng_channel channel
;
2385 xmlNodePtr contexts_node
= NULL
;
2386 xmlNodePtr events_node
= NULL
;
2387 xmlNodePtr channel_attr_node
;
2389 memset(&channel
, 0, sizeof(channel
));
2390 lttng_channel_set_default_attr(&domain
, &channel
.attr
);
2392 for (channel_attr_node
= xmlFirstElementChild(node
);
2393 channel_attr_node
; channel_attr_node
=
2394 xmlNextElementSibling(channel_attr_node
)) {
2395 ret
= process_channel_attr_node(channel_attr_node
,
2396 &channel
, &contexts_node
, &events_node
);
2402 ret
= lttng_enable_channel(handle
, &channel
);
2407 ret
= process_events_node(events_node
, handle
, channel
.name
);
2412 ret
= process_contexts_node(contexts_node
, handle
,
2419 /* get the trackers node */
2420 for (node
= xmlFirstElementChild(domain_node
); node
;
2421 node
= xmlNextElementSibling(node
)) {
2422 if (!strcmp((const char *) node
->name
,
2423 config_element_trackers
)) {
2424 trackers_node
= node
;
2429 if (!trackers_node
) {
2433 for (node
= xmlFirstElementChild(trackers_node
); node
;
2434 node
= xmlNextElementSibling(node
)) {
2435 if (!strcmp((const char *)node
->name
,config_element_pid_tracker
)) {
2436 pid_tracker_node
= node
;
2437 ret
= process_pid_tracker_node(pid_tracker_node
, handle
);
2444 if (!pid_tracker_node
) {
2445 lttng_track_pid(handle
, -1);
2449 lttng_destroy_handle(handle
);
2454 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
2456 const struct config_load_session_override_attr
*overrides
)
2458 int ret
, started
= -1, snapshot_mode
= -1;
2459 uint64_t live_timer_interval
= UINT64_MAX
;
2460 xmlChar
*name
= NULL
;
2461 xmlChar
*shm_path
= NULL
;
2462 xmlNodePtr domains_node
= NULL
;
2463 xmlNodePtr output_node
= NULL
;
2465 struct lttng_domain
*kernel_domain
= NULL
;
2466 struct lttng_domain
*ust_domain
= NULL
;
2467 struct lttng_domain
*jul_domain
= NULL
;
2468 struct lttng_domain
*log4j_domain
= NULL
;
2469 struct lttng_domain
*python_domain
= NULL
;
2471 for (node
= xmlFirstElementChild(session_node
); node
;
2472 node
= xmlNextElementSibling(node
)) {
2473 if (!name
&& !strcmp((const char *) node
->name
,
2474 config_element_name
)) {
2476 xmlChar
*node_content
= xmlNodeGetContent(node
);
2477 if (!node_content
) {
2478 ret
= -LTTNG_ERR_NOMEM
;
2482 name
= node_content
;
2483 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
2484 config_element_domains
)) {
2486 domains_node
= node
;
2487 } else if (started
== -1 && !strcmp((const char *) node
->name
,
2488 config_element_started
)) {
2490 xmlChar
*node_content
= xmlNodeGetContent(node
);
2491 if (!node_content
) {
2492 ret
= -LTTNG_ERR_NOMEM
;
2496 ret
= parse_bool(node_content
, &started
);
2499 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2502 } else if (!output_node
&& !strcmp((const char *) node
->name
,
2503 config_element_output
)) {
2506 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
2507 config_element_shared_memory_path
)) {
2508 /* shared memory path */
2509 xmlChar
*node_content
= xmlNodeGetContent(node
);
2510 if (!node_content
) {
2511 ret
= -LTTNG_ERR_NOMEM
;
2515 shm_path
= node_content
;
2517 /* attributes, snapshot_mode or live_timer_interval */
2518 xmlNodePtr attributes_child
=
2519 xmlFirstElementChild(node
);
2521 if (!strcmp((const char *) attributes_child
->name
,
2522 config_element_snapshot_mode
)) {
2524 xmlChar
*snapshot_mode_content
=
2525 xmlNodeGetContent(attributes_child
);
2526 if (!snapshot_mode_content
) {
2527 ret
= -LTTNG_ERR_NOMEM
;
2531 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
2532 free(snapshot_mode_content
);
2534 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2538 /* live_timer_interval */
2539 xmlChar
*timer_interval_content
=
2540 xmlNodeGetContent(attributes_child
);
2541 if (!timer_interval_content
) {
2542 ret
= -LTTNG_ERR_NOMEM
;
2546 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
2547 free(timer_interval_content
);
2549 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2557 /* Mandatory attribute, as defined in the session XSD */
2558 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2562 if (session_name
&& strcmp((char *) name
, session_name
)) {
2563 /* This is not the session we are looking for */
2564 ret
= -LTTNG_ERR_NO_SESSION
;
2568 /* Init domains to create the session handles */
2569 for (node
= xmlFirstElementChild(domains_node
); node
;
2570 node
= xmlNextElementSibling(node
)) {
2571 struct lttng_domain
*domain
;
2573 domain
= zmalloc(sizeof(*domain
));
2575 ret
= -LTTNG_ERR_NOMEM
;
2579 ret
= init_domain(node
, domain
);
2581 goto domain_init_error
;
2584 switch (domain
->type
) {
2585 case LTTNG_DOMAIN_KERNEL
:
2586 if (kernel_domain
) {
2587 /* Same domain seen twice, invalid! */
2588 goto domain_init_error
;
2590 kernel_domain
= domain
;
2592 case LTTNG_DOMAIN_UST
:
2594 /* Same domain seen twice, invalid! */
2595 goto domain_init_error
;
2597 ust_domain
= domain
;
2599 case LTTNG_DOMAIN_JUL
:
2601 /* Same domain seen twice, invalid! */
2602 goto domain_init_error
;
2604 jul_domain
= domain
;
2606 case LTTNG_DOMAIN_LOG4J
:
2608 /* Same domain seen twice, invalid! */
2609 goto domain_init_error
;
2611 log4j_domain
= domain
;
2613 case LTTNG_DOMAIN_PYTHON
:
2614 if (python_domain
) {
2615 /* Same domain seen twice, invalid! */
2616 goto domain_init_error
;
2618 python_domain
= domain
;
2621 WARN("Invalid domain type");
2622 goto domain_init_error
;
2627 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2631 /* Apply overrides */
2633 if (overrides
->session_name
) {
2634 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
2635 if (!name_override
) {
2636 ret
= -LTTNG_ERR_NOMEM
;
2640 /* Overrides the session name to the provided name */
2642 name
= name_override
;
2647 /* Destroy session if it exists */
2648 ret
= lttng_destroy_session((const char *) name
);
2649 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
2650 ERR("Failed to destroy existing session.");
2655 /* Create session type depending on output type */
2656 if (snapshot_mode
&& snapshot_mode
!= -1) {
2657 ret
= create_snapshot_session((const char *) name
, output_node
,
2659 } else if (live_timer_interval
&&
2660 live_timer_interval
!= UINT64_MAX
) {
2661 ret
= create_session((const char *) name
, kernel_domain
,
2662 ust_domain
, jul_domain
, log4j_domain
,
2663 output_node
, live_timer_interval
, overrides
);
2665 /* regular session */
2666 ret
= create_session((const char *) name
, kernel_domain
,
2667 ust_domain
, jul_domain
, log4j_domain
,
2668 output_node
, UINT64_MAX
, overrides
);
2675 ret
= lttng_set_session_shm_path((const char *) name
,
2676 (const char *) shm_path
);
2682 for (node
= xmlFirstElementChild(domains_node
); node
;
2683 node
= xmlNextElementSibling(node
)) {
2684 ret
= process_domain_node(node
, (const char *) name
);
2691 ret
= lttng_start_tracing((const char *) name
);
2699 ERR("Failed to load session %s: %s", (const char *) name
,
2700 lttng_strerror(ret
));
2701 lttng_destroy_session((const char *) name
);
2705 free(kernel_domain
);
2709 free(python_domain
);
2716 * Return 1 if the given path is readable by the current UID or 0 if not.
2717 * Return -1 if the path is EPERM.
2719 static int validate_file_read_creds(const char *path
)
2725 /* Can we read the file. */
2726 ret
= access(path
, R_OK
);
2730 if (errno
== EACCES
) {
2741 int load_session_from_file(const char *path
, const char *session_name
,
2742 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2743 const struct config_load_session_override_attr
*overrides
)
2745 int ret
, session_found
= !session_name
;
2746 xmlDocPtr doc
= NULL
;
2747 xmlNodePtr sessions_node
;
2748 xmlNodePtr session_node
;
2751 assert(validation_ctx
);
2753 ret
= validate_file_read_creds(path
);
2756 ret
= -LTTNG_ERR_EPERM
;
2758 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2763 doc
= xmlParseFile(path
);
2765 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2769 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
2771 ERR("Session configuration file validation failed");
2772 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2776 sessions_node
= xmlDocGetRootElement(doc
);
2777 if (!sessions_node
) {
2781 for (session_node
= xmlFirstElementChild(sessions_node
);
2782 session_node
; session_node
=
2783 xmlNextElementSibling(session_node
)) {
2784 ret
= process_session_node(session_node
,
2785 session_name
, overwrite
, overrides
);
2786 if (session_name
&& ret
== 0) {
2787 /* Target session found and loaded */
2795 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
2800 /* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
2802 struct dirent
*alloc_dirent(const char *path
)
2806 struct dirent
*entry
;
2808 name_max
= pathconf(path
, _PC_NAME_MAX
);
2809 if (name_max
== -1) {
2810 name_max
= PATH_MAX
;
2812 len
= offsetof(struct dirent
, d_name
) + name_max
+ 1;
2813 entry
= zmalloc(len
);
2818 int load_session_from_path(const char *path
, const char *session_name
,
2819 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2820 const struct config_load_session_override_attr
*overrides
)
2822 int ret
, session_found
= !session_name
;
2823 DIR *directory
= NULL
;
2826 assert(validation_ctx
);
2828 directory
= opendir(path
);
2832 /* Try the file loading. */
2835 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2838 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2843 struct dirent
*entry
;
2844 struct dirent
*result
;
2845 char *file_path
= NULL
;
2846 size_t path_len
= strlen(path
);
2848 if (path_len
>= PATH_MAX
) {
2849 ret
= -LTTNG_ERR_INVALID
;
2853 entry
= alloc_dirent(path
);
2855 ret
= -LTTNG_ERR_NOMEM
;
2859 file_path
= zmalloc(PATH_MAX
);
2861 ret
= -LTTNG_ERR_NOMEM
;
2866 strncpy(file_path
, path
, path_len
);
2867 if (file_path
[path_len
- 1] != '/') {
2868 file_path
[path_len
++] = '/';
2872 /* Search for *.lttng files */
2873 while (!readdir_r(directory
, entry
, &result
) && result
) {
2874 size_t file_name_len
= strlen(result
->d_name
);
2876 if (file_name_len
<=
2877 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
2881 if (path_len
+ file_name_len
>= PATH_MAX
) {
2885 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
2886 result
->d_name
+ file_name_len
- sizeof(
2887 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
2891 strncpy(file_path
+ path_len
, result
->d_name
, file_name_len
);
2892 file_path
[path_len
+ file_name_len
] = '\0';
2894 ret
= load_session_from_file(file_path
, session_name
,
2895 validation_ctx
, overwrite
, overrides
);
2896 if (session_name
&& !ret
) {
2905 ret
= load_session_from_file(path
, session_name
,
2906 validation_ctx
, overwrite
, overrides
);
2916 if (closedir(directory
)) {
2921 if (session_found
&& !ret
) {
2929 * Validate that the given path's credentials and the current process have the
2930 * same UID. If so, return 1 else return 0 if it does NOT match.
2932 static int validate_path_creds(const char *path
)
2934 int ret
, uid
= getuid();
2943 ret
= stat(path
, &buf
);
2945 if (errno
!= ENOENT
) {
2948 ret
= -LTTNG_ERR_INVALID
;
2952 if (buf
.st_uid
!= uid
) {
2963 int config_load_session(const char *path
, const char *session_name
,
2964 int overwrite
, unsigned int autoload
,
2965 const struct config_load_session_override_attr
*overrides
)
2968 bool session_loaded
= false;
2969 const char *path_ptr
= NULL
;
2970 struct session_config_validation_ctx validation_ctx
= { 0 };
2972 ret
= init_session_config_validation_ctx(&validation_ctx
);
2979 const char *sys_path
;
2982 home_path
= utils_get_home_dir();
2984 char path
[PATH_MAX
];
2987 * Try user session configuration path. Ignore error here so we can
2988 * continue loading the system wide sessions.
2991 ret
= snprintf(path
, sizeof(path
),
2992 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
2993 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
2995 PERROR("snprintf session autoload home config path");
3000 * Credentials are only validated for the autoload in order to
3001 * avoid any user session daemon to try to load kernel sessions
3002 * automatically and failing all the times.
3004 ret
= validate_path_creds(path
);
3009 ret
= snprintf(path
, sizeof(path
),
3010 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3012 PERROR("snprintf session home config path");
3018 ret
= load_session_from_path(path_ptr
, session_name
,
3019 &validation_ctx
, overwrite
, overrides
);
3020 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3024 * Continue even if the session was found since we have to try
3025 * the system wide sessions.
3027 session_loaded
= true;
3031 /* Reset path pointer for the system wide dir. */
3034 /* Try system wide configuration directory. */
3036 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3037 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3038 ret
= validate_path_creds(sys_path
);
3040 path_ptr
= sys_path
;
3043 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3044 path_ptr
= sys_path
;
3048 ret
= load_session_from_path(path_ptr
, session_name
,
3049 &validation_ctx
, overwrite
, overrides
);
3051 session_loaded
= true;
3055 ret
= access(path
, F_OK
);
3060 ret
= -LTTNG_ERR_INVALID
;
3061 WARN("Session configuration path does not exist.");
3064 ret
= -LTTNG_ERR_EPERM
;
3067 ret
= -LTTNG_ERR_UNK
;
3073 ret
= load_session_from_path(path
, session_name
,
3074 &validation_ctx
, overwrite
, overrides
);
3077 fini_session_config_validation_ctx(&validation_ctx
);
3078 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3080 * Don't report an error if no sessions are found when called
3081 * without a session_name or a search path.
3086 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3087 /* A matching session was found in one of the search paths. */
3094 void __attribute__((destructor
)) session_config_exit(void)