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_blocking_timeout
= "blocking_timeout";
96 const char * const config_element_output
= "output";
97 const char * const config_element_output_type
= "output_type";
98 const char * const config_element_tracefile_size
= "tracefile_size";
99 const char * const config_element_tracefile_count
= "tracefile_count";
100 const char * const config_element_live_timer_interval
= "live_timer_interval";
101 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
102 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
103 const char * const config_element_type
= "type";
104 const char * const config_element_buffer_type
= "buffer_type";
105 const char * const config_element_session
= "session";
106 const char * const config_element_sessions
= "sessions";
107 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
108 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
109 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
110 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
111 const char * const config_element_config
= "config";
112 const char * const config_element_started
= "started";
113 const char * const config_element_snapshot_mode
= "snapshot_mode";
114 const char * const config_element_loglevel
= "loglevel";
115 const char * const config_element_loglevel_type
= "loglevel_type";
116 const char * const config_element_filter
= "filter";
117 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
118 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
119 const char * const config_element_consumer_output
= "consumer_output";
120 const char * const config_element_destination
= "destination";
121 const char * const config_element_path
= "path";
122 const char * const config_element_net_output
= "net_output";
123 const char * const config_element_control_uri
= "control_uri";
124 const char * const config_element_data_uri
= "data_uri";
125 const char * const config_element_max_size
= "max_size";
126 const char * const config_element_pid
= "pid";
127 const char * const config_element_pids
= "pids";
128 const char * const config_element_shared_memory_path
= "shared_memory_path";
129 const char * const config_element_pid_tracker
= "pid_tracker";
130 const char * const config_element_trackers
= "trackers";
131 const char * const config_element_targets
= "targets";
132 const char * const config_element_target_pid
= "pid_target";
134 const char * const config_domain_type_kernel
= "KERNEL";
135 const char * const config_domain_type_ust
= "UST";
136 const char * const config_domain_type_jul
= "JUL";
137 const char * const config_domain_type_log4j
= "LOG4J";
138 const char * const config_domain_type_python
= "PYTHON";
140 const char * const config_buffer_type_per_pid
= "PER_PID";
141 const char * const config_buffer_type_per_uid
= "PER_UID";
142 const char * const config_buffer_type_global
= "GLOBAL";
144 const char * const config_overwrite_mode_discard
= "DISCARD";
145 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
147 const char * const config_output_type_splice
= "SPLICE";
148 const char * const config_output_type_mmap
= "MMAP";
150 const char * const config_loglevel_type_all
= "ALL";
151 const char * const config_loglevel_type_range
= "RANGE";
152 const char * const config_loglevel_type_single
= "SINGLE";
154 const char * const config_event_type_all
= "ALL";
155 const char * const config_event_type_tracepoint
= "TRACEPOINT";
156 const char * const config_event_type_probe
= "PROBE";
157 const char * const config_event_type_function
= "FUNCTION";
158 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
159 const char * const config_event_type_noop
= "NOOP";
160 const char * const config_event_type_syscall
= "SYSCALL";
161 const char * const config_event_type_kprobe
= "KPROBE";
162 const char * const config_event_type_kretprobe
= "KRETPROBE";
164 const char * const config_event_context_pid
= "PID";
165 const char * const config_event_context_procname
= "PROCNAME";
166 const char * const config_event_context_prio
= "PRIO";
167 const char * const config_event_context_nice
= "NICE";
168 const char * const config_event_context_vpid
= "VPID";
169 const char * const config_event_context_tid
= "TID";
170 const char * const config_event_context_vtid
= "VTID";
171 const char * const config_event_context_ppid
= "PPID";
172 const char * const config_event_context_vppid
= "VPPID";
173 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
174 const char * const config_event_context_hostname
= "HOSTNAME";
175 const char * const config_event_context_ip
= "IP";
176 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
177 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
178 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
179 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
180 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
181 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
183 /* Deprecated symbols */
184 const char * const config_element_perf
;
186 enum process_event_node_phase
{
191 struct consumer_output
{
198 static int config_entry_handler_filter(struct handler_filter_args
*args
,
199 const char *section
, const char *name
, const char *value
)
202 struct config_entry entry
= { section
, name
, value
};
206 if (!section
|| !name
|| !value
) {
212 if (strcmp(args
->section
, section
)) {
217 ret
= args
->handler(&entry
, args
->user_data
);
223 int config_get_section_entries(const char *override_path
, const char *section
,
224 config_entry_handler_cb handler
, void *user_data
)
228 FILE *config_file
= NULL
;
229 struct handler_filter_args filter
= { section
, handler
, user_data
};
231 /* First, try system-wide conf. file. */
232 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
234 config_file
= fopen(path
, "r");
236 DBG("Loading daemon conf file at %s", path
);
238 * Return value is not very important here since error or not, we
239 * continue and try the next possible conf. file.
241 (void) ini_parse_file(config_file
,
242 (ini_entry_handler
) config_entry_handler_filter
,
247 /* Second is the user local configuration. */
248 path
= utils_get_home_dir();
250 char fullpath
[PATH_MAX
];
252 ret
= snprintf(fullpath
, sizeof(fullpath
),
253 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
255 PERROR("snprintf user conf. path");
259 config_file
= fopen(fullpath
, "r");
261 DBG("Loading daemon user conf file at %s", path
);
263 * Return value is not very important here since error or not, we
264 * continue and try the next possible conf. file.
266 (void) ini_parse_file(config_file
,
267 (ini_entry_handler
) config_entry_handler_filter
,
273 /* Final path is the one that the user might have provided. */
275 config_file
= fopen(override_path
, "r");
277 DBG("Loading daemon command line conf file at %s", override_path
);
278 (void) ini_parse_file(config_file
,
279 (ini_entry_handler
) config_entry_handler_filter
,
283 ERR("Failed to open daemon configuration file at %s",
290 /* Everything went well. */
298 int config_parse_value(const char *value
)
301 char *endptr
, *lower_str
;
311 v
= strtoul(value
, &endptr
, 10);
312 if (endptr
!= value
) {
317 lower_str
= zmalloc(len
+ 1);
324 for (i
= 0; i
< len
; i
++) {
325 lower_str
[i
] = tolower(value
[i
]);
328 if (!strcmp(lower_str
, config_str_yes
) ||
329 !strcmp(lower_str
, config_str_true
) ||
330 !strcmp(lower_str
, config_str_on
)) {
332 } else if (!strcmp(lower_str
, config_str_no
) ||
333 !strcmp(lower_str
, config_str_false
) ||
334 !strcmp(lower_str
, config_str_off
)) {
346 * Returns a xmlChar string which must be released using xmlFree().
348 static xmlChar
*encode_string(const char *in_str
)
350 xmlChar
*out_str
= NULL
;
351 xmlCharEncodingHandlerPtr handler
;
352 int out_len
, ret
, in_len
;
356 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
358 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
362 in_len
= strlen(in_str
);
364 * Add 1 byte for the NULL terminted character. The factor 4 here is
365 * used because UTF-8 characters can take up to 4 bytes.
367 out_len
= (in_len
* 4) + 1;
368 out_str
= xmlMalloc(out_len
);
373 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
380 /* out_len is now the size of out_str */
381 out_str
[out_len
] = '\0';
387 struct config_writer
*config_writer_create(int fd_output
, int indent
)
390 struct config_writer
*writer
;
391 xmlOutputBufferPtr buffer
;
393 writer
= zmalloc(sizeof(struct config_writer
));
395 PERROR("zmalloc config_writer_create");
399 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
404 writer
->writer
= xmlNewTextWriter(buffer
);
405 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
406 config_xml_encoding
, NULL
);
411 ret
= xmlTextWriterSetIndentString(writer
->writer
,
412 BAD_CAST config_xml_indent_string
);
417 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
425 config_writer_destroy(writer
);
430 int config_writer_destroy(struct config_writer
*writer
)
439 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
440 WARN("Could not close XML document");
444 if (writer
->writer
) {
445 xmlFreeTextWriter(writer
->writer
);
454 int config_writer_open_element(struct config_writer
*writer
,
455 const char *element_name
)
458 xmlChar
*encoded_element_name
;
460 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
465 encoded_element_name
= encode_string(element_name
);
466 if (!encoded_element_name
) {
471 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
472 xmlFree(encoded_element_name
);
474 return ret
>= 0 ? 0 : ret
;
478 int config_writer_write_attribute(struct config_writer
*writer
,
479 const char *name
, const char *value
)
482 xmlChar
*encoded_name
= NULL
;
483 xmlChar
*encoded_value
= NULL
;
485 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
490 encoded_name
= encode_string(name
);
496 encoded_value
= encode_string(value
);
497 if (!encoded_value
) {
502 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
505 xmlFree(encoded_name
);
506 xmlFree(encoded_value
);
507 return ret
>= 0 ? 0 : ret
;
511 int config_writer_close_element(struct config_writer
*writer
)
515 if (!writer
|| !writer
->writer
) {
520 ret
= xmlTextWriterEndElement(writer
->writer
);
522 return ret
>= 0 ? 0 : ret
;
526 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
527 const char *element_name
, uint64_t value
)
530 xmlChar
*encoded_element_name
;
532 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
537 encoded_element_name
= encode_string(element_name
);
538 if (!encoded_element_name
) {
543 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
544 encoded_element_name
, "%" PRIu64
, value
);
545 xmlFree(encoded_element_name
);
547 return ret
>= 0 ? 0 : ret
;
551 int config_writer_write_element_signed_int(struct config_writer
*writer
,
552 const char *element_name
, int64_t value
)
555 xmlChar
*encoded_element_name
;
557 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
562 encoded_element_name
= encode_string(element_name
);
563 if (!encoded_element_name
) {
568 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
569 encoded_element_name
, "%" PRIi64
, value
);
570 xmlFree(encoded_element_name
);
572 return ret
>= 0 ? 0 : ret
;
576 int config_writer_write_element_bool(struct config_writer
*writer
,
577 const char *element_name
, int value
)
579 return config_writer_write_element_string(writer
, element_name
,
580 value
? config_xml_true
: config_xml_false
);
584 int config_writer_write_element_string(struct config_writer
*writer
,
585 const char *element_name
, const char *value
)
588 xmlChar
*encoded_element_name
= NULL
;
589 xmlChar
*encoded_value
= NULL
;
591 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
597 encoded_element_name
= encode_string(element_name
);
598 if (!encoded_element_name
) {
603 encoded_value
= encode_string(value
);
604 if (!encoded_value
) {
609 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
612 xmlFree(encoded_element_name
);
613 xmlFree(encoded_value
);
614 return ret
>= 0 ? 0 : ret
;
618 void xml_error_handler(void *ctx
, const char *format
, ...)
624 va_start(args
, format
);
625 ret
= vasprintf(&errMsg
, format
, args
);
628 ERR("String allocation failed in xml error handler");
632 fprintf(stderr
, "XML Error: %s", errMsg
);
637 void fini_session_config_validation_ctx(
638 struct session_config_validation_ctx
*ctx
)
640 if (ctx
->parser_ctx
) {
641 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
645 xmlSchemaFree(ctx
->schema
);
648 if (ctx
->schema_validation_ctx
) {
649 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
652 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
656 char *get_session_config_xsd_path()
659 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
660 size_t base_path_len
;
664 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
667 base_path_len
= strlen(base_path
);
668 max_path_len
= base_path_len
+
669 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
670 xsd_path
= zmalloc(max_path_len
);
675 strncpy(xsd_path
, base_path
, max_path_len
);
676 if (xsd_path
[base_path_len
- 1] != '/') {
677 xsd_path
[base_path_len
++] = '/';
680 strncpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
,
681 max_path_len
- base_path_len
);
687 int init_session_config_validation_ctx(
688 struct session_config_validation_ctx
*ctx
)
691 char *xsd_path
= get_session_config_xsd_path();
694 ret
= -LTTNG_ERR_NOMEM
;
698 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
699 if (!ctx
->parser_ctx
) {
700 ERR("XSD parser context creation failed");
701 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
704 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
705 xml_error_handler
, NULL
);
707 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
709 ERR("XSD parsing failed");
710 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
714 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
715 if (!ctx
->schema_validation_ctx
) {
716 ERR("XSD validation context creation failed");
717 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
721 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
722 xml_error_handler
, NULL
);
727 fini_session_config_validation_ctx(ctx
);
735 int parse_uint(xmlChar
*str
, uint64_t *val
)
745 *val
= strtoull((const char *) str
, &endptr
, 10);
746 if (!endptr
|| *endptr
) {
757 int parse_int(xmlChar
*str
, int64_t *val
)
767 *val
= strtoll((const char *) str
, &endptr
, 10);
768 if (!endptr
|| *endptr
) {
779 int parse_bool(xmlChar
*str
, int *val
)
788 if (!strcmp((const char *) str
, config_xml_true
)) {
790 } else if (!strcmp((const char *) str
, config_xml_false
)) {
793 WARN("Invalid boolean value encoutered (%s).",
802 int get_domain_type(xmlChar
*domain
)
810 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
811 ret
= LTTNG_DOMAIN_KERNEL
;
812 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
813 ret
= LTTNG_DOMAIN_UST
;
814 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
815 ret
= LTTNG_DOMAIN_JUL
;
816 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
817 ret
= LTTNG_DOMAIN_LOG4J
;
818 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
819 ret
= LTTNG_DOMAIN_PYTHON
;
830 int get_buffer_type(xmlChar
*buffer_type
)
838 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
839 ret
= LTTNG_BUFFER_GLOBAL
;
840 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
841 ret
= LTTNG_BUFFER_PER_UID
;
842 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
843 ret
= LTTNG_BUFFER_PER_PID
;
854 int get_overwrite_mode(xmlChar
*overwrite_mode
)
858 if (!overwrite_mode
) {
862 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
864 } else if (!strcmp((char *) overwrite_mode
,
865 config_overwrite_mode_discard
)) {
877 int get_output_type(xmlChar
*output_type
)
885 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
886 ret
= LTTNG_EVENT_MMAP
;
887 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
888 ret
= LTTNG_EVENT_SPLICE
;
899 int get_event_type(xmlChar
*event_type
)
907 if (!strcmp((char *) event_type
, config_event_type_all
)) {
908 ret
= LTTNG_EVENT_ALL
;
909 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
910 ret
= LTTNG_EVENT_TRACEPOINT
;
911 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
912 ret
= LTTNG_EVENT_PROBE
;
913 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
914 ret
= LTTNG_EVENT_FUNCTION
;
915 } else if (!strcmp((char *) event_type
,
916 config_event_type_function_entry
)) {
917 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
918 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
919 ret
= LTTNG_EVENT_NOOP
;
920 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
921 ret
= LTTNG_EVENT_SYSCALL
;
932 int get_loglevel_type(xmlChar
*loglevel_type
)
936 if (!loglevel_type
) {
940 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
941 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
942 } else if (!strcmp((char *) loglevel_type
,
943 config_loglevel_type_range
)) {
944 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
945 } else if (!strcmp((char *) loglevel_type
,
946 config_loglevel_type_single
)) {
947 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
958 * Return the context type or -1 on error.
961 int get_context_type(xmlChar
*context_type
)
969 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
970 ret
= LTTNG_EVENT_CONTEXT_PID
;
971 } else if (!strcmp((char *) context_type
,
972 config_event_context_procname
)) {
973 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
974 } else if (!strcmp((char *) context_type
,
975 config_event_context_prio
)) {
976 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
977 } else if (!strcmp((char *) context_type
,
978 config_event_context_nice
)) {
979 ret
= LTTNG_EVENT_CONTEXT_NICE
;
980 } else if (!strcmp((char *) context_type
,
981 config_event_context_vpid
)) {
982 ret
= LTTNG_EVENT_CONTEXT_VPID
;
983 } else if (!strcmp((char *) context_type
,
984 config_event_context_tid
)) {
985 ret
= LTTNG_EVENT_CONTEXT_TID
;
986 } else if (!strcmp((char *) context_type
,
987 config_event_context_vtid
)) {
988 ret
= LTTNG_EVENT_CONTEXT_VTID
;
989 } else if (!strcmp((char *) context_type
,
990 config_event_context_ppid
)) {
991 ret
= LTTNG_EVENT_CONTEXT_PPID
;
992 } else if (!strcmp((char *) context_type
,
993 config_event_context_vppid
)) {
994 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
995 } else if (!strcmp((char *) context_type
,
996 config_event_context_pthread_id
)) {
997 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
998 } else if (!strcmp((char *) context_type
,
999 config_event_context_hostname
)) {
1000 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1001 } else if (!strcmp((char *) context_type
,
1002 config_event_context_ip
)) {
1003 ret
= LTTNG_EVENT_CONTEXT_IP
;
1004 } else if (!strcmp((char *) context_type
,
1005 config_event_context_interruptible
)) {
1006 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1007 } else if (!strcmp((char *) context_type
,
1008 config_event_context_preemptible
)) {
1009 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1010 } else if (!strcmp((char *) context_type
,
1011 config_event_context_need_reschedule
)) {
1012 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1013 } else if (!strcmp((char *) context_type
,
1014 config_event_context_migratable
)) {
1015 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1026 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1031 for (node
= xmlFirstElementChild(domain_node
); node
;
1032 node
= xmlNextElementSibling(node
)) {
1033 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1035 xmlChar
*node_content
= xmlNodeGetContent(node
);
1036 if (!node_content
) {
1037 ret
= -LTTNG_ERR_NOMEM
;
1041 ret
= get_domain_type(node_content
);
1044 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1049 } else if (!strcmp((const char *) node
->name
,
1050 config_element_buffer_type
)) {
1052 xmlChar
*node_content
= xmlNodeGetContent(node
);
1053 if (!node_content
) {
1054 ret
= -LTTNG_ERR_NOMEM
;
1058 ret
= get_buffer_type(node_content
);
1061 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1065 domain
->buf_type
= ret
;
1074 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1079 for (node
= xmlFirstElementChild(net_output_node
); node
;
1080 node
= xmlNextElementSibling(node
)) {
1081 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1083 *control_uri
= (char *) xmlNodeGetContent(node
);
1084 if (!*control_uri
) {
1089 *data_uri
= (char *) xmlNodeGetContent(node
);
1096 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1100 int process_consumer_output(xmlNodePtr consumer_output_node
,
1101 struct consumer_output
*output
)
1108 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1109 node
= xmlNextElementSibling(node
)) {
1110 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1111 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1115 ret
= -LTTNG_ERR_NOMEM
;
1119 ret
= parse_bool(enabled_str
, &output
->enabled
);
1125 xmlNodePtr output_type_node
;
1128 output_type_node
= xmlFirstElementChild(node
);
1129 if (!output_type_node
) {
1130 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1134 if (!strcmp((const char *) output_type_node
->name
,
1135 config_element_path
)) {
1137 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1138 if (!output
->path
) {
1139 ret
= -LTTNG_ERR_NOMEM
;
1144 ret
= get_net_output_uris(output_type_node
,
1145 &output
->control_uri
, &output
->data_uri
);
1157 free(output
->control_uri
);
1158 free(output
->data_uri
);
1159 memset(output
, 0, sizeof(struct consumer_output
));
1165 int create_session_net_output(const char *name
, const char *control_uri
,
1166 const char *data_uri
)
1169 struct lttng_handle
*handle
;
1170 const char *uri
= NULL
;
1174 handle
= lttng_create_handle(name
, NULL
);
1176 ret
= -LTTNG_ERR_NOMEM
;
1180 if (!control_uri
|| !data_uri
) {
1181 uri
= control_uri
? control_uri
: data_uri
;
1186 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1187 lttng_destroy_handle(handle
);
1193 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1194 const struct config_load_session_override_attr
*overrides
)
1197 xmlNodePtr node
= NULL
;
1198 xmlNodePtr snapshot_output_list_node
;
1199 xmlNodePtr snapshot_output_node
;
1201 assert(session_name
);
1203 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1212 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1214 /* Parse and create snapshot outputs */
1216 for (snapshot_output_node
=
1217 xmlFirstElementChild(snapshot_output_list_node
);
1218 snapshot_output_node
; snapshot_output_node
=
1219 xmlNextElementSibling(snapshot_output_node
)) {
1221 uint64_t max_size
= UINT64_MAX
;
1222 struct consumer_output output
= { 0 };
1223 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1224 const char *control_uri
= NULL
;
1225 const char *data_uri
= NULL
;
1226 const char *path
= NULL
;
1228 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1229 node
= xmlNextElementSibling(node
)) {
1230 if (!strcmp((const char *) node
->name
,
1231 config_element_name
)) {
1233 name
= (char *) xmlNodeGetContent(node
);
1235 ret
= -LTTNG_ERR_NOMEM
;
1236 goto error_snapshot_output
;
1238 } else if (!strcmp((const char *) node
->name
,
1239 config_element_max_size
)) {
1240 xmlChar
*content
= xmlNodeGetContent(node
);
1244 ret
= -LTTNG_ERR_NOMEM
;
1245 goto error_snapshot_output
;
1247 ret
= parse_uint(content
, &max_size
);
1250 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1251 goto error_snapshot_output
;
1254 /* consumer_output */
1255 ret
= process_consumer_output(node
, &output
);
1257 goto error_snapshot_output
;
1262 control_uri
= output
.control_uri
;
1263 data_uri
= output
.data_uri
;
1267 if (overrides
->path_url
) {
1268 path
= overrides
->path_url
;
1269 /* Control/data_uri are null */
1273 if (overrides
->ctrl_url
) {
1274 control_uri
= overrides
->ctrl_url
;
1278 if (overrides
->data_url
) {
1279 data_uri
= overrides
->data_url
;
1286 snapshot_output
= lttng_snapshot_output_create();
1287 if (!snapshot_output
) {
1288 ret
= -LTTNG_ERR_NOMEM
;
1289 goto error_snapshot_output
;
1292 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1294 goto error_snapshot_output
;
1297 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1299 goto error_snapshot_output
;
1303 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1306 goto error_snapshot_output
;
1310 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1313 goto error_snapshot_output
;
1318 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1321 goto error_snapshot_output
;
1326 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1327 error_snapshot_output
:
1330 free(output
.control_uri
);
1331 free(output
.data_uri
);
1332 lttng_snapshot_output_destroy(snapshot_output
);
1342 int create_session(const char *name
,
1343 struct lttng_domain
*kernel_domain
,
1344 struct lttng_domain
*ust_domain
,
1345 struct lttng_domain
*jul_domain
,
1346 struct lttng_domain
*log4j_domain
,
1347 xmlNodePtr output_node
,
1348 uint64_t live_timer_interval
,
1349 const struct config_load_session_override_attr
*overrides
)
1352 struct consumer_output output
= { 0 };
1353 xmlNodePtr consumer_output_node
;
1354 const char *control_uri
= NULL
;
1355 const char *data_uri
= NULL
;
1356 const char *path
= NULL
;
1361 consumer_output_node
= xmlFirstElementChild(output_node
);
1362 if (!consumer_output_node
) {
1363 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1367 if (strcmp((const char *) consumer_output_node
->name
,
1368 config_element_consumer_output
)) {
1369 WARN("Invalid output type, expected %s node",
1370 config_element_consumer_output
);
1371 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1375 ret
= process_consumer_output(consumer_output_node
, &output
);
1381 control_uri
= output
.control_uri
;
1382 data_uri
= output
.data_uri
;
1385 /* Check for override and apply them */
1387 if (overrides
->path_url
) {
1388 path
= overrides
->path_url
;
1389 /* control/data_uri are null */;
1393 if (overrides
->ctrl_url
) {
1394 control_uri
= overrides
->ctrl_url
;
1398 if (overrides
->data_url
) {
1399 data_uri
= overrides
->data_url
;
1407 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1408 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1412 if (control_uri
|| data_uri
) {
1413 /* network destination */
1414 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1416 * URLs are provided for sure since the test above make sure that
1417 * with a live timer the data and control URIs are provided. So,
1418 * NULL is passed here and will be set right after.
1420 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1422 ret
= lttng_create_session(name
, NULL
);
1428 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1434 /* either local output or no output */
1435 ret
= lttng_create_session(name
, path
);
1442 free(output
.control_uri
);
1443 free(output
.data_uri
);
1447 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1448 struct lttng_event_probe_attr
*attr
)
1452 assert(probe_attribute_node
);
1455 if (!strcmp((const char *) probe_attribute_node
->name
,
1456 config_element_address
)) {
1461 content
= xmlNodeGetContent(probe_attribute_node
);
1463 ret
= -LTTNG_ERR_NOMEM
;
1467 ret
= parse_uint(content
, &addr
);
1470 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1475 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1476 config_element_offset
)) {
1478 uint64_t offset
= 0;
1481 content
= xmlNodeGetContent(probe_attribute_node
);
1483 ret
= -LTTNG_ERR_NOMEM
;
1487 ret
= parse_uint(content
, &offset
);
1490 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1494 attr
->offset
= offset
;
1495 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1496 config_element_symbol_name
)) {
1501 content
= xmlNodeGetContent(probe_attribute_node
);
1503 ret
= -LTTNG_ERR_NOMEM
;
1507 name_len
= strlen((char *) content
);
1508 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1509 WARN("symbol_name too long.");
1510 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1515 strncpy(attr
->symbol_name
, (const char *) content
, name_len
);
1524 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1525 const char *channel_name
, const enum process_event_node_phase phase
)
1529 struct lttng_event event
;
1530 char **exclusions
= NULL
;
1531 unsigned long exclusion_count
= 0;
1532 char *filter_expression
= NULL
;
1536 assert(channel_name
);
1538 memset(&event
, 0, sizeof(event
));
1540 /* Initialize default log level which varies by domain */
1541 switch (handle
->domain
.type
)
1543 case LTTNG_DOMAIN_JUL
:
1544 event
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1546 case LTTNG_DOMAIN_LOG4J
:
1547 event
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1549 case LTTNG_DOMAIN_PYTHON
:
1550 event
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1552 case LTTNG_DOMAIN_UST
:
1553 case LTTNG_DOMAIN_KERNEL
:
1554 event
.loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1560 for (node
= xmlFirstElementChild(event_node
); node
;
1561 node
= xmlNextElementSibling(node
)) {
1562 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1567 content
= xmlNodeGetContent(node
);
1569 ret
= -LTTNG_ERR_NOMEM
;
1573 name_len
= strlen((char *) content
);
1574 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1575 WARN("Channel name too long.");
1576 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1581 strncpy(event
.name
, (const char *) content
, name_len
);
1583 } else if (!strcmp((const char *) node
->name
,
1584 config_element_enabled
)) {
1585 xmlChar
*content
= xmlNodeGetContent(node
);
1589 ret
= -LTTNG_ERR_NOMEM
;
1593 ret
= parse_bool(content
, &event
.enabled
);
1596 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1599 } else if (!strcmp((const char *) node
->name
,
1600 config_element_type
)) {
1601 xmlChar
*content
= xmlNodeGetContent(node
);
1605 ret
= -LTTNG_ERR_NOMEM
;
1609 ret
= get_event_type(content
);
1612 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1617 } else if (!strcmp((const char *) node
->name
,
1618 config_element_loglevel_type
)) {
1619 xmlChar
*content
= xmlNodeGetContent(node
);
1623 ret
= -LTTNG_ERR_NOMEM
;
1627 ret
= get_loglevel_type(content
);
1630 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1634 event
.loglevel_type
= ret
;
1635 } else if (!strcmp((const char *) node
->name
,
1636 config_element_loglevel
)) {
1638 int64_t loglevel
= 0;
1641 content
= xmlNodeGetContent(node
);
1643 ret
= -LTTNG_ERR_NOMEM
;
1647 ret
= parse_int(content
, &loglevel
);
1650 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1654 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1655 WARN("loglevel out of range.");
1656 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1660 event
.loglevel
= loglevel
;
1661 } else if (!strcmp((const char *) node
->name
,
1662 config_element_filter
)) {
1664 xmlNodeGetContent(node
);
1668 ret
= -LTTNG_ERR_NOMEM
;
1672 free(filter_expression
);
1673 filter_expression
= strdup((char *) content
);
1675 if (!filter_expression
) {
1676 ret
= -LTTNG_ERR_NOMEM
;
1679 } else if (!strcmp((const char *) node
->name
,
1680 config_element_exclusions
)) {
1681 xmlNodePtr exclusion_node
;
1682 int exclusion_index
= 0;
1687 * Exclusions has already been initialized,
1690 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1694 exclusion_count
= xmlChildElementCount(node
);
1695 if (!exclusion_count
) {
1699 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1701 exclusion_count
= 0;
1702 ret
= -LTTNG_ERR_NOMEM
;
1706 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1707 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1709 xmlNodeGetContent(exclusion_node
);
1712 ret
= -LTTNG_ERR_NOMEM
;
1716 exclusions
[exclusion_index
] = strdup((const char *) content
);
1718 if (!exclusions
[exclusion_index
]) {
1719 ret
= -LTTNG_ERR_NOMEM
;
1725 event
.exclusion
= 1;
1726 } else if (!strcmp((const char *) node
->name
,
1727 config_element_attributes
)) {
1728 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1731 if (!attribute_node
) {
1732 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1736 if (!strcmp((const char *) node
->name
,
1737 config_element_probe_attributes
)) {
1738 xmlNodePtr probe_attribute_node
;
1740 /* probe_attributes */
1741 for (probe_attribute_node
=
1742 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1743 probe_attribute_node
= xmlNextElementSibling(
1744 probe_attribute_node
)) {
1746 ret
= process_probe_attribute_node(probe_attribute_node
,
1755 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1757 /* function_attributes */
1758 content
= xmlNodeGetContent(symbol_node
);
1760 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1764 sym_len
= strlen((char *) content
);
1765 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1766 WARN("Function name too long.");
1767 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1772 strncpy(event
.attr
.ftrace
.symbol_name
, (char *) content
,
1779 if ((event
.enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1780 ret
= lttng_enable_event_with_exclusions(handle
, &event
, channel_name
,
1781 filter_expression
, exclusion_count
, exclusions
);
1783 WARN("Enabling event (name:%s) on load failed.", event
.name
);
1784 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1789 for (i
= 0; i
< exclusion_count
; i
++) {
1790 free(exclusions
[i
]);
1794 free(filter_expression
);
1799 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
1800 const char *channel_name
)
1803 struct lttng_event event
;
1806 assert(events_node
);
1808 assert(channel_name
);
1810 for (node
= xmlFirstElementChild(events_node
); node
;
1811 node
= xmlNextElementSibling(node
)) {
1812 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
1819 * Disable all events to enable only the necessary events.
1820 * Limitations regarding lttng_disable_events and tuple descriptor
1821 * force this approach.
1823 memset(&event
, 0, sizeof(event
));
1824 event
.loglevel
= -1;
1825 event
.type
= LTTNG_EVENT_ALL
;
1826 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
1831 for (node
= xmlFirstElementChild(events_node
); node
;
1832 node
= xmlNextElementSibling(node
)) {
1833 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
1844 int process_channel_attr_node(xmlNodePtr attr_node
,
1845 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
1846 xmlNodePtr
*events_node
)
1852 assert(contexts_node
);
1853 assert(events_node
);
1855 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
1860 content
= xmlNodeGetContent(attr_node
);
1862 ret
= -LTTNG_ERR_NOMEM
;
1866 name_len
= strlen((char *) content
);
1867 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1868 WARN("Channel name too long.");
1869 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1874 strncpy(channel
->name
, (const char *) content
, name_len
);
1876 } else if (!strcmp((const char *) attr_node
->name
,
1877 config_element_enabled
)) {
1882 content
= xmlNodeGetContent(attr_node
);
1884 ret
= -LTTNG_ERR_NOMEM
;
1888 ret
= parse_bool(content
, &enabled
);
1891 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1895 channel
->enabled
= enabled
;
1896 } else if (!strcmp((const char *) attr_node
->name
,
1897 config_element_overwrite_mode
)) {
1900 /* overwrite_mode */
1901 content
= xmlNodeGetContent(attr_node
);
1903 ret
= -LTTNG_ERR_NOMEM
;
1907 ret
= get_overwrite_mode(content
);
1910 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1914 channel
->attr
.overwrite
= ret
;
1915 } else if (!strcmp((const char *) attr_node
->name
,
1916 config_element_subbuf_size
)) {
1919 /* subbuffer_size */
1920 content
= xmlNodeGetContent(attr_node
);
1922 ret
= -LTTNG_ERR_NOMEM
;
1926 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
1929 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1932 } else if (!strcmp((const char *) attr_node
->name
,
1933 config_element_num_subbuf
)) {
1936 /* subbuffer_count */
1937 content
= xmlNodeGetContent(attr_node
);
1939 ret
= -LTTNG_ERR_NOMEM
;
1943 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
1946 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1949 } else if (!strcmp((const char *) attr_node
->name
,
1950 config_element_switch_timer_interval
)) {
1952 uint64_t switch_timer_interval
= 0;
1954 /* switch_timer_interval */
1955 content
= xmlNodeGetContent(attr_node
);
1957 ret
= -LTTNG_ERR_NOMEM
;
1961 ret
= parse_uint(content
, &switch_timer_interval
);
1964 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1968 if (switch_timer_interval
> UINT_MAX
) {
1969 WARN("switch_timer_interval out of range.");
1970 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1974 channel
->attr
.switch_timer_interval
=
1975 switch_timer_interval
;
1976 } else if (!strcmp((const char *) attr_node
->name
,
1977 config_element_read_timer_interval
)) {
1979 uint64_t read_timer_interval
= 0;
1981 /* read_timer_interval */
1982 content
= xmlNodeGetContent(attr_node
);
1984 ret
= -LTTNG_ERR_NOMEM
;
1988 ret
= parse_uint(content
, &read_timer_interval
);
1991 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1995 if (read_timer_interval
> UINT_MAX
) {
1996 WARN("read_timer_interval out of range.");
1997 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2001 channel
->attr
.read_timer_interval
=
2002 read_timer_interval
;
2003 } else if (!strcmp((const char *) attr_node
->name
,
2004 config_element_output_type
)) {
2008 content
= xmlNodeGetContent(attr_node
);
2010 ret
= -LTTNG_ERR_NOMEM
;
2014 ret
= get_output_type(content
);
2017 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2021 channel
->attr
.output
= ret
;
2022 } else if (!strcmp((const char *) attr_node
->name
,
2023 config_element_tracefile_size
)) {
2026 /* tracefile_size */
2027 content
= xmlNodeGetContent(attr_node
);
2029 ret
= -LTTNG_ERR_NOMEM
;
2033 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2036 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2039 } else if (!strcmp((const char *) attr_node
->name
,
2040 config_element_tracefile_count
)) {
2043 /* tracefile_count */
2044 content
= xmlNodeGetContent(attr_node
);
2046 ret
= -LTTNG_ERR_NOMEM
;
2050 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2053 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2056 } else if (!strcmp((const char *) attr_node
->name
,
2057 config_element_live_timer_interval
)) {
2059 uint64_t live_timer_interval
= 0;
2061 /* live_timer_interval */
2062 content
= xmlNodeGetContent(attr_node
);
2064 ret
= -LTTNG_ERR_NOMEM
;
2068 ret
= parse_uint(content
, &live_timer_interval
);
2071 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2075 if (live_timer_interval
> UINT_MAX
) {
2076 WARN("live_timer_interval out of range.");
2077 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2081 channel
->attr
.live_timer_interval
=
2082 live_timer_interval
;
2083 } else if (!strcmp((const char *) attr_node
->name
,
2084 config_element_events
)) {
2086 *events_node
= attr_node
;
2089 *contexts_node
= attr_node
;
2097 int process_context_node(xmlNodePtr context_node
,
2098 struct lttng_handle
*handle
, const char *channel_name
)
2101 struct lttng_event_context context
;
2102 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2105 assert(channel_name
);
2107 if (!context_child_node
) {
2108 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2112 memset(&context
, 0, sizeof(context
));
2114 if (!strcmp((const char *) context_child_node
->name
,
2115 config_element_type
)) {
2117 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2120 ret
= -LTTNG_ERR_NOMEM
;
2124 ret
= get_context_type(content
);
2127 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2132 } else if (!strcmp((const char *) context_child_node
->name
,
2133 config_element_context_perf
)) {
2135 xmlNodePtr perf_attr_node
;
2137 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2138 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2139 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2140 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2141 perf_attr_node
; perf_attr_node
=
2142 xmlNextElementSibling(perf_attr_node
)) {
2143 if (!strcmp((const char *) perf_attr_node
->name
,
2144 config_element_type
)) {
2149 content
= xmlNodeGetContent(perf_attr_node
);
2151 ret
= -LTTNG_ERR_NOMEM
;
2155 ret
= parse_uint(content
, &type
);
2158 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2162 if (type
> UINT32_MAX
) {
2163 WARN("perf context type out of range.");
2164 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2168 context
.u
.perf_counter
.type
= type
;
2169 } else if (!strcmp((const char *) perf_attr_node
->name
,
2170 config_element_config
)) {
2172 uint64_t config
= 0;
2175 content
= xmlNodeGetContent(perf_attr_node
);
2177 ret
= -LTTNG_ERR_NOMEM
;
2181 ret
= parse_uint(content
, &config
);
2184 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2188 context
.u
.perf_counter
.config
= config
;
2189 } else if (!strcmp((const char *) perf_attr_node
->name
,
2190 config_element_name
)) {
2195 content
= xmlNodeGetContent(perf_attr_node
);
2197 ret
= -LTTNG_ERR_NOMEM
;
2201 name_len
= strlen((char *) content
);
2202 if (name_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2203 WARN("perf context name too long.");
2204 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2209 strncpy(context
.u
.perf_counter
.name
, (const char *) content
,
2214 } else if (!strcmp((const char *) context_child_node
->name
,
2215 config_element_context_app
)) {
2216 /* application context */
2217 xmlNodePtr app_ctx_node
;
2219 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2220 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2221 app_ctx_node
; app_ctx_node
=
2222 xmlNextElementSibling(app_ctx_node
)) {
2224 char **target
= strcmp(
2225 (const char *) app_ctx_node
->name
,
2226 config_element_context_app_provider_name
) == 0 ?
2227 &context
.u
.app_ctx
.provider_name
:
2228 &context
.u
.app_ctx
.ctx_name
;
2230 content
= xmlNodeGetContent(app_ctx_node
);
2232 ret
= -LTTNG_ERR_NOMEM
;
2236 *target
= (char *) content
;
2239 /* Unrecognized context type */
2240 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2244 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2245 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2246 free(context
.u
.app_ctx
.provider_name
);
2247 free(context
.u
.app_ctx
.ctx_name
);
2254 int process_contexts_node(xmlNodePtr contexts_node
,
2255 struct lttng_handle
*handle
, const char *channel_name
)
2258 xmlNodePtr context_node
;
2260 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2261 context_node
= xmlNextElementSibling(context_node
)) {
2262 ret
= process_context_node(context_node
, handle
, channel_name
);
2272 int process_pid_tracker_node(xmlNodePtr pid_tracker_node
,
2273 struct lttng_handle
*handle
)
2276 xmlNodePtr targets_node
= NULL
;
2280 assert(pid_tracker_node
);
2281 /* get the targets node */
2282 for (node
= xmlFirstElementChild(pid_tracker_node
); node
;
2283 node
= xmlNextElementSibling(node
)) {
2284 if (!strcmp((const char *) node
->name
,
2285 config_element_targets
)) {
2286 targets_node
= node
;
2291 if (!targets_node
) {
2292 ret
= LTTNG_ERR_INVALID
;
2296 /* Go through all pid_target node */
2297 child
= xmlChildElementCount(targets_node
);
2299 /* The session is explicitly set to target nothing. */
2300 ret
= lttng_untrack_pid(handle
, -1);
2305 for (node
= xmlFirstElementChild(targets_node
); node
;
2306 node
= xmlNextElementSibling(node
)) {
2307 xmlNodePtr pid_target_node
= node
;
2309 /* get pid node and track it */
2310 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2311 node
= xmlNextElementSibling(node
)) {
2312 if (!strcmp((const char *) node
->name
,
2313 config_element_pid
)) {
2315 xmlChar
*content
= NULL
;
2317 content
= xmlNodeGetContent(node
);
2319 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2323 ret
= parse_int(content
, &pid
);
2326 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2330 ret
= lttng_track_pid(handle
, (int) pid
);
2336 node
= pid_target_node
;
2345 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2348 struct lttng_domain domain
= { 0 };
2349 struct lttng_handle
*handle
= NULL
;
2350 xmlNodePtr channels_node
= NULL
;
2351 xmlNodePtr trackers_node
= NULL
;
2352 xmlNodePtr pid_tracker_node
= NULL
;
2355 assert(session_name
);
2357 ret
= init_domain(domain_node
, &domain
);
2362 handle
= lttng_create_handle(session_name
, &domain
);
2364 ret
= -LTTNG_ERR_NOMEM
;
2368 /* get the channels node */
2369 for (node
= xmlFirstElementChild(domain_node
); node
;
2370 node
= xmlNextElementSibling(node
)) {
2371 if (!strcmp((const char *) node
->name
,
2372 config_element_channels
)) {
2373 channels_node
= node
;
2378 if (!channels_node
) {
2382 /* create all channels */
2383 for (node
= xmlFirstElementChild(channels_node
); node
;
2384 node
= xmlNextElementSibling(node
)) {
2385 struct lttng_channel channel
;
2386 xmlNodePtr contexts_node
= NULL
;
2387 xmlNodePtr events_node
= NULL
;
2388 xmlNodePtr channel_attr_node
;
2390 memset(&channel
, 0, sizeof(channel
));
2391 lttng_channel_set_default_attr(&domain
, &channel
.attr
);
2393 for (channel_attr_node
= xmlFirstElementChild(node
);
2394 channel_attr_node
; channel_attr_node
=
2395 xmlNextElementSibling(channel_attr_node
)) {
2396 ret
= process_channel_attr_node(channel_attr_node
,
2397 &channel
, &contexts_node
, &events_node
);
2403 ret
= lttng_enable_channel(handle
, &channel
);
2408 ret
= process_events_node(events_node
, handle
, channel
.name
);
2413 ret
= process_contexts_node(contexts_node
, handle
,
2420 /* get the trackers node */
2421 for (node
= xmlFirstElementChild(domain_node
); node
;
2422 node
= xmlNextElementSibling(node
)) {
2423 if (!strcmp((const char *) node
->name
,
2424 config_element_trackers
)) {
2425 trackers_node
= node
;
2430 if (!trackers_node
) {
2434 for (node
= xmlFirstElementChild(trackers_node
); node
;
2435 node
= xmlNextElementSibling(node
)) {
2436 if (!strcmp((const char *)node
->name
,config_element_pid_tracker
)) {
2437 pid_tracker_node
= node
;
2438 ret
= process_pid_tracker_node(pid_tracker_node
, handle
);
2445 if (!pid_tracker_node
) {
2446 lttng_track_pid(handle
, -1);
2450 lttng_destroy_handle(handle
);
2455 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
2457 const struct config_load_session_override_attr
*overrides
)
2459 int ret
, started
= -1, snapshot_mode
= -1;
2460 uint64_t live_timer_interval
= UINT64_MAX
;
2461 xmlChar
*name
= NULL
;
2462 xmlChar
*shm_path
= NULL
;
2463 xmlNodePtr domains_node
= NULL
;
2464 xmlNodePtr output_node
= NULL
;
2466 struct lttng_domain
*kernel_domain
= NULL
;
2467 struct lttng_domain
*ust_domain
= NULL
;
2468 struct lttng_domain
*jul_domain
= NULL
;
2469 struct lttng_domain
*log4j_domain
= NULL
;
2470 struct lttng_domain
*python_domain
= NULL
;
2472 for (node
= xmlFirstElementChild(session_node
); node
;
2473 node
= xmlNextElementSibling(node
)) {
2474 if (!name
&& !strcmp((const char *) node
->name
,
2475 config_element_name
)) {
2477 xmlChar
*node_content
= xmlNodeGetContent(node
);
2478 if (!node_content
) {
2479 ret
= -LTTNG_ERR_NOMEM
;
2483 name
= node_content
;
2484 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
2485 config_element_domains
)) {
2487 domains_node
= node
;
2488 } else if (started
== -1 && !strcmp((const char *) node
->name
,
2489 config_element_started
)) {
2491 xmlChar
*node_content
= xmlNodeGetContent(node
);
2492 if (!node_content
) {
2493 ret
= -LTTNG_ERR_NOMEM
;
2497 ret
= parse_bool(node_content
, &started
);
2500 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2503 } else if (!output_node
&& !strcmp((const char *) node
->name
,
2504 config_element_output
)) {
2507 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
2508 config_element_shared_memory_path
)) {
2509 /* shared memory path */
2510 xmlChar
*node_content
= xmlNodeGetContent(node
);
2511 if (!node_content
) {
2512 ret
= -LTTNG_ERR_NOMEM
;
2516 shm_path
= node_content
;
2518 /* attributes, snapshot_mode or live_timer_interval */
2519 xmlNodePtr attributes_child
=
2520 xmlFirstElementChild(node
);
2522 if (!strcmp((const char *) attributes_child
->name
,
2523 config_element_snapshot_mode
)) {
2525 xmlChar
*snapshot_mode_content
=
2526 xmlNodeGetContent(attributes_child
);
2527 if (!snapshot_mode_content
) {
2528 ret
= -LTTNG_ERR_NOMEM
;
2532 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
2533 free(snapshot_mode_content
);
2535 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2539 /* live_timer_interval */
2540 xmlChar
*timer_interval_content
=
2541 xmlNodeGetContent(attributes_child
);
2542 if (!timer_interval_content
) {
2543 ret
= -LTTNG_ERR_NOMEM
;
2547 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
2548 free(timer_interval_content
);
2550 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2558 /* Mandatory attribute, as defined in the session XSD */
2559 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2563 if (session_name
&& strcmp((char *) name
, session_name
)) {
2564 /* This is not the session we are looking for */
2565 ret
= -LTTNG_ERR_NO_SESSION
;
2569 /* Init domains to create the session handles */
2570 for (node
= xmlFirstElementChild(domains_node
); node
;
2571 node
= xmlNextElementSibling(node
)) {
2572 struct lttng_domain
*domain
;
2574 domain
= zmalloc(sizeof(*domain
));
2576 ret
= -LTTNG_ERR_NOMEM
;
2580 ret
= init_domain(node
, domain
);
2582 goto domain_init_error
;
2585 switch (domain
->type
) {
2586 case LTTNG_DOMAIN_KERNEL
:
2587 if (kernel_domain
) {
2588 /* Same domain seen twice, invalid! */
2589 goto domain_init_error
;
2591 kernel_domain
= domain
;
2593 case LTTNG_DOMAIN_UST
:
2595 /* Same domain seen twice, invalid! */
2596 goto domain_init_error
;
2598 ust_domain
= domain
;
2600 case LTTNG_DOMAIN_JUL
:
2602 /* Same domain seen twice, invalid! */
2603 goto domain_init_error
;
2605 jul_domain
= domain
;
2607 case LTTNG_DOMAIN_LOG4J
:
2609 /* Same domain seen twice, invalid! */
2610 goto domain_init_error
;
2612 log4j_domain
= domain
;
2614 case LTTNG_DOMAIN_PYTHON
:
2615 if (python_domain
) {
2616 /* Same domain seen twice, invalid! */
2617 goto domain_init_error
;
2619 python_domain
= domain
;
2622 WARN("Invalid domain type");
2623 goto domain_init_error
;
2628 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2632 /* Apply overrides */
2634 if (overrides
->session_name
) {
2635 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
2636 if (!name_override
) {
2637 ret
= -LTTNG_ERR_NOMEM
;
2641 /* Overrides the session name to the provided name */
2643 name
= name_override
;
2648 /* Destroy session if it exists */
2649 ret
= lttng_destroy_session((const char *) name
);
2650 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
2651 ERR("Failed to destroy existing session.");
2656 /* Create session type depending on output type */
2657 if (snapshot_mode
&& snapshot_mode
!= -1) {
2658 ret
= create_snapshot_session((const char *) name
, output_node
,
2660 } else if (live_timer_interval
&&
2661 live_timer_interval
!= UINT64_MAX
) {
2662 ret
= create_session((const char *) name
, kernel_domain
,
2663 ust_domain
, jul_domain
, log4j_domain
,
2664 output_node
, live_timer_interval
, overrides
);
2666 /* regular session */
2667 ret
= create_session((const char *) name
, kernel_domain
,
2668 ust_domain
, jul_domain
, log4j_domain
,
2669 output_node
, UINT64_MAX
, overrides
);
2676 ret
= lttng_set_session_shm_path((const char *) name
,
2677 (const char *) shm_path
);
2683 for (node
= xmlFirstElementChild(domains_node
); node
;
2684 node
= xmlNextElementSibling(node
)) {
2685 ret
= process_domain_node(node
, (const char *) name
);
2692 ret
= lttng_start_tracing((const char *) name
);
2700 ERR("Failed to load session %s: %s", (const char *) name
,
2701 lttng_strerror(ret
));
2702 lttng_destroy_session((const char *) name
);
2706 free(kernel_domain
);
2710 free(python_domain
);
2717 * Return 1 if the given path is readable by the current UID or 0 if not.
2718 * Return -1 if the path is EPERM.
2720 static int validate_file_read_creds(const char *path
)
2726 /* Can we read the file. */
2727 ret
= access(path
, R_OK
);
2731 if (errno
== EACCES
) {
2742 int load_session_from_file(const char *path
, const char *session_name
,
2743 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2744 const struct config_load_session_override_attr
*overrides
)
2746 int ret
, session_found
= !session_name
;
2747 xmlDocPtr doc
= NULL
;
2748 xmlNodePtr sessions_node
;
2749 xmlNodePtr session_node
;
2752 assert(validation_ctx
);
2754 ret
= validate_file_read_creds(path
);
2757 ret
= -LTTNG_ERR_EPERM
;
2759 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2764 doc
= xmlParseFile(path
);
2766 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2770 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
2772 ERR("Session configuration file validation failed");
2773 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2777 sessions_node
= xmlDocGetRootElement(doc
);
2778 if (!sessions_node
) {
2782 for (session_node
= xmlFirstElementChild(sessions_node
);
2783 session_node
; session_node
=
2784 xmlNextElementSibling(session_node
)) {
2785 ret
= process_session_node(session_node
,
2786 session_name
, overwrite
, overrides
);
2787 if (session_name
&& ret
== 0) {
2788 /* Target session found and loaded */
2796 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
2801 /* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
2803 struct dirent
*alloc_dirent(const char *path
)
2807 struct dirent
*entry
;
2809 name_max
= pathconf(path
, _PC_NAME_MAX
);
2810 if (name_max
== -1) {
2811 name_max
= PATH_MAX
;
2813 len
= offsetof(struct dirent
, d_name
) + name_max
+ 1;
2814 entry
= zmalloc(len
);
2819 int load_session_from_path(const char *path
, const char *session_name
,
2820 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
2821 const struct config_load_session_override_attr
*overrides
)
2823 int ret
, session_found
= !session_name
;
2824 DIR *directory
= NULL
;
2827 assert(validation_ctx
);
2829 directory
= opendir(path
);
2833 /* Try the file loading. */
2836 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
2839 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
2844 struct dirent
*entry
;
2845 struct dirent
*result
;
2846 char *file_path
= NULL
;
2847 size_t path_len
= strlen(path
);
2849 if (path_len
>= PATH_MAX
) {
2850 ret
= -LTTNG_ERR_INVALID
;
2854 entry
= alloc_dirent(path
);
2856 ret
= -LTTNG_ERR_NOMEM
;
2860 file_path
= zmalloc(PATH_MAX
);
2862 ret
= -LTTNG_ERR_NOMEM
;
2867 strncpy(file_path
, path
, path_len
);
2868 if (file_path
[path_len
- 1] != '/') {
2869 file_path
[path_len
++] = '/';
2873 /* Search for *.lttng files */
2874 while (!readdir_r(directory
, entry
, &result
) && result
) {
2875 size_t file_name_len
= strlen(result
->d_name
);
2877 if (file_name_len
<=
2878 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
2882 if (path_len
+ file_name_len
>= PATH_MAX
) {
2886 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
2887 result
->d_name
+ file_name_len
- sizeof(
2888 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
2892 strncpy(file_path
+ path_len
, result
->d_name
, file_name_len
);
2893 file_path
[path_len
+ file_name_len
] = '\0';
2895 ret
= load_session_from_file(file_path
, session_name
,
2896 validation_ctx
, overwrite
, overrides
);
2897 if (session_name
&& !ret
) {
2906 ret
= load_session_from_file(path
, session_name
,
2907 validation_ctx
, overwrite
, overrides
);
2917 if (closedir(directory
)) {
2922 if (session_found
&& !ret
) {
2930 * Validate that the given path's credentials and the current process have the
2931 * same UID. If so, return 1 else return 0 if it does NOT match.
2933 static int validate_path_creds(const char *path
)
2935 int ret
, uid
= getuid();
2944 ret
= stat(path
, &buf
);
2946 if (errno
!= ENOENT
) {
2949 ret
= -LTTNG_ERR_INVALID
;
2953 if (buf
.st_uid
!= uid
) {
2964 int config_load_session(const char *path
, const char *session_name
,
2965 int overwrite
, unsigned int autoload
,
2966 const struct config_load_session_override_attr
*overrides
)
2969 bool session_loaded
= false;
2970 const char *path_ptr
= NULL
;
2971 struct session_config_validation_ctx validation_ctx
= { 0 };
2973 ret
= init_session_config_validation_ctx(&validation_ctx
);
2980 const char *sys_path
;
2983 home_path
= utils_get_home_dir();
2985 char path
[PATH_MAX
];
2988 * Try user session configuration path. Ignore error here so we can
2989 * continue loading the system wide sessions.
2992 ret
= snprintf(path
, sizeof(path
),
2993 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
2994 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
2996 PERROR("snprintf session autoload home config path");
3001 * Credentials are only validated for the autoload in order to
3002 * avoid any user session daemon to try to load kernel sessions
3003 * automatically and failing all the times.
3005 ret
= validate_path_creds(path
);
3010 ret
= snprintf(path
, sizeof(path
),
3011 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3013 PERROR("snprintf session home config path");
3019 ret
= load_session_from_path(path_ptr
, session_name
,
3020 &validation_ctx
, overwrite
, overrides
);
3021 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3025 * Continue even if the session was found since we have to try
3026 * the system wide sessions.
3028 session_loaded
= true;
3032 /* Reset path pointer for the system wide dir. */
3035 /* Try system wide configuration directory. */
3037 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3038 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3039 ret
= validate_path_creds(sys_path
);
3041 path_ptr
= sys_path
;
3044 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3045 path_ptr
= sys_path
;
3049 ret
= load_session_from_path(path_ptr
, session_name
,
3050 &validation_ctx
, overwrite
, overrides
);
3052 session_loaded
= true;
3056 ret
= access(path
, F_OK
);
3061 ret
= -LTTNG_ERR_INVALID
;
3062 WARN("Session configuration path does not exist.");
3065 ret
= -LTTNG_ERR_EPERM
;
3068 ret
= -LTTNG_ERR_UNK
;
3074 ret
= load_session_from_path(path
, session_name
,
3075 &validation_ctx
, overwrite
, overrides
);
3078 fini_session_config_validation_ctx(&validation_ctx
);
3079 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3081 * Don't report an error if no sessions are found when called
3082 * without a session_name or a search path.
3087 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3088 /* A matching session was found in one of the search paths. */
3095 void __attribute__((destructor
)) session_config_exit(void)