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/compat/getenv.h>
28 #include <lttng/lttng-error.h>
29 #include <libxml/parser.h>
30 #include <libxml/valid.h>
31 #include <libxml/xmlschemas.h>
32 #include <libxml/tree.h>
33 #include <lttng/lttng.h>
34 #include <lttng/snapshot.h>
35 #include <lttng/rotation.h>
36 #include <lttng/userspace-probe.h>
38 #include "session-config.h"
39 #include "config-internal.h"
41 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
43 struct handler_filter_args
{
45 config_entry_handler_cb handler
;
49 struct session_config_validation_ctx
{
50 xmlSchemaParserCtxtPtr parser_ctx
;
52 xmlSchemaValidCtxtPtr schema_validation_ctx
;
55 LTTNG_HIDDEN
const char * const config_element_all
= "all";
56 const char * const config_str_yes
= "yes";
57 const char * const config_str_true
= "true";
58 const char * const config_str_on
= "on";
59 const char * const config_str_no
= "no";
60 const char * const config_str_false
= "false";
61 const char * const config_str_off
= "off";
62 const char * const config_xml_encoding
= "UTF-8";
63 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
64 const char * const config_xml_indent_string
= "\t";
65 const char * const config_xml_true
= "true";
66 const char * const config_xml_false
= "false";
68 const char * const config_element_channel
= "channel";
69 const char * const config_element_channels
= "channels";
70 const char * const config_element_domain
= "domain";
71 const char * const config_element_domains
= "domains";
72 const char * const config_element_event
= "event";
73 const char * const config_element_events
= "events";
74 const char * const config_element_context
= "context";
75 const char * const config_element_contexts
= "contexts";
76 const char * const config_element_attributes
= "attributes";
77 const char * const config_element_exclusion
= "exclusion";
78 const char * const config_element_exclusions
= "exclusions";
79 const char * const config_element_function_attributes
= "function_attributes";
80 const char * const config_element_probe_attributes
= "probe_attributes";
81 const char * const config_element_symbol_name
= "symbol_name";
82 const char * const config_element_address
= "address";
83 const char * const config_element_offset
= "offset";
85 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
86 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
87 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
88 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
89 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
90 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
91 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
92 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
93 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
96 const char * const config_element_name
= "name";
97 const char * const config_element_enabled
= "enabled";
98 const char * const config_element_overwrite_mode
= "overwrite_mode";
99 const char * const config_element_subbuf_size
= "subbuffer_size";
100 const char * const config_element_num_subbuf
= "subbuffer_count";
101 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
102 const char * const config_element_read_timer_interval
= "read_timer_interval";
103 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
104 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
105 const char * const config_element_output
= "output";
106 const char * const config_element_output_type
= "output_type";
107 const char * const config_element_tracefile_size
= "tracefile_size";
108 const char * const config_element_tracefile_count
= "tracefile_count";
109 const char * const config_element_live_timer_interval
= "live_timer_interval";
110 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
111 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
112 const char * const config_element_type
= "type";
113 const char * const config_element_buffer_type
= "buffer_type";
114 const char * const config_element_session
= "session";
115 const char * const config_element_sessions
= "sessions";
116 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
117 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
118 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
119 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
120 const char * const config_element_config
= "config";
121 const char * const config_element_started
= "started";
122 const char * const config_element_snapshot_mode
= "snapshot_mode";
123 const char * const config_element_loglevel
= "loglevel";
124 const char * const config_element_loglevel_type
= "loglevel_type";
125 const char * const config_element_filter
= "filter";
126 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
127 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
128 const char * const config_element_consumer_output
= "consumer_output";
129 const char * const config_element_destination
= "destination";
130 const char * const config_element_path
= "path";
131 const char * const config_element_net_output
= "net_output";
132 const char * const config_element_control_uri
= "control_uri";
133 const char * const config_element_data_uri
= "data_uri";
134 const char * const config_element_max_size
= "max_size";
135 const char * const config_element_pid
= "pid";
136 const char * const config_element_pids
= "pids";
137 const char * const config_element_shared_memory_path
= "shared_memory_path";
139 LTTNG_HIDDEN
const char * const config_element_process_attr_id
= "id";
140 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
141 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
142 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
143 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
144 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
145 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
146 LTTNG_HIDDEN
const char * const config_element_process_attr_trackers
= "process_attr_trackers";
147 LTTNG_HIDDEN
const char * const config_element_process_attr_values
= "process_attr_values";
148 LTTNG_HIDDEN
const char * const config_element_process_attr_value_type
= "process_attr_value_type";
149 LTTNG_HIDDEN
const char * const config_element_process_attr_pid_value
= "pid";
150 LTTNG_HIDDEN
const char * const config_element_process_attr_vpid_value
= "vpid";
151 LTTNG_HIDDEN
const char * const config_element_process_attr_uid_value
= "uid";
152 LTTNG_HIDDEN
const char * const config_element_process_attr_vuid_value
= "vuid";
153 LTTNG_HIDDEN
const char * const config_element_process_attr_gid_value
= "gid";
154 LTTNG_HIDDEN
const char * const config_element_process_attr_vgid_value
= "vgid";
155 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
157 /* Used for support of legacy tracker serialization (< 2.12). */
158 LTTNG_HIDDEN
const char * const config_element_trackers_legacy
= "trackers";
159 LTTNG_HIDDEN
const char * const config_element_pid_tracker_legacy
= "pid_tracker";
160 LTTNG_HIDDEN
const char * const config_element_tracker_targets_legacy
= "targets";
161 LTTNG_HIDDEN
const char * const config_element_tracker_pid_target_legacy
= "pid_target";
162 LTTNG_HIDDEN
const char * const config_element_tracker_pid_legacy
= "pid";
164 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
165 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
166 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
167 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
168 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
170 const char * const config_domain_type_kernel
= "KERNEL";
171 const char * const config_domain_type_ust
= "UST";
172 const char * const config_domain_type_jul
= "JUL";
173 const char * const config_domain_type_log4j
= "LOG4J";
174 const char * const config_domain_type_python
= "PYTHON";
176 const char * const config_buffer_type_per_pid
= "PER_PID";
177 const char * const config_buffer_type_per_uid
= "PER_UID";
178 const char * const config_buffer_type_global
= "GLOBAL";
180 const char * const config_overwrite_mode_discard
= "DISCARD";
181 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
183 const char * const config_output_type_splice
= "SPLICE";
184 const char * const config_output_type_mmap
= "MMAP";
186 const char * const config_loglevel_type_all
= "ALL";
187 const char * const config_loglevel_type_range
= "RANGE";
188 const char * const config_loglevel_type_single
= "SINGLE";
190 const char * const config_event_type_all
= "ALL";
191 const char * const config_event_type_tracepoint
= "TRACEPOINT";
192 const char * const config_event_type_probe
= "PROBE";
193 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
194 const char * const config_event_type_function
= "FUNCTION";
195 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
196 const char * const config_event_type_noop
= "NOOP";
197 const char * const config_event_type_syscall
= "SYSCALL";
198 const char * const config_event_type_kprobe
= "KPROBE";
199 const char * const config_event_type_kretprobe
= "KRETPROBE";
201 const char * const config_event_context_pid
= "PID";
202 const char * const config_event_context_procname
= "PROCNAME";
203 const char * const config_event_context_prio
= "PRIO";
204 const char * const config_event_context_nice
= "NICE";
205 const char * const config_event_context_vpid
= "VPID";
206 const char * const config_event_context_tid
= "TID";
207 const char * const config_event_context_vtid
= "VTID";
208 const char * const config_event_context_ppid
= "PPID";
209 const char * const config_event_context_vppid
= "VPPID";
210 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
211 const char * const config_event_context_hostname
= "HOSTNAME";
212 const char * const config_event_context_ip
= "IP";
213 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
214 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
215 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
216 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
217 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
218 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
219 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
220 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
221 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
222 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
223 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
224 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
225 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
226 LTTNG_HIDDEN
const char * const config_event_context_time_ns
= "TIME_NS";
227 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
228 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
229 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
230 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
231 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
232 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
233 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
234 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
235 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
236 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
237 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
238 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
239 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
240 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
242 /* Deprecated symbols */
243 const char * const config_element_perf
;
245 enum process_event_node_phase
{
250 struct consumer_output
{
257 static int config_entry_handler_filter(struct handler_filter_args
*args
,
258 const char *section
, const char *name
, const char *value
)
261 struct config_entry entry
= { section
, name
, value
};
265 if (!section
|| !name
|| !value
) {
271 if (strcmp(args
->section
, section
)) {
276 ret
= args
->handler(&entry
, args
->user_data
);
282 int config_get_section_entries(const char *override_path
, const char *section
,
283 config_entry_handler_cb handler
, void *user_data
)
287 FILE *config_file
= NULL
;
288 struct handler_filter_args filter
= { section
, handler
, user_data
};
290 /* First, try system-wide conf. file. */
291 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
293 config_file
= fopen(path
, "r");
295 DBG("Loading daemon conf file at %s", path
);
297 * Return value is not very important here since error or not, we
298 * continue and try the next possible conf. file.
300 (void) ini_parse_file(config_file
,
301 (ini_entry_handler
) config_entry_handler_filter
,
306 /* Second is the user local configuration. */
307 path
= utils_get_home_dir();
309 char fullpath
[PATH_MAX
];
311 ret
= snprintf(fullpath
, sizeof(fullpath
),
312 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
314 PERROR("snprintf user conf. path");
318 config_file
= fopen(fullpath
, "r");
320 DBG("Loading daemon user conf file at %s", path
);
322 * Return value is not very important here since error or not, we
323 * continue and try the next possible conf. file.
325 (void) ini_parse_file(config_file
,
326 (ini_entry_handler
) config_entry_handler_filter
,
332 /* Final path is the one that the user might have provided. */
334 config_file
= fopen(override_path
, "r");
336 DBG("Loading daemon command line conf file at %s", override_path
);
337 (void) ini_parse_file(config_file
,
338 (ini_entry_handler
) config_entry_handler_filter
,
342 ERR("Failed to open daemon configuration file at %s",
349 /* Everything went well. */
357 int config_parse_value(const char *value
)
360 char *endptr
, *lower_str
;
370 v
= strtoul(value
, &endptr
, 10);
371 if (endptr
!= value
) {
376 lower_str
= zmalloc(len
+ 1);
383 for (i
= 0; i
< len
; i
++) {
384 lower_str
[i
] = tolower(value
[i
]);
387 if (!strcmp(lower_str
, config_str_yes
) ||
388 !strcmp(lower_str
, config_str_true
) ||
389 !strcmp(lower_str
, config_str_on
)) {
391 } else if (!strcmp(lower_str
, config_str_no
) ||
392 !strcmp(lower_str
, config_str_false
) ||
393 !strcmp(lower_str
, config_str_off
)) {
405 * Returns a xmlChar string which must be released using xmlFree().
407 static xmlChar
*encode_string(const char *in_str
)
409 xmlChar
*out_str
= NULL
;
410 xmlCharEncodingHandlerPtr handler
;
411 int out_len
, ret
, in_len
;
415 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
417 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
421 in_len
= strlen(in_str
);
423 * Add 1 byte for the NULL terminted character. The factor 4 here is
424 * used because UTF-8 characters can take up to 4 bytes.
426 out_len
= (in_len
* 4) + 1;
427 out_str
= xmlMalloc(out_len
);
432 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
439 /* out_len is now the size of out_str */
440 out_str
[out_len
] = '\0';
446 struct config_writer
*config_writer_create(int fd_output
, int indent
)
449 struct config_writer
*writer
;
450 xmlOutputBufferPtr buffer
;
452 writer
= zmalloc(sizeof(struct config_writer
));
454 PERROR("zmalloc config_writer_create");
458 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
463 writer
->writer
= xmlNewTextWriter(buffer
);
464 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
465 config_xml_encoding
, NULL
);
470 ret
= xmlTextWriterSetIndentString(writer
->writer
,
471 BAD_CAST config_xml_indent_string
);
476 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
484 config_writer_destroy(writer
);
489 int config_writer_destroy(struct config_writer
*writer
)
498 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
499 WARN("Could not close XML document");
503 if (writer
->writer
) {
504 xmlFreeTextWriter(writer
->writer
);
513 int config_writer_open_element(struct config_writer
*writer
,
514 const char *element_name
)
517 xmlChar
*encoded_element_name
;
519 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
524 encoded_element_name
= encode_string(element_name
);
525 if (!encoded_element_name
) {
530 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
531 xmlFree(encoded_element_name
);
533 return ret
>= 0 ? 0 : ret
;
537 int config_writer_write_attribute(struct config_writer
*writer
,
538 const char *name
, const char *value
)
541 xmlChar
*encoded_name
= NULL
;
542 xmlChar
*encoded_value
= NULL
;
544 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
549 encoded_name
= encode_string(name
);
555 encoded_value
= encode_string(value
);
556 if (!encoded_value
) {
561 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
564 xmlFree(encoded_name
);
565 xmlFree(encoded_value
);
566 return ret
>= 0 ? 0 : ret
;
570 int config_writer_close_element(struct config_writer
*writer
)
574 if (!writer
|| !writer
->writer
) {
579 ret
= xmlTextWriterEndElement(writer
->writer
);
581 return ret
>= 0 ? 0 : ret
;
585 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
586 const char *element_name
, uint64_t value
)
589 xmlChar
*encoded_element_name
;
591 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
596 encoded_element_name
= encode_string(element_name
);
597 if (!encoded_element_name
) {
602 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
603 encoded_element_name
, "%" PRIu64
, value
);
604 xmlFree(encoded_element_name
);
606 return ret
>= 0 ? 0 : ret
;
610 int config_writer_write_element_signed_int(struct config_writer
*writer
,
611 const char *element_name
, int64_t value
)
614 xmlChar
*encoded_element_name
;
616 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
621 encoded_element_name
= encode_string(element_name
);
622 if (!encoded_element_name
) {
627 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
628 encoded_element_name
, "%" PRIi64
, value
);
629 xmlFree(encoded_element_name
);
631 return ret
>= 0 ? 0 : ret
;
635 int config_writer_write_element_bool(struct config_writer
*writer
,
636 const char *element_name
, int value
)
638 return config_writer_write_element_string(writer
, element_name
,
639 value
? config_xml_true
: config_xml_false
);
643 int config_writer_write_element_double(struct config_writer
*writer
,
644 const char *element_name
,
648 xmlChar
*encoded_element_name
;
650 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
655 encoded_element_name
= encode_string(element_name
);
656 if (!encoded_element_name
) {
661 ret
= xmlTextWriterWriteFormatElement(
662 writer
->writer
, encoded_element_name
, "%f", value
);
663 xmlFree(encoded_element_name
);
665 return ret
>= 0 ? 0 : ret
;
669 int config_writer_write_element_string(struct config_writer
*writer
,
670 const char *element_name
, const char *value
)
673 xmlChar
*encoded_element_name
= NULL
;
674 xmlChar
*encoded_value
= NULL
;
676 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
682 encoded_element_name
= encode_string(element_name
);
683 if (!encoded_element_name
) {
688 encoded_value
= encode_string(value
);
689 if (!encoded_value
) {
694 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
697 xmlFree(encoded_element_name
);
698 xmlFree(encoded_value
);
699 return ret
>= 0 ? 0 : ret
;
703 void xml_error_handler(void *ctx
, const char *format
, ...)
709 va_start(args
, format
);
710 ret
= vasprintf(&errMsg
, format
, args
);
713 ERR("String allocation failed in xml error handler");
717 fprintf(stderr
, "XML Error: %s", errMsg
);
722 void fini_session_config_validation_ctx(
723 struct session_config_validation_ctx
*ctx
)
725 if (ctx
->parser_ctx
) {
726 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
730 xmlSchemaFree(ctx
->schema
);
733 if (ctx
->schema_validation_ctx
) {
734 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
737 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
741 char *get_session_config_xsd_path(void)
744 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
745 size_t base_path_len
;
749 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
752 base_path_len
= strlen(base_path
);
753 max_path_len
= base_path_len
+
754 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
755 xsd_path
= zmalloc(max_path_len
);
760 strcpy(xsd_path
, base_path
);
761 if (xsd_path
[base_path_len
- 1] != '/') {
762 xsd_path
[base_path_len
++] = '/';
765 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
771 int init_session_config_validation_ctx(
772 struct session_config_validation_ctx
*ctx
)
775 char *xsd_path
= get_session_config_xsd_path();
778 ret
= -LTTNG_ERR_NOMEM
;
782 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
783 if (!ctx
->parser_ctx
) {
784 ERR("XSD parser context creation failed");
785 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
788 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
789 xml_error_handler
, NULL
);
791 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
793 ERR("XSD parsing failed");
794 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
798 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
799 if (!ctx
->schema_validation_ctx
) {
800 ERR("XSD validation context creation failed");
801 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
805 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
806 xml_error_handler
, NULL
);
811 fini_session_config_validation_ctx(ctx
);
819 int parse_uint(xmlChar
*str
, uint64_t *val
)
829 *val
= strtoull((const char *) str
, &endptr
, 10);
830 if (!endptr
|| *endptr
) {
841 int parse_int(xmlChar
*str
, int64_t *val
)
851 *val
= strtoll((const char *) str
, &endptr
, 10);
852 if (!endptr
|| *endptr
) {
863 int parse_bool(xmlChar
*str
, int *val
)
872 if (!strcmp((const char *) str
, config_xml_true
) ||
873 !strcmp((const char *) str
, "1")) {
875 } else if (!strcmp((const char *) str
, config_xml_false
) ||
876 !strcmp((const char *) str
, "0")) {
879 WARN("Invalid boolean value encountered (%s).",
888 int get_domain_type(xmlChar
*domain
)
896 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
897 ret
= LTTNG_DOMAIN_KERNEL
;
898 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
899 ret
= LTTNG_DOMAIN_UST
;
900 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
901 ret
= LTTNG_DOMAIN_JUL
;
902 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
903 ret
= LTTNG_DOMAIN_LOG4J
;
904 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
905 ret
= LTTNG_DOMAIN_PYTHON
;
916 int get_buffer_type(xmlChar
*buffer_type
)
924 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
925 ret
= LTTNG_BUFFER_GLOBAL
;
926 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
927 ret
= LTTNG_BUFFER_PER_UID
;
928 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
929 ret
= LTTNG_BUFFER_PER_PID
;
940 int get_overwrite_mode(xmlChar
*overwrite_mode
)
944 if (!overwrite_mode
) {
948 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
950 } else if (!strcmp((char *) overwrite_mode
,
951 config_overwrite_mode_discard
)) {
963 int get_output_type(xmlChar
*output_type
)
971 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
972 ret
= LTTNG_EVENT_MMAP
;
973 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
974 ret
= LTTNG_EVENT_SPLICE
;
985 int get_event_type(xmlChar
*event_type
)
993 if (!strcmp((char *) event_type
, config_event_type_all
)) {
994 ret
= LTTNG_EVENT_ALL
;
995 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
996 ret
= LTTNG_EVENT_TRACEPOINT
;
997 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
998 ret
= LTTNG_EVENT_PROBE
;
999 } else if (!strcmp((char *) event_type
,
1000 config_event_type_userspace_probe
)) {
1001 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
1002 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
1003 ret
= LTTNG_EVENT_FUNCTION
;
1004 } else if (!strcmp((char *) event_type
,
1005 config_event_type_function_entry
)) {
1006 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
1007 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
1008 ret
= LTTNG_EVENT_NOOP
;
1009 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
1010 ret
= LTTNG_EVENT_SYSCALL
;
1021 int get_loglevel_type(xmlChar
*loglevel_type
)
1025 if (!loglevel_type
) {
1029 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1030 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1031 } else if (!strcmp((char *) loglevel_type
,
1032 config_loglevel_type_range
)) {
1033 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1034 } else if (!strcmp((char *) loglevel_type
,
1035 config_loglevel_type_single
)) {
1036 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1047 * Return the context type or -1 on error.
1050 int get_context_type(xmlChar
*context_type
)
1054 if (!context_type
) {
1058 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1059 ret
= LTTNG_EVENT_CONTEXT_PID
;
1060 } else if (!strcmp((char *) context_type
,
1061 config_event_context_procname
)) {
1062 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1063 } else if (!strcmp((char *) context_type
,
1064 config_event_context_prio
)) {
1065 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1066 } else if (!strcmp((char *) context_type
,
1067 config_event_context_nice
)) {
1068 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1069 } else if (!strcmp((char *) context_type
,
1070 config_event_context_vpid
)) {
1071 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1072 } else if (!strcmp((char *) context_type
,
1073 config_event_context_tid
)) {
1074 ret
= LTTNG_EVENT_CONTEXT_TID
;
1075 } else if (!strcmp((char *) context_type
,
1076 config_event_context_vtid
)) {
1077 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1078 } else if (!strcmp((char *) context_type
,
1079 config_event_context_ppid
)) {
1080 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1081 } else if (!strcmp((char *) context_type
,
1082 config_event_context_vppid
)) {
1083 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1084 } else if (!strcmp((char *) context_type
,
1085 config_event_context_pthread_id
)) {
1086 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1087 } else if (!strcmp((char *) context_type
,
1088 config_event_context_hostname
)) {
1089 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1090 } else if (!strcmp((char *) context_type
,
1091 config_event_context_ip
)) {
1092 ret
= LTTNG_EVENT_CONTEXT_IP
;
1093 } else if (!strcmp((char *) context_type
,
1094 config_event_context_interruptible
)) {
1095 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1096 } else if (!strcmp((char *) context_type
,
1097 config_event_context_preemptible
)) {
1098 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1099 } else if (!strcmp((char *) context_type
,
1100 config_event_context_need_reschedule
)) {
1101 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1102 } else if (!strcmp((char *) context_type
,
1103 config_event_context_migratable
)) {
1104 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1105 } else if (!strcmp((char *) context_type
,
1106 config_event_context_callstack_user
)) {
1107 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1108 } else if (!strcmp((char *) context_type
,
1109 config_event_context_callstack_kernel
)) {
1110 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1111 } else if (!strcmp((char *) context_type
,
1112 config_event_context_cgroup_ns
)) {
1113 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1114 } else if (!strcmp((char *) context_type
,
1115 config_event_context_ipc_ns
)) {
1116 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1117 } else if (!strcmp((char *) context_type
,
1118 config_event_context_mnt_ns
)) {
1119 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1120 } else if (!strcmp((char *) context_type
,
1121 config_event_context_net_ns
)) {
1122 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1123 } else if (!strcmp((char *) context_type
,
1124 config_event_context_pid_ns
)) {
1125 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1126 } else if (!strcmp((char *) context_type
,
1127 config_event_context_time_ns
)) {
1128 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1129 } else if (!strcmp((char *) context_type
,
1130 config_event_context_user_ns
)) {
1131 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1132 } else if (!strcmp((char *) context_type
,
1133 config_event_context_uts_ns
)) {
1134 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1135 } else if (!strcmp((char *) context_type
,
1136 config_event_context_uid
)) {
1137 ret
= LTTNG_EVENT_CONTEXT_UID
;
1138 } else if (!strcmp((char *) context_type
,
1139 config_event_context_euid
)) {
1140 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1141 } else if (!strcmp((char *) context_type
,
1142 config_event_context_suid
)) {
1143 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1144 } else if (!strcmp((char *) context_type
,
1145 config_event_context_gid
)) {
1146 ret
= LTTNG_EVENT_CONTEXT_GID
;
1147 } else if (!strcmp((char *) context_type
,
1148 config_event_context_egid
)) {
1149 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1150 } else if (!strcmp((char *) context_type
,
1151 config_event_context_sgid
)) {
1152 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1153 } else if (!strcmp((char *) context_type
,
1154 config_event_context_vuid
)) {
1155 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1156 } else if (!strcmp((char *) context_type
,
1157 config_event_context_veuid
)) {
1158 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1159 } else if (!strcmp((char *) context_type
,
1160 config_event_context_vsuid
)) {
1161 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1162 } else if (!strcmp((char *) context_type
,
1163 config_event_context_vgid
)) {
1164 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1165 } else if (!strcmp((char *) context_type
,
1166 config_event_context_vegid
)) {
1167 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1168 } else if (!strcmp((char *) context_type
,
1169 config_event_context_vsgid
)) {
1170 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1181 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1186 for (node
= xmlFirstElementChild(domain_node
); node
;
1187 node
= xmlNextElementSibling(node
)) {
1188 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1190 xmlChar
*node_content
= xmlNodeGetContent(node
);
1191 if (!node_content
) {
1192 ret
= -LTTNG_ERR_NOMEM
;
1196 ret
= get_domain_type(node_content
);
1199 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1204 } else if (!strcmp((const char *) node
->name
,
1205 config_element_buffer_type
)) {
1207 xmlChar
*node_content
= xmlNodeGetContent(node
);
1208 if (!node_content
) {
1209 ret
= -LTTNG_ERR_NOMEM
;
1213 ret
= get_buffer_type(node_content
);
1216 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1220 domain
->buf_type
= ret
;
1229 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1234 for (node
= xmlFirstElementChild(net_output_node
); node
;
1235 node
= xmlNextElementSibling(node
)) {
1236 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1238 *control_uri
= (char *) xmlNodeGetContent(node
);
1239 if (!*control_uri
) {
1244 *data_uri
= (char *) xmlNodeGetContent(node
);
1251 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1255 int process_consumer_output(xmlNodePtr consumer_output_node
,
1256 struct consumer_output
*output
)
1263 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1264 node
= xmlNextElementSibling(node
)) {
1265 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1266 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1270 ret
= -LTTNG_ERR_NOMEM
;
1274 ret
= parse_bool(enabled_str
, &output
->enabled
);
1280 xmlNodePtr output_type_node
;
1283 output_type_node
= xmlFirstElementChild(node
);
1284 if (!output_type_node
) {
1285 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1289 if (!strcmp((const char *) output_type_node
->name
,
1290 config_element_path
)) {
1292 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1293 if (!output
->path
) {
1294 ret
= -LTTNG_ERR_NOMEM
;
1299 ret
= get_net_output_uris(output_type_node
,
1300 &output
->control_uri
, &output
->data_uri
);
1312 free(output
->control_uri
);
1313 free(output
->data_uri
);
1314 memset(output
, 0, sizeof(struct consumer_output
));
1320 int create_session_net_output(const char *name
, const char *control_uri
,
1321 const char *data_uri
)
1324 struct lttng_handle
*handle
;
1325 const char *uri
= NULL
;
1329 handle
= lttng_create_handle(name
, NULL
);
1331 ret
= -LTTNG_ERR_NOMEM
;
1335 if (!control_uri
|| !data_uri
) {
1336 uri
= control_uri
? control_uri
: data_uri
;
1341 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1342 lttng_destroy_handle(handle
);
1348 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1349 const struct config_load_session_override_attr
*overrides
)
1352 xmlNodePtr node
= NULL
;
1353 xmlNodePtr snapshot_output_list_node
;
1354 xmlNodePtr snapshot_output_node
;
1356 assert(session_name
);
1358 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1367 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1369 /* Parse and create snapshot outputs */
1371 for (snapshot_output_node
=
1372 xmlFirstElementChild(snapshot_output_list_node
);
1373 snapshot_output_node
; snapshot_output_node
=
1374 xmlNextElementSibling(snapshot_output_node
)) {
1376 uint64_t max_size
= UINT64_MAX
;
1377 struct consumer_output output
= { 0 };
1378 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1379 const char *control_uri
= NULL
;
1380 const char *data_uri
= NULL
;
1381 const char *path
= NULL
;
1383 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1384 node
= xmlNextElementSibling(node
)) {
1385 if (!strcmp((const char *) node
->name
,
1386 config_element_name
)) {
1388 name
= (char *) xmlNodeGetContent(node
);
1390 ret
= -LTTNG_ERR_NOMEM
;
1391 goto error_snapshot_output
;
1393 } else if (!strcmp((const char *) node
->name
,
1394 config_element_max_size
)) {
1395 xmlChar
*content
= xmlNodeGetContent(node
);
1399 ret
= -LTTNG_ERR_NOMEM
;
1400 goto error_snapshot_output
;
1402 ret
= parse_uint(content
, &max_size
);
1405 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1406 goto error_snapshot_output
;
1409 /* consumer_output */
1410 ret
= process_consumer_output(node
, &output
);
1412 goto error_snapshot_output
;
1417 control_uri
= output
.control_uri
;
1418 data_uri
= output
.data_uri
;
1422 if (overrides
->path_url
) {
1423 path
= overrides
->path_url
;
1424 /* Control/data_uri are null */
1428 if (overrides
->ctrl_url
) {
1429 control_uri
= overrides
->ctrl_url
;
1433 if (overrides
->data_url
) {
1434 data_uri
= overrides
->data_url
;
1441 snapshot_output
= lttng_snapshot_output_create();
1442 if (!snapshot_output
) {
1443 ret
= -LTTNG_ERR_NOMEM
;
1444 goto error_snapshot_output
;
1447 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1449 goto error_snapshot_output
;
1452 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1454 goto error_snapshot_output
;
1458 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1461 goto error_snapshot_output
;
1465 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1468 goto error_snapshot_output
;
1473 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1476 goto error_snapshot_output
;
1481 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1482 error_snapshot_output
:
1485 free(output
.control_uri
);
1486 free(output
.data_uri
);
1487 lttng_snapshot_output_destroy(snapshot_output
);
1497 int create_session(const char *name
,
1498 xmlNodePtr output_node
,
1499 uint64_t live_timer_interval
,
1500 const struct config_load_session_override_attr
*overrides
)
1503 struct consumer_output output
= { 0 };
1504 xmlNodePtr consumer_output_node
;
1505 const char *control_uri
= NULL
;
1506 const char *data_uri
= NULL
;
1507 const char *path
= NULL
;
1512 consumer_output_node
= xmlFirstElementChild(output_node
);
1513 if (!consumer_output_node
) {
1514 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1518 if (strcmp((const char *) consumer_output_node
->name
,
1519 config_element_consumer_output
)) {
1520 WARN("Invalid output type, expected %s node",
1521 config_element_consumer_output
);
1522 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1526 ret
= process_consumer_output(consumer_output_node
, &output
);
1532 control_uri
= output
.control_uri
;
1533 data_uri
= output
.data_uri
;
1536 /* Check for override and apply them */
1538 if (overrides
->path_url
) {
1539 path
= overrides
->path_url
;
1540 /* control/data_uri are null */;
1544 if (overrides
->ctrl_url
) {
1545 control_uri
= overrides
->ctrl_url
;
1549 if (overrides
->data_url
) {
1550 data_uri
= overrides
->data_url
;
1558 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1559 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1563 if (control_uri
|| data_uri
) {
1564 /* network destination */
1565 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1567 * URLs are provided for sure since the test above make sure that
1568 * with a live timer the data and control URIs are provided. So,
1569 * NULL is passed here and will be set right after.
1571 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1573 ret
= lttng_create_session(name
, NULL
);
1579 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1585 /* either local output or no output */
1586 ret
= lttng_create_session(name
, path
);
1593 free(output
.control_uri
);
1594 free(output
.data_uri
);
1599 struct lttng_userspace_probe_location
*
1600 process_userspace_probe_function_attribute_node(
1601 xmlNodePtr attribute_node
)
1603 xmlNodePtr function_attribute_node
;
1604 char *function_name
= NULL
, *binary_path
= NULL
;
1605 struct lttng_userspace_probe_location
*location
= NULL
;
1606 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1609 * Process userspace probe location function attributes. The order of
1610 * the fields are not guaranteed so we need to iterate over all fields
1611 * and check at the end if everything we need for this location type is
1614 for (function_attribute_node
=
1615 xmlFirstElementChild(attribute_node
);
1616 function_attribute_node
;
1617 function_attribute_node
= xmlNextElementSibling(
1618 function_attribute_node
)) {
1619 /* Handle function name, binary path and lookup method. */
1620 if (!strcmp((const char *) function_attribute_node
->name
,
1621 config_element_userspace_probe_function_location_function_name
)) {
1622 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1623 if (!function_name
) {
1626 } else if (!strcmp((const char *) function_attribute_node
->name
,
1627 config_element_userspace_probe_location_binary_path
)) {
1628 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1632 } else if (!strcmp((const char *) function_attribute_node
->name
,
1633 config_element_userspace_probe_lookup
)) {
1634 char *lookup_method_name
;
1636 lookup_method_name
= (char *) xmlNodeGetContent(
1637 function_attribute_node
);
1638 if (!lookup_method_name
) {
1643 * function_default lookup method defaults to
1644 * function_elf lookup method at the moment.
1646 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1647 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1648 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1649 if (!lookup_method
) {
1650 PERROR("Error creating function default/ELF lookup method");
1653 WARN("Unknown function lookup method");
1656 free(lookup_method_name
);
1657 if (!lookup_method
) {
1664 /* Check if all the necessary fields were found. */
1665 if (binary_path
&& function_name
&& lookup_method
) {
1666 /* Ownership of lookup_method is transferred. */
1668 lttng_userspace_probe_location_function_create(
1669 binary_path
, function_name
,
1671 lookup_method
= NULL
;
1676 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1678 free(function_name
);
1683 struct lttng_userspace_probe_location
*
1684 process_userspace_probe_tracepoint_attribute_node(
1685 xmlNodePtr attribute_node
)
1687 xmlNodePtr tracepoint_attribute_node
;
1688 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1689 struct lttng_userspace_probe_location
*location
= NULL
;
1690 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1693 * Process userspace probe location tracepoint attributes. The order of
1694 * the fields are not guaranteed so we need to iterate over all fields
1695 * and check at the end if everything we need for this location type is
1698 for (tracepoint_attribute_node
=
1699 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1700 tracepoint_attribute_node
= xmlNextElementSibling(
1701 tracepoint_attribute_node
)) {
1702 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1703 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1704 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1708 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1709 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1710 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1711 if (!provider_name
) {
1714 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1715 config_element_userspace_probe_location_binary_path
)) {
1716 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1720 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1721 config_element_userspace_probe_lookup
)) {
1722 char *lookup_method_name
;
1724 lookup_method_name
= (char *) xmlNodeGetContent(
1725 tracepoint_attribute_node
);
1726 if (!lookup_method_name
) {
1730 if (!strcmp(lookup_method_name
,
1731 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1733 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1734 if (!lookup_method
) {
1735 PERROR("Error creating tracepoint SDT lookup method");
1738 WARN("Unknown tracepoint lookup method");
1741 free(lookup_method_name
);
1742 if (!lookup_method
) {
1746 WARN("Unknown tracepoint attribute");
1750 /* Check if all the necessary fields were found. */
1751 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1752 /* Ownership of lookup_method is transferred. */
1754 lttng_userspace_probe_location_tracepoint_create(
1755 binary_path
, provider_name
,
1756 probe_name
, lookup_method
);
1757 lookup_method
= NULL
;
1762 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1764 free(provider_name
);
1770 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1771 struct lttng_event_probe_attr
*attr
)
1775 assert(probe_attribute_node
);
1778 if (!strcmp((const char *) probe_attribute_node
->name
,
1779 config_element_address
)) {
1784 content
= xmlNodeGetContent(probe_attribute_node
);
1786 ret
= -LTTNG_ERR_NOMEM
;
1790 ret
= parse_uint(content
, &addr
);
1793 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1798 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1799 config_element_offset
)) {
1801 uint64_t offset
= 0;
1804 content
= xmlNodeGetContent(probe_attribute_node
);
1806 ret
= -LTTNG_ERR_NOMEM
;
1810 ret
= parse_uint(content
, &offset
);
1813 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1817 attr
->offset
= offset
;
1818 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1819 config_element_symbol_name
)) {
1823 content
= xmlNodeGetContent(probe_attribute_node
);
1825 ret
= -LTTNG_ERR_NOMEM
;
1829 ret
= lttng_strncpy(attr
->symbol_name
,
1830 (const char *) content
,
1831 LTTNG_SYMBOL_NAME_LEN
);
1833 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1834 (const char *) content
,
1835 strlen((const char *) content
),
1836 LTTNG_SYMBOL_NAME_LEN
);
1837 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1849 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1850 const char *channel_name
, const enum process_event_node_phase phase
)
1854 struct lttng_event
*event
;
1855 char **exclusions
= NULL
;
1856 unsigned long exclusion_count
= 0;
1857 char *filter_expression
= NULL
;
1861 assert(channel_name
);
1863 event
= lttng_event_create();
1865 ret
= -LTTNG_ERR_NOMEM
;
1869 /* Initialize default log level which varies by domain */
1870 switch (handle
->domain
.type
)
1872 case LTTNG_DOMAIN_JUL
:
1873 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1875 case LTTNG_DOMAIN_LOG4J
:
1876 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1878 case LTTNG_DOMAIN_PYTHON
:
1879 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1881 case LTTNG_DOMAIN_UST
:
1882 case LTTNG_DOMAIN_KERNEL
:
1883 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1889 for (node
= xmlFirstElementChild(event_node
); node
;
1890 node
= xmlNextElementSibling(node
)) {
1891 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1895 content
= xmlNodeGetContent(node
);
1897 ret
= -LTTNG_ERR_NOMEM
;
1901 ret
= lttng_strncpy(event
->name
,
1902 (const char *) content
,
1903 LTTNG_SYMBOL_NAME_LEN
);
1905 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1906 (const char *) content
,
1907 strlen((const char *) content
),
1908 LTTNG_SYMBOL_NAME_LEN
);
1909 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1914 } else if (!strcmp((const char *) node
->name
,
1915 config_element_enabled
)) {
1916 xmlChar
*content
= xmlNodeGetContent(node
);
1920 ret
= -LTTNG_ERR_NOMEM
;
1924 ret
= parse_bool(content
, &event
->enabled
);
1927 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1930 } else if (!strcmp((const char *) node
->name
,
1931 config_element_type
)) {
1932 xmlChar
*content
= xmlNodeGetContent(node
);
1936 ret
= -LTTNG_ERR_NOMEM
;
1940 ret
= get_event_type(content
);
1943 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1948 } else if (!strcmp((const char *) node
->name
,
1949 config_element_loglevel_type
)) {
1950 xmlChar
*content
= xmlNodeGetContent(node
);
1954 ret
= -LTTNG_ERR_NOMEM
;
1958 ret
= get_loglevel_type(content
);
1961 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1965 event
->loglevel_type
= ret
;
1966 } else if (!strcmp((const char *) node
->name
,
1967 config_element_loglevel
)) {
1969 int64_t loglevel
= 0;
1972 content
= xmlNodeGetContent(node
);
1974 ret
= -LTTNG_ERR_NOMEM
;
1978 ret
= parse_int(content
, &loglevel
);
1981 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1985 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1986 WARN("loglevel out of range.");
1987 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1991 event
->loglevel
= loglevel
;
1992 } else if (!strcmp((const char *) node
->name
,
1993 config_element_filter
)) {
1995 xmlNodeGetContent(node
);
1999 ret
= -LTTNG_ERR_NOMEM
;
2003 free(filter_expression
);
2004 filter_expression
= strdup((char *) content
);
2006 if (!filter_expression
) {
2007 ret
= -LTTNG_ERR_NOMEM
;
2010 } else if (!strcmp((const char *) node
->name
,
2011 config_element_exclusions
)) {
2012 xmlNodePtr exclusion_node
;
2013 int exclusion_index
= 0;
2018 * Exclusions has already been initialized,
2021 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2025 exclusion_count
= xmlChildElementCount(node
);
2026 if (!exclusion_count
) {
2030 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2032 exclusion_count
= 0;
2033 ret
= -LTTNG_ERR_NOMEM
;
2037 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2038 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2040 xmlNodeGetContent(exclusion_node
);
2043 ret
= -LTTNG_ERR_NOMEM
;
2047 exclusions
[exclusion_index
] = strdup((const char *) content
);
2049 if (!exclusions
[exclusion_index
]) {
2050 ret
= -LTTNG_ERR_NOMEM
;
2056 event
->exclusion
= 1;
2057 } else if (!strcmp((const char *) node
->name
,
2058 config_element_attributes
)) {
2059 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2062 if (!attribute_node
) {
2063 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2067 if (!strcmp((const char *) attribute_node
->name
,
2068 config_element_probe_attributes
)) {
2069 xmlNodePtr probe_attribute_node
;
2071 /* probe_attributes */
2072 for (probe_attribute_node
=
2073 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2074 probe_attribute_node
= xmlNextElementSibling(
2075 probe_attribute_node
)) {
2077 ret
= process_probe_attribute_node(probe_attribute_node
,
2078 &event
->attr
.probe
);
2083 } else if (!strcmp((const char *) attribute_node
->name
,
2084 config_element_function_attributes
)) {
2087 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2089 /* function_attributes */
2090 content
= xmlNodeGetContent(symbol_node
);
2092 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2096 sym_len
= strlen((char *) content
);
2097 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2098 WARN("Function name too long.");
2099 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2104 ret
= lttng_strncpy(
2105 event
->attr
.ftrace
.symbol_name
,
2106 (char *) content
, sym_len
);
2108 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2113 } else if (!strcmp((const char *) attribute_node
->name
,
2114 config_element_userspace_probe_tracepoint_attributes
)) {
2115 struct lttng_userspace_probe_location
*location
;
2117 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2119 WARN("Error processing userspace probe tracepoint attribute");
2120 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2123 ret
= lttng_event_set_userspace_probe_location(
2126 WARN("Error setting userspace probe location field");
2127 lttng_userspace_probe_location_destroy(
2129 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2132 } else if (!strcmp((const char *) attribute_node
->name
,
2133 config_element_userspace_probe_function_attributes
)) {
2134 struct lttng_userspace_probe_location
*location
;
2137 process_userspace_probe_function_attribute_node(
2140 WARN("Error processing userspace probe function attribute");
2141 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2145 ret
= lttng_event_set_userspace_probe_location(
2148 WARN("Error setting userspace probe location field");
2149 lttng_userspace_probe_location_destroy(
2151 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2155 /* Unknown event attribute. */
2156 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2162 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2163 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2164 filter_expression
, exclusion_count
, exclusions
);
2166 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2167 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2173 for (i
= 0; i
< exclusion_count
; i
++) {
2174 free(exclusions
[i
]);
2177 lttng_event_destroy(event
);
2179 free(filter_expression
);
2184 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2185 const char *channel_name
)
2188 struct lttng_event event
;
2191 assert(events_node
);
2193 assert(channel_name
);
2195 for (node
= xmlFirstElementChild(events_node
); node
;
2196 node
= xmlNextElementSibling(node
)) {
2197 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2204 * Disable all events to enable only the necessary events.
2205 * Limitations regarding lttng_disable_events and tuple descriptor
2206 * force this approach.
2208 memset(&event
, 0, sizeof(event
));
2209 event
.loglevel
= -1;
2210 event
.type
= LTTNG_EVENT_ALL
;
2211 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2216 for (node
= xmlFirstElementChild(events_node
); node
;
2217 node
= xmlNextElementSibling(node
)) {
2218 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2229 int process_channel_attr_node(xmlNodePtr attr_node
,
2230 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2231 xmlNodePtr
*events_node
)
2237 assert(contexts_node
);
2238 assert(events_node
);
2240 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2244 content
= xmlNodeGetContent(attr_node
);
2246 ret
= -LTTNG_ERR_NOMEM
;
2250 ret
= lttng_strncpy(channel
->name
,
2251 (const char *) content
,
2252 LTTNG_SYMBOL_NAME_LEN
);
2254 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2255 (const char *) content
,
2256 strlen((const char *) content
),
2257 LTTNG_SYMBOL_NAME_LEN
);
2258 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2263 } else if (!strcmp((const char *) attr_node
->name
,
2264 config_element_enabled
)) {
2269 content
= xmlNodeGetContent(attr_node
);
2271 ret
= -LTTNG_ERR_NOMEM
;
2275 ret
= parse_bool(content
, &enabled
);
2278 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2282 channel
->enabled
= enabled
;
2283 } else if (!strcmp((const char *) attr_node
->name
,
2284 config_element_overwrite_mode
)) {
2287 /* overwrite_mode */
2288 content
= xmlNodeGetContent(attr_node
);
2290 ret
= -LTTNG_ERR_NOMEM
;
2294 ret
= get_overwrite_mode(content
);
2297 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2301 channel
->attr
.overwrite
= ret
;
2302 } else if (!strcmp((const char *) attr_node
->name
,
2303 config_element_subbuf_size
)) {
2306 /* subbuffer_size */
2307 content
= xmlNodeGetContent(attr_node
);
2309 ret
= -LTTNG_ERR_NOMEM
;
2313 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2316 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2319 } else if (!strcmp((const char *) attr_node
->name
,
2320 config_element_num_subbuf
)) {
2323 /* subbuffer_count */
2324 content
= xmlNodeGetContent(attr_node
);
2326 ret
= -LTTNG_ERR_NOMEM
;
2330 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2333 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2336 } else if (!strcmp((const char *) attr_node
->name
,
2337 config_element_switch_timer_interval
)) {
2339 uint64_t switch_timer_interval
= 0;
2341 /* switch_timer_interval */
2342 content
= xmlNodeGetContent(attr_node
);
2344 ret
= -LTTNG_ERR_NOMEM
;
2348 ret
= parse_uint(content
, &switch_timer_interval
);
2351 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2355 if (switch_timer_interval
> UINT_MAX
) {
2356 WARN("switch_timer_interval out of range.");
2357 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2361 channel
->attr
.switch_timer_interval
=
2362 switch_timer_interval
;
2363 } else if (!strcmp((const char *) attr_node
->name
,
2364 config_element_read_timer_interval
)) {
2366 uint64_t read_timer_interval
= 0;
2368 /* read_timer_interval */
2369 content
= xmlNodeGetContent(attr_node
);
2371 ret
= -LTTNG_ERR_NOMEM
;
2375 ret
= parse_uint(content
, &read_timer_interval
);
2378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2382 if (read_timer_interval
> UINT_MAX
) {
2383 WARN("read_timer_interval out of range.");
2384 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2388 channel
->attr
.read_timer_interval
=
2389 read_timer_interval
;
2390 } else if (!strcmp((const char *) attr_node
->name
,
2391 config_element_output_type
)) {
2395 content
= xmlNodeGetContent(attr_node
);
2397 ret
= -LTTNG_ERR_NOMEM
;
2401 ret
= get_output_type(content
);
2404 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2408 channel
->attr
.output
= ret
;
2409 } else if (!strcmp((const char *) attr_node
->name
,
2410 config_element_tracefile_size
)) {
2413 /* tracefile_size */
2414 content
= xmlNodeGetContent(attr_node
);
2416 ret
= -LTTNG_ERR_NOMEM
;
2420 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2423 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2426 } else if (!strcmp((const char *) attr_node
->name
,
2427 config_element_tracefile_count
)) {
2430 /* tracefile_count */
2431 content
= xmlNodeGetContent(attr_node
);
2433 ret
= -LTTNG_ERR_NOMEM
;
2437 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2440 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2443 } else if (!strcmp((const char *) attr_node
->name
,
2444 config_element_live_timer_interval
)) {
2446 uint64_t live_timer_interval
= 0;
2448 /* live_timer_interval */
2449 content
= xmlNodeGetContent(attr_node
);
2451 ret
= -LTTNG_ERR_NOMEM
;
2455 ret
= parse_uint(content
, &live_timer_interval
);
2458 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2462 if (live_timer_interval
> UINT_MAX
) {
2463 WARN("live_timer_interval out of range.");
2464 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2468 channel
->attr
.live_timer_interval
=
2469 live_timer_interval
;
2470 } else if (!strcmp((const char *) attr_node
->name
,
2471 config_element_monitor_timer_interval
)) {
2473 uint64_t monitor_timer_interval
= 0;
2475 /* monitor_timer_interval */
2476 content
= xmlNodeGetContent(attr_node
);
2478 ret
= -LTTNG_ERR_NOMEM
;
2482 ret
= parse_uint(content
, &monitor_timer_interval
);
2485 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2489 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2490 monitor_timer_interval
);
2492 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2495 } else if (!strcmp((const char *) attr_node
->name
,
2496 config_element_blocking_timeout
)) {
2498 int64_t blocking_timeout
= 0;
2500 /* blocking_timeout */
2501 content
= xmlNodeGetContent(attr_node
);
2503 ret
= -LTTNG_ERR_NOMEM
;
2507 ret
= parse_int(content
, &blocking_timeout
);
2510 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2514 ret
= lttng_channel_set_blocking_timeout(channel
,
2517 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2520 } else if (!strcmp((const char *) attr_node
->name
,
2521 config_element_events
)) {
2523 *events_node
= attr_node
;
2526 *contexts_node
= attr_node
;
2534 int process_context_node(xmlNodePtr context_node
,
2535 struct lttng_handle
*handle
, const char *channel_name
)
2538 struct lttng_event_context context
;
2539 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2542 assert(channel_name
);
2544 if (!context_child_node
) {
2545 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2549 memset(&context
, 0, sizeof(context
));
2551 if (!strcmp((const char *) context_child_node
->name
,
2552 config_element_type
)) {
2554 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2557 ret
= -LTTNG_ERR_NOMEM
;
2561 ret
= get_context_type(content
);
2564 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2569 } else if (!strcmp((const char *) context_child_node
->name
,
2570 config_element_context_perf
)) {
2572 xmlNodePtr perf_attr_node
;
2574 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2575 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2576 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2577 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2578 perf_attr_node
; perf_attr_node
=
2579 xmlNextElementSibling(perf_attr_node
)) {
2580 if (!strcmp((const char *) perf_attr_node
->name
,
2581 config_element_type
)) {
2586 content
= xmlNodeGetContent(perf_attr_node
);
2588 ret
= -LTTNG_ERR_NOMEM
;
2592 ret
= parse_uint(content
, &type
);
2595 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2599 if (type
> UINT32_MAX
) {
2600 WARN("perf context type out of range.");
2601 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2605 context
.u
.perf_counter
.type
= type
;
2606 } else if (!strcmp((const char *) perf_attr_node
->name
,
2607 config_element_config
)) {
2609 uint64_t config
= 0;
2612 content
= xmlNodeGetContent(perf_attr_node
);
2614 ret
= -LTTNG_ERR_NOMEM
;
2618 ret
= parse_uint(content
, &config
);
2621 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2625 context
.u
.perf_counter
.config
= config
;
2626 } else if (!strcmp((const char *) perf_attr_node
->name
,
2627 config_element_name
)) {
2631 content
= xmlNodeGetContent(perf_attr_node
);
2633 ret
= -LTTNG_ERR_NOMEM
;
2637 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2638 (const char *) content
,
2639 LTTNG_SYMBOL_NAME_LEN
);
2641 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2642 (const char *) content
,
2643 strlen((const char *) content
),
2644 LTTNG_SYMBOL_NAME_LEN
);
2645 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2652 } else if (!strcmp((const char *) context_child_node
->name
,
2653 config_element_context_app
)) {
2654 /* application context */
2655 xmlNodePtr app_ctx_node
;
2657 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2658 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2659 app_ctx_node
; app_ctx_node
=
2660 xmlNextElementSibling(app_ctx_node
)) {
2662 char **target
= strcmp(
2663 (const char *) app_ctx_node
->name
,
2664 config_element_context_app_provider_name
) == 0 ?
2665 &context
.u
.app_ctx
.provider_name
:
2666 &context
.u
.app_ctx
.ctx_name
;
2668 content
= xmlNodeGetContent(app_ctx_node
);
2670 ret
= -LTTNG_ERR_NOMEM
;
2674 *target
= (char *) content
;
2677 /* Unrecognized context type */
2678 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2682 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2683 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2684 free(context
.u
.app_ctx
.provider_name
);
2685 free(context
.u
.app_ctx
.ctx_name
);
2692 int process_contexts_node(xmlNodePtr contexts_node
,
2693 struct lttng_handle
*handle
, const char *channel_name
)
2696 xmlNodePtr context_node
;
2698 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2699 context_node
= xmlNextElementSibling(context_node
)) {
2700 ret
= process_context_node(context_node
, handle
, channel_name
);
2709 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2710 const char **element_id_tracker
,
2711 const char **element_value_type
,
2712 const char **element_value
,
2713 const char **element_value_alias
,
2714 const char **element_name
)
2718 switch (process_attr
) {
2719 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2720 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2721 *element_value_type
= config_element_process_attr_pid_value
;
2722 *element_value
= config_element_process_attr_id
;
2723 *element_value_alias
= config_element_process_attr_id
;
2724 *element_name
= NULL
;
2726 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2727 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2728 *element_value_type
= config_element_process_attr_vpid_value
;
2729 *element_value
= config_element_process_attr_id
;
2730 *element_value_alias
= NULL
;
2731 *element_name
= NULL
;
2733 case LTTNG_PROCESS_ATTR_USER_ID
:
2734 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2735 *element_value_type
= config_element_process_attr_uid_value
;
2736 *element_value
= config_element_process_attr_id
;
2737 *element_value_alias
= NULL
;
2738 *element_name
= config_element_name
;
2740 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2741 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2742 *element_value_type
= config_element_process_attr_vuid_value
;
2743 *element_value
= config_element_process_attr_id
;
2744 *element_value_alias
= NULL
;
2745 *element_name
= config_element_name
;
2747 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2748 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2749 *element_value_type
= config_element_process_attr_gid_value
;
2750 *element_value
= config_element_process_attr_id
;
2751 *element_value_alias
= NULL
;
2752 *element_name
= config_element_name
;
2754 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2755 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2756 *element_value_type
= config_element_process_attr_vgid_value
;
2757 *element_value
= config_element_process_attr_id
;
2758 *element_value_alias
= NULL
;
2759 *element_name
= config_element_name
;
2762 ret
= LTTNG_ERR_INVALID
;
2767 static int process_legacy_pid_tracker_node(
2768 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2770 int ret
= 0, child_count
;
2771 xmlNodePtr targets_node
= NULL
;
2773 const char *element_id_tracker
;
2774 const char *element_target_id
;
2775 const char *element_id
;
2776 const char *element_id_alias
;
2777 const char *element_name
;
2778 enum lttng_error_code tracker_handle_ret_code
;
2779 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2780 enum lttng_process_attr_tracker_handle_status status
;
2781 const enum lttng_process_attr process_attr
=
2782 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2783 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2784 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2788 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2789 handle
->session_name
, handle
->domain
.type
,
2792 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2793 ret
= LTTNG_ERR_INVALID
;
2797 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2798 &element_target_id
, &element_id
, &element_id_alias
,
2804 /* Get the targets node */
2805 for (node
= xmlFirstElementChild(trackers_node
); node
;
2806 node
= xmlNextElementSibling(node
)) {
2807 if (!strcmp((const char *) node
->name
,
2808 config_element_tracker_targets_legacy
)) {
2809 targets_node
= node
;
2814 if (!targets_node
) {
2815 ret
= LTTNG_ERR_INVALID
;
2819 /* Go through all id target node */
2820 child_count
= xmlChildElementCount(targets_node
);
2821 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2823 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2824 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2825 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2826 ret
= LTTNG_ERR_UNK
;
2830 /* Add all tracked values. */
2831 for (node
= xmlFirstElementChild(targets_node
); node
;
2832 node
= xmlNextElementSibling(node
)) {
2833 xmlNodePtr pid_target_node
= node
;
2835 /* get pid_target node and track it */
2836 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2837 node
= xmlNextElementSibling(node
)) {
2838 if (!strcmp((const char *) node
->name
,
2839 config_element_tracker_pid_legacy
)) {
2841 xmlChar
*content
= xmlNodeGetContent(node
);
2844 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2848 ret
= parse_int(content
, &id
);
2851 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2855 switch (process_attr
) {
2856 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2857 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2861 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2862 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2867 ret
= LTTNG_ERR_INVALID
;
2872 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2874 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2875 ret
= LTTNG_ERR_INVALID
;
2877 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2878 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2880 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2881 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2883 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2884 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2886 ret
= LTTNG_ERR_UNK
;
2890 node
= pid_target_node
;
2894 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2898 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2899 struct lttng_handle
*handle
,
2900 enum lttng_process_attr process_attr
)
2902 int ret
= 0, child_count
;
2903 xmlNodePtr values_node
= NULL
;
2905 const char *element_id_tracker
;
2906 const char *element_target_id
;
2907 const char *element_id
;
2908 const char *element_id_alias
;
2909 const char *element_name
;
2910 enum lttng_error_code tracker_handle_ret_code
;
2911 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2912 enum lttng_process_attr_tracker_handle_status status
;
2915 assert(id_tracker_node
);
2917 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2918 handle
->session_name
, handle
->domain
.type
, process_attr
,
2920 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2921 ret
= LTTNG_ERR_INVALID
;
2925 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2926 &element_target_id
, &element_id
, &element_id_alias
,
2932 /* get the values node */
2933 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2934 node
= xmlNextElementSibling(node
)) {
2935 if (!strcmp((const char *) node
->name
,
2936 config_element_process_attr_values
)) {
2943 ret
= LTTNG_ERR_INVALID
;
2947 /* Go through all id target node */
2948 child_count
= xmlChildElementCount(values_node
);
2949 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2951 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2952 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2953 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2954 ret
= LTTNG_ERR_UNK
;
2958 /* Add all tracked values. */
2959 for (node
= xmlFirstElementChild(values_node
); node
;
2960 node
= xmlNextElementSibling(node
)) {
2961 xmlNodePtr id_target_node
= node
;
2963 /* get id node and track it */
2964 for (node
= xmlFirstElementChild(id_target_node
); node
;
2965 node
= xmlNextElementSibling(node
)) {
2966 if (!strcmp((const char *) node
->name
, element_id
) ||
2967 (element_id_alias
&&
2968 !strcmp((const char *) node
->name
,
2969 element_id_alias
))) {
2971 xmlChar
*content
= xmlNodeGetContent(node
);
2974 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2978 ret
= parse_int(content
, &id
);
2981 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2985 switch (process_attr
) {
2986 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2987 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2991 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2992 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2996 case LTTNG_PROCESS_ATTR_USER_ID
:
2997 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
3001 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3002 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
3006 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3007 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
3011 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3012 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
3017 ret
= LTTNG_ERR_INVALID
;
3020 } else if (element_name
&&
3021 !strcmp((const char *) node
->name
,
3023 xmlChar
*content
= xmlNodeGetContent(node
);
3026 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3030 switch (process_attr
) {
3031 case LTTNG_PROCESS_ATTR_USER_ID
:
3032 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3034 (const char *) content
);
3036 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3037 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3039 (const char *) content
);
3041 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3042 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3044 (const char *) content
);
3046 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3047 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3049 (const char *) content
);
3053 ret
= LTTNG_ERR_INVALID
;
3059 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3061 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3062 ret
= LTTNG_ERR_INVALID
;
3064 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3065 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3067 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3068 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3070 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3071 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3073 ret
= LTTNG_ERR_UNK
;
3077 node
= id_target_node
;
3081 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3086 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3089 struct lttng_domain domain
= { 0 };
3090 struct lttng_handle
*handle
= NULL
;
3091 struct lttng_channel
*channel
= NULL
;
3092 xmlNodePtr channels_node
= NULL
;
3093 xmlNodePtr trackers_node
= NULL
;
3094 xmlNodePtr pid_tracker_node
= NULL
;
3095 xmlNodePtr vpid_tracker_node
= NULL
;
3096 xmlNodePtr uid_tracker_node
= NULL
;
3097 xmlNodePtr vuid_tracker_node
= NULL
;
3098 xmlNodePtr gid_tracker_node
= NULL
;
3099 xmlNodePtr vgid_tracker_node
= NULL
;
3102 assert(session_name
);
3104 ret
= init_domain(domain_node
, &domain
);
3109 handle
= lttng_create_handle(session_name
, &domain
);
3111 ret
= -LTTNG_ERR_NOMEM
;
3115 /* get the channels node */
3116 for (node
= xmlFirstElementChild(domain_node
); node
;
3117 node
= xmlNextElementSibling(node
)) {
3118 if (!strcmp((const char *) node
->name
,
3119 config_element_channels
)) {
3120 channels_node
= node
;
3125 if (!channels_node
) {
3129 /* create all channels */
3130 for (node
= xmlFirstElementChild(channels_node
); node
;
3131 node
= xmlNextElementSibling(node
)) {
3132 const enum lttng_domain_type original_domain
= domain
.type
;
3133 xmlNodePtr contexts_node
= NULL
;
3134 xmlNodePtr events_node
= NULL
;
3135 xmlNodePtr channel_attr_node
;
3138 * Channels of the "agent" types cannot be created directly.
3139 * They are meant to be created implicitly through the
3140 * activation of events in their domain. However, a user
3141 * can override the default channel configuration attributes
3142 * by creating the underlying UST channel _before_ enabling
3143 * an agent domain event.
3145 * Hence, the channel's type is substituted before the creation
3146 * and restored by the time the events are created.
3148 switch (domain
.type
) {
3149 case LTTNG_DOMAIN_JUL
:
3150 case LTTNG_DOMAIN_LOG4J
:
3151 case LTTNG_DOMAIN_PYTHON
:
3152 domain
.type
= LTTNG_DOMAIN_UST
;
3157 channel
= lttng_channel_create(&domain
);
3163 for (channel_attr_node
= xmlFirstElementChild(node
);
3164 channel_attr_node
; channel_attr_node
=
3165 xmlNextElementSibling(channel_attr_node
)) {
3166 ret
= process_channel_attr_node(channel_attr_node
,
3167 channel
, &contexts_node
, &events_node
);
3173 ret
= lttng_enable_channel(handle
, channel
);
3178 /* Restore the original channel domain. */
3179 domain
.type
= original_domain
;
3181 ret
= process_events_node(events_node
, handle
, channel
->name
);
3186 ret
= process_contexts_node(contexts_node
, handle
,
3192 lttng_channel_destroy(channel
);
3196 /* get the trackers node */
3197 for (node
= xmlFirstElementChild(domain_node
); node
;
3198 node
= xmlNextElementSibling(node
)) {
3199 if (!strcmp((const char *) node
->name
,
3200 config_element_process_attr_trackers
) ||
3201 !strcmp((const char *) node
->name
,
3202 config_element_trackers_legacy
)) {
3203 if (trackers_node
) {
3204 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3205 config_element_process_attr_trackers
,
3206 config_element_trackers_legacy
);
3210 trackers_node
= node
;
3215 if (!trackers_node
) {
3219 for (node
= xmlFirstElementChild(trackers_node
); node
;
3220 node
= xmlNextElementSibling(node
)) {
3221 if (!strcmp((const char *) node
->name
,
3222 config_element_process_attr_tracker_pid
)) {
3223 pid_tracker_node
= node
;
3224 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3225 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3230 if (!strcmp((const char *) node
->name
,
3231 config_element_process_attr_tracker_vpid
)) {
3232 vpid_tracker_node
= node
;
3233 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3234 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3239 if (!strcmp((const char *) node
->name
,
3240 config_element_process_attr_tracker_uid
)) {
3241 uid_tracker_node
= node
;
3242 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3243 LTTNG_PROCESS_ATTR_USER_ID
);
3248 if (!strcmp((const char *) node
->name
,
3249 config_element_process_attr_tracker_vuid
)) {
3250 vuid_tracker_node
= node
;
3251 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3252 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3257 if (!strcmp((const char *) node
->name
,
3258 config_element_process_attr_tracker_gid
)) {
3259 gid_tracker_node
= node
;
3260 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3261 LTTNG_PROCESS_ATTR_GROUP_ID
);
3266 if (!strcmp((const char *) node
->name
,
3267 config_element_process_attr_tracker_vgid
)) {
3268 vgid_tracker_node
= node
;
3269 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3270 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3275 if (!strcmp((const char *) node
->name
,
3276 config_element_pid_tracker_legacy
)) {
3277 ret
= process_legacy_pid_tracker_node(node
, handle
);
3285 lttng_channel_destroy(channel
);
3286 lttng_destroy_handle(handle
);
3291 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3294 enum lttng_rotation_status status
;
3295 struct lttng_rotation_schedule
*periodic
=
3296 lttng_rotation_schedule_periodic_create();
3299 ret
= -LTTNG_ERR_NOMEM
;
3303 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3305 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3306 ret
= -LTTNG_ERR_INVALID
;
3310 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3312 case LTTNG_ROTATION_STATUS_OK
:
3315 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3316 case LTTNG_ROTATION_STATUS_INVALID
:
3317 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3320 ret
= -LTTNG_ERR_UNK
;
3324 lttng_rotation_schedule_destroy(periodic
);
3329 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3332 enum lttng_rotation_status status
;
3333 struct lttng_rotation_schedule
*size
=
3334 lttng_rotation_schedule_size_threshold_create();
3337 ret
= -LTTNG_ERR_NOMEM
;
3341 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3343 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3344 ret
= -LTTNG_ERR_INVALID
;
3348 status
= lttng_session_add_rotation_schedule(name
, size
);
3350 case LTTNG_ROTATION_STATUS_OK
:
3353 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3354 case LTTNG_ROTATION_STATUS_INVALID
:
3355 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3358 ret
= -LTTNG_ERR_UNK
;
3362 lttng_rotation_schedule_destroy(size
);
3367 int process_session_rotation_schedules_node(
3368 xmlNodePtr schedules_node
,
3369 uint64_t *rotation_timer_interval
,
3370 uint64_t *rotation_size
)
3375 for (child
= xmlFirstElementChild(schedules_node
);
3377 child
= xmlNextElementSibling(child
)) {
3378 if (!strcmp((const char *) child
->name
,
3379 config_element_rotation_schedule_periodic
)) {
3381 xmlNodePtr time_us_node
;
3383 /* periodic rotation schedule */
3384 time_us_node
= xmlFirstElementChild(child
);
3385 if (!time_us_node
||
3386 strcmp((const char *) time_us_node
->name
,
3387 config_element_rotation_schedule_periodic_time_us
)) {
3388 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3393 content
= xmlNodeGetContent(time_us_node
);
3395 ret
= -LTTNG_ERR_NOMEM
;
3398 ret
= parse_uint(content
, rotation_timer_interval
);
3401 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3404 } else if (!strcmp((const char *) child
->name
,
3405 config_element_rotation_schedule_size_threshold
)) {
3407 xmlNodePtr bytes_node
;
3409 /* size_threshold rotation schedule */
3410 bytes_node
= xmlFirstElementChild(child
);
3412 strcmp((const char *) bytes_node
->name
,
3413 config_element_rotation_schedule_size_threshold_bytes
)) {
3414 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3419 content
= xmlNodeGetContent(bytes_node
);
3421 ret
= -LTTNG_ERR_NOMEM
;
3424 ret
= parse_uint(content
, rotation_size
);
3427 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3438 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3440 const struct config_load_session_override_attr
*overrides
)
3442 int ret
, started
= -1, snapshot_mode
= -1;
3443 uint64_t live_timer_interval
= UINT64_MAX
,
3444 rotation_timer_interval
= 0,
3446 xmlChar
*name
= NULL
;
3447 xmlChar
*shm_path
= NULL
;
3448 xmlNodePtr domains_node
= NULL
;
3449 xmlNodePtr output_node
= NULL
;
3451 xmlNodePtr attributes_child
;
3452 struct lttng_domain
*kernel_domain
= NULL
;
3453 struct lttng_domain
*ust_domain
= NULL
;
3454 struct lttng_domain
*jul_domain
= NULL
;
3455 struct lttng_domain
*log4j_domain
= NULL
;
3456 struct lttng_domain
*python_domain
= NULL
;
3458 for (node
= xmlFirstElementChild(session_node
); node
;
3459 node
= xmlNextElementSibling(node
)) {
3460 if (!name
&& !strcmp((const char *) node
->name
,
3461 config_element_name
)) {
3463 xmlChar
*node_content
= xmlNodeGetContent(node
);
3464 if (!node_content
) {
3465 ret
= -LTTNG_ERR_NOMEM
;
3469 name
= node_content
;
3470 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3471 config_element_domains
)) {
3473 domains_node
= node
;
3474 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3475 config_element_started
)) {
3477 xmlChar
*node_content
= xmlNodeGetContent(node
);
3478 if (!node_content
) {
3479 ret
= -LTTNG_ERR_NOMEM
;
3483 ret
= parse_bool(node_content
, &started
);
3486 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3489 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3490 config_element_output
)) {
3493 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3494 config_element_shared_memory_path
)) {
3495 /* shared memory path */
3496 xmlChar
*node_content
= xmlNodeGetContent(node
);
3497 if (!node_content
) {
3498 ret
= -LTTNG_ERR_NOMEM
;
3502 shm_path
= node_content
;
3505 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3506 * rotation_timer_interval.
3508 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3509 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3510 if (!strcmp((const char *) attributes_child
->name
,
3511 config_element_snapshot_mode
)) {
3513 xmlChar
*snapshot_mode_content
=
3514 xmlNodeGetContent(attributes_child
);
3515 if (!snapshot_mode_content
) {
3516 ret
= -LTTNG_ERR_NOMEM
;
3520 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3521 free(snapshot_mode_content
);
3523 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3526 } else if (!strcmp((const char *) attributes_child
->name
,
3527 config_element_live_timer_interval
)) {
3528 /* live_timer_interval */
3529 xmlChar
*timer_interval_content
=
3530 xmlNodeGetContent(attributes_child
);
3531 if (!timer_interval_content
) {
3532 ret
= -LTTNG_ERR_NOMEM
;
3536 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3537 free(timer_interval_content
);
3539 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3542 } else if (!strcmp((const char *) attributes_child
->name
,
3543 config_element_rotation_schedules
)) {
3544 ret
= process_session_rotation_schedules_node(
3546 &rotation_timer_interval
,
3549 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3559 /* Mandatory attribute, as defined in the session XSD */
3560 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3564 if (session_name
&& strcmp((char *) name
, session_name
)) {
3565 /* This is not the session we are looking for */
3566 ret
= -LTTNG_ERR_NO_SESSION
;
3570 /* Init domains to create the session handles */
3571 for (node
= xmlFirstElementChild(domains_node
); node
;
3572 node
= xmlNextElementSibling(node
)) {
3573 struct lttng_domain
*domain
;
3575 domain
= zmalloc(sizeof(*domain
));
3577 ret
= -LTTNG_ERR_NOMEM
;
3581 ret
= init_domain(node
, domain
);
3583 goto domain_init_error
;
3586 switch (domain
->type
) {
3587 case LTTNG_DOMAIN_KERNEL
:
3588 if (kernel_domain
) {
3589 /* Same domain seen twice, invalid! */
3590 goto domain_init_error
;
3592 kernel_domain
= domain
;
3594 case LTTNG_DOMAIN_UST
:
3596 /* Same domain seen twice, invalid! */
3597 goto domain_init_error
;
3599 ust_domain
= domain
;
3601 case LTTNG_DOMAIN_JUL
:
3603 /* Same domain seen twice, invalid! */
3604 goto domain_init_error
;
3606 jul_domain
= domain
;
3608 case LTTNG_DOMAIN_LOG4J
:
3610 /* Same domain seen twice, invalid! */
3611 goto domain_init_error
;
3613 log4j_domain
= domain
;
3615 case LTTNG_DOMAIN_PYTHON
:
3616 if (python_domain
) {
3617 /* Same domain seen twice, invalid! */
3618 goto domain_init_error
;
3620 python_domain
= domain
;
3623 WARN("Invalid domain type");
3624 goto domain_init_error
;
3629 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3633 /* Apply overrides */
3635 if (overrides
->session_name
) {
3636 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3637 if (!name_override
) {
3638 ret
= -LTTNG_ERR_NOMEM
;
3642 /* Overrides the session name to the provided name */
3644 name
= name_override
;
3649 /* Destroy session if it exists */
3650 ret
= lttng_destroy_session((const char *) name
);
3651 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3652 ERR("Failed to destroy existing session.");
3657 /* Create session type depending on output type */
3658 if (snapshot_mode
&& snapshot_mode
!= -1) {
3659 ret
= create_snapshot_session((const char *) name
, output_node
,
3661 } else if (live_timer_interval
&&
3662 live_timer_interval
!= UINT64_MAX
) {
3663 ret
= create_session((const char *) name
,
3664 output_node
, live_timer_interval
, overrides
);
3666 /* regular session */
3667 ret
= create_session((const char *) name
,
3668 output_node
, UINT64_MAX
, overrides
);
3675 ret
= lttng_set_session_shm_path((const char *) name
,
3676 (const char *) shm_path
);
3682 for (node
= xmlFirstElementChild(domains_node
); node
;
3683 node
= xmlNextElementSibling(node
)) {
3684 ret
= process_domain_node(node
, (const char *) name
);
3690 if (rotation_timer_interval
) {
3691 ret
= add_periodic_rotation((const char *) name
,
3692 rotation_timer_interval
);
3697 if (rotation_size
) {
3698 ret
= add_size_rotation((const char *) name
,
3706 ret
= lttng_start_tracing((const char *) name
);
3714 ERR("Failed to load session %s: %s", (const char *) name
,
3715 lttng_strerror(ret
));
3716 lttng_destroy_session((const char *) name
);
3720 free(kernel_domain
);
3724 free(python_domain
);
3731 * Return 1 if the given path is readable by the current UID or 0 if not.
3732 * Return -1 if the path is EPERM.
3734 static int validate_file_read_creds(const char *path
)
3740 /* Can we read the file. */
3741 ret
= access(path
, R_OK
);
3745 if (errno
== EACCES
) {
3756 int load_session_from_file(const char *path
, const char *session_name
,
3757 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3758 const struct config_load_session_override_attr
*overrides
)
3760 int ret
, session_found
= !session_name
;
3761 xmlDocPtr doc
= NULL
;
3762 xmlNodePtr sessions_node
;
3763 xmlNodePtr session_node
;
3766 assert(validation_ctx
);
3768 ret
= validate_file_read_creds(path
);
3771 ret
= -LTTNG_ERR_EPERM
;
3773 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3778 doc
= xmlParseFile(path
);
3780 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3784 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3786 ERR("Session configuration file validation failed");
3787 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3791 sessions_node
= xmlDocGetRootElement(doc
);
3792 if (!sessions_node
) {
3793 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3797 for (session_node
= xmlFirstElementChild(sessions_node
);
3798 session_node
; session_node
=
3799 xmlNextElementSibling(session_node
)) {
3800 ret
= process_session_node(session_node
,
3801 session_name
, overwrite
, overrides
);
3802 if (!session_name
&& ret
) {
3803 /* Loading error occurred. */
3805 } else if (session_name
) {
3807 /* Target session found and loaded */
3810 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3812 * Ignore this error, we are looking for a
3817 /* Loading error occurred. */
3825 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3831 int load_session_from_path(const char *path
, const char *session_name
,
3832 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3833 const struct config_load_session_override_attr
*overrides
)
3835 int ret
, session_found
= !session_name
;
3836 DIR *directory
= NULL
;
3837 struct lttng_dynamic_buffer file_path
;
3841 assert(validation_ctx
);
3842 path_len
= strlen(path
);
3843 lttng_dynamic_buffer_init(&file_path
);
3844 if (path_len
>= LTTNG_PATH_MAX
) {
3845 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3846 path
, path_len
, LTTNG_PATH_MAX
);
3847 ret
= -LTTNG_ERR_INVALID
;
3851 directory
= opendir(path
);
3855 /* Try the file loading. */
3858 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3861 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3866 size_t file_path_root_len
;
3868 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3871 ret
= -LTTNG_ERR_NOMEM
;
3875 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3877 ret
= -LTTNG_ERR_NOMEM
;
3881 if (file_path
.data
[file_path
.size
- 1] != '/') {
3882 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3884 ret
= -LTTNG_ERR_NOMEM
;
3888 file_path_root_len
= file_path
.size
;
3890 /* Search for *.lttng files */
3892 size_t file_name_len
;
3893 struct dirent
*result
;
3896 * When the end of the directory stream is reached, NULL
3897 * is returned and errno is kept unchanged. When an
3898 * error occurs, NULL is returned and errno is set
3899 * accordingly. To distinguish between the two, set
3900 * errno to zero before calling readdir().
3902 * On success, readdir() returns a pointer to a dirent
3903 * structure. This structure may be statically
3904 * allocated, do not attempt to free(3) it.
3907 result
= readdir(directory
);
3909 /* Reached end of dir stream or error out. */
3912 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3913 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3919 file_name_len
= strlen(result
->d_name
);
3921 if (file_name_len
<=
3922 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3926 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3927 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3929 /* +1 to account for NULL terminator. */
3930 file_path
.size
+ file_name_len
+ 1,
3935 /* Does the file end with .lttng? */
3936 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3937 result
->d_name
+ file_name_len
- sizeof(
3938 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3942 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3945 ret
= -LTTNG_ERR_NOMEM
;
3949 ret
= load_session_from_file(file_path
.data
, session_name
,
3950 validation_ctx
, overwrite
, overrides
);
3952 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3956 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3960 * Reset the buffer's size to the location of the
3961 * path's trailing '/'.
3963 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3964 file_path_root_len
);
3966 ret
= -LTTNG_ERR_UNK
;
3971 ret
= load_session_from_file(path
, session_name
,
3972 validation_ctx
, overwrite
, overrides
);
3982 if (closedir(directory
)) {
3986 if (!ret
&& !session_found
) {
3987 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3989 lttng_dynamic_buffer_reset(&file_path
);
3994 * Validate that the given path's credentials and the current process have the
3995 * same UID. If so, return 1 else return 0 if it does NOT match.
3997 static int validate_path_creds(const char *path
)
3999 int ret
, uid
= getuid();
4008 ret
= stat(path
, &buf
);
4010 if (errno
!= ENOENT
) {
4016 if (buf
.st_uid
!= uid
) {
4027 int config_load_session(const char *path
, const char *session_name
,
4028 int overwrite
, unsigned int autoload
,
4029 const struct config_load_session_override_attr
*overrides
)
4032 bool session_loaded
= false;
4033 const char *path_ptr
= NULL
;
4034 struct session_config_validation_ctx validation_ctx
= { 0 };
4036 ret
= init_session_config_validation_ctx(&validation_ctx
);
4042 const char *home_path
;
4043 const char *sys_path
;
4046 home_path
= utils_get_home_dir();
4048 char path_buf
[PATH_MAX
];
4051 * Try user session configuration path. Ignore error here so we can
4052 * continue loading the system wide sessions.
4055 ret
= snprintf(path_buf
, sizeof(path_buf
),
4056 DEFAULT_SESSION_HOME_CONFIGPATH
4057 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
4060 PERROR("snprintf session autoload home config path");
4061 ret
= -LTTNG_ERR_INVALID
;
4066 * Credentials are only validated for the autoload in order to
4067 * avoid any user session daemon to try to load kernel sessions
4068 * automatically and failing all the times.
4070 ret
= validate_path_creds(path_buf
);
4072 path_ptr
= path_buf
;
4075 ret
= snprintf(path_buf
, sizeof(path_buf
),
4076 DEFAULT_SESSION_HOME_CONFIGPATH
,
4079 PERROR("snprintf session home config path");
4080 ret
= -LTTNG_ERR_INVALID
;
4083 path_ptr
= path_buf
;
4086 ret
= load_session_from_path(path_ptr
, session_name
,
4087 &validation_ctx
, overwrite
, overrides
);
4088 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4092 * Continue even if the session was found since we have to try
4093 * the system wide sessions.
4095 session_loaded
= true;
4099 /* Reset path pointer for the system wide dir. */
4102 /* Try system wide configuration directory. */
4104 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4105 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4106 ret
= validate_path_creds(sys_path
);
4108 path_ptr
= sys_path
;
4111 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4112 path_ptr
= sys_path
;
4116 ret
= load_session_from_path(path_ptr
, session_name
,
4117 &validation_ctx
, overwrite
, overrides
);
4119 session_loaded
= true;
4125 ret
= access(path
, F_OK
);
4130 ret
= -LTTNG_ERR_INVALID
;
4131 WARN("Session configuration path does not exist.");
4134 ret
= -LTTNG_ERR_EPERM
;
4137 ret
= -LTTNG_ERR_UNK
;
4143 ret
= load_session_from_path(path
, session_name
,
4144 &validation_ctx
, overwrite
, overrides
);
4147 fini_session_config_validation_ctx(&validation_ctx
);
4148 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4150 * Don't report an error if no sessions are found when called
4151 * without a session_name or a search path.
4156 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4157 /* A matching session was found in one of the search paths. */
4164 void __attribute__((destructor
)) session_config_exit(void)