2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "lttng/tracker.h"
18 #include <sys/types.h>
22 #include <common/defaults.h>
23 #include <common/error.h>
24 #include <common/macros.h>
25 #include <common/utils.h>
26 #include <common/dynamic-buffer.h>
27 #include <common/dynamic-array.h>
28 #include <common/compat/getenv.h>
29 #include <lttng/lttng-error.h>
30 #include <libxml/parser.h>
31 #include <libxml/valid.h>
32 #include <libxml/xmlschemas.h>
33 #include <libxml/tree.h>
34 #include <lttng/lttng.h>
35 #include <lttng/snapshot.h>
36 #include <lttng/rotation.h>
37 #include <lttng/userspace-probe.h>
39 #include "session-config.h"
40 #include "config-internal.h"
42 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
44 struct handler_filter_args
{
46 config_entry_handler_cb handler
;
50 struct session_config_validation_ctx
{
51 xmlSchemaParserCtxtPtr parser_ctx
;
53 xmlSchemaValidCtxtPtr schema_validation_ctx
;
56 LTTNG_HIDDEN
const char * const config_element_all
= "all";
57 const char * const config_str_yes
= "yes";
58 const char * const config_str_true
= "true";
59 const char * const config_str_on
= "on";
60 const char * const config_str_no
= "no";
61 const char * const config_str_false
= "false";
62 const char * const config_str_off
= "off";
63 const char * const config_xml_encoding
= "UTF-8";
64 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
65 const char * const config_xml_indent_string
= "\t";
66 const char * const config_xml_true
= "true";
67 const char * const config_xml_false
= "false";
69 const char * const config_element_channel
= "channel";
70 const char * const config_element_channels
= "channels";
71 const char * const config_element_map
= "map";
72 const char * const config_element_maps
= "maps";
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";
88 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
89 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
90 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
91 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
92 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
93 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
95 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
96 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
97 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
99 const char * const config_element_name
= "name";
100 const char * const config_element_enabled
= "enabled";
101 const char * const config_element_overwrite_mode
= "overwrite_mode";
102 const char * const config_element_subbuf_size
= "subbuffer_size";
103 const char * const config_element_num_subbuf
= "subbuffer_count";
104 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
105 const char * const config_element_read_timer_interval
= "read_timer_interval";
106 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
107 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
108 const char * const config_element_output
= "output";
109 const char * const config_element_output_type
= "output_type";
110 const char * const config_element_tracefile_size
= "tracefile_size";
111 const char * const config_element_tracefile_count
= "tracefile_count";
112 const char * const config_element_live_timer_interval
= "live_timer_interval";
113 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
114 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
115 const char * const config_element_type
= "type";
116 const char * const config_element_buffer_type
= "buffer_type";
117 const char * const config_element_session
= "session";
118 const char * const config_element_sessions
= "sessions";
119 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
120 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
121 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
122 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
123 const char * const config_element_config
= "config";
124 const char * const config_element_started
= "started";
125 const char * const config_element_snapshot_mode
= "snapshot_mode";
126 const char * const config_element_loglevel
= "loglevel";
127 const char * const config_element_loglevel_type
= "loglevel_type";
128 const char * const config_element_filter
= "filter";
129 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
130 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
131 const char * const config_element_consumer_output
= "consumer_output";
132 const char * const config_element_destination
= "destination";
133 const char * const config_element_path
= "path";
134 const char * const config_element_net_output
= "net_output";
135 const char * const config_element_control_uri
= "control_uri";
136 const char * const config_element_data_uri
= "data_uri";
137 const char * const config_element_max_size
= "max_size";
138 const char * const config_element_pid
= "pid";
139 const char * const config_element_pids
= "pids";
140 const char * const config_element_shared_memory_path
= "shared_memory_path";
142 LTTNG_HIDDEN
const char * const config_element_process_attr_id
= "id";
143 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
144 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
145 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
146 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
147 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
148 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
149 LTTNG_HIDDEN
const char * const config_element_process_attr_trackers
= "process_attr_trackers";
150 LTTNG_HIDDEN
const char * const config_element_process_attr_values
= "process_attr_values";
151 LTTNG_HIDDEN
const char * const config_element_process_attr_value_type
= "process_attr_value_type";
152 LTTNG_HIDDEN
const char * const config_element_process_attr_pid_value
= "pid";
153 LTTNG_HIDDEN
const char * const config_element_process_attr_vpid_value
= "vpid";
154 LTTNG_HIDDEN
const char * const config_element_process_attr_uid_value
= "uid";
155 LTTNG_HIDDEN
const char * const config_element_process_attr_vuid_value
= "vuid";
156 LTTNG_HIDDEN
const char * const config_element_process_attr_gid_value
= "gid";
157 LTTNG_HIDDEN
const char * const config_element_process_attr_vgid_value
= "vgid";
158 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
160 /* Used for support of legacy tracker serialization (< 2.12). */
161 LTTNG_HIDDEN
const char * const config_element_trackers_legacy
= "trackers";
162 LTTNG_HIDDEN
const char * const config_element_pid_tracker_legacy
= "pid_tracker";
163 LTTNG_HIDDEN
const char * const config_element_tracker_targets_legacy
= "targets";
164 LTTNG_HIDDEN
const char * const config_element_tracker_pid_target_legacy
= "pid_target";
165 LTTNG_HIDDEN
const char * const config_element_tracker_pid_legacy
= "pid";
167 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
168 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
169 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
170 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
171 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
173 const char * const config_domain_type_kernel
= "KERNEL";
174 const char * const config_domain_type_ust
= "UST";
175 const char * const config_domain_type_jul
= "JUL";
176 const char * const config_domain_type_log4j
= "LOG4J";
177 const char * const config_domain_type_python
= "PYTHON";
179 const char * const config_buffer_type_per_pid
= "PER_PID";
180 const char * const config_buffer_type_per_uid
= "PER_UID";
181 const char * const config_buffer_type_global
= "GLOBAL";
183 const char * const config_overwrite_mode_discard
= "DISCARD";
184 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
186 const char * const config_output_type_splice
= "SPLICE";
187 const char * const config_output_type_mmap
= "MMAP";
189 LTTNG_HIDDEN
const char * const config_element_bitness
= "bitness";
190 LTTNG_HIDDEN
const char * const config_element_boundary_policy
= "boundary_policy";
191 LTTNG_HIDDEN
const char * const config_element_coalesce_hits
= "coalesce_hits";
192 LTTNG_HIDDEN
const char * const config_element_dimensions
= "dimensions";
193 LTTNG_HIDDEN
const char * const config_element_dimension
= "dimension";
194 LTTNG_HIDDEN
const char * const config_element_dimension_size
= "size";
196 LTTNG_HIDDEN
const char * const config_boundary_policy_overflow
= "OVERFLOW";
198 const char * const config_loglevel_type_all
= "ALL";
199 const char * const config_loglevel_type_range
= "RANGE";
200 const char * const config_loglevel_type_single
= "SINGLE";
202 const char * const config_event_type_all
= "ALL";
203 const char * const config_event_type_tracepoint
= "TRACEPOINT";
204 const char * const config_event_type_probe
= "PROBE";
205 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
206 const char * const config_event_type_function
= "FUNCTION";
207 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
208 const char * const config_event_type_noop
= "NOOP";
209 const char * const config_event_type_syscall
= "SYSCALL";
210 const char * const config_event_type_kprobe
= "KPROBE";
211 const char * const config_event_type_kretprobe
= "KRETPROBE";
213 const char * const config_event_context_pid
= "PID";
214 const char * const config_event_context_procname
= "PROCNAME";
215 const char * const config_event_context_prio
= "PRIO";
216 const char * const config_event_context_nice
= "NICE";
217 const char * const config_event_context_vpid
= "VPID";
218 const char * const config_event_context_tid
= "TID";
219 const char * const config_event_context_vtid
= "VTID";
220 const char * const config_event_context_ppid
= "PPID";
221 const char * const config_event_context_vppid
= "VPPID";
222 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
223 const char * const config_event_context_hostname
= "HOSTNAME";
224 const char * const config_event_context_ip
= "IP";
225 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
226 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
227 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
228 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
229 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
230 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
231 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
232 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
233 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
234 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
235 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
236 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
237 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
238 LTTNG_HIDDEN
const char * const config_event_context_time_ns
= "TIME_NS";
239 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
240 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
241 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
242 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
243 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
244 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
245 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
246 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
247 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
248 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
249 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
250 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
251 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
252 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
254 /* Deprecated symbols */
255 const char * const config_element_perf
;
257 enum process_event_node_phase
{
262 struct consumer_output
{
269 static int config_entry_handler_filter(struct handler_filter_args
*args
,
270 const char *section
, const char *name
, const char *value
)
273 struct config_entry entry
= { section
, name
, value
};
277 if (!section
|| !name
|| !value
) {
283 if (strcmp(args
->section
, section
)) {
288 ret
= args
->handler(&entry
, args
->user_data
);
294 int config_get_section_entries(const char *override_path
, const char *section
,
295 config_entry_handler_cb handler
, void *user_data
)
299 FILE *config_file
= NULL
;
300 struct handler_filter_args filter
= { section
, handler
, user_data
};
302 /* First, try system-wide conf. file. */
303 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
305 config_file
= fopen(path
, "r");
307 DBG("Loading daemon conf file at %s", path
);
309 * Return value is not very important here since error or not, we
310 * continue and try the next possible conf. file.
312 (void) ini_parse_file(config_file
,
313 (ini_entry_handler
) config_entry_handler_filter
,
318 /* Second is the user local configuration. */
319 path
= utils_get_home_dir();
321 char fullpath
[PATH_MAX
];
323 ret
= snprintf(fullpath
, sizeof(fullpath
),
324 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
326 PERROR("snprintf user conf. path");
330 config_file
= fopen(fullpath
, "r");
332 DBG("Loading daemon user conf file at %s", path
);
334 * Return value is not very important here since error or not, we
335 * continue and try the next possible conf. file.
337 (void) ini_parse_file(config_file
,
338 (ini_entry_handler
) config_entry_handler_filter
,
344 /* Final path is the one that the user might have provided. */
346 config_file
= fopen(override_path
, "r");
348 DBG("Loading daemon command line conf file at %s", override_path
);
349 (void) ini_parse_file(config_file
,
350 (ini_entry_handler
) config_entry_handler_filter
,
354 ERR("Failed to open daemon configuration file at %s",
361 /* Everything went well. */
369 int config_parse_value(const char *value
)
372 char *endptr
, *lower_str
;
382 v
= strtoul(value
, &endptr
, 10);
383 if (endptr
!= value
) {
388 lower_str
= zmalloc(len
+ 1);
395 for (i
= 0; i
< len
; i
++) {
396 lower_str
[i
] = tolower(value
[i
]);
399 if (!strcmp(lower_str
, config_str_yes
) ||
400 !strcmp(lower_str
, config_str_true
) ||
401 !strcmp(lower_str
, config_str_on
)) {
403 } else if (!strcmp(lower_str
, config_str_no
) ||
404 !strcmp(lower_str
, config_str_false
) ||
405 !strcmp(lower_str
, config_str_off
)) {
417 * Returns a xmlChar string which must be released using xmlFree().
419 static xmlChar
*encode_string(const char *in_str
)
421 xmlChar
*out_str
= NULL
;
422 xmlCharEncodingHandlerPtr handler
;
423 int out_len
, ret
, in_len
;
427 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
429 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
433 in_len
= strlen(in_str
);
435 * Add 1 byte for the NULL terminted character. The factor 4 here is
436 * used because UTF-8 characters can take up to 4 bytes.
438 out_len
= (in_len
* 4) + 1;
439 out_str
= xmlMalloc(out_len
);
444 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
451 /* out_len is now the size of out_str */
452 out_str
[out_len
] = '\0';
458 struct config_writer
*config_writer_create(int fd_output
, int indent
)
461 struct config_writer
*writer
;
462 xmlOutputBufferPtr buffer
;
464 writer
= zmalloc(sizeof(struct config_writer
));
466 PERROR("zmalloc config_writer_create");
470 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
475 writer
->writer
= xmlNewTextWriter(buffer
);
476 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
477 config_xml_encoding
, NULL
);
482 ret
= xmlTextWriterSetIndentString(writer
->writer
,
483 BAD_CAST config_xml_indent_string
);
488 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
496 config_writer_destroy(writer
);
501 int config_writer_destroy(struct config_writer
*writer
)
510 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
511 WARN("Could not close XML document");
515 if (writer
->writer
) {
516 xmlFreeTextWriter(writer
->writer
);
525 int config_writer_open_element(struct config_writer
*writer
,
526 const char *element_name
)
529 xmlChar
*encoded_element_name
;
531 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
536 encoded_element_name
= encode_string(element_name
);
537 if (!encoded_element_name
) {
542 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
543 xmlFree(encoded_element_name
);
545 return ret
>= 0 ? 0 : ret
;
549 int config_writer_write_attribute(struct config_writer
*writer
,
550 const char *name
, const char *value
)
553 xmlChar
*encoded_name
= NULL
;
554 xmlChar
*encoded_value
= NULL
;
556 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
561 encoded_name
= encode_string(name
);
567 encoded_value
= encode_string(value
);
568 if (!encoded_value
) {
573 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
576 xmlFree(encoded_name
);
577 xmlFree(encoded_value
);
578 return ret
>= 0 ? 0 : ret
;
582 int config_writer_close_element(struct config_writer
*writer
)
586 if (!writer
|| !writer
->writer
) {
591 ret
= xmlTextWriterEndElement(writer
->writer
);
593 return ret
>= 0 ? 0 : ret
;
597 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
598 const char *element_name
, uint64_t value
)
601 xmlChar
*encoded_element_name
;
603 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
608 encoded_element_name
= encode_string(element_name
);
609 if (!encoded_element_name
) {
614 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
615 encoded_element_name
, "%" PRIu64
, value
);
616 xmlFree(encoded_element_name
);
618 return ret
>= 0 ? 0 : ret
;
622 int config_writer_write_element_signed_int(struct config_writer
*writer
,
623 const char *element_name
, int64_t value
)
626 xmlChar
*encoded_element_name
;
628 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
633 encoded_element_name
= encode_string(element_name
);
634 if (!encoded_element_name
) {
639 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
640 encoded_element_name
, "%" PRIi64
, value
);
641 xmlFree(encoded_element_name
);
643 return ret
>= 0 ? 0 : ret
;
647 int config_writer_write_element_bool(struct config_writer
*writer
,
648 const char *element_name
, int value
)
650 return config_writer_write_element_string(writer
, element_name
,
651 value
? config_xml_true
: config_xml_false
);
655 int config_writer_write_element_string(struct config_writer
*writer
,
656 const char *element_name
, const char *value
)
659 xmlChar
*encoded_element_name
= NULL
;
660 xmlChar
*encoded_value
= NULL
;
662 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
668 encoded_element_name
= encode_string(element_name
);
669 if (!encoded_element_name
) {
674 encoded_value
= encode_string(value
);
675 if (!encoded_value
) {
680 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
683 xmlFree(encoded_element_name
);
684 xmlFree(encoded_value
);
685 return ret
>= 0 ? 0 : ret
;
689 void xml_error_handler(void *ctx
, const char *format
, ...)
695 va_start(args
, format
);
696 ret
= vasprintf(&errMsg
, format
, args
);
699 ERR("String allocation failed in xml error handler");
703 fprintf(stderr
, "XML Error: %s", errMsg
);
708 void fini_session_config_validation_ctx(
709 struct session_config_validation_ctx
*ctx
)
711 if (ctx
->parser_ctx
) {
712 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
716 xmlSchemaFree(ctx
->schema
);
719 if (ctx
->schema_validation_ctx
) {
720 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
723 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
727 char *get_session_config_xsd_path(void)
730 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
731 size_t base_path_len
;
735 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
738 base_path_len
= strlen(base_path
);
739 max_path_len
= base_path_len
+
740 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
741 xsd_path
= zmalloc(max_path_len
);
746 strcpy(xsd_path
, base_path
);
747 if (xsd_path
[base_path_len
- 1] != '/') {
748 xsd_path
[base_path_len
++] = '/';
751 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
757 int init_session_config_validation_ctx(
758 struct session_config_validation_ctx
*ctx
)
761 char *xsd_path
= get_session_config_xsd_path();
764 ret
= -LTTNG_ERR_NOMEM
;
768 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
769 if (!ctx
->parser_ctx
) {
770 ERR("XSD parser context creation failed");
771 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
774 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
775 xml_error_handler
, NULL
);
777 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
779 ERR("XSD parsing failed");
780 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
784 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
785 if (!ctx
->schema_validation_ctx
) {
786 ERR("XSD validation context creation failed");
787 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
791 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
792 xml_error_handler
, NULL
);
797 fini_session_config_validation_ctx(ctx
);
805 int parse_uint(xmlChar
*str
, uint64_t *val
)
815 *val
= strtoull((const char *) str
, &endptr
, 10);
816 if (!endptr
|| *endptr
) {
827 int parse_int(xmlChar
*str
, int64_t *val
)
837 *val
= strtoll((const char *) str
, &endptr
, 10);
838 if (!endptr
|| *endptr
) {
849 int parse_bool(xmlChar
*str
, int *val
)
858 if (!strcmp((const char *) str
, config_xml_true
)) {
860 } else if (!strcmp((const char *) str
, config_xml_false
)) {
863 WARN("Invalid boolean value encoutered (%s).",
872 int get_domain_type(xmlChar
*domain
)
880 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
881 ret
= LTTNG_DOMAIN_KERNEL
;
882 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
883 ret
= LTTNG_DOMAIN_UST
;
884 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
885 ret
= LTTNG_DOMAIN_JUL
;
886 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
887 ret
= LTTNG_DOMAIN_LOG4J
;
888 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
889 ret
= LTTNG_DOMAIN_PYTHON
;
900 int get_buffer_type(xmlChar
*buffer_type
)
908 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
909 ret
= LTTNG_BUFFER_GLOBAL
;
910 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
911 ret
= LTTNG_BUFFER_PER_UID
;
912 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
913 ret
= LTTNG_BUFFER_PER_PID
;
924 int get_overwrite_mode(xmlChar
*overwrite_mode
)
928 if (!overwrite_mode
) {
932 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
934 } else if (!strcmp((char *) overwrite_mode
,
935 config_overwrite_mode_discard
)) {
947 int get_output_type(xmlChar
*output_type
)
955 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
956 ret
= LTTNG_EVENT_MMAP
;
957 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
958 ret
= LTTNG_EVENT_SPLICE
;
969 int get_event_type(xmlChar
*event_type
)
977 if (!strcmp((char *) event_type
, config_event_type_all
)) {
978 ret
= LTTNG_EVENT_ALL
;
979 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
980 ret
= LTTNG_EVENT_TRACEPOINT
;
981 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
982 ret
= LTTNG_EVENT_PROBE
;
983 } else if (!strcmp((char *) event_type
,
984 config_event_type_userspace_probe
)) {
985 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
986 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
987 ret
= LTTNG_EVENT_FUNCTION
;
988 } else if (!strcmp((char *) event_type
,
989 config_event_type_function_entry
)) {
990 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
991 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
992 ret
= LTTNG_EVENT_NOOP
;
993 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
994 ret
= LTTNG_EVENT_SYSCALL
;
1005 int get_loglevel_type(xmlChar
*loglevel_type
)
1009 if (!loglevel_type
) {
1013 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1014 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1015 } else if (!strcmp((char *) loglevel_type
,
1016 config_loglevel_type_range
)) {
1017 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1018 } else if (!strcmp((char *) loglevel_type
,
1019 config_loglevel_type_single
)) {
1020 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1031 * Return the context type or -1 on error.
1034 int get_context_type(xmlChar
*context_type
)
1038 if (!context_type
) {
1042 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1043 ret
= LTTNG_EVENT_CONTEXT_PID
;
1044 } else if (!strcmp((char *) context_type
,
1045 config_event_context_procname
)) {
1046 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1047 } else if (!strcmp((char *) context_type
,
1048 config_event_context_prio
)) {
1049 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1050 } else if (!strcmp((char *) context_type
,
1051 config_event_context_nice
)) {
1052 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1053 } else if (!strcmp((char *) context_type
,
1054 config_event_context_vpid
)) {
1055 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1056 } else if (!strcmp((char *) context_type
,
1057 config_event_context_tid
)) {
1058 ret
= LTTNG_EVENT_CONTEXT_TID
;
1059 } else if (!strcmp((char *) context_type
,
1060 config_event_context_vtid
)) {
1061 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1062 } else if (!strcmp((char *) context_type
,
1063 config_event_context_ppid
)) {
1064 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1065 } else if (!strcmp((char *) context_type
,
1066 config_event_context_vppid
)) {
1067 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1068 } else if (!strcmp((char *) context_type
,
1069 config_event_context_pthread_id
)) {
1070 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1071 } else if (!strcmp((char *) context_type
,
1072 config_event_context_hostname
)) {
1073 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1074 } else if (!strcmp((char *) context_type
,
1075 config_event_context_ip
)) {
1076 ret
= LTTNG_EVENT_CONTEXT_IP
;
1077 } else if (!strcmp((char *) context_type
,
1078 config_event_context_interruptible
)) {
1079 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1080 } else if (!strcmp((char *) context_type
,
1081 config_event_context_preemptible
)) {
1082 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1083 } else if (!strcmp((char *) context_type
,
1084 config_event_context_need_reschedule
)) {
1085 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1086 } else if (!strcmp((char *) context_type
,
1087 config_event_context_migratable
)) {
1088 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1089 } else if (!strcmp((char *) context_type
,
1090 config_event_context_callstack_user
)) {
1091 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1092 } else if (!strcmp((char *) context_type
,
1093 config_event_context_callstack_kernel
)) {
1094 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1095 } else if (!strcmp((char *) context_type
,
1096 config_event_context_cgroup_ns
)) {
1097 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1098 } else if (!strcmp((char *) context_type
,
1099 config_event_context_ipc_ns
)) {
1100 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1101 } else if (!strcmp((char *) context_type
,
1102 config_event_context_mnt_ns
)) {
1103 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1104 } else if (!strcmp((char *) context_type
,
1105 config_event_context_net_ns
)) {
1106 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1107 } else if (!strcmp((char *) context_type
,
1108 config_event_context_pid_ns
)) {
1109 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1110 } else if (!strcmp((char *) context_type
,
1111 config_event_context_time_ns
)) {
1112 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1113 } else if (!strcmp((char *) context_type
,
1114 config_event_context_user_ns
)) {
1115 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1116 } else if (!strcmp((char *) context_type
,
1117 config_event_context_uts_ns
)) {
1118 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1119 } else if (!strcmp((char *) context_type
,
1120 config_event_context_uid
)) {
1121 ret
= LTTNG_EVENT_CONTEXT_UID
;
1122 } else if (!strcmp((char *) context_type
,
1123 config_event_context_euid
)) {
1124 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1125 } else if (!strcmp((char *) context_type
,
1126 config_event_context_suid
)) {
1127 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1128 } else if (!strcmp((char *) context_type
,
1129 config_event_context_gid
)) {
1130 ret
= LTTNG_EVENT_CONTEXT_GID
;
1131 } else if (!strcmp((char *) context_type
,
1132 config_event_context_egid
)) {
1133 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1134 } else if (!strcmp((char *) context_type
,
1135 config_event_context_sgid
)) {
1136 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1137 } else if (!strcmp((char *) context_type
,
1138 config_event_context_vuid
)) {
1139 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1140 } else if (!strcmp((char *) context_type
,
1141 config_event_context_veuid
)) {
1142 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1143 } else if (!strcmp((char *) context_type
,
1144 config_event_context_vsuid
)) {
1145 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1146 } else if (!strcmp((char *) context_type
,
1147 config_event_context_vgid
)) {
1148 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1149 } else if (!strcmp((char *) context_type
,
1150 config_event_context_vegid
)) {
1151 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1152 } else if (!strcmp((char *) context_type
,
1153 config_event_context_vsgid
)) {
1154 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1165 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1170 for (node
= xmlFirstElementChild(domain_node
); node
;
1171 node
= xmlNextElementSibling(node
)) {
1172 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1174 xmlChar
*node_content
= xmlNodeGetContent(node
);
1175 if (!node_content
) {
1176 ret
= -LTTNG_ERR_NOMEM
;
1180 ret
= get_domain_type(node_content
);
1183 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1188 } else if (!strcmp((const char *) node
->name
,
1189 config_element_buffer_type
)) {
1191 xmlChar
*node_content
= xmlNodeGetContent(node
);
1192 if (!node_content
) {
1193 ret
= -LTTNG_ERR_NOMEM
;
1197 ret
= get_buffer_type(node_content
);
1200 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1204 domain
->buf_type
= ret
;
1213 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1218 for (node
= xmlFirstElementChild(net_output_node
); node
;
1219 node
= xmlNextElementSibling(node
)) {
1220 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1222 *control_uri
= (char *) xmlNodeGetContent(node
);
1223 if (!*control_uri
) {
1228 *data_uri
= (char *) xmlNodeGetContent(node
);
1235 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1239 int process_consumer_output(xmlNodePtr consumer_output_node
,
1240 struct consumer_output
*output
)
1247 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1248 node
= xmlNextElementSibling(node
)) {
1249 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1250 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1254 ret
= -LTTNG_ERR_NOMEM
;
1258 ret
= parse_bool(enabled_str
, &output
->enabled
);
1264 xmlNodePtr output_type_node
;
1267 output_type_node
= xmlFirstElementChild(node
);
1268 if (!output_type_node
) {
1269 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1273 if (!strcmp((const char *) output_type_node
->name
,
1274 config_element_path
)) {
1276 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1277 if (!output
->path
) {
1278 ret
= -LTTNG_ERR_NOMEM
;
1283 ret
= get_net_output_uris(output_type_node
,
1284 &output
->control_uri
, &output
->data_uri
);
1296 free(output
->control_uri
);
1297 free(output
->data_uri
);
1298 memset(output
, 0, sizeof(struct consumer_output
));
1304 int create_session_net_output(const char *name
, const char *control_uri
,
1305 const char *data_uri
)
1308 struct lttng_handle
*handle
;
1309 const char *uri
= NULL
;
1313 handle
= lttng_create_handle(name
, NULL
);
1315 ret
= -LTTNG_ERR_NOMEM
;
1319 if (!control_uri
|| !data_uri
) {
1320 uri
= control_uri
? control_uri
: data_uri
;
1325 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1326 lttng_destroy_handle(handle
);
1332 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1333 const struct config_load_session_override_attr
*overrides
)
1336 xmlNodePtr node
= NULL
;
1337 xmlNodePtr snapshot_output_list_node
;
1338 xmlNodePtr snapshot_output_node
;
1340 assert(session_name
);
1342 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1351 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1353 /* Parse and create snapshot outputs */
1355 for (snapshot_output_node
=
1356 xmlFirstElementChild(snapshot_output_list_node
);
1357 snapshot_output_node
; snapshot_output_node
=
1358 xmlNextElementSibling(snapshot_output_node
)) {
1360 uint64_t max_size
= UINT64_MAX
;
1361 struct consumer_output output
= { 0 };
1362 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1363 const char *control_uri
= NULL
;
1364 const char *data_uri
= NULL
;
1365 const char *path
= NULL
;
1367 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1368 node
= xmlNextElementSibling(node
)) {
1369 if (!strcmp((const char *) node
->name
,
1370 config_element_name
)) {
1372 name
= (char *) xmlNodeGetContent(node
);
1374 ret
= -LTTNG_ERR_NOMEM
;
1375 goto error_snapshot_output
;
1377 } else if (!strcmp((const char *) node
->name
,
1378 config_element_max_size
)) {
1379 xmlChar
*content
= xmlNodeGetContent(node
);
1383 ret
= -LTTNG_ERR_NOMEM
;
1384 goto error_snapshot_output
;
1386 ret
= parse_uint(content
, &max_size
);
1389 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1390 goto error_snapshot_output
;
1393 /* consumer_output */
1394 ret
= process_consumer_output(node
, &output
);
1396 goto error_snapshot_output
;
1401 control_uri
= output
.control_uri
;
1402 data_uri
= output
.data_uri
;
1406 if (overrides
->path_url
) {
1407 path
= overrides
->path_url
;
1408 /* Control/data_uri are null */
1412 if (overrides
->ctrl_url
) {
1413 control_uri
= overrides
->ctrl_url
;
1417 if (overrides
->data_url
) {
1418 data_uri
= overrides
->data_url
;
1425 snapshot_output
= lttng_snapshot_output_create();
1426 if (!snapshot_output
) {
1427 ret
= -LTTNG_ERR_NOMEM
;
1428 goto error_snapshot_output
;
1431 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1433 goto error_snapshot_output
;
1436 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1438 goto error_snapshot_output
;
1442 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1445 goto error_snapshot_output
;
1449 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1452 goto error_snapshot_output
;
1457 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1460 goto error_snapshot_output
;
1465 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1466 error_snapshot_output
:
1469 free(output
.control_uri
);
1470 free(output
.data_uri
);
1471 lttng_snapshot_output_destroy(snapshot_output
);
1481 int create_session(const char *name
,
1482 xmlNodePtr output_node
,
1483 uint64_t live_timer_interval
,
1484 const struct config_load_session_override_attr
*overrides
)
1487 struct consumer_output output
= { 0 };
1488 xmlNodePtr consumer_output_node
;
1489 const char *control_uri
= NULL
;
1490 const char *data_uri
= NULL
;
1491 const char *path
= NULL
;
1496 consumer_output_node
= xmlFirstElementChild(output_node
);
1497 if (!consumer_output_node
) {
1498 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1502 if (strcmp((const char *) consumer_output_node
->name
,
1503 config_element_consumer_output
)) {
1504 WARN("Invalid output type, expected %s node",
1505 config_element_consumer_output
);
1506 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1510 ret
= process_consumer_output(consumer_output_node
, &output
);
1516 control_uri
= output
.control_uri
;
1517 data_uri
= output
.data_uri
;
1520 /* Check for override and apply them */
1522 if (overrides
->path_url
) {
1523 path
= overrides
->path_url
;
1524 /* control/data_uri are null */;
1528 if (overrides
->ctrl_url
) {
1529 control_uri
= overrides
->ctrl_url
;
1533 if (overrides
->data_url
) {
1534 data_uri
= overrides
->data_url
;
1542 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1543 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1547 if (control_uri
|| data_uri
) {
1548 /* network destination */
1549 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1551 * URLs are provided for sure since the test above make sure that
1552 * with a live timer the data and control URIs are provided. So,
1553 * NULL is passed here and will be set right after.
1555 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1557 ret
= lttng_create_session(name
, NULL
);
1563 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1569 /* either local output or no output */
1570 ret
= lttng_create_session(name
, path
);
1577 free(output
.control_uri
);
1578 free(output
.data_uri
);
1583 struct lttng_userspace_probe_location
*
1584 process_userspace_probe_function_attribute_node(
1585 xmlNodePtr attribute_node
)
1587 xmlNodePtr function_attribute_node
;
1588 char *function_name
= NULL
, *binary_path
= NULL
;
1589 struct lttng_userspace_probe_location
*location
= NULL
;
1590 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1593 * Process userspace probe location function attributes. The order of
1594 * the fields are not guaranteed so we need to iterate over all fields
1595 * and check at the end if everything we need for this location type is
1598 for (function_attribute_node
=
1599 xmlFirstElementChild(attribute_node
);
1600 function_attribute_node
;
1601 function_attribute_node
= xmlNextElementSibling(
1602 function_attribute_node
)) {
1603 /* Handle function name, binary path and lookup method. */
1604 if (!strcmp((const char *) function_attribute_node
->name
,
1605 config_element_userspace_probe_function_location_function_name
)) {
1606 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1607 if (!function_name
) {
1610 } else if (!strcmp((const char *) function_attribute_node
->name
,
1611 config_element_userspace_probe_location_binary_path
)) {
1612 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1616 } else if (!strcmp((const char *) function_attribute_node
->name
,
1617 config_element_userspace_probe_lookup
)) {
1618 char *lookup_method_name
;
1620 lookup_method_name
= (char *) xmlNodeGetContent(
1621 function_attribute_node
);
1622 if (!lookup_method_name
) {
1627 * function_default lookup method defaults to
1628 * function_elf lookup method at the moment.
1630 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1631 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1632 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1633 if (!lookup_method
) {
1634 PERROR("Error creating function default/ELF lookup method");
1637 WARN("Unknown function lookup method");
1640 free(lookup_method_name
);
1641 if (!lookup_method
) {
1648 /* Check if all the necessary fields were found. */
1649 if (binary_path
&& function_name
&& lookup_method
) {
1650 /* Ownership of lookup_method is transferred. */
1652 lttng_userspace_probe_location_function_create(
1653 binary_path
, function_name
,
1655 lookup_method
= NULL
;
1660 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1662 free(function_name
);
1667 struct lttng_userspace_probe_location
*
1668 process_userspace_probe_tracepoint_attribute_node(
1669 xmlNodePtr attribute_node
)
1671 xmlNodePtr tracepoint_attribute_node
;
1672 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1673 struct lttng_userspace_probe_location
*location
= NULL
;
1674 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1677 * Process userspace probe location tracepoint attributes. The order of
1678 * the fields are not guaranteed so we need to iterate over all fields
1679 * and check at the end if everything we need for this location type is
1682 for (tracepoint_attribute_node
=
1683 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1684 tracepoint_attribute_node
= xmlNextElementSibling(
1685 tracepoint_attribute_node
)) {
1686 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1687 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1688 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1692 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1693 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1694 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1695 if (!provider_name
) {
1698 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1699 config_element_userspace_probe_location_binary_path
)) {
1700 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1704 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1705 config_element_userspace_probe_lookup
)) {
1706 char *lookup_method_name
;
1708 lookup_method_name
= (char *) xmlNodeGetContent(
1709 tracepoint_attribute_node
);
1710 if (!lookup_method_name
) {
1714 if (!strcmp(lookup_method_name
,
1715 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1717 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1718 if (!lookup_method
) {
1719 PERROR("Error creating tracepoint SDT lookup method");
1722 WARN("Unknown tracepoint lookup method");
1725 free(lookup_method_name
);
1726 if (!lookup_method
) {
1730 WARN("Unknown tracepoint attribute");
1734 /* Check if all the necessary fields were found. */
1735 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1736 /* Ownership of lookup_method is transferred. */
1738 lttng_userspace_probe_location_tracepoint_create(
1739 binary_path
, provider_name
,
1740 probe_name
, lookup_method
);
1741 lookup_method
= NULL
;
1746 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1748 free(provider_name
);
1754 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1755 struct lttng_event_probe_attr
*attr
)
1759 assert(probe_attribute_node
);
1762 if (!strcmp((const char *) probe_attribute_node
->name
,
1763 config_element_address
)) {
1768 content
= xmlNodeGetContent(probe_attribute_node
);
1770 ret
= -LTTNG_ERR_NOMEM
;
1774 ret
= parse_uint(content
, &addr
);
1777 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1782 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1783 config_element_offset
)) {
1785 uint64_t offset
= 0;
1788 content
= xmlNodeGetContent(probe_attribute_node
);
1790 ret
= -LTTNG_ERR_NOMEM
;
1794 ret
= parse_uint(content
, &offset
);
1797 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1801 attr
->offset
= offset
;
1802 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1803 config_element_symbol_name
)) {
1807 content
= xmlNodeGetContent(probe_attribute_node
);
1809 ret
= -LTTNG_ERR_NOMEM
;
1813 ret
= lttng_strncpy(attr
->symbol_name
,
1814 (const char *) content
,
1815 LTTNG_SYMBOL_NAME_LEN
);
1817 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1818 (const char *) content
,
1819 strlen((const char *) content
),
1820 LTTNG_SYMBOL_NAME_LEN
);
1821 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1833 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1834 const char *channel_name
, const enum process_event_node_phase phase
)
1838 struct lttng_event
*event
;
1839 char **exclusions
= NULL
;
1840 unsigned long exclusion_count
= 0;
1841 char *filter_expression
= NULL
;
1845 assert(channel_name
);
1847 event
= lttng_event_create();
1849 ret
= -LTTNG_ERR_NOMEM
;
1853 /* Initialize default log level which varies by domain */
1854 switch (handle
->domain
.type
)
1856 case LTTNG_DOMAIN_JUL
:
1857 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1859 case LTTNG_DOMAIN_LOG4J
:
1860 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1862 case LTTNG_DOMAIN_PYTHON
:
1863 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1865 case LTTNG_DOMAIN_UST
:
1866 case LTTNG_DOMAIN_KERNEL
:
1867 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1873 for (node
= xmlFirstElementChild(event_node
); node
;
1874 node
= xmlNextElementSibling(node
)) {
1875 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1879 content
= xmlNodeGetContent(node
);
1881 ret
= -LTTNG_ERR_NOMEM
;
1885 ret
= lttng_strncpy(event
->name
,
1886 (const char *) content
,
1887 LTTNG_SYMBOL_NAME_LEN
);
1889 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1890 (const char *) content
,
1891 strlen((const char *) content
),
1892 LTTNG_SYMBOL_NAME_LEN
);
1893 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1898 } else if (!strcmp((const char *) node
->name
,
1899 config_element_enabled
)) {
1900 xmlChar
*content
= xmlNodeGetContent(node
);
1904 ret
= -LTTNG_ERR_NOMEM
;
1908 ret
= parse_bool(content
, &event
->enabled
);
1911 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1914 } else if (!strcmp((const char *) node
->name
,
1915 config_element_type
)) {
1916 xmlChar
*content
= xmlNodeGetContent(node
);
1920 ret
= -LTTNG_ERR_NOMEM
;
1924 ret
= get_event_type(content
);
1927 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1932 } else if (!strcmp((const char *) node
->name
,
1933 config_element_loglevel_type
)) {
1934 xmlChar
*content
= xmlNodeGetContent(node
);
1938 ret
= -LTTNG_ERR_NOMEM
;
1942 ret
= get_loglevel_type(content
);
1945 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1949 event
->loglevel_type
= ret
;
1950 } else if (!strcmp((const char *) node
->name
,
1951 config_element_loglevel
)) {
1953 int64_t loglevel
= 0;
1956 content
= xmlNodeGetContent(node
);
1958 ret
= -LTTNG_ERR_NOMEM
;
1962 ret
= parse_int(content
, &loglevel
);
1965 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1969 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1970 WARN("loglevel out of range.");
1971 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1975 event
->loglevel
= loglevel
;
1976 } else if (!strcmp((const char *) node
->name
,
1977 config_element_filter
)) {
1979 xmlNodeGetContent(node
);
1983 ret
= -LTTNG_ERR_NOMEM
;
1987 free(filter_expression
);
1988 filter_expression
= strdup((char *) content
);
1990 if (!filter_expression
) {
1991 ret
= -LTTNG_ERR_NOMEM
;
1994 } else if (!strcmp((const char *) node
->name
,
1995 config_element_exclusions
)) {
1996 xmlNodePtr exclusion_node
;
1997 int exclusion_index
= 0;
2002 * Exclusions has already been initialized,
2005 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2009 exclusion_count
= xmlChildElementCount(node
);
2010 if (!exclusion_count
) {
2014 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2016 exclusion_count
= 0;
2017 ret
= -LTTNG_ERR_NOMEM
;
2021 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2022 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2024 xmlNodeGetContent(exclusion_node
);
2027 ret
= -LTTNG_ERR_NOMEM
;
2031 exclusions
[exclusion_index
] = strdup((const char *) content
);
2033 if (!exclusions
[exclusion_index
]) {
2034 ret
= -LTTNG_ERR_NOMEM
;
2040 event
->exclusion
= 1;
2041 } else if (!strcmp((const char *) node
->name
,
2042 config_element_attributes
)) {
2043 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2046 if (!attribute_node
) {
2047 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2051 if (!strcmp((const char *) attribute_node
->name
,
2052 config_element_probe_attributes
)) {
2053 xmlNodePtr probe_attribute_node
;
2055 /* probe_attributes */
2056 for (probe_attribute_node
=
2057 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2058 probe_attribute_node
= xmlNextElementSibling(
2059 probe_attribute_node
)) {
2061 ret
= process_probe_attribute_node(probe_attribute_node
,
2062 &event
->attr
.probe
);
2067 } else if (!strcmp((const char *) attribute_node
->name
,
2068 config_element_function_attributes
)) {
2071 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2073 /* function_attributes */
2074 content
= xmlNodeGetContent(symbol_node
);
2076 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2080 sym_len
= strlen((char *) content
);
2081 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2082 WARN("Function name too long.");
2083 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2088 ret
= lttng_strncpy(
2089 event
->attr
.ftrace
.symbol_name
,
2090 (char *) content
, sym_len
);
2092 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2097 } else if (!strcmp((const char *) attribute_node
->name
,
2098 config_element_userspace_probe_tracepoint_attributes
)) {
2099 struct lttng_userspace_probe_location
*location
;
2101 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2103 WARN("Error processing userspace probe tracepoint attribute");
2104 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2107 ret
= lttng_event_set_userspace_probe_location(
2110 WARN("Error setting userspace probe location field");
2111 lttng_userspace_probe_location_destroy(
2113 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2116 } else if (!strcmp((const char *) attribute_node
->name
,
2117 config_element_userspace_probe_function_attributes
)) {
2118 struct lttng_userspace_probe_location
*location
;
2121 process_userspace_probe_function_attribute_node(
2124 WARN("Error processing userspace probe function attribute");
2125 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2129 ret
= lttng_event_set_userspace_probe_location(
2132 WARN("Error setting userspace probe location field");
2133 lttng_userspace_probe_location_destroy(
2135 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2139 /* Unknown event attribute. */
2140 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2146 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2147 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2148 filter_expression
, exclusion_count
, exclusions
);
2150 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2151 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2157 for (i
= 0; i
< exclusion_count
; i
++) {
2158 free(exclusions
[i
]);
2161 lttng_event_destroy(event
);
2163 free(filter_expression
);
2168 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2169 const char *channel_name
)
2172 struct lttng_event event
;
2175 assert(events_node
);
2177 assert(channel_name
);
2179 for (node
= xmlFirstElementChild(events_node
); node
;
2180 node
= xmlNextElementSibling(node
)) {
2181 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2188 * Disable all events to enable only the necessary events.
2189 * Limitations regarding lttng_disable_events and tuple descriptor
2190 * force this approach.
2192 memset(&event
, 0, sizeof(event
));
2193 event
.loglevel
= -1;
2194 event
.type
= LTTNG_EVENT_ALL
;
2195 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2200 for (node
= xmlFirstElementChild(events_node
); node
;
2201 node
= xmlNextElementSibling(node
)) {
2202 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2213 int process_channel_attr_node(xmlNodePtr attr_node
,
2214 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2215 xmlNodePtr
*events_node
)
2221 assert(contexts_node
);
2222 assert(events_node
);
2224 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2228 content
= xmlNodeGetContent(attr_node
);
2230 ret
= -LTTNG_ERR_NOMEM
;
2234 ret
= lttng_strncpy(channel
->name
,
2235 (const char *) content
,
2236 LTTNG_SYMBOL_NAME_LEN
);
2238 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2239 (const char *) content
,
2240 strlen((const char *) content
),
2241 LTTNG_SYMBOL_NAME_LEN
);
2242 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2247 } else if (!strcmp((const char *) attr_node
->name
,
2248 config_element_enabled
)) {
2253 content
= xmlNodeGetContent(attr_node
);
2255 ret
= -LTTNG_ERR_NOMEM
;
2259 ret
= parse_bool(content
, &enabled
);
2262 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2266 channel
->enabled
= enabled
;
2267 } else if (!strcmp((const char *) attr_node
->name
,
2268 config_element_overwrite_mode
)) {
2271 /* overwrite_mode */
2272 content
= xmlNodeGetContent(attr_node
);
2274 ret
= -LTTNG_ERR_NOMEM
;
2278 ret
= get_overwrite_mode(content
);
2281 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2285 channel
->attr
.overwrite
= ret
;
2286 } else if (!strcmp((const char *) attr_node
->name
,
2287 config_element_subbuf_size
)) {
2290 /* subbuffer_size */
2291 content
= xmlNodeGetContent(attr_node
);
2293 ret
= -LTTNG_ERR_NOMEM
;
2297 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2300 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2303 } else if (!strcmp((const char *) attr_node
->name
,
2304 config_element_num_subbuf
)) {
2307 /* subbuffer_count */
2308 content
= xmlNodeGetContent(attr_node
);
2310 ret
= -LTTNG_ERR_NOMEM
;
2314 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2317 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2320 } else if (!strcmp((const char *) attr_node
->name
,
2321 config_element_switch_timer_interval
)) {
2323 uint64_t switch_timer_interval
= 0;
2325 /* switch_timer_interval */
2326 content
= xmlNodeGetContent(attr_node
);
2328 ret
= -LTTNG_ERR_NOMEM
;
2332 ret
= parse_uint(content
, &switch_timer_interval
);
2335 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2339 if (switch_timer_interval
> UINT_MAX
) {
2340 WARN("switch_timer_interval out of range.");
2341 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2345 channel
->attr
.switch_timer_interval
=
2346 switch_timer_interval
;
2347 } else if (!strcmp((const char *) attr_node
->name
,
2348 config_element_read_timer_interval
)) {
2350 uint64_t read_timer_interval
= 0;
2352 /* read_timer_interval */
2353 content
= xmlNodeGetContent(attr_node
);
2355 ret
= -LTTNG_ERR_NOMEM
;
2359 ret
= parse_uint(content
, &read_timer_interval
);
2362 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2366 if (read_timer_interval
> UINT_MAX
) {
2367 WARN("read_timer_interval out of range.");
2368 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2372 channel
->attr
.read_timer_interval
=
2373 read_timer_interval
;
2374 } else if (!strcmp((const char *) attr_node
->name
,
2375 config_element_output_type
)) {
2379 content
= xmlNodeGetContent(attr_node
);
2381 ret
= -LTTNG_ERR_NOMEM
;
2385 ret
= get_output_type(content
);
2388 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2392 channel
->attr
.output
= ret
;
2393 } else if (!strcmp((const char *) attr_node
->name
,
2394 config_element_tracefile_size
)) {
2397 /* tracefile_size */
2398 content
= xmlNodeGetContent(attr_node
);
2400 ret
= -LTTNG_ERR_NOMEM
;
2404 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2407 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2410 } else if (!strcmp((const char *) attr_node
->name
,
2411 config_element_tracefile_count
)) {
2414 /* tracefile_count */
2415 content
= xmlNodeGetContent(attr_node
);
2417 ret
= -LTTNG_ERR_NOMEM
;
2421 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2424 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2427 } else if (!strcmp((const char *) attr_node
->name
,
2428 config_element_live_timer_interval
)) {
2430 uint64_t live_timer_interval
= 0;
2432 /* live_timer_interval */
2433 content
= xmlNodeGetContent(attr_node
);
2435 ret
= -LTTNG_ERR_NOMEM
;
2439 ret
= parse_uint(content
, &live_timer_interval
);
2442 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2446 if (live_timer_interval
> UINT_MAX
) {
2447 WARN("live_timer_interval out of range.");
2448 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2452 channel
->attr
.live_timer_interval
=
2453 live_timer_interval
;
2454 } else if (!strcmp((const char *) attr_node
->name
,
2455 config_element_monitor_timer_interval
)) {
2457 uint64_t monitor_timer_interval
= 0;
2459 /* monitor_timer_interval */
2460 content
= xmlNodeGetContent(attr_node
);
2462 ret
= -LTTNG_ERR_NOMEM
;
2466 ret
= parse_uint(content
, &monitor_timer_interval
);
2469 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2473 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2474 monitor_timer_interval
);
2476 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2479 } else if (!strcmp((const char *) attr_node
->name
,
2480 config_element_blocking_timeout
)) {
2482 int64_t blocking_timeout
= 0;
2484 /* blocking_timeout */
2485 content
= xmlNodeGetContent(attr_node
);
2487 ret
= -LTTNG_ERR_NOMEM
;
2491 ret
= parse_int(content
, &blocking_timeout
);
2494 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2498 ret
= lttng_channel_set_blocking_timeout(channel
,
2501 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2504 } else if (!strcmp((const char *) attr_node
->name
,
2505 config_element_events
)) {
2507 *events_node
= attr_node
;
2510 *contexts_node
= attr_node
;
2518 int process_context_node(xmlNodePtr context_node
,
2519 struct lttng_handle
*handle
, const char *channel_name
)
2522 struct lttng_event_context context
;
2523 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2526 assert(channel_name
);
2528 if (!context_child_node
) {
2529 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2533 memset(&context
, 0, sizeof(context
));
2535 if (!strcmp((const char *) context_child_node
->name
,
2536 config_element_type
)) {
2538 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2541 ret
= -LTTNG_ERR_NOMEM
;
2545 ret
= get_context_type(content
);
2548 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2553 } else if (!strcmp((const char *) context_child_node
->name
,
2554 config_element_context_perf
)) {
2556 xmlNodePtr perf_attr_node
;
2558 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2559 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2560 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2561 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2562 perf_attr_node
; perf_attr_node
=
2563 xmlNextElementSibling(perf_attr_node
)) {
2564 if (!strcmp((const char *) perf_attr_node
->name
,
2565 config_element_type
)) {
2570 content
= xmlNodeGetContent(perf_attr_node
);
2572 ret
= -LTTNG_ERR_NOMEM
;
2576 ret
= parse_uint(content
, &type
);
2579 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2583 if (type
> UINT32_MAX
) {
2584 WARN("perf context type out of range.");
2585 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2589 context
.u
.perf_counter
.type
= type
;
2590 } else if (!strcmp((const char *) perf_attr_node
->name
,
2591 config_element_config
)) {
2593 uint64_t config
= 0;
2596 content
= xmlNodeGetContent(perf_attr_node
);
2598 ret
= -LTTNG_ERR_NOMEM
;
2602 ret
= parse_uint(content
, &config
);
2605 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2609 context
.u
.perf_counter
.config
= config
;
2610 } else if (!strcmp((const char *) perf_attr_node
->name
,
2611 config_element_name
)) {
2615 content
= xmlNodeGetContent(perf_attr_node
);
2617 ret
= -LTTNG_ERR_NOMEM
;
2621 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2622 (const char *) content
,
2623 LTTNG_SYMBOL_NAME_LEN
);
2625 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2626 (const char *) content
,
2627 strlen((const char *) content
),
2628 LTTNG_SYMBOL_NAME_LEN
);
2629 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2636 } else if (!strcmp((const char *) context_child_node
->name
,
2637 config_element_context_app
)) {
2638 /* application context */
2639 xmlNodePtr app_ctx_node
;
2641 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2642 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2643 app_ctx_node
; app_ctx_node
=
2644 xmlNextElementSibling(app_ctx_node
)) {
2646 char **target
= strcmp(
2647 (const char *) app_ctx_node
->name
,
2648 config_element_context_app_provider_name
) == 0 ?
2649 &context
.u
.app_ctx
.provider_name
:
2650 &context
.u
.app_ctx
.ctx_name
;
2652 content
= xmlNodeGetContent(app_ctx_node
);
2654 ret
= -LTTNG_ERR_NOMEM
;
2658 *target
= (char *) content
;
2661 /* Unrecognized context type */
2662 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2666 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2667 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2668 free(context
.u
.app_ctx
.provider_name
);
2669 free(context
.u
.app_ctx
.ctx_name
);
2676 int process_contexts_node(xmlNodePtr contexts_node
,
2677 struct lttng_handle
*handle
, const char *channel_name
)
2680 xmlNodePtr context_node
;
2682 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2683 context_node
= xmlNextElementSibling(context_node
)) {
2684 ret
= process_context_node(context_node
, handle
, channel_name
);
2693 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2694 const char **element_id_tracker
,
2695 const char **element_value_type
,
2696 const char **element_value
,
2697 const char **element_value_alias
,
2698 const char **element_name
)
2702 switch (process_attr
) {
2703 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2704 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2705 *element_value_type
= config_element_process_attr_pid_value
;
2706 *element_value
= config_element_process_attr_id
;
2707 *element_value_alias
= config_element_process_attr_id
;
2708 *element_name
= NULL
;
2710 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2711 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2712 *element_value_type
= config_element_process_attr_vpid_value
;
2713 *element_value
= config_element_process_attr_id
;
2714 *element_value_alias
= NULL
;
2715 *element_name
= NULL
;
2717 case LTTNG_PROCESS_ATTR_USER_ID
:
2718 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2719 *element_value_type
= config_element_process_attr_uid_value
;
2720 *element_value
= config_element_process_attr_id
;
2721 *element_value_alias
= NULL
;
2722 *element_name
= config_element_name
;
2724 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2725 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2726 *element_value_type
= config_element_process_attr_vuid_value
;
2727 *element_value
= config_element_process_attr_id
;
2728 *element_value_alias
= NULL
;
2729 *element_name
= config_element_name
;
2731 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2732 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2733 *element_value_type
= config_element_process_attr_gid_value
;
2734 *element_value
= config_element_process_attr_id
;
2735 *element_value_alias
= NULL
;
2736 *element_name
= config_element_name
;
2738 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2739 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2740 *element_value_type
= config_element_process_attr_vgid_value
;
2741 *element_value
= config_element_process_attr_id
;
2742 *element_value_alias
= NULL
;
2743 *element_name
= config_element_name
;
2746 ret
= LTTNG_ERR_INVALID
;
2751 static int process_legacy_pid_tracker_node(
2752 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2754 int ret
= 0, child_count
;
2755 xmlNodePtr targets_node
= NULL
;
2757 const char *element_id_tracker
;
2758 const char *element_target_id
;
2759 const char *element_id
;
2760 const char *element_id_alias
;
2761 const char *element_name
;
2762 enum lttng_error_code tracker_handle_ret_code
;
2763 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2764 enum lttng_process_attr_tracker_handle_status status
;
2765 const enum lttng_process_attr process_attr
=
2766 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2767 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2768 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2772 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2773 handle
->session_name
, handle
->domain
.type
,
2776 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2777 ret
= LTTNG_ERR_INVALID
;
2781 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2782 &element_target_id
, &element_id
, &element_id_alias
,
2788 /* Get the targets node */
2789 for (node
= xmlFirstElementChild(trackers_node
); node
;
2790 node
= xmlNextElementSibling(node
)) {
2791 if (!strcmp((const char *) node
->name
,
2792 config_element_tracker_targets_legacy
)) {
2793 targets_node
= node
;
2798 if (!targets_node
) {
2799 ret
= LTTNG_ERR_INVALID
;
2803 /* Go through all id target node */
2804 child_count
= xmlChildElementCount(targets_node
);
2805 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2807 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2808 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2809 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2810 ret
= LTTNG_ERR_UNK
;
2814 /* Add all tracked values. */
2815 for (node
= xmlFirstElementChild(targets_node
); node
;
2816 node
= xmlNextElementSibling(node
)) {
2817 xmlNodePtr pid_target_node
= node
;
2819 /* get pid_target node and track it */
2820 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2821 node
= xmlNextElementSibling(node
)) {
2822 if (!strcmp((const char *) node
->name
,
2823 config_element_tracker_pid_legacy
)) {
2825 xmlChar
*content
= xmlNodeGetContent(node
);
2828 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2832 ret
= parse_int(content
, &id
);
2835 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2839 switch (process_attr
) {
2840 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2841 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2845 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2846 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2851 ret
= LTTNG_ERR_INVALID
;
2856 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2858 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2859 ret
= LTTNG_ERR_INVALID
;
2861 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2862 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2864 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2865 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2867 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2868 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2870 ret
= LTTNG_ERR_UNK
;
2874 node
= pid_target_node
;
2878 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2882 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2883 struct lttng_handle
*handle
,
2884 enum lttng_process_attr process_attr
)
2886 int ret
= 0, child_count
;
2887 xmlNodePtr values_node
= NULL
;
2889 const char *element_id_tracker
;
2890 const char *element_target_id
;
2891 const char *element_id
;
2892 const char *element_id_alias
;
2893 const char *element_name
;
2894 enum lttng_error_code tracker_handle_ret_code
;
2895 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2896 enum lttng_process_attr_tracker_handle_status status
;
2899 assert(id_tracker_node
);
2901 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2902 handle
->session_name
, handle
->domain
.type
, process_attr
,
2904 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2905 ret
= LTTNG_ERR_INVALID
;
2909 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2910 &element_target_id
, &element_id
, &element_id_alias
,
2916 /* get the values node */
2917 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2918 node
= xmlNextElementSibling(node
)) {
2919 if (!strcmp((const char *) node
->name
,
2920 config_element_process_attr_values
)) {
2927 ret
= LTTNG_ERR_INVALID
;
2931 /* Go through all id target node */
2932 child_count
= xmlChildElementCount(values_node
);
2933 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2935 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2936 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2937 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2938 ret
= LTTNG_ERR_UNK
;
2942 /* Add all tracked values. */
2943 for (node
= xmlFirstElementChild(values_node
); node
;
2944 node
= xmlNextElementSibling(node
)) {
2945 xmlNodePtr id_target_node
= node
;
2947 /* get id node and track it */
2948 for (node
= xmlFirstElementChild(id_target_node
); node
;
2949 node
= xmlNextElementSibling(node
)) {
2950 if (!strcmp((const char *) node
->name
, element_id
) ||
2951 (element_id_alias
&&
2952 !strcmp((const char *) node
->name
,
2953 element_id_alias
))) {
2955 xmlChar
*content
= xmlNodeGetContent(node
);
2958 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2962 ret
= parse_int(content
, &id
);
2965 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2969 switch (process_attr
) {
2970 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2971 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2975 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2976 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2980 case LTTNG_PROCESS_ATTR_USER_ID
:
2981 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2985 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2986 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2990 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2991 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2995 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2996 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
3001 ret
= LTTNG_ERR_INVALID
;
3004 } else if (element_name
&&
3005 !strcmp((const char *) node
->name
,
3007 xmlChar
*content
= xmlNodeGetContent(node
);
3010 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3014 switch (process_attr
) {
3015 case LTTNG_PROCESS_ATTR_USER_ID
:
3016 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3018 (const char *) content
);
3020 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3021 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3023 (const char *) content
);
3025 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3026 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3028 (const char *) content
);
3030 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3031 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3033 (const char *) content
);
3037 ret
= LTTNG_ERR_INVALID
;
3043 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3045 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3046 ret
= LTTNG_ERR_INVALID
;
3048 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3049 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3051 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3052 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3054 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3055 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3057 ret
= LTTNG_ERR_UNK
;
3061 node
= id_target_node
;
3065 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3070 int process_channel_node(xmlNodePtr channel_node
, struct lttng_handle
*handle
,
3071 struct lttng_domain
*domain
,
3072 enum lttng_domain_type original_domain
)
3075 struct lttng_channel
*channel
= NULL
;
3076 xmlNodePtr contexts_node
= NULL
;
3077 xmlNodePtr events_node
= NULL
;
3078 xmlNodePtr channel_attr_node
;
3081 * Channels of the "agent" types cannot be created directly.
3082 * They are meant to be created implicitly through the
3083 * activation of events in their domain. However, a user
3084 * can override the default channel configuration attributes
3085 * by creating the underlying UST channel _before_ enabling
3086 * an agent domain event.
3088 * Hence, the channel's type is substituted before the creation
3089 * and restored by the time the events are created.
3091 switch (domain
->type
) {
3092 case LTTNG_DOMAIN_JUL
:
3093 case LTTNG_DOMAIN_LOG4J
:
3094 case LTTNG_DOMAIN_PYTHON
:
3095 domain
->type
= LTTNG_DOMAIN_UST
;
3100 channel
= lttng_channel_create(domain
);
3106 for (channel_attr_node
= xmlFirstElementChild(channel_node
);
3107 channel_attr_node
; channel_attr_node
=
3108 xmlNextElementSibling(channel_attr_node
)) {
3109 ret
= process_channel_attr_node(channel_attr_node
,
3110 channel
, &contexts_node
, &events_node
);
3116 ret
= lttng_enable_channel(handle
, channel
);
3121 /* Restore the original channel domain-> */
3122 domain
->type
= original_domain
;
3124 ret
= process_events_node(events_node
, handle
, channel
->name
);
3129 ret
= process_contexts_node(contexts_node
, handle
,
3136 lttng_channel_destroy(channel
);
3140 static int process_dimension_node(xmlNodePtr dimension_node
,
3141 struct lttng_dynamic_array
*dimension_sizes
)
3145 xmlChar
*size_str
= NULL
;
3148 assert(strcmp((const char *) dimension_node
->name
,
3149 config_element_dimension
) == 0);
3150 assert(dimension_sizes
->element_size
== sizeof(uint64_t));
3152 for (node
= xmlFirstElementChild(dimension_node
); node
;
3153 node
= xmlNextElementSibling(node
)) {
3154 if (strcmp((const char *) node
->name
,
3155 config_element_dimension_size
) == 0) {
3157 size_str
= xmlNodeGetContent(node
);
3159 ERR("Failed to get dimension size node content.");
3160 ret
= -LTTNG_ERR_NOMEM
;
3164 ret
= parse_uint(size_str
, &size
);
3167 ret
= lttng_dynamic_array_add_element(dimension_sizes
, &size
);
3183 /* `dimensions_sizes` must be initialized to hold uint64_t elements. */
3185 static int process_dimensions_node(xmlNodePtr dimensions_node
,
3186 struct lttng_dynamic_array
*dimension_sizes
)
3188 xmlNodePtr dimension_node
;
3191 assert(strcmp((const char *) dimensions_node
->name
,
3192 config_element_dimensions
) == 0);
3193 assert(dimension_sizes
->element_size
== sizeof(uint64_t));
3194 assert(lttng_dynamic_array_get_count(dimension_sizes
) == 0);
3196 for (dimension_node
= xmlFirstElementChild(dimensions_node
);
3197 dimension_node
; dimension_node
= xmlNextElementSibling(
3199 ret
= process_dimension_node(dimension_node
, dimension_sizes
);
3205 assert(lttng_dynamic_array_get_count(dimension_sizes
) > 0);
3211 static int process_map_node(xmlNodePtr map_node
, struct lttng_handle
*handle
)
3215 xmlChar
*name
= NULL
;
3216 xmlChar
*enabled_str
= NULL
;
3218 xmlChar
*bitness_str
= NULL
;
3219 enum lttng_map_bitness bitness
= LTTNG_MAP_BITNESS_32BITS
;
3220 xmlChar
*boundary_policy_str
= NULL
;
3221 enum lttng_map_boundary_policy boundary_policy
= LTTNG_MAP_BOUNDARY_POLICY_OVERFLOW
;
3222 xmlChar
*coalesce_hits_str
= NULL
;
3224 enum lttng_map_status map_status
;
3225 struct lttng_map
*map
= NULL
;
3226 struct lttng_dynamic_array dimension_sizes
;
3227 enum lttng_error_code error_code
;
3229 assert(strcmp((const char *) map_node
->name
, config_element_map
) == 0);
3231 lttng_dynamic_array_init(&dimension_sizes
, sizeof(uint64_t), NULL
);
3233 for (node
= xmlFirstElementChild(map_node
); node
;
3234 node
= xmlNextElementSibling(node
)) {
3235 if (strcmp((const char *) node
->name
, config_element_name
) ==
3238 name
= xmlNodeGetContent(node
);
3240 ERR("Failed to get map name node content.");
3241 ret
= -LTTNG_ERR_NOMEM
;
3244 } else if (strcmp((const char *) node
->name
,
3245 config_element_enabled
) == 0) {
3246 assert(!enabled_str
);
3247 enabled_str
= xmlNodeGetContent(node
);
3249 ERR("Failed to get map enabled node content.");
3250 ret
= -LTTNG_ERR_NOMEM
;
3254 ret
= parse_bool(enabled_str
, &enabled
);
3256 } else if (strcmp((const char *) node
->name
,
3257 config_element_bitness
) == 0) {
3258 assert(!bitness_str
);
3259 bitness_str
= xmlNodeGetContent(node
);
3261 ERR("Failed to get map bitness node content.");
3262 ret
= -LTTNG_ERR_NOMEM
;
3266 if (strcmp((const char *) bitness_str
, "32") == 0) {
3267 bitness
= LTTNG_MAP_BITNESS_32BITS
;
3269 assert(strcmp((const char *) bitness_str
,
3271 bitness
= LTTNG_MAP_BITNESS_64BITS
;
3273 } else if (strcmp((const char *) node
->name
,
3274 config_element_boundary_policy
) ==
3276 assert(!boundary_policy_str
);
3277 boundary_policy_str
= xmlNodeGetContent(node
);
3278 if (!boundary_policy_str
) {
3279 ERR("Failed to get map boundary policy node content.");
3280 ret
= -LTTNG_ERR_NOMEM
;
3284 assert(strcmp((const char *) boundary_policy_str
,
3285 config_boundary_policy_overflow
) ==
3287 boundary_policy
= LTTNG_MAP_BOUNDARY_POLICY_OVERFLOW
;
3288 } else if (strcmp((const char *) node
->name
,
3289 config_element_coalesce_hits
) == 0) {
3290 assert(!coalesce_hits_str
);
3291 coalesce_hits_str
= xmlNodeGetContent(node
);
3292 if (!coalesce_hits_str
) {
3293 ERR("Failed to get map coalesce hits node content.");
3294 ret
= -LTTNG_ERR_NOMEM
;
3298 ret
= parse_bool(coalesce_hits_str
, &coalesce_hits
);
3300 } else if (strcmp((const char *) node
->name
,
3301 config_element_dimensions
) == 0) {
3302 ret
= process_dimensions_node(node
, &dimension_sizes
);
3312 map_status
= lttng_map_create((const char *) name
,
3313 lttng_dynamic_array_get_count(&dimension_sizes
),
3314 (uint64_t *) dimension_sizes
.buffer
.data
,
3315 handle
->domain
.type
, handle
->domain
.buf_type
, bitness
,
3316 boundary_policy
, coalesce_hits
, &map
);
3317 if (map_status
!= LTTNG_MAP_STATUS_OK
) {
3318 ERR("Failed to create map.");
3319 ret
= -LTTNG_ERR_UNK
;
3323 error_code
= lttng_add_map(handle
, map
);
3324 if (error_code
!= LTTNG_OK
) {
3325 ERR("Adding map \"%s\": %s", (const char *) name
,
3326 lttng_strerror(error_code
));
3331 // FIXME: disabling the map after creating leaves a window of time
3332 // where it is enabled, does it matter?
3334 ret
= lttng_disable_map(handle
, (const char *) name
);
3344 xmlFree(enabled_str
);
3345 xmlFree(bitness_str
);
3346 xmlFree(boundary_policy_str
);
3347 xmlFree(coalesce_hits_str
);
3348 lttng_dynamic_array_reset(&dimension_sizes
);
3349 lttng_map_destroy(map
);
3355 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3358 struct lttng_domain domain
= { 0 };
3359 struct lttng_handle
*handle
= NULL
;
3360 xmlNodePtr channels_node
= NULL
;
3361 xmlNodePtr maps_node
= NULL
;
3362 xmlNodePtr trackers_node
= NULL
;
3363 xmlNodePtr pid_tracker_node
= NULL
;
3364 xmlNodePtr vpid_tracker_node
= NULL
;
3365 xmlNodePtr uid_tracker_node
= NULL
;
3366 xmlNodePtr vuid_tracker_node
= NULL
;
3367 xmlNodePtr gid_tracker_node
= NULL
;
3368 xmlNodePtr vgid_tracker_node
= NULL
;
3371 assert(session_name
);
3373 ret
= init_domain(domain_node
, &domain
);
3378 handle
= lttng_create_handle(session_name
, &domain
);
3380 ret
= -LTTNG_ERR_NOMEM
;
3384 /* get the channels node */
3385 for (node
= xmlFirstElementChild(domain_node
); node
;
3386 node
= xmlNextElementSibling(node
)) {
3387 if (!strcmp((const char *) node
->name
,
3388 config_element_channels
)) {
3389 channels_node
= node
;
3394 if (channels_node
) {
3395 /* create all channels */
3396 for (node
= xmlFirstElementChild(channels_node
); node
;
3397 node
= xmlNextElementSibling(node
)) {
3398 const enum lttng_domain_type original_domain
= domain
.type
;
3400 ret
= process_channel_node(node
, handle
, &domain
,
3408 /* get the maps node */
3409 for (node
= xmlFirstElementChild(domain_node
); node
;
3410 node
= xmlNextElementSibling(node
)) {
3411 if (!strcmp((const char *) node
->name
, config_element_maps
)) {
3418 /* create all maps */
3419 for (node
= xmlFirstElementChild(maps_node
); node
;
3420 node
= xmlNextElementSibling(node
)) {
3421 ret
= process_map_node(node
, handle
);
3428 /* get the trackers node */
3429 for (node
= xmlFirstElementChild(domain_node
); node
;
3430 node
= xmlNextElementSibling(node
)) {
3431 if (!strcmp((const char *) node
->name
,
3432 config_element_process_attr_trackers
) ||
3433 !strcmp((const char *) node
->name
,
3434 config_element_trackers_legacy
)) {
3435 if (trackers_node
) {
3436 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3437 config_element_process_attr_trackers
,
3438 config_element_trackers_legacy
);
3442 trackers_node
= node
;
3447 if (!trackers_node
) {
3451 for (node
= xmlFirstElementChild(trackers_node
); node
;
3452 node
= xmlNextElementSibling(node
)) {
3453 if (!strcmp((const char *) node
->name
,
3454 config_element_process_attr_tracker_pid
)) {
3455 pid_tracker_node
= node
;
3456 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3457 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3462 if (!strcmp((const char *) node
->name
,
3463 config_element_process_attr_tracker_vpid
)) {
3464 vpid_tracker_node
= node
;
3465 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3466 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3471 if (!strcmp((const char *) node
->name
,
3472 config_element_process_attr_tracker_uid
)) {
3473 uid_tracker_node
= node
;
3474 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3475 LTTNG_PROCESS_ATTR_USER_ID
);
3480 if (!strcmp((const char *) node
->name
,
3481 config_element_process_attr_tracker_vuid
)) {
3482 vuid_tracker_node
= node
;
3483 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3484 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3489 if (!strcmp((const char *) node
->name
,
3490 config_element_process_attr_tracker_gid
)) {
3491 gid_tracker_node
= node
;
3492 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3493 LTTNG_PROCESS_ATTR_GROUP_ID
);
3498 if (!strcmp((const char *) node
->name
,
3499 config_element_process_attr_tracker_vgid
)) {
3500 vgid_tracker_node
= node
;
3501 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3502 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3507 if (!strcmp((const char *) node
->name
,
3508 config_element_pid_tracker_legacy
)) {
3509 ret
= process_legacy_pid_tracker_node(node
, handle
);
3517 lttng_destroy_handle(handle
);
3522 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3525 enum lttng_rotation_status status
;
3526 struct lttng_rotation_schedule
*periodic
=
3527 lttng_rotation_schedule_periodic_create();
3530 ret
= -LTTNG_ERR_NOMEM
;
3534 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3536 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3537 ret
= -LTTNG_ERR_INVALID
;
3541 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3543 case LTTNG_ROTATION_STATUS_OK
:
3546 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3547 case LTTNG_ROTATION_STATUS_INVALID
:
3548 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3551 ret
= -LTTNG_ERR_UNK
;
3555 lttng_rotation_schedule_destroy(periodic
);
3560 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3563 enum lttng_rotation_status status
;
3564 struct lttng_rotation_schedule
*size
=
3565 lttng_rotation_schedule_size_threshold_create();
3568 ret
= -LTTNG_ERR_NOMEM
;
3572 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3574 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3575 ret
= -LTTNG_ERR_INVALID
;
3579 status
= lttng_session_add_rotation_schedule(name
, size
);
3581 case LTTNG_ROTATION_STATUS_OK
:
3584 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3585 case LTTNG_ROTATION_STATUS_INVALID
:
3586 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3589 ret
= -LTTNG_ERR_UNK
;
3593 lttng_rotation_schedule_destroy(size
);
3598 int process_session_rotation_schedules_node(
3599 xmlNodePtr schedules_node
,
3600 uint64_t *rotation_timer_interval
,
3601 uint64_t *rotation_size
)
3606 for (child
= xmlFirstElementChild(schedules_node
);
3608 child
= xmlNextElementSibling(child
)) {
3609 if (!strcmp((const char *) child
->name
,
3610 config_element_rotation_schedule_periodic
)) {
3612 xmlNodePtr time_us_node
;
3614 /* periodic rotation schedule */
3615 time_us_node
= xmlFirstElementChild(child
);
3616 if (!time_us_node
||
3617 strcmp((const char *) time_us_node
->name
,
3618 config_element_rotation_schedule_periodic_time_us
)) {
3619 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3624 content
= xmlNodeGetContent(time_us_node
);
3626 ret
= -LTTNG_ERR_NOMEM
;
3629 ret
= parse_uint(content
, rotation_timer_interval
);
3632 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3635 } else if (!strcmp((const char *) child
->name
,
3636 config_element_rotation_schedule_size_threshold
)) {
3638 xmlNodePtr bytes_node
;
3640 /* size_threshold rotation schedule */
3641 bytes_node
= xmlFirstElementChild(child
);
3643 strcmp((const char *) bytes_node
->name
,
3644 config_element_rotation_schedule_size_threshold_bytes
)) {
3645 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3650 content
= xmlNodeGetContent(bytes_node
);
3652 ret
= -LTTNG_ERR_NOMEM
;
3655 ret
= parse_uint(content
, rotation_size
);
3658 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3669 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3671 const struct config_load_session_override_attr
*overrides
)
3673 int ret
, started
= -1, snapshot_mode
= -1;
3674 uint64_t live_timer_interval
= UINT64_MAX
,
3675 rotation_timer_interval
= 0,
3677 xmlChar
*name
= NULL
;
3678 xmlChar
*shm_path
= NULL
;
3679 xmlNodePtr domains_node
= NULL
;
3680 xmlNodePtr output_node
= NULL
;
3682 xmlNodePtr attributes_child
;
3683 struct lttng_domain
*kernel_domain
= NULL
;
3684 struct lttng_domain
*ust_domain
= NULL
;
3685 struct lttng_domain
*jul_domain
= NULL
;
3686 struct lttng_domain
*log4j_domain
= NULL
;
3687 struct lttng_domain
*python_domain
= NULL
;
3689 for (node
= xmlFirstElementChild(session_node
); node
;
3690 node
= xmlNextElementSibling(node
)) {
3691 if (!name
&& !strcmp((const char *) node
->name
,
3692 config_element_name
)) {
3694 xmlChar
*node_content
= xmlNodeGetContent(node
);
3695 if (!node_content
) {
3696 ret
= -LTTNG_ERR_NOMEM
;
3700 name
= node_content
;
3701 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3702 config_element_domains
)) {
3704 domains_node
= node
;
3705 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3706 config_element_started
)) {
3708 xmlChar
*node_content
= xmlNodeGetContent(node
);
3709 if (!node_content
) {
3710 ret
= -LTTNG_ERR_NOMEM
;
3714 ret
= parse_bool(node_content
, &started
);
3717 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3720 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3721 config_element_output
)) {
3724 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3725 config_element_shared_memory_path
)) {
3726 /* shared memory path */
3727 xmlChar
*node_content
= xmlNodeGetContent(node
);
3728 if (!node_content
) {
3729 ret
= -LTTNG_ERR_NOMEM
;
3733 shm_path
= node_content
;
3736 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3737 * rotation_timer_interval.
3739 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3740 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3741 if (!strcmp((const char *) attributes_child
->name
,
3742 config_element_snapshot_mode
)) {
3744 xmlChar
*snapshot_mode_content
=
3745 xmlNodeGetContent(attributes_child
);
3746 if (!snapshot_mode_content
) {
3747 ret
= -LTTNG_ERR_NOMEM
;
3751 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3752 free(snapshot_mode_content
);
3754 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3757 } else if (!strcmp((const char *) attributes_child
->name
,
3758 config_element_live_timer_interval
)) {
3759 /* live_timer_interval */
3760 xmlChar
*timer_interval_content
=
3761 xmlNodeGetContent(attributes_child
);
3762 if (!timer_interval_content
) {
3763 ret
= -LTTNG_ERR_NOMEM
;
3767 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3768 free(timer_interval_content
);
3770 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3773 } else if (!strcmp((const char *) attributes_child
->name
,
3774 config_element_rotation_schedules
)) {
3775 ret
= process_session_rotation_schedules_node(
3777 &rotation_timer_interval
,
3780 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3790 /* Mandatory attribute, as defined in the session XSD */
3791 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3795 if (session_name
&& strcmp((char *) name
, session_name
)) {
3796 /* This is not the session we are looking for */
3797 ret
= -LTTNG_ERR_NO_SESSION
;
3801 /* Init domains to create the session handles */
3802 for (node
= xmlFirstElementChild(domains_node
); node
;
3803 node
= xmlNextElementSibling(node
)) {
3804 struct lttng_domain
*domain
;
3806 domain
= zmalloc(sizeof(*domain
));
3808 ret
= -LTTNG_ERR_NOMEM
;
3812 ret
= init_domain(node
, domain
);
3814 goto domain_init_error
;
3817 switch (domain
->type
) {
3818 case LTTNG_DOMAIN_KERNEL
:
3819 if (kernel_domain
) {
3820 /* Same domain seen twice, invalid! */
3821 goto domain_init_error
;
3823 kernel_domain
= domain
;
3825 case LTTNG_DOMAIN_UST
:
3827 /* Same domain seen twice, invalid! */
3828 goto domain_init_error
;
3830 ust_domain
= domain
;
3832 case LTTNG_DOMAIN_JUL
:
3834 /* Same domain seen twice, invalid! */
3835 goto domain_init_error
;
3837 jul_domain
= domain
;
3839 case LTTNG_DOMAIN_LOG4J
:
3841 /* Same domain seen twice, invalid! */
3842 goto domain_init_error
;
3844 log4j_domain
= domain
;
3846 case LTTNG_DOMAIN_PYTHON
:
3847 if (python_domain
) {
3848 /* Same domain seen twice, invalid! */
3849 goto domain_init_error
;
3851 python_domain
= domain
;
3854 WARN("Invalid domain type");
3855 goto domain_init_error
;
3860 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3864 /* Apply overrides */
3866 if (overrides
->session_name
) {
3867 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3868 if (!name_override
) {
3869 ret
= -LTTNG_ERR_NOMEM
;
3873 /* Overrides the session name to the provided name */
3875 name
= name_override
;
3880 /* Destroy session if it exists */
3881 ret
= lttng_destroy_session((const char *) name
);
3882 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3883 ERR("Failed to destroy existing session.");
3888 /* Create session type depending on output type */
3889 if (snapshot_mode
&& snapshot_mode
!= -1) {
3890 ret
= create_snapshot_session((const char *) name
, output_node
,
3892 } else if (live_timer_interval
&&
3893 live_timer_interval
!= UINT64_MAX
) {
3894 ret
= create_session((const char *) name
,
3895 output_node
, live_timer_interval
, overrides
);
3897 /* regular session */
3898 ret
= create_session((const char *) name
,
3899 output_node
, UINT64_MAX
, overrides
);
3906 ret
= lttng_set_session_shm_path((const char *) name
,
3907 (const char *) shm_path
);
3913 for (node
= xmlFirstElementChild(domains_node
); node
;
3914 node
= xmlNextElementSibling(node
)) {
3915 ret
= process_domain_node(node
, (const char *) name
);
3921 if (rotation_timer_interval
) {
3922 ret
= add_periodic_rotation((const char *) name
,
3923 rotation_timer_interval
);
3928 if (rotation_size
) {
3929 ret
= add_size_rotation((const char *) name
,
3937 ret
= lttng_start_tracing((const char *) name
);
3945 ERR("Failed to load session %s: %s", (const char *) name
,
3946 lttng_strerror(ret
));
3947 lttng_destroy_session((const char *) name
);
3951 free(kernel_domain
);
3955 free(python_domain
);
3962 * Return 1 if the given path is readable by the current UID or 0 if not.
3963 * Return -1 if the path is EPERM.
3965 static int validate_file_read_creds(const char *path
)
3971 /* Can we read the file. */
3972 ret
= access(path
, R_OK
);
3976 if (errno
== EACCES
) {
3987 int load_session_from_file(const char *path
, const char *session_name
,
3988 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3989 const struct config_load_session_override_attr
*overrides
)
3991 int ret
, session_found
= !session_name
;
3992 xmlDocPtr doc
= NULL
;
3993 xmlNodePtr sessions_node
;
3994 xmlNodePtr session_node
;
3997 assert(validation_ctx
);
3999 ret
= validate_file_read_creds(path
);
4002 ret
= -LTTNG_ERR_EPERM
;
4004 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
4009 doc
= xmlParseFile(path
);
4011 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
4015 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
4017 ERR("Session configuration file validation failed");
4018 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
4022 sessions_node
= xmlDocGetRootElement(doc
);
4023 if (!sessions_node
) {
4024 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
4028 for (session_node
= xmlFirstElementChild(sessions_node
);
4029 session_node
; session_node
=
4030 xmlNextElementSibling(session_node
)) {
4031 ret
= process_session_node(session_node
,
4032 session_name
, overwrite
, overrides
);
4033 if (!session_name
&& ret
) {
4034 /* Loading error occurred. */
4036 } else if (session_name
) {
4038 /* Target session found and loaded */
4041 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
4043 * Ignore this error, we are looking for a
4048 /* Loading error occurred. */
4056 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
4062 int load_session_from_path(const char *path
, const char *session_name
,
4063 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
4064 const struct config_load_session_override_attr
*overrides
)
4066 int ret
, session_found
= !session_name
;
4067 DIR *directory
= NULL
;
4068 struct lttng_dynamic_buffer file_path
;
4072 assert(validation_ctx
);
4073 path_len
= strlen(path
);
4074 lttng_dynamic_buffer_init(&file_path
);
4075 if (path_len
>= LTTNG_PATH_MAX
) {
4076 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
4077 path
, path_len
, LTTNG_PATH_MAX
);
4078 ret
= -LTTNG_ERR_INVALID
;
4082 directory
= opendir(path
);
4086 /* Try the file loading. */
4089 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
4092 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
4097 size_t file_path_root_len
;
4099 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
4102 ret
= -LTTNG_ERR_NOMEM
;
4106 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
4108 ret
= -LTTNG_ERR_NOMEM
;
4112 if (file_path
.data
[file_path
.size
- 1] != '/') {
4113 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
4115 ret
= -LTTNG_ERR_NOMEM
;
4119 file_path_root_len
= file_path
.size
;
4121 /* Search for *.lttng files */
4123 size_t file_name_len
;
4124 struct dirent
*result
;
4127 * When the end of the directory stream is reached, NULL
4128 * is returned and errno is kept unchanged. When an
4129 * error occurs, NULL is returned and errno is set
4130 * accordingly. To distinguish between the two, set
4131 * errno to zero before calling readdir().
4133 * On success, readdir() returns a pointer to a dirent
4134 * structure. This structure may be statically
4135 * allocated, do not attempt to free(3) it.
4138 result
= readdir(directory
);
4140 /* Reached end of dir stream or error out. */
4143 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
4144 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
4150 file_name_len
= strlen(result
->d_name
);
4152 if (file_name_len
<=
4153 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
4157 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
4158 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
4160 /* +1 to account for NULL terminator. */
4161 file_path
.size
+ file_name_len
+ 1,
4166 /* Does the file end with .lttng? */
4167 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
4168 result
->d_name
+ file_name_len
- sizeof(
4169 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
4173 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
4176 ret
= -LTTNG_ERR_NOMEM
;
4180 ret
= load_session_from_file(file_path
.data
, session_name
,
4181 validation_ctx
, overwrite
, overrides
);
4183 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
4187 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4191 * Reset the buffer's size to the location of the
4192 * path's trailing '/'.
4194 ret
= lttng_dynamic_buffer_set_size(&file_path
,
4195 file_path_root_len
);
4197 ret
= -LTTNG_ERR_UNK
;
4202 ret
= load_session_from_file(path
, session_name
,
4203 validation_ctx
, overwrite
, overrides
);
4213 if (closedir(directory
)) {
4217 if (!ret
&& !session_found
) {
4218 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
4220 lttng_dynamic_buffer_reset(&file_path
);
4225 * Validate that the given path's credentials and the current process have the
4226 * same UID. If so, return 1 else return 0 if it does NOT match.
4228 static int validate_path_creds(const char *path
)
4230 int ret
, uid
= getuid();
4239 ret
= stat(path
, &buf
);
4241 if (errno
!= ENOENT
) {
4247 if (buf
.st_uid
!= uid
) {
4258 int config_load_session(const char *path
, const char *session_name
,
4259 int overwrite
, unsigned int autoload
,
4260 const struct config_load_session_override_attr
*overrides
)
4263 bool session_loaded
= false;
4264 const char *path_ptr
= NULL
;
4265 struct session_config_validation_ctx validation_ctx
= { 0 };
4267 ret
= init_session_config_validation_ctx(&validation_ctx
);
4273 const char *home_path
;
4274 const char *sys_path
;
4277 home_path
= utils_get_home_dir();
4279 char path
[PATH_MAX
];
4282 * Try user session configuration path. Ignore error here so we can
4283 * continue loading the system wide sessions.
4286 ret
= snprintf(path
, sizeof(path
),
4287 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
4288 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
4290 PERROR("snprintf session autoload home config path");
4291 ret
= -LTTNG_ERR_INVALID
;
4296 * Credentials are only validated for the autoload in order to
4297 * avoid any user session daemon to try to load kernel sessions
4298 * automatically and failing all the times.
4300 ret
= validate_path_creds(path
);
4305 ret
= snprintf(path
, sizeof(path
),
4306 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
4308 PERROR("snprintf session home config path");
4309 ret
= -LTTNG_ERR_INVALID
;
4315 ret
= load_session_from_path(path_ptr
, session_name
,
4316 &validation_ctx
, overwrite
, overrides
);
4317 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4321 * Continue even if the session was found since we have to try
4322 * the system wide sessions.
4324 session_loaded
= true;
4328 /* Reset path pointer for the system wide dir. */
4331 /* Try system wide configuration directory. */
4333 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4334 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4335 ret
= validate_path_creds(sys_path
);
4337 path_ptr
= sys_path
;
4340 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4341 path_ptr
= sys_path
;
4345 ret
= load_session_from_path(path_ptr
, session_name
,
4346 &validation_ctx
, overwrite
, overrides
);
4348 session_loaded
= true;
4354 ret
= access(path
, F_OK
);
4359 ret
= -LTTNG_ERR_INVALID
;
4360 WARN("Session configuration path does not exist.");
4363 ret
= -LTTNG_ERR_EPERM
;
4366 ret
= -LTTNG_ERR_UNK
;
4372 ret
= load_session_from_path(path
, session_name
,
4373 &validation_ctx
, overwrite
, overrides
);
4376 fini_session_config_validation_ctx(&validation_ctx
);
4377 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4379 * Don't report an error if no sessions are found when called
4380 * without a session_name or a search path.
4385 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4386 /* A matching session was found in one of the search paths. */
4393 void __attribute__((destructor
)) session_config_exit(void)