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_output
= "output";
95 const char * const config_element_output_type
= "output_type";
96 const char * const config_element_tracefile_size
= "tracefile_size";
97 const char * const config_element_tracefile_count
= "tracefile_count";
98 const char * const config_element_live_timer_interval
= "live_timer_interval";
99 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
100 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
101 const char * const config_element_type
= "type";
102 const char * const config_element_buffer_type
= "buffer_type";
103 const char * const config_element_session
= "session";
104 const char * const config_element_sessions
= "sessions";
105 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
106 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
107 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
108 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
109 const char * const config_element_config
= "config";
110 const char * const config_element_started
= "started";
111 const char * const config_element_snapshot_mode
= "snapshot_mode";
112 const char * const config_element_loglevel
= "loglevel";
113 const char * const config_element_loglevel_type
= "loglevel_type";
114 const char * const config_element_filter
= "filter";
115 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
116 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
117 const char * const config_element_consumer_output
= "consumer_output";
118 const char * const config_element_destination
= "destination";
119 const char * const config_element_path
= "path";
120 const char * const config_element_net_output
= "net_output";
121 const char * const config_element_control_uri
= "control_uri";
122 const char * const config_element_data_uri
= "data_uri";
123 const char * const config_element_max_size
= "max_size";
124 const char * const config_element_pid
= "pid";
125 const char * const config_element_pids
= "pids";
126 const char * const config_element_shared_memory_path
= "shared_memory_path";
127 const char * const config_element_pid_tracker
= "pid_tracker";
128 const char * const config_element_trackers
= "trackers";
129 const char * const config_element_targets
= "targets";
130 const char * const config_element_target_pid
= "pid_target";
132 const char * const config_domain_type_kernel
= "KERNEL";
133 const char * const config_domain_type_ust
= "UST";
134 const char * const config_domain_type_jul
= "JUL";
135 const char * const config_domain_type_log4j
= "LOG4J";
136 const char * const config_domain_type_python
= "PYTHON";
138 const char * const config_buffer_type_per_pid
= "PER_PID";
139 const char * const config_buffer_type_per_uid
= "PER_UID";
140 const char * const config_buffer_type_global
= "GLOBAL";
142 const char * const config_overwrite_mode_discard
= "DISCARD";
143 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
145 const char * const config_output_type_splice
= "SPLICE";
146 const char * const config_output_type_mmap
= "MMAP";
148 const char * const config_loglevel_type_all
= "ALL";
149 const char * const config_loglevel_type_range
= "RANGE";
150 const char * const config_loglevel_type_single
= "SINGLE";
152 const char * const config_event_type_all
= "ALL";
153 const char * const config_event_type_tracepoint
= "TRACEPOINT";
154 const char * const config_event_type_probe
= "PROBE";
155 const char * const config_event_type_function
= "FUNCTION";
156 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
157 const char * const config_event_type_noop
= "NOOP";
158 const char * const config_event_type_syscall
= "SYSCALL";
159 const char * const config_event_type_kprobe
= "KPROBE";
160 const char * const config_event_type_kretprobe
= "KRETPROBE";
162 const char * const config_event_context_pid
= "PID";
163 const char * const config_event_context_procname
= "PROCNAME";
164 const char * const config_event_context_prio
= "PRIO";
165 const char * const config_event_context_nice
= "NICE";
166 const char * const config_event_context_vpid
= "VPID";
167 const char * const config_event_context_tid
= "TID";
168 const char * const config_event_context_vtid
= "VTID";
169 const char * const config_event_context_ppid
= "PPID";
170 const char * const config_event_context_vppid
= "VPPID";
171 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
172 const char * const config_event_context_hostname
= "HOSTNAME";
173 const char * const config_event_context_ip
= "IP";
174 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
175 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
176 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
177 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
178 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
179 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
181 /* Deprecated symbols */
182 const char * const config_element_perf
;
184 enum process_event_node_phase
{
189 struct consumer_output
{
196 static int config_entry_handler_filter(struct handler_filter_args
*args
,
197 const char *section
, const char *name
, const char *value
)
200 struct config_entry entry
= { section
, name
, value
};
204 if (!section
|| !name
|| !value
) {
210 if (strcmp(args
->section
, section
)) {
215 ret
= args
->handler(&entry
, args
->user_data
);
221 int config_get_section_entries(const char *override_path
, const char *section
,
222 config_entry_handler_cb handler
, void *user_data
)
226 FILE *config_file
= NULL
;
227 struct handler_filter_args filter
= { section
, handler
, user_data
};
229 /* First, try system-wide conf. file. */
230 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
232 config_file
= fopen(path
, "r");
234 DBG("Loading daemon conf file at %s", path
);
236 * Return value is not very important here since error or not, we
237 * continue and try the next possible conf. file.
239 (void) ini_parse_file(config_file
,
240 (ini_entry_handler
) config_entry_handler_filter
,
245 /* Second is the user local configuration. */
246 path
= utils_get_home_dir();
248 char fullpath
[PATH_MAX
];
250 ret
= snprintf(fullpath
, sizeof(fullpath
),
251 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
253 PERROR("snprintf user conf. path");
257 config_file
= fopen(fullpath
, "r");
259 DBG("Loading daemon user conf file at %s", path
);
261 * Return value is not very important here since error or not, we
262 * continue and try the next possible conf. file.
264 (void) ini_parse_file(config_file
,
265 (ini_entry_handler
) config_entry_handler_filter
,
271 /* Final path is the one that the user might have provided. */
273 config_file
= fopen(override_path
, "r");
275 DBG("Loading daemon command line conf file at %s", override_path
);
276 (void) ini_parse_file(config_file
,
277 (ini_entry_handler
) config_entry_handler_filter
,
281 ERR("Failed to open daemon configuration file at %s",
288 /* Everything went well. */
296 int config_parse_value(const char *value
)
299 char *endptr
, *lower_str
;
309 v
= strtoul(value
, &endptr
, 10);
310 if (endptr
!= value
) {
315 lower_str
= zmalloc(len
+ 1);
322 for (i
= 0; i
< len
; i
++) {
323 lower_str
[i
] = tolower(value
[i
]);
326 if (!strcmp(lower_str
, config_str_yes
) ||
327 !strcmp(lower_str
, config_str_true
) ||
328 !strcmp(lower_str
, config_str_on
)) {
330 } else if (!strcmp(lower_str
, config_str_no
) ||
331 !strcmp(lower_str
, config_str_false
) ||
332 !strcmp(lower_str
, config_str_off
)) {
344 * Returns a xmlChar string which must be released using xmlFree().
346 static xmlChar
*encode_string(const char *in_str
)
348 xmlChar
*out_str
= NULL
;
349 xmlCharEncodingHandlerPtr handler
;
350 int out_len
, ret
, in_len
;
354 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
356 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
360 in_len
= strlen(in_str
);
362 * Add 1 byte for the NULL terminted character. The factor 4 here is
363 * used because UTF-8 characters can take up to 4 bytes.
365 out_len
= (in_len
* 4) + 1;
366 out_str
= xmlMalloc(out_len
);
371 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
378 /* out_len is now the size of out_str */
379 out_str
[out_len
] = '\0';
385 struct config_writer
*config_writer_create(int fd_output
, int indent
)
388 struct config_writer
*writer
;
389 xmlOutputBufferPtr buffer
;
391 writer
= zmalloc(sizeof(struct config_writer
));
393 PERROR("zmalloc config_writer_create");
397 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
402 writer
->writer
= xmlNewTextWriter(buffer
);
403 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
404 config_xml_encoding
, NULL
);
409 ret
= xmlTextWriterSetIndentString(writer
->writer
,
410 BAD_CAST config_xml_indent_string
);
415 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
423 config_writer_destroy(writer
);
428 int config_writer_destroy(struct config_writer
*writer
)
437 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
438 WARN("Could not close XML document");
442 if (writer
->writer
) {
443 xmlFreeTextWriter(writer
->writer
);
452 int config_writer_open_element(struct config_writer
*writer
,
453 const char *element_name
)
456 xmlChar
*encoded_element_name
;
458 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
463 encoded_element_name
= encode_string(element_name
);
464 if (!encoded_element_name
) {
469 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
470 xmlFree(encoded_element_name
);
472 return ret
>= 0 ? 0 : ret
;
476 int config_writer_write_attribute(struct config_writer
*writer
,
477 const char *name
, const char *value
)
480 xmlChar
*encoded_name
= NULL
;
481 xmlChar
*encoded_value
= NULL
;
483 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
488 encoded_name
= encode_string(name
);
494 encoded_value
= encode_string(value
);
495 if (!encoded_value
) {
500 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
503 xmlFree(encoded_name
);
504 xmlFree(encoded_value
);
505 return ret
>= 0 ? 0 : ret
;
509 int config_writer_close_element(struct config_writer
*writer
)
513 if (!writer
|| !writer
->writer
) {
518 ret
= xmlTextWriterEndElement(writer
->writer
);
520 return ret
>= 0 ? 0 : ret
;
524 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
525 const char *element_name
, uint64_t value
)
528 xmlChar
*encoded_element_name
;
530 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
535 encoded_element_name
= encode_string(element_name
);
536 if (!encoded_element_name
) {
541 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
542 encoded_element_name
, "%" PRIu64
, value
);
543 xmlFree(encoded_element_name
);
545 return ret
>= 0 ? 0 : ret
;
549 int config_writer_write_element_signed_int(struct config_writer
*writer
,
550 const char *element_name
, int64_t value
)
553 xmlChar
*encoded_element_name
;
555 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
560 encoded_element_name
= encode_string(element_name
);
561 if (!encoded_element_name
) {
566 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
567 encoded_element_name
, "%" PRIi64
, value
);
568 xmlFree(encoded_element_name
);
570 return ret
>= 0 ? 0 : ret
;
574 int config_writer_write_element_bool(struct config_writer
*writer
,
575 const char *element_name
, int value
)
577 return config_writer_write_element_string(writer
, element_name
,
578 value
? config_xml_true
: config_xml_false
);
582 int config_writer_write_element_string(struct config_writer
*writer
,
583 const char *element_name
, const char *value
)
586 xmlChar
*encoded_element_name
= NULL
;
587 xmlChar
*encoded_value
= NULL
;
589 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
595 encoded_element_name
= encode_string(element_name
);
596 if (!encoded_element_name
) {
601 encoded_value
= encode_string(value
);
602 if (!encoded_value
) {
607 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
610 xmlFree(encoded_element_name
);
611 xmlFree(encoded_value
);
612 return ret
>= 0 ? 0 : ret
;
616 void xml_error_handler(void *ctx
, const char *format
, ...)
622 va_start(args
, format
);
623 ret
= vasprintf(&errMsg
, format
, args
);
626 ERR("String allocation failed in xml error handler");
630 fprintf(stderr
, "XML Error: %s", errMsg
);
635 void fini_session_config_validation_ctx(
636 struct session_config_validation_ctx
*ctx
)
638 if (ctx
->parser_ctx
) {
639 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
643 xmlSchemaFree(ctx
->schema
);
646 if (ctx
->schema_validation_ctx
) {
647 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
650 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
654 char *get_session_config_xsd_path()
657 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
658 size_t base_path_len
;
662 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
665 base_path_len
= strlen(base_path
);
666 max_path_len
= base_path_len
+
667 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
668 xsd_path
= zmalloc(max_path_len
);
673 strncpy(xsd_path
, base_path
, max_path_len
);
674 if (xsd_path
[base_path_len
- 1] != '/') {
675 xsd_path
[base_path_len
++] = '/';
678 strncpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
,
679 max_path_len
- base_path_len
);
685 int init_session_config_validation_ctx(
686 struct session_config_validation_ctx
*ctx
)
689 char *xsd_path
= get_session_config_xsd_path();
692 ret
= -LTTNG_ERR_NOMEM
;
696 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
697 if (!ctx
->parser_ctx
) {
698 ERR("XSD parser context creation failed");
699 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
702 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
703 xml_error_handler
, NULL
);
705 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
707 ERR("XSD parsing failed");
708 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
712 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
713 if (!ctx
->schema_validation_ctx
) {
714 ERR("XSD validation context creation failed");
715 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
719 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
720 xml_error_handler
, NULL
);
725 fini_session_config_validation_ctx(ctx
);
733 int parse_uint(xmlChar
*str
, uint64_t *val
)
743 *val
= strtoull((const char *) str
, &endptr
, 10);
744 if (!endptr
|| *endptr
) {
755 int parse_int(xmlChar
*str
, int64_t *val
)
765 *val
= strtoll((const char *) str
, &endptr
, 10);
766 if (!endptr
|| *endptr
) {
777 int parse_bool(xmlChar
*str
, int *val
)
786 if (!strcmp((const char *) str
, config_xml_true
)) {
788 } else if (!strcmp((const char *) str
, config_xml_false
)) {
791 WARN("Invalid boolean value encoutered (%s).",
800 int get_domain_type(xmlChar
*domain
)
808 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
809 ret
= LTTNG_DOMAIN_KERNEL
;
810 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
811 ret
= LTTNG_DOMAIN_UST
;
812 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
813 ret
= LTTNG_DOMAIN_JUL
;
814 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
815 ret
= LTTNG_DOMAIN_LOG4J
;
816 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
817 ret
= LTTNG_DOMAIN_PYTHON
;
828 int get_buffer_type(xmlChar
*buffer_type
)
836 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
837 ret
= LTTNG_BUFFER_GLOBAL
;
838 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
839 ret
= LTTNG_BUFFER_PER_UID
;
840 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
841 ret
= LTTNG_BUFFER_PER_PID
;
852 int get_overwrite_mode(xmlChar
*overwrite_mode
)
856 if (!overwrite_mode
) {
860 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
862 } else if (!strcmp((char *) overwrite_mode
,
863 config_overwrite_mode_discard
)) {
875 int get_output_type(xmlChar
*output_type
)
883 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
884 ret
= LTTNG_EVENT_MMAP
;
885 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
886 ret
= LTTNG_EVENT_SPLICE
;
897 int get_event_type(xmlChar
*event_type
)
905 if (!strcmp((char *) event_type
, config_event_type_all
)) {
906 ret
= LTTNG_EVENT_ALL
;
907 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
908 ret
= LTTNG_EVENT_TRACEPOINT
;
909 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
910 ret
= LTTNG_EVENT_PROBE
;
911 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
912 ret
= LTTNG_EVENT_FUNCTION
;
913 } else if (!strcmp((char *) event_type
,
914 config_event_type_function_entry
)) {
915 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
916 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
917 ret
= LTTNG_EVENT_NOOP
;
918 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
919 ret
= LTTNG_EVENT_SYSCALL
;
930 int get_loglevel_type(xmlChar
*loglevel_type
)
934 if (!loglevel_type
) {
938 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
939 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
940 } else if (!strcmp((char *) loglevel_type
,
941 config_loglevel_type_range
)) {
942 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
943 } else if (!strcmp((char *) loglevel_type
,
944 config_loglevel_type_single
)) {
945 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
956 * Return the context type or -1 on error.
959 int get_context_type(xmlChar
*context_type
)
967 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
968 ret
= LTTNG_EVENT_CONTEXT_PID
;
969 } else if (!strcmp((char *) context_type
,
970 config_event_context_procname
)) {
971 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
972 } else if (!strcmp((char *) context_type
,
973 config_event_context_prio
)) {
974 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
975 } else if (!strcmp((char *) context_type
,
976 config_event_context_nice
)) {
977 ret
= LTTNG_EVENT_CONTEXT_NICE
;
978 } else if (!strcmp((char *) context_type
,
979 config_event_context_vpid
)) {
980 ret
= LTTNG_EVENT_CONTEXT_VPID
;
981 } else if (!strcmp((char *) context_type
,
982 config_event_context_tid
)) {
983 ret
= LTTNG_EVENT_CONTEXT_TID
;
984 } else if (!strcmp((char *) context_type
,
985 config_event_context_vtid
)) {
986 ret
= LTTNG_EVENT_CONTEXT_VTID
;
987 } else if (!strcmp((char *) context_type
,
988 config_event_context_ppid
)) {
989 ret
= LTTNG_EVENT_CONTEXT_PPID
;
990 } else if (!strcmp((char *) context_type
,
991 config_event_context_vppid
)) {
992 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
993 } else if (!strcmp((char *) context_type
,
994 config_event_context_pthread_id
)) {
995 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
996 } else if (!strcmp((char *) context_type
,
997 config_event_context_hostname
)) {
998 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
999 } else if (!strcmp((char *) context_type
,
1000 config_event_context_ip
)) {
1001 ret
= LTTNG_EVENT_CONTEXT_IP
;
1002 } else if (!strcmp((char *) context_type
,
1003 config_event_context_interruptible
)) {
1004 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1005 } else if (!strcmp((char *) context_type
,
1006 config_event_context_preemptible
)) {
1007 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1008 } else if (!strcmp((char *) context_type
,
1009 config_event_context_need_reschedule
)) {
1010 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1011 } else if (!strcmp((char *) context_type
,
1012 config_event_context_migratable
)) {
1013 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1024 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1029 for (node
= xmlFirstElementChild(domain_node
); node
;
1030 node
= xmlNextElementSibling(node
)) {
1031 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1033 xmlChar
*node_content
= xmlNodeGetContent(node
);
1034 if (!node_content
) {
1035 ret
= -LTTNG_ERR_NOMEM
;
1039 ret
= get_domain_type(node_content
);
1042 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1047 } else if (!strcmp((const char *) node
->name
,
1048 config_element_buffer_type
)) {
1050 xmlChar
*node_content
= xmlNodeGetContent(node
);
1051 if (!node_content
) {
1052 ret
= -LTTNG_ERR_NOMEM
;
1056 ret
= get_buffer_type(node_content
);
1059 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1063 domain
->buf_type
= ret
;
1072 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1077 for (node
= xmlFirstElementChild(net_output_node
); node
;
1078 node
= xmlNextElementSibling(node
)) {
1079 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1081 *control_uri
= (char *) xmlNodeGetContent(node
);
1082 if (!*control_uri
) {
1087 *data_uri
= (char *) xmlNodeGetContent(node
);
1094 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1098 int process_consumer_output(xmlNodePtr consumer_output_node
,
1099 struct consumer_output
*output
)
1106 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1107 node
= xmlNextElementSibling(node
)) {
1108 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1109 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1113 ret
= -LTTNG_ERR_NOMEM
;
1117 ret
= parse_bool(enabled_str
, &output
->enabled
);
1123 xmlNodePtr output_type_node
;
1126 output_type_node
= xmlFirstElementChild(node
);
1127 if (!output_type_node
) {
1128 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1132 if (!strcmp((const char *) output_type_node
->name
,
1133 config_element_path
)) {
1135 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1136 if (!output
->path
) {
1137 ret
= -LTTNG_ERR_NOMEM
;
1142 ret
= get_net_output_uris(output_type_node
,
1143 &output
->control_uri
, &output
->data_uri
);
1155 free(output
->control_uri
);
1156 free(output
->data_uri
);
1157 memset(output
, 0, sizeof(struct consumer_output
));
1163 int create_session_net_output(const char *name
, const char *control_uri
,
1164 const char *data_uri
)
1167 struct lttng_handle
*handle
;
1168 const char *uri
= NULL
;
1172 handle
= lttng_create_handle(name
, NULL
);
1174 ret
= -LTTNG_ERR_NOMEM
;
1178 if (!control_uri
|| !data_uri
) {
1179 uri
= control_uri
? control_uri
: data_uri
;
1184 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1185 lttng_destroy_handle(handle
);
1191 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1192 const struct config_load_session_override_attr
*overrides
)
1195 xmlNodePtr node
= NULL
;
1196 xmlNodePtr snapshot_output_list_node
;
1197 xmlNodePtr snapshot_output_node
;
1199 assert(session_name
);
1201 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1210 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1212 /* Parse and create snapshot outputs */
1214 for (snapshot_output_node
=
1215 xmlFirstElementChild(snapshot_output_list_node
);
1216 snapshot_output_node
; snapshot_output_node
=
1217 xmlNextElementSibling(snapshot_output_node
)) {
1219 uint64_t max_size
= UINT64_MAX
;
1220 struct consumer_output output
= { 0 };
1221 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1222 const char *control_uri
= NULL
;
1223 const char *data_uri
= NULL
;
1224 const char *path
= NULL
;
1226 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1227 node
= xmlNextElementSibling(node
)) {
1228 if (!strcmp((const char *) node
->name
,
1229 config_element_name
)) {
1231 name
= (char *) xmlNodeGetContent(node
);
1233 ret
= -LTTNG_ERR_NOMEM
;
1234 goto error_snapshot_output
;
1236 } else if (!strcmp((const char *) node
->name
,
1237 config_element_max_size
)) {
1238 xmlChar
*content
= xmlNodeGetContent(node
);
1242 ret
= -LTTNG_ERR_NOMEM
;
1243 goto error_snapshot_output
;
1245 ret
= parse_uint(content
, &max_size
);
1248 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1249 goto error_snapshot_output
;
1252 /* consumer_output */
1253 ret
= process_consumer_output(node
, &output
);
1255 goto error_snapshot_output
;
1260 control_uri
= output
.control_uri
;
1261 data_uri
= output
.data_uri
;
1265 if (overrides
->path_url
) {
1266 path
= overrides
->path_url
;
1267 /* Control/data_uri are null */
1271 if (overrides
->ctrl_url
) {
1272 control_uri
= overrides
->ctrl_url
;
1276 if (overrides
->data_url
) {
1277 data_uri
= overrides
->data_url
;
1284 snapshot_output
= lttng_snapshot_output_create();
1285 if (!snapshot_output
) {
1286 ret
= -LTTNG_ERR_NOMEM
;
1287 goto error_snapshot_output
;
1290 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1292 goto error_snapshot_output
;
1295 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1297 goto error_snapshot_output
;
1301 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1304 goto error_snapshot_output
;
1308 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1311 goto error_snapshot_output
;
1316 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1319 goto error_snapshot_output
;
1324 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1325 error_snapshot_output
:
1328 free(output
.control_uri
);
1329 free(output
.data_uri
);
1330 lttng_snapshot_output_destroy(snapshot_output
);
1340 int create_session(const char *name
,
1341 struct lttng_domain
*kernel_domain
,
1342 struct lttng_domain
*ust_domain
,
1343 struct lttng_domain
*jul_domain
,
1344 struct lttng_domain
*log4j_domain
,
1345 xmlNodePtr output_node
,
1346 uint64_t live_timer_interval
,
1347 const struct config_load_session_override_attr
*overrides
)
1350 struct consumer_output output
= { 0 };
1351 xmlNodePtr consumer_output_node
;
1352 const char *control_uri
= NULL
;
1353 const char *data_uri
= NULL
;
1354 const char *path
= NULL
;
1359 consumer_output_node
= xmlFirstElementChild(output_node
);
1360 if (!consumer_output_node
) {
1361 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1365 if (strcmp((const char *) consumer_output_node
->name
,
1366 config_element_consumer_output
)) {
1367 WARN("Invalid output type, expected %s node",
1368 config_element_consumer_output
);
1369 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1373 ret
= process_consumer_output(consumer_output_node
, &output
);
1379 control_uri
= output
.control_uri
;
1380 data_uri
= output
.data_uri
;
1383 /* Check for override and apply them */
1385 if (overrides
->path_url
) {
1386 path
= overrides
->path_url
;
1387 /* control/data_uri are null */;
1391 if (overrides
->ctrl_url
) {
1392 control_uri
= overrides
->ctrl_url
;
1396 if (overrides
->data_url
) {
1397 data_uri
= overrides
->data_url
;
1405 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1406 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1410 if (control_uri
|| data_uri
) {
1411 /* network destination */
1412 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1414 * URLs are provided for sure since the test above make sure that
1415 * with a live timer the data and control URIs are provided. So,
1416 * NULL is passed here and will be set right after.
1418 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1420 ret
= lttng_create_session(name
, NULL
);
1426 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1432 /* either local output or no output */
1433 ret
= lttng_create_session(name
, path
);
1440 free(output
.control_uri
);
1441 free(output
.data_uri
);
1445 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1446 struct lttng_event_probe_attr
*attr
)
1450 assert(probe_attribute_node
);
1453 if (!strcmp((const char *) probe_attribute_node
->name
,
1454 config_element_address
)) {
1459 content
= xmlNodeGetContent(probe_attribute_node
);
1461 ret
= -LTTNG_ERR_NOMEM
;
1465 ret
= parse_uint(content
, &addr
);
1468 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1473 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1474 config_element_offset
)) {
1476 uint64_t offset
= 0;
1479 content
= xmlNodeGetContent(probe_attribute_node
);
1481 ret
= -LTTNG_ERR_NOMEM
;
1485 ret
= parse_uint(content
, &offset
);
1488 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1492 attr
->offset
= offset
;
1493 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1494 config_element_symbol_name
)) {
1499 content
= xmlNodeGetContent(probe_attribute_node
);
1501 ret
= -LTTNG_ERR_NOMEM
;
1505 name_len
= strlen((char *) content
);
1506 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1507 WARN("symbol_name too long.");
1508 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1513 strncpy(attr
->symbol_name
, (const char *) content
, name_len
);
1522 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1523 const char *channel_name
, const enum process_event_node_phase phase
)
1527 struct lttng_event event
;
1528 char **exclusions
= NULL
;
1529 unsigned long exclusion_count
= 0;
1530 char *filter_expression
= NULL
;
1534 assert(channel_name
);
1536 memset(&event
, 0, sizeof(event
));
1538 /* Initialize default log level which varies by domain */
1539 switch (handle
->domain
.type
)
1541 case LTTNG_DOMAIN_JUL
:
1542 event
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1544 case LTTNG_DOMAIN_LOG4J
:
1545 event
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1547 case LTTNG_DOMAIN_PYTHON
:
1548 event
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1550 case LTTNG_DOMAIN_UST
:
1551 case LTTNG_DOMAIN_KERNEL
:
1552 event
.loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1558 for (node
= xmlFirstElementChild(event_node
); node
;
1559 node
= xmlNextElementSibling(node
)) {
1560 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1565 content
= xmlNodeGetContent(node
);
1567 ret
= -LTTNG_ERR_NOMEM
;
1571 name_len
= strlen((char *) content
);
1572 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1573 WARN("Channel name too long.");
1574 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1579 strncpy(event
.name
, (const char *) content
, name_len
);
1581 } else if (!strcmp((const char *) node
->name
,
1582 config_element_enabled
)) {
1583 xmlChar
*content
= xmlNodeGetContent(node
);
1587 ret
= -LTTNG_ERR_NOMEM
;
1591 ret
= parse_bool(content
, &event
.enabled
);
1594 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1597 } else if (!strcmp((const char *) node
->name
,
1598 config_element_type
)) {
1599 xmlChar
*content
= xmlNodeGetContent(node
);
1603 ret
= -LTTNG_ERR_NOMEM
;
1607 ret
= get_event_type(content
);
1610 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1615 } else if (!strcmp((const char *) node
->name
,
1616 config_element_loglevel_type
)) {
1617 xmlChar
*content
= xmlNodeGetContent(node
);
1621 ret
= -LTTNG_ERR_NOMEM
;
1625 ret
= get_loglevel_type(content
);
1628 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1632 event
.loglevel_type
= ret
;
1633 } else if (!strcmp((const char *) node
->name
,
1634 config_element_loglevel
)) {
1636 int64_t loglevel
= 0;
1639 content
= xmlNodeGetContent(node
);
1641 ret
= -LTTNG_ERR_NOMEM
;
1645 ret
= parse_int(content
, &loglevel
);
1648 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1652 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1653 WARN("loglevel out of range.");
1654 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1658 event
.loglevel
= loglevel
;
1659 } else if (!strcmp((const char *) node
->name
,
1660 config_element_filter
)) {
1662 xmlNodeGetContent(node
);
1666 ret
= -LTTNG_ERR_NOMEM
;
1670 free(filter_expression
);
1671 filter_expression
= strdup((char *) content
);
1673 if (!filter_expression
) {
1674 ret
= -LTTNG_ERR_NOMEM
;
1677 } else if (!strcmp((const char *) node
->name
,
1678 config_element_exclusions
)) {
1679 xmlNodePtr exclusion_node
;
1680 int exclusion_index
= 0;
1685 * Exclusions has already been initialized,
1688 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1692 exclusion_count
= xmlChildElementCount(node
);
1693 if (!exclusion_count
) {
1697 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1699 exclusion_count
= 0;
1700 ret
= -LTTNG_ERR_NOMEM
;
1704 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1705 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1707 xmlNodeGetContent(exclusion_node
);
1710 ret
= -LTTNG_ERR_NOMEM
;
1714 exclusions
[exclusion_index
] = strdup((const char *) content
);
1716 if (!exclusions
[exclusion_index
]) {
1717 ret
= -LTTNG_ERR_NOMEM
;
1723 event
.exclusion
= 1;
1724 } else if (!strcmp((const char *) node
->name
,
1725 config_element_attributes
)) {
1726 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1729 if (!attribute_node
) {
1730 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1734 if (!strcmp((const char *) node
->name
,
1735 config_element_probe_attributes
)) {
1736 xmlNodePtr probe_attribute_node
;
1738 /* probe_attributes */
1739 for (probe_attribute_node
=
1740 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1741 probe_attribute_node
= xmlNextElementSibling(
1742 probe_attribute_node
)) {
1744 ret
= process_probe_attribute_node(probe_attribute_node
,
1753 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1755 /* function_attributes */
1756 content
= xmlNodeGetContent(symbol_node
);
1758 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1762 sym_len
= strlen((char *) content
);
1763 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1764 WARN("Function name too long.");
1765 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1770 strncpy(event
.attr
.ftrace
.symbol_name
, (char *) content
,
1777 if ((event
.enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1778 ret
= lttng_enable_event_with_exclusions(handle
, &event
, channel_name
,
1779 filter_expression
, exclusion_count
, exclusions
);
1781 WARN("Enabling event (name:%s) on load failed.", event
.name
);
1782 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1787 for (i
= 0; i
< exclusion_count
; i
++) {
1788 free(exclusions
[i
]);
1792 free(filter_expression
);
1797 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
1798 const char *channel_name
)
1801 struct lttng_event event
;
1804 assert(events_node
);
1806 assert(channel_name
);
1808 for (node
= xmlFirstElementChild(events_node
); node
;
1809 node
= xmlNextElementSibling(node
)) {
1810 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
1817 * Disable all events to enable only the necessary events.
1818 * Limitations regarding lttng_disable_events and tuple descriptor
1819 * force this approach.
1821 memset(&event
, 0, sizeof(event
));
1822 event
.loglevel
= -1;
1823 event
.type
= LTTNG_EVENT_ALL
;
1824 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
1829 for (node
= xmlFirstElementChild(events_node
); node
;
1830 node
= xmlNextElementSibling(node
)) {
1831 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
1842 int process_channel_attr_node(xmlNodePtr attr_node
,
1843 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
1844 xmlNodePtr
*events_node
)
1850 assert(contexts_node
);
1851 assert(events_node
);
1853 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
1858 content
= xmlNodeGetContent(attr_node
);
1860 ret
= -LTTNG_ERR_NOMEM
;
1864 name_len
= strlen((char *) content
);
1865 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1866 WARN("Channel name too long.");
1867 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1872 strncpy(channel
->name
, (const char *) content
, name_len
);
1874 } else if (!strcmp((const char *) attr_node
->name
,
1875 config_element_enabled
)) {
1880 content
= xmlNodeGetContent(attr_node
);
1882 ret
= -LTTNG_ERR_NOMEM
;
1886 ret
= parse_bool(content
, &enabled
);
1889 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1893 channel
->enabled
= enabled
;
1894 } else if (!strcmp((const char *) attr_node
->name
,
1895 config_element_overwrite_mode
)) {
1898 /* overwrite_mode */
1899 content
= xmlNodeGetContent(attr_node
);
1901 ret
= -LTTNG_ERR_NOMEM
;
1905 ret
= get_overwrite_mode(content
);
1908 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1912 channel
->attr
.overwrite
= ret
;
1913 } else if (!strcmp((const char *) attr_node
->name
,
1914 config_element_subbuf_size
)) {
1917 /* subbuffer_size */
1918 content
= xmlNodeGetContent(attr_node
);
1920 ret
= -LTTNG_ERR_NOMEM
;
1924 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
1927 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1930 } else if (!strcmp((const char *) attr_node
->name
,
1931 config_element_num_subbuf
)) {
1934 /* subbuffer_count */
1935 content
= xmlNodeGetContent(attr_node
);
1937 ret
= -LTTNG_ERR_NOMEM
;
1941 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
1944 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1947 } else if (!strcmp((const char *) attr_node
->name
,
1948 config_element_switch_timer_interval
)) {
1950 uint64_t switch_timer_interval
= 0;
1952 /* switch_timer_interval */
1953 content
= xmlNodeGetContent(attr_node
);
1955 ret
= -LTTNG_ERR_NOMEM
;
1959 ret
= parse_uint(content
, &switch_timer_interval
);
1962 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1966 if (switch_timer_interval
> UINT_MAX
) {
1967 WARN("switch_timer_interval out of range.");
1968 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1972 channel
->attr
.switch_timer_interval
=
1973 switch_timer_interval
;
1974 } else if (!strcmp((const char *) attr_node
->name
,
1975 config_element_read_timer_interval
)) {
1977 uint64_t read_timer_interval
= 0;
1979 /* read_timer_interval */
1980 content
= xmlNodeGetContent(attr_node
);
1982 ret
= -LTTNG_ERR_NOMEM
;
1986 ret
= parse_uint(content
, &read_timer_interval
);
1989 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1993 if (read_timer_interval
> UINT_MAX
) {
1994 WARN("read_timer_interval out of range.");
1995 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1999 channel
->attr
.read_timer_interval
=
2000 read_timer_interval
;
2001 } else if (!strcmp((const char *) attr_node
->name
,
2002 config_element_output_type
)) {
2006 content
= xmlNodeGetContent(attr_node
);
2008 ret
= -LTTNG_ERR_NOMEM
;
2012 ret
= get_output_type(content
);
2015 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2019 channel
->attr
.output
= ret
;
2020 } else if (!strcmp((const char *) attr_node
->name
,
2021 config_element_tracefile_size
)) {
2024 /* tracefile_size */
2025 content
= xmlNodeGetContent(attr_node
);
2027 ret
= -LTTNG_ERR_NOMEM
;
2031 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2034 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2037 } else if (!strcmp((const char *) attr_node
->name
,
2038 config_element_tracefile_count
)) {
2041 /* tracefile_count */
2042 content
= xmlNodeGetContent(attr_node
);
2044 ret
= -LTTNG_ERR_NOMEM
;
2048 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2051 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2054 } else if (!strcmp((const char *) attr_node
->name
,
2055 config_element_live_timer_interval
)) {
2057 uint64_t live_timer_interval
= 0;
2059 /* live_timer_interval */
2060 content
= xmlNodeGetContent(attr_node
);
2062 ret
= -LTTNG_ERR_NOMEM
;
2066 ret
= parse_uint(content
, &live_timer_interval
);
2069 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2073 if (live_timer_interval
> UINT_MAX
) {
2074 WARN("live_timer_interval out of range.");
2075 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2079 channel
->attr
.live_timer_interval
=
2080 live_timer_interval
;
2081 } else if (!strcmp((const char *) attr_node
->name
,
2082 config_element_events
)) {
2084 *events_node
= attr_node
;
2087 *contexts_node
= attr_node
;
2095 int process_context_node(xmlNodePtr context_node
,
2096 struct lttng_handle
*handle
, const char *channel_name
)
2099 struct lttng_event_context context
;
2100 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2103 assert(channel_name
);
2105 if (!context_child_node
) {
2106 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2110 memset(&context
, 0, sizeof(context
));
2112 if (!strcmp((const char *) context_child_node
->name
,
2113 config_element_type
)) {
2115 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2118 ret
= -LTTNG_ERR_NOMEM
;
2122 ret
= get_context_type(content
);
2125 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2130 } else if (!strcmp((const char *) context_child_node
->name
,
2131 config_element_context_perf
)) {
2133 xmlNodePtr perf_attr_node
;
2135 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2136 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2137 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2138 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2139 perf_attr_node
; perf_attr_node
=
2140 xmlNextElementSibling(perf_attr_node
)) {
2141 if (!strcmp((const char *) perf_attr_node
->name
,
2142 config_element_type
)) {
2147 content
= xmlNodeGetContent(perf_attr_node
);
2149 ret
= -LTTNG_ERR_NOMEM
;
2153 ret
= parse_uint(content
, &type
);
2156 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2160 if (type
> UINT32_MAX
) {
2161 WARN("perf context type out of range.");
2162 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2166 context
.u
.perf_counter
.type
= type
;
2167 } else if (!strcmp((const char *) perf_attr_node
->name
,
2168 config_element_config
)) {
2170 uint64_t config
= 0;
2173 content
= xmlNodeGetContent(perf_attr_node
);
2175 ret
= -LTTNG_ERR_NOMEM
;
2179 ret
= parse_uint(content
, &config
);
2182 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2186 context
.u
.perf_counter
.config
= config
;
2187 } else if (!strcmp((const char *) perf_attr_node
->name
,
2188 config_element_name
)) {
2193 content
= xmlNodeGetContent(perf_attr_node
);
2195 ret
= -LTTNG_ERR_NOMEM
;
2199 name_len
= strlen((char *) content
);
2200 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2201 WARN("perf context name too long.");
2202 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2207 strncpy(context
.u
.perf_counter
.name
, (const char *) content
,
2212 } else if (!strcmp((const char *) context_child_node
->name
,
2213 config_element_context_app
)) {
2214 /* application context */
2215 xmlNodePtr app_ctx_node
;
2217 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2218 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2219 app_ctx_node
; app_ctx_node
=
2220 xmlNextElementSibling(app_ctx_node
)) {
2222 char **target
= strcmp(
2223 (const char *) app_ctx_node
->name
,
2224 config_element_context_app_provider_name
) == 0 ?
2225 &context
.u
.app_ctx
.provider_name
:
2226 &context
.u
.app_ctx
.ctx_name
;
2228 content
= xmlNodeGetContent(app_ctx_node
);
2230 ret
= -LTTNG_ERR_NOMEM
;
2234 *target
= (char *) content
;
2237 /* Unrecognized context type */
2238 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2242 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2243 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2244 free(context
.u
.app_ctx
.provider_name
);
2245 free(context
.u
.app_ctx
.ctx_name
);
2252 int process_contexts_node(xmlNodePtr contexts_node
,
2253 struct lttng_handle
*handle
, const char *channel_name
)
2256 xmlNodePtr context_node
;
2258 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2259 context_node
= xmlNextElementSibling(context_node
)) {
2260 ret
= process_context_node(context_node
, handle
, channel_name
);
2270 int process_pid_tracker_node(xmlNodePtr pid_tracker_node
,
2271 struct lttng_handle
*handle
)
2274 xmlNodePtr targets_node
= NULL
;
2278 assert(pid_tracker_node
);
2279 /* get the targets node */
2280 for (node
= xmlFirstElementChild(pid_tracker_node
); node
;
2281 node
= xmlNextElementSibling(node
)) {
2282 if (!strcmp((const char *) node
->name
,
2283 config_element_targets
)) {
2284 targets_node
= node
;
2289 if (!targets_node
) {
2290 ret
= LTTNG_ERR_INVALID
;
2294 /* Go through all pid_target node */
2295 child
= xmlChildElementCount(targets_node
);
2297 /* The session is explicitly set to target nothing. */
2298 ret
= lttng_untrack_pid(handle
, -1);
2303 for (node
= xmlFirstElementChild(targets_node
); node
;
2304 node
= xmlNextElementSibling(node
)) {
2305 xmlNodePtr pid_target_node
= node
;
2307 /* get pid node and track it */
2308 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2309 node
= xmlNextElementSibling(node
)) {
2310 if (!strcmp((const char *) node
->name
,
2311 config_element_pid
)) {
2313 xmlChar
*content
= NULL
;
2315 content
= xmlNodeGetContent(node
);
2317 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2321 ret
= parse_int(content
, &pid
);
2324 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2328 ret
= lttng_track_pid(handle
, (int) pid
);
2334 node
= pid_target_node
;
2343 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2346 struct lttng_domain domain
= { 0 };
2347 struct lttng_handle
*handle
= NULL
;
2348 xmlNodePtr channels_node
= NULL
;
2349 xmlNodePtr trackers_node
= NULL
;
2350 xmlNodePtr pid_tracker_node
= NULL
;
2353 assert(session_name
);
2355 ret
= init_domain(domain_node
, &domain
);
2360 handle
= lttng_create_handle(session_name
, &domain
);
2362 ret
= -LTTNG_ERR_NOMEM
;
2366 /* get the channels node */
2367 for (node
= xmlFirstElementChild(domain_node
); node
;
2368 node
= xmlNextElementSibling(node
)) {
2369 if (!strcmp((const char *) node
->name
,
2370 config_element_channels
)) {
2371 channels_node
= node
;
2376 if (!channels_node
) {
2380 /* create all channels */
2381 for (node
= xmlFirstElementChild(channels_node
); node
;
2382 node
= xmlNextElementSibling(node
)) {
2383 struct lttng_channel channel
;
2384 xmlNodePtr contexts_node
= NULL
;
2385 xmlNodePtr events_node
= NULL
;
2386 xmlNodePtr channel_attr_node
;
2388 memset(&channel
, 0, sizeof(channel
));
2389 lttng_channel_set_default_attr(&domain
, &channel
.attr
);
2391 for (channel_attr_node
= xmlFirstElementChild(node
);
2392 channel_attr_node
; channel_attr_node
=
2393 xmlNextElementSibling(channel_attr_node
)) {
2394 ret
= process_channel_attr_node(channel_attr_node
,
2395 &channel
, &contexts_node
, &events_node
);
2401 ret
= lttng_enable_channel(handle
, &channel
);
2406 ret
= process_events_node(events_node
, handle
, channel
.name
);
2411 ret
= process_contexts_node(contexts_node
, handle
,
2418 /* get the trackers node */
2419 for (node
= xmlFirstElementChild(domain_node
); node
;
2420 node
= xmlNextElementSibling(node
)) {
2421 if (!strcmp((const char *) node
->name
,
2422 config_element_trackers
)) {
2423 trackers_node
= node
;
2428 if (!trackers_node
) {
2432 for (node
= xmlFirstElementChild(trackers_node
); node
;
2433 node
= xmlNextElementSibling(node
)) {
2434 if (!strcmp((const char *)node
->name
,config_element_pid_tracker
)) {
2435 pid_tracker_node
= node
;
2436 ret
= process_pid_tracker_node(pid_tracker_node
, handle
);
2443 if (!pid_tracker_node
) {
2444 lttng_track_pid(handle
, -1);
2448 lttng_destroy_handle(handle
);
2453 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
2455 const struct config_load_session_override_attr
*overrides
)
2457 int ret
, started
= -1, snapshot_mode
= -1;
2458 uint64_t live_timer_interval
= UINT64_MAX
;
2459 xmlChar
*name
= NULL
;
2460 xmlChar
*shm_path
= NULL
;
2461 xmlNodePtr domains_node
= NULL
;
2462 xmlNodePtr output_node
= NULL
;
2464 struct lttng_domain
*kernel_domain
= NULL
;
2465 struct lttng_domain
*ust_domain
= NULL
;
2466 struct lttng_domain
*jul_domain
= NULL
;
2467 struct lttng_domain
*log4j_domain
= NULL
;
2468 struct lttng_domain
*python_domain
= NULL
;
2470 for (node
= xmlFirstElementChild(session_node
); node
;
2471 node
= xmlNextElementSibling(node
)) {
2472 if (!name
&& !strcmp((const char *) node
->name
,
2473 config_element_name
)) {
2475 xmlChar
*node_content
= xmlNodeGetContent(node
);
2476 if (!node_content
) {
2477 ret
= -LTTNG_ERR_NOMEM
;
2481 name
= node_content
;
2482 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
2483 config_element_domains
)) {
2485 domains_node
= node
;
2486 } else if (started
== -1 && !strcmp((const char *) node
->name
,
2487 config_element_started
)) {
2489 xmlChar
*node_content
= xmlNodeGetContent(node
);
2490 if (!node_content
) {
2491 ret
= -LTTNG_ERR_NOMEM
;
2495 ret
= parse_bool(node_content
, &started
);
2498 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2501 } else if (!output_node
&& !strcmp((const char *) node
->name
,
2502 config_element_output
)) {
2505 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
2506 config_element_shared_memory_path
)) {
2507 /* shared memory path */
2508 xmlChar
*node_content
= xmlNodeGetContent(node
);
2509 if (!node_content
) {
2510 ret
= -LTTNG_ERR_NOMEM
;
2514 shm_path
= node_content
;
2516 /* attributes, snapshot_mode or live_timer_interval */
2517 xmlNodePtr attributes_child
=
2518 xmlFirstElementChild(node
);
2520 if (!strcmp((const char *) attributes_child
->name
,
2521 config_element_snapshot_mode
)) {
2523 xmlChar
*snapshot_mode_content
=
2524 xmlNodeGetContent(attributes_child
);
2525 if (!snapshot_mode_content
) {
2526 ret
= -LTTNG_ERR_NOMEM
;
2530 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
2531 free(snapshot_mode_content
);
2533 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2537 /* live_timer_interval */
2538 xmlChar
*timer_interval_content
=
2539 xmlNodeGetContent(attributes_child
);
2540 if (!timer_interval_content
) {
2541 ret
= -LTTNG_ERR_NOMEM
;
2545 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
2546 free(timer_interval_content
);
2548 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2556 /* Mandatory attribute, as defined in the session XSD */
2557 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2561 if (session_name
&& strcmp((char *) name
, session_name
)) {
2562 /* This is not the session we are looking for */
2563 ret
= -LTTNG_ERR_NO_SESSION
;
2567 /* Init domains to create the session handles */
2568 for (node
= xmlFirstElementChild(domains_node
); node
;
2569 node
= xmlNextElementSibling(node
)) {
2570 struct lttng_domain
*domain
;
2572 domain
= zmalloc(sizeof(*domain
));
2574 ret
= -LTTNG_ERR_NOMEM
;
2578 ret
= init_domain(node
, domain
);
2580 goto domain_init_error
;
2583 switch (domain
->type
) {
2584 case LTTNG_DOMAIN_KERNEL
:
2585 if (kernel_domain
) {
2586 /* Same domain seen twice, invalid! */
2587 goto domain_init_error
;
2589 kernel_domain
= domain
;
2591 case LTTNG_DOMAIN_UST
:
2593 /* Same domain seen twice, invalid! */
2594 goto domain_init_error
;
2596 ust_domain
= domain
;
2598 case LTTNG_DOMAIN_JUL
:
2600 /* Same domain seen twice, invalid! */
2601 goto domain_init_error
;
2603 jul_domain
= domain
;
2605 case LTTNG_DOMAIN_LOG4J
:
2607 /* Same domain seen twice, invalid! */
2608 goto domain_init_error
;
2610 log4j_domain
= domain
;
2612 case LTTNG_DOMAIN_PYTHON
:
2613 if (python_domain
) {
2614 /* Same domain seen twice, invalid! */
2615 goto domain_init_error
;
2617 python_domain
= domain
;
2620 WARN("Invalid domain type");
2621 goto domain_init_error
;
2626 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2630 /* Apply overrides */
2632 if (overrides
->session_name
) {
2633 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
2634 if (!name_override
) {
2635 ret
= -LTTNG_ERR_NOMEM
;
2639 /* Overrides the session name to the provided name */
2641 name
= name_override
;
2646 /* Destroy session if it exists */
2647 ret
= lttng_destroy_session((const char *) name
);
2648 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
2649 ERR("Failed to destroy existing session.");
2654 /* Create session type depending on output type */
2655 if (snapshot_mode
&& snapshot_mode
!= -1) {
2656 ret
= create_snapshot_session((const char *) name
, output_node
,
2658 } else if (live_timer_interval
&&
2659 live_timer_interval
!= UINT64_MAX
) {
2660 ret
= create_session((const char *) name
, kernel_domain
,
2661 ust_domain
, jul_domain
, log4j_domain
,
2662 output_node
, live_timer_interval
, overrides
);
2664 /* regular session */
2665 ret
= create_session((const char *) name
, kernel_domain
,
2666 ust_domain
, jul_domain
, log4j_domain
,
2667 output_node
, UINT64_MAX
, overrides
);
2674 ret
= lttng_set_session_shm_path((const char *) name
,
2675 (const char *) shm_path
);
2681 for (node
= xmlFirstElementChild(domains_node
); node
;
2682 node
= xmlNextElementSibling(node
)) {
2683 ret
= process_domain_node(node
, (const char *) name
);
2690 ret
= lttng_start_tracing((const char *) name
);
2698 ERR("Failed to load session %s: %s", (const char *) name
,
2699 lttng_strerror(ret
));
2700 lttng_destroy_session((const char *) name
);
2704 free(kernel_domain
);
2708 free(python_domain
);
2715 * Return 1 if the given path is readable by the current UID or 0 if not.
2716 * Return -1 if the path is EPERM.
2718 static int validate_file_read_creds(const char *path
)
2724 /* Can we read the file. */
2725 ret
= access(path
, R_OK
);
2729 if (errno
== EACCES
) {
2740 int load_session_from_file(const char *path
, const char *session_name
,
2741 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2742 const struct config_load_session_override_attr
*overrides
)
2744 int ret
, session_found
= !session_name
;
2745 xmlDocPtr doc
= NULL
;
2746 xmlNodePtr sessions_node
;
2747 xmlNodePtr session_node
;
2750 assert(validation_ctx
);
2752 ret
= validate_file_read_creds(path
);
2755 ret
= -LTTNG_ERR_EPERM
;
2757 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2762 doc
= xmlParseFile(path
);
2764 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2768 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
2770 ERR("Session configuration file validation failed");
2771 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2775 sessions_node
= xmlDocGetRootElement(doc
);
2776 if (!sessions_node
) {
2780 for (session_node
= xmlFirstElementChild(sessions_node
);
2781 session_node
; session_node
=
2782 xmlNextElementSibling(session_node
)) {
2783 ret
= process_session_node(session_node
,
2784 session_name
, overwrite
, overrides
);
2785 if (session_name
&& ret
== 0) {
2786 /* Target session found and loaded */
2794 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
2799 /* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
2801 struct dirent
*alloc_dirent(const char *path
)
2805 struct dirent
*entry
;
2807 name_max
= pathconf(path
, _PC_NAME_MAX
);
2808 if (name_max
== -1) {
2809 name_max
= PATH_MAX
;
2811 len
= offsetof(struct dirent
, d_name
) + name_max
+ 1;
2812 entry
= zmalloc(len
);
2817 int load_session_from_path(const char *path
, const char *session_name
,
2818 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2819 const struct config_load_session_override_attr
*overrides
)
2821 int ret
, session_found
= !session_name
;
2822 DIR *directory
= NULL
;
2825 assert(validation_ctx
);
2827 directory
= opendir(path
);
2831 /* Try the file loading. */
2834 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2837 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2842 struct dirent
*entry
;
2843 struct dirent
*result
;
2844 char *file_path
= NULL
;
2845 size_t path_len
= strlen(path
);
2847 if (path_len
>= PATH_MAX
) {
2848 ret
= -LTTNG_ERR_INVALID
;
2852 entry
= alloc_dirent(path
);
2854 ret
= -LTTNG_ERR_NOMEM
;
2858 file_path
= zmalloc(PATH_MAX
);
2860 ret
= -LTTNG_ERR_NOMEM
;
2865 strncpy(file_path
, path
, path_len
);
2866 if (file_path
[path_len
- 1] != '/') {
2867 file_path
[path_len
++] = '/';
2871 /* Search for *.lttng files */
2872 while (!readdir_r(directory
, entry
, &result
) && result
) {
2873 size_t file_name_len
= strlen(result
->d_name
);
2875 if (file_name_len
<=
2876 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
2880 if (path_len
+ file_name_len
>= PATH_MAX
) {
2884 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
2885 result
->d_name
+ file_name_len
- sizeof(
2886 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
2890 strncpy(file_path
+ path_len
, result
->d_name
, file_name_len
);
2891 file_path
[path_len
+ file_name_len
] = '\0';
2893 ret
= load_session_from_file(file_path
, session_name
,
2894 validation_ctx
, overwrite
, overrides
);
2895 if (session_name
&& !ret
) {
2904 ret
= load_session_from_file(path
, session_name
,
2905 validation_ctx
, overwrite
, overrides
);
2915 if (closedir(directory
)) {
2920 if (session_found
&& !ret
) {
2928 * Validate that the given path's credentials and the current process have the
2929 * same UID. If so, return 1 else return 0 if it does NOT match.
2931 static int validate_path_creds(const char *path
)
2933 int ret
, uid
= getuid();
2942 ret
= stat(path
, &buf
);
2944 if (errno
!= ENOENT
) {
2947 ret
= -LTTNG_ERR_INVALID
;
2951 if (buf
.st_uid
!= uid
) {
2962 int config_load_session(const char *path
, const char *session_name
,
2963 int overwrite
, unsigned int autoload
,
2964 const struct config_load_session_override_attr
*overrides
)
2967 bool session_loaded
= false;
2968 const char *path_ptr
= NULL
;
2969 struct session_config_validation_ctx validation_ctx
= { 0 };
2971 ret
= init_session_config_validation_ctx(&validation_ctx
);
2978 const char *sys_path
;
2981 home_path
= utils_get_home_dir();
2983 char path
[PATH_MAX
];
2986 * Try user session configuration path. Ignore error here so we can
2987 * continue loading the system wide sessions.
2990 ret
= snprintf(path
, sizeof(path
),
2991 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
2992 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
2994 PERROR("snprintf session autoload home config path");
2999 * Credentials are only validated for the autoload in order to
3000 * avoid any user session daemon to try to load kernel sessions
3001 * automatically and failing all the times.
3003 ret
= validate_path_creds(path
);
3008 ret
= snprintf(path
, sizeof(path
),
3009 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3011 PERROR("snprintf session home config path");
3017 ret
= load_session_from_path(path_ptr
, session_name
,
3018 &validation_ctx
, overwrite
, overrides
);
3019 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3023 * Continue even if the session was found since we have to try
3024 * the system wide sessions.
3026 session_loaded
= true;
3030 /* Reset path pointer for the system wide dir. */
3033 /* Try system wide configuration directory. */
3035 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3036 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3037 ret
= validate_path_creds(sys_path
);
3039 path_ptr
= sys_path
;
3042 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3043 path_ptr
= sys_path
;
3047 ret
= load_session_from_path(path_ptr
, session_name
,
3048 &validation_ctx
, overwrite
, overrides
);
3050 session_loaded
= true;
3054 ret
= access(path
, F_OK
);
3059 ret
= -LTTNG_ERR_INVALID
;
3060 WARN("Session configuration path does not exist.");
3063 ret
= -LTTNG_ERR_EPERM
;
3066 ret
= -LTTNG_ERR_UNK
;
3072 ret
= load_session_from_path(path
, session_name
,
3073 &validation_ctx
, overwrite
, overrides
);
3076 fini_session_config_validation_ctx(&validation_ctx
);
3077 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3079 * Don't report an error if no sessions are found when called
3080 * without a session_name or a search path.
3085 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3086 /* A matching session was found in one of the search paths. */
3093 void __attribute__((destructor
)) session_config_exit(void)