2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include "lttng/tracker.h"
17 #include <sys/types.h>
21 #include <common/defaults.h>
22 #include <common/error.h>
23 #include <common/macros.h>
24 #include <common/utils.h>
25 #include <common/dynamic-buffer.h>
26 #include <common/compat/getenv.h>
27 #include <lttng/lttng-error.h>
28 #include <libxml/parser.h>
29 #include <libxml/valid.h>
30 #include <libxml/xmlschemas.h>
31 #include <libxml/tree.h>
32 #include <lttng/lttng.h>
33 #include <lttng/snapshot.h>
34 #include <lttng/rotation.h>
35 #include <lttng/userspace-probe.h>
37 #include "session-config.h"
38 #include "config-internal.h"
40 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
42 struct session_config_validation_ctx
{
43 xmlSchemaParserCtxtPtr parser_ctx
;
45 xmlSchemaValidCtxtPtr schema_validation_ctx
;
48 const char * const config_element_all
= "all";
49 LTTNG_EXPORT
const char *config_xml_encoding
= "UTF-8";
50 LTTNG_EXPORT
size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
51 LTTNG_EXPORT
const char *config_xml_indent_string
= "\t";
52 LTTNG_EXPORT
const char *config_xml_true
= "true";
53 LTTNG_EXPORT
const char *config_xml_false
= "false";
55 const char * const config_element_channel
= "channel";
56 const char * const config_element_channels
= "channels";
57 const char * const config_element_domain
= "domain";
58 const char * const config_element_domains
= "domains";
59 const char * const config_element_event
= "event";
60 const char * const config_element_events
= "events";
61 const char * const config_element_context
= "context";
62 const char * const config_element_contexts
= "contexts";
63 const char * const config_element_attributes
= "attributes";
64 const char * const config_element_exclusion
= "exclusion";
65 const char * const config_element_exclusions
= "exclusions";
66 const char * const config_element_function_attributes
= "function_attributes";
67 const char * const config_element_probe_attributes
= "probe_attributes";
68 const char * const config_element_symbol_name
= "symbol_name";
69 const char * const config_element_address
= "address";
70 const char * const config_element_offset
= "offset";
72 const char * const config_element_userspace_probe_lookup
= "lookup_method";
73 const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
74 const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
75 const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
76 const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
77 const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
78 const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
79 const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
80 const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
81 const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
83 const char * const config_element_name
= "name";
84 const char * const config_element_enabled
= "enabled";
85 const char * const config_element_overwrite_mode
= "overwrite_mode";
86 const char * const config_element_subbuf_size
= "subbuffer_size";
87 const char * const config_element_num_subbuf
= "subbuffer_count";
88 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
89 const char * const config_element_read_timer_interval
= "read_timer_interval";
90 const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
91 const char * const config_element_blocking_timeout
= "blocking_timeout";
92 const char * const config_element_output
= "output";
93 const char * const config_element_output_type
= "output_type";
94 const char * const config_element_tracefile_size
= "tracefile_size";
95 const char * const config_element_tracefile_count
= "tracefile_count";
96 const char * const config_element_live_timer_interval
= "live_timer_interval";
97 const char * const config_element_discarded_events
= "discarded_events";
98 const char * const config_element_lost_packets
= "lost_packets";
99 const char * const config_element_type
= "type";
100 const char * const config_element_buffer_type
= "buffer_type";
101 const char * const config_element_session
= "session";
102 const char * const config_element_sessions
= "sessions";
103 const char * const config_element_context_perf
= "perf";
104 const char * const config_element_context_app
= "app";
105 const char * const config_element_context_app_provider_name
= "provider_name";
106 const char * const config_element_context_app_ctx_name
= "ctx_name";
107 const char * const config_element_config
= "config";
108 const char * const config_element_started
= "started";
109 const char * const config_element_snapshot_mode
= "snapshot_mode";
110 const char * const config_element_loglevel
= "loglevel";
111 const char * const config_element_loglevel_type
= "loglevel_type";
112 const char * const config_element_filter
= "filter";
113 const char * const config_element_filter_expression
= "filter_expression";
114 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
115 const char * const config_element_consumer_output
= "consumer_output";
116 const char * const config_element_destination
= "destination";
117 const char * const config_element_path
= "path";
118 const char * const config_element_net_output
= "net_output";
119 const char * const config_element_control_uri
= "control_uri";
120 const char * const config_element_data_uri
= "data_uri";
121 const char * const config_element_max_size
= "max_size";
122 const char * const config_element_pid
= "pid";
123 const char * const config_element_pids
= "pids";
124 const char * const config_element_shared_memory_path
= "shared_memory_path";
126 const char * const config_element_process_attr_id
= "id";
127 const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
128 const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
129 const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
130 const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
131 const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
132 const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
133 const char * const config_element_process_attr_trackers
= "process_attr_trackers";
134 const char * const config_element_process_attr_values
= "process_attr_values";
135 const char * const config_element_process_attr_value_type
= "process_attr_value_type";
136 const char * const config_element_process_attr_pid_value
= "pid";
137 const char * const config_element_process_attr_vpid_value
= "vpid";
138 const char * const config_element_process_attr_uid_value
= "uid";
139 const char * const config_element_process_attr_vuid_value
= "vuid";
140 const char * const config_element_process_attr_gid_value
= "gid";
141 const char * const config_element_process_attr_vgid_value
= "vgid";
142 const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
144 /* Used for support of legacy tracker serialization (< 2.12). */
145 const char * const config_element_trackers_legacy
= "trackers";
146 const char * const config_element_pid_tracker_legacy
= "pid_tracker";
147 const char * const config_element_tracker_targets_legacy
= "targets";
148 const char * const config_element_tracker_pid_legacy
= "pid";
150 const char * const config_element_rotation_schedules
= "rotation_schedules";
151 const char * const config_element_rotation_schedule_periodic
= "periodic";
152 const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
153 const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
154 const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
156 const char * const config_domain_type_kernel
= "KERNEL";
157 const char * const config_domain_type_ust
= "UST";
158 const char * const config_domain_type_jul
= "JUL";
159 const char * const config_domain_type_log4j
= "LOG4J";
160 const char * const config_domain_type_python
= "PYTHON";
162 const char * const config_buffer_type_per_pid
= "PER_PID";
163 const char * const config_buffer_type_per_uid
= "PER_UID";
164 const char * const config_buffer_type_global
= "GLOBAL";
166 const char * const config_overwrite_mode_discard
= "DISCARD";
167 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
169 const char * const config_output_type_splice
= "SPLICE";
170 const char * const config_output_type_mmap
= "MMAP";
172 const char * const config_loglevel_type_all
= "ALL";
173 const char * const config_loglevel_type_range
= "RANGE";
174 const char * const config_loglevel_type_single
= "SINGLE";
176 const char * const config_event_type_all
= "ALL";
177 const char * const config_event_type_tracepoint
= "TRACEPOINT";
178 const char * const config_event_type_probe
= "PROBE";
179 const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
180 const char * const config_event_type_function
= "FUNCTION";
181 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
182 const char * const config_event_type_noop
= "NOOP";
183 const char * const config_event_type_syscall
= "SYSCALL";
184 const char * const config_event_type_kprobe
= "KPROBE";
185 const char * const config_event_type_kretprobe
= "KRETPROBE";
187 const char * const config_event_context_pid
= "PID";
188 const char * const config_event_context_procname
= "PROCNAME";
189 const char * const config_event_context_prio
= "PRIO";
190 const char * const config_event_context_nice
= "NICE";
191 const char * const config_event_context_vpid
= "VPID";
192 const char * const config_event_context_tid
= "TID";
193 const char * const config_event_context_vtid
= "VTID";
194 const char * const config_event_context_ppid
= "PPID";
195 const char * const config_event_context_vppid
= "VPPID";
196 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
197 const char * const config_event_context_hostname
= "HOSTNAME";
198 const char * const config_event_context_ip
= "IP";
199 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
200 const char * const config_event_context_app
= "APP";
201 const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
202 const char * const config_event_context_preemptible
= "PREEMPTIBLE";
203 const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
204 const char * const config_event_context_migratable
= "MIGRATABLE";
205 const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
206 const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
207 const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
208 const char * const config_event_context_ipc_ns
= "IPC_NS";
209 const char * const config_event_context_mnt_ns
= "MNT_NS";
210 const char * const config_event_context_net_ns
= "NET_NS";
211 const char * const config_event_context_pid_ns
= "PID_NS";
212 const char * const config_event_context_time_ns
= "TIME_NS";
213 const char * const config_event_context_user_ns
= "USER_NS";
214 const char * const config_event_context_uts_ns
= "UTS_NS";
215 const char * const config_event_context_uid
= "UID";
216 const char * const config_event_context_euid
= "EUID";
217 const char * const config_event_context_suid
= "SUID";
218 const char * const config_event_context_gid
= "GID";
219 const char * const config_event_context_egid
= "EGID";
220 const char * const config_event_context_sgid
= "SGID";
221 const char * const config_event_context_vuid
= "VUID";
222 const char * const config_event_context_veuid
= "VEUID";
223 const char * const config_event_context_vsuid
= "VSUID";
224 const char * const config_event_context_vgid
= "VGID";
225 const char * const config_event_context_vegid
= "VEGID";
226 const char * const config_event_context_vsgid
= "VSGID";
228 /* Deprecated symbols */
229 LTTNG_EXPORT
const char *config_element_perf
;
231 enum process_event_node_phase
{
236 struct consumer_output
{
244 * Returns a xmlChar string which must be released using xmlFree().
246 static xmlChar
*encode_string(const char *in_str
)
248 xmlChar
*out_str
= NULL
;
249 xmlCharEncodingHandlerPtr handler
;
250 int out_len
, ret
, in_len
;
252 LTTNG_ASSERT(in_str
);
254 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
256 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
260 in_len
= strlen(in_str
);
262 * Add 1 byte for the NULL terminted character. The factor 4 here is
263 * used because UTF-8 characters can take up to 4 bytes.
265 out_len
= (in_len
* 4) + 1;
266 out_str
= (xmlChar
*) xmlMalloc(out_len
);
271 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
278 /* out_len is now the size of out_str */
279 out_str
[out_len
] = '\0';
284 struct config_writer
*config_writer_create(int fd_output
, int indent
)
287 struct config_writer
*writer
;
288 xmlOutputBufferPtr buffer
;
290 writer
= (config_writer
*) zmalloc(sizeof(struct config_writer
));
292 PERROR("zmalloc config_writer_create");
296 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
301 writer
->writer
= xmlNewTextWriter(buffer
);
302 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
303 config_xml_encoding
, NULL
);
308 ret
= xmlTextWriterSetIndentString(writer
->writer
,
309 BAD_CAST config_xml_indent_string
);
314 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
322 config_writer_destroy(writer
);
326 int config_writer_destroy(struct config_writer
*writer
)
335 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
336 WARN("Could not close XML document");
340 if (writer
->writer
) {
341 xmlFreeTextWriter(writer
->writer
);
349 int config_writer_open_element(struct config_writer
*writer
,
350 const char *element_name
)
353 xmlChar
*encoded_element_name
;
355 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
360 encoded_element_name
= encode_string(element_name
);
361 if (!encoded_element_name
) {
366 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
367 xmlFree(encoded_element_name
);
369 return ret
>= 0 ? 0 : ret
;
372 int config_writer_write_attribute(struct config_writer
*writer
,
373 const char *name
, const char *value
)
376 xmlChar
*encoded_name
= NULL
;
377 xmlChar
*encoded_value
= NULL
;
379 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
384 encoded_name
= encode_string(name
);
390 encoded_value
= encode_string(value
);
391 if (!encoded_value
) {
396 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
399 xmlFree(encoded_name
);
400 xmlFree(encoded_value
);
401 return ret
>= 0 ? 0 : ret
;
404 int config_writer_close_element(struct config_writer
*writer
)
408 if (!writer
|| !writer
->writer
) {
413 ret
= xmlTextWriterEndElement(writer
->writer
);
415 return ret
>= 0 ? 0 : ret
;
418 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
419 const char *element_name
, uint64_t value
)
422 xmlChar
*encoded_element_name
;
424 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
429 encoded_element_name
= encode_string(element_name
);
430 if (!encoded_element_name
) {
435 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
436 encoded_element_name
, "%" PRIu64
, value
);
437 xmlFree(encoded_element_name
);
439 return ret
>= 0 ? 0 : ret
;
442 int config_writer_write_element_signed_int(struct config_writer
*writer
,
443 const char *element_name
, int64_t value
)
446 xmlChar
*encoded_element_name
;
448 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
453 encoded_element_name
= encode_string(element_name
);
454 if (!encoded_element_name
) {
459 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
460 encoded_element_name
, "%" PRIi64
, value
);
461 xmlFree(encoded_element_name
);
463 return ret
>= 0 ? 0 : ret
;
466 int config_writer_write_element_bool(struct config_writer
*writer
,
467 const char *element_name
, int value
)
469 return config_writer_write_element_string(writer
, element_name
,
470 value
? config_xml_true
: config_xml_false
);
473 int config_writer_write_element_double(struct config_writer
*writer
,
474 const char *element_name
,
478 xmlChar
*encoded_element_name
;
480 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
485 encoded_element_name
= encode_string(element_name
);
486 if (!encoded_element_name
) {
491 ret
= xmlTextWriterWriteFormatElement(
492 writer
->writer
, encoded_element_name
, "%f", value
);
493 xmlFree(encoded_element_name
);
495 return ret
>= 0 ? 0 : ret
;
498 int config_writer_write_element_string(struct config_writer
*writer
,
499 const char *element_name
, const char *value
)
502 xmlChar
*encoded_element_name
= NULL
;
503 xmlChar
*encoded_value
= NULL
;
505 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
511 encoded_element_name
= encode_string(element_name
);
512 if (!encoded_element_name
) {
517 encoded_value
= encode_string(value
);
518 if (!encoded_value
) {
523 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
526 xmlFree(encoded_element_name
);
527 xmlFree(encoded_value
);
528 return ret
>= 0 ? 0 : ret
;
531 static ATTR_FORMAT_PRINTF(2, 3)
532 void xml_error_handler(void *ctx
, const char *format
, ...)
538 va_start(args
, format
);
539 ret
= vasprintf(&errMsg
, format
, args
);
542 ERR("String allocation failed in xml error handler");
546 fprintf(stderr
, "XML Error: %s", errMsg
);
551 void fini_session_config_validation_ctx(
552 struct session_config_validation_ctx
*ctx
)
554 if (ctx
->parser_ctx
) {
555 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
559 xmlSchemaFree(ctx
->schema
);
562 if (ctx
->schema_validation_ctx
) {
563 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
566 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
570 char *get_session_config_xsd_path(void)
573 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
574 size_t base_path_len
;
578 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
581 base_path_len
= strlen(base_path
);
582 max_path_len
= base_path_len
+
583 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
584 xsd_path
= (char *) zmalloc(max_path_len
);
589 strcpy(xsd_path
, base_path
);
590 if (xsd_path
[base_path_len
- 1] != '/') {
591 xsd_path
[base_path_len
++] = '/';
594 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
600 int init_session_config_validation_ctx(
601 struct session_config_validation_ctx
*ctx
)
604 char *xsd_path
= get_session_config_xsd_path();
607 ret
= -LTTNG_ERR_NOMEM
;
611 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
612 if (!ctx
->parser_ctx
) {
613 ERR("XSD parser context creation failed");
614 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
617 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
618 xml_error_handler
, NULL
);
620 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
622 ERR("XSD parsing failed");
623 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
627 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
628 if (!ctx
->schema_validation_ctx
) {
629 ERR("XSD validation context creation failed");
630 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
634 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
635 xml_error_handler
, NULL
);
640 fini_session_config_validation_ctx(ctx
);
648 int parse_uint(xmlChar
*str
, uint64_t *val
)
658 *val
= strtoull((const char *) str
, &endptr
, 10);
659 if (!endptr
|| *endptr
) {
670 int parse_int(xmlChar
*str
, int64_t *val
)
680 *val
= strtoll((const char *) str
, &endptr
, 10);
681 if (!endptr
|| *endptr
) {
692 int parse_bool(xmlChar
*str
, int *val
)
701 if (!strcmp((const char *) str
, config_xml_true
) ||
702 !strcmp((const char *) str
, "1")) {
704 } else if (!strcmp((const char *) str
, config_xml_false
) ||
705 !strcmp((const char *) str
, "0")) {
708 WARN("Invalid boolean value encountered (%s).",
717 int get_domain_type(xmlChar
*domain
)
725 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
726 ret
= LTTNG_DOMAIN_KERNEL
;
727 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
728 ret
= LTTNG_DOMAIN_UST
;
729 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
730 ret
= LTTNG_DOMAIN_JUL
;
731 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
732 ret
= LTTNG_DOMAIN_LOG4J
;
733 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
734 ret
= LTTNG_DOMAIN_PYTHON
;
745 int get_buffer_type(xmlChar
*buffer_type
)
753 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
754 ret
= LTTNG_BUFFER_GLOBAL
;
755 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
756 ret
= LTTNG_BUFFER_PER_UID
;
757 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
758 ret
= LTTNG_BUFFER_PER_PID
;
769 int get_overwrite_mode(xmlChar
*overwrite_mode
)
773 if (!overwrite_mode
) {
777 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
779 } else if (!strcmp((char *) overwrite_mode
,
780 config_overwrite_mode_discard
)) {
792 int get_output_type(xmlChar
*output_type
)
800 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
801 ret
= LTTNG_EVENT_MMAP
;
802 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
803 ret
= LTTNG_EVENT_SPLICE
;
814 int get_event_type(xmlChar
*event_type
)
822 if (!strcmp((char *) event_type
, config_event_type_all
)) {
823 ret
= LTTNG_EVENT_ALL
;
824 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
825 ret
= LTTNG_EVENT_TRACEPOINT
;
826 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
827 ret
= LTTNG_EVENT_PROBE
;
828 } else if (!strcmp((char *) event_type
,
829 config_event_type_userspace_probe
)) {
830 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
831 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
832 ret
= LTTNG_EVENT_FUNCTION
;
833 } else if (!strcmp((char *) event_type
,
834 config_event_type_function_entry
)) {
835 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
836 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
837 ret
= LTTNG_EVENT_NOOP
;
838 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
839 ret
= LTTNG_EVENT_SYSCALL
;
850 int get_loglevel_type(xmlChar
*loglevel_type
)
854 if (!loglevel_type
) {
858 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
859 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
860 } else if (!strcmp((char *) loglevel_type
,
861 config_loglevel_type_range
)) {
862 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
863 } else if (!strcmp((char *) loglevel_type
,
864 config_loglevel_type_single
)) {
865 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
876 * Return the context type or -1 on error.
879 int get_context_type(xmlChar
*context_type
)
887 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
888 ret
= LTTNG_EVENT_CONTEXT_PID
;
889 } else if (!strcmp((char *) context_type
,
890 config_event_context_procname
)) {
891 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
892 } else if (!strcmp((char *) context_type
,
893 config_event_context_prio
)) {
894 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
895 } else if (!strcmp((char *) context_type
,
896 config_event_context_nice
)) {
897 ret
= LTTNG_EVENT_CONTEXT_NICE
;
898 } else if (!strcmp((char *) context_type
,
899 config_event_context_vpid
)) {
900 ret
= LTTNG_EVENT_CONTEXT_VPID
;
901 } else if (!strcmp((char *) context_type
,
902 config_event_context_tid
)) {
903 ret
= LTTNG_EVENT_CONTEXT_TID
;
904 } else if (!strcmp((char *) context_type
,
905 config_event_context_vtid
)) {
906 ret
= LTTNG_EVENT_CONTEXT_VTID
;
907 } else if (!strcmp((char *) context_type
,
908 config_event_context_ppid
)) {
909 ret
= LTTNG_EVENT_CONTEXT_PPID
;
910 } else if (!strcmp((char *) context_type
,
911 config_event_context_vppid
)) {
912 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
913 } else if (!strcmp((char *) context_type
,
914 config_event_context_pthread_id
)) {
915 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
916 } else if (!strcmp((char *) context_type
,
917 config_event_context_hostname
)) {
918 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
919 } else if (!strcmp((char *) context_type
,
920 config_event_context_ip
)) {
921 ret
= LTTNG_EVENT_CONTEXT_IP
;
922 } else if (!strcmp((char *) context_type
,
923 config_event_context_interruptible
)) {
924 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
925 } else if (!strcmp((char *) context_type
,
926 config_event_context_preemptible
)) {
927 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
928 } else if (!strcmp((char *) context_type
,
929 config_event_context_need_reschedule
)) {
930 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
931 } else if (!strcmp((char *) context_type
,
932 config_event_context_migratable
)) {
933 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
934 } else if (!strcmp((char *) context_type
,
935 config_event_context_callstack_user
)) {
936 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
937 } else if (!strcmp((char *) context_type
,
938 config_event_context_callstack_kernel
)) {
939 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
940 } else if (!strcmp((char *) context_type
,
941 config_event_context_cgroup_ns
)) {
942 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
943 } else if (!strcmp((char *) context_type
,
944 config_event_context_ipc_ns
)) {
945 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
946 } else if (!strcmp((char *) context_type
,
947 config_event_context_mnt_ns
)) {
948 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
949 } else if (!strcmp((char *) context_type
,
950 config_event_context_net_ns
)) {
951 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
952 } else if (!strcmp((char *) context_type
,
953 config_event_context_pid_ns
)) {
954 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
955 } else if (!strcmp((char *) context_type
,
956 config_event_context_time_ns
)) {
957 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
958 } else if (!strcmp((char *) context_type
,
959 config_event_context_user_ns
)) {
960 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
961 } else if (!strcmp((char *) context_type
,
962 config_event_context_uts_ns
)) {
963 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
964 } else if (!strcmp((char *) context_type
,
965 config_event_context_uid
)) {
966 ret
= LTTNG_EVENT_CONTEXT_UID
;
967 } else if (!strcmp((char *) context_type
,
968 config_event_context_euid
)) {
969 ret
= LTTNG_EVENT_CONTEXT_EUID
;
970 } else if (!strcmp((char *) context_type
,
971 config_event_context_suid
)) {
972 ret
= LTTNG_EVENT_CONTEXT_SUID
;
973 } else if (!strcmp((char *) context_type
,
974 config_event_context_gid
)) {
975 ret
= LTTNG_EVENT_CONTEXT_GID
;
976 } else if (!strcmp((char *) context_type
,
977 config_event_context_egid
)) {
978 ret
= LTTNG_EVENT_CONTEXT_EGID
;
979 } else if (!strcmp((char *) context_type
,
980 config_event_context_sgid
)) {
981 ret
= LTTNG_EVENT_CONTEXT_SGID
;
982 } else if (!strcmp((char *) context_type
,
983 config_event_context_vuid
)) {
984 ret
= LTTNG_EVENT_CONTEXT_VUID
;
985 } else if (!strcmp((char *) context_type
,
986 config_event_context_veuid
)) {
987 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
988 } else if (!strcmp((char *) context_type
,
989 config_event_context_vsuid
)) {
990 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
991 } else if (!strcmp((char *) context_type
,
992 config_event_context_vgid
)) {
993 ret
= LTTNG_EVENT_CONTEXT_VGID
;
994 } else if (!strcmp((char *) context_type
,
995 config_event_context_vegid
)) {
996 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
997 } else if (!strcmp((char *) context_type
,
998 config_event_context_vsgid
)) {
999 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1010 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1015 for (node
= xmlFirstElementChild(domain_node
); node
;
1016 node
= xmlNextElementSibling(node
)) {
1017 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1019 xmlChar
*node_content
= xmlNodeGetContent(node
);
1020 if (!node_content
) {
1021 ret
= -LTTNG_ERR_NOMEM
;
1025 ret
= get_domain_type(node_content
);
1028 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1032 domain
->type
= (lttng_domain_type
) ret
;
1033 } else if (!strcmp((const char *) node
->name
,
1034 config_element_buffer_type
)) {
1036 xmlChar
*node_content
= xmlNodeGetContent(node
);
1037 if (!node_content
) {
1038 ret
= -LTTNG_ERR_NOMEM
;
1042 ret
= get_buffer_type(node_content
);
1045 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1049 domain
->buf_type
= (lttng_buffer_type
) ret
;
1058 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1063 for (node
= xmlFirstElementChild(net_output_node
); node
;
1064 node
= xmlNextElementSibling(node
)) {
1065 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1067 *control_uri
= (char *) xmlNodeGetContent(node
);
1068 if (!*control_uri
) {
1073 *data_uri
= (char *) xmlNodeGetContent(node
);
1080 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1084 int process_consumer_output(xmlNodePtr consumer_output_node
,
1085 struct consumer_output
*output
)
1090 LTTNG_ASSERT(output
);
1092 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1093 node
= xmlNextElementSibling(node
)) {
1094 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1095 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1099 ret
= -LTTNG_ERR_NOMEM
;
1103 ret
= parse_bool(enabled_str
, &output
->enabled
);
1109 xmlNodePtr output_type_node
;
1112 output_type_node
= xmlFirstElementChild(node
);
1113 if (!output_type_node
) {
1114 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1118 if (!strcmp((const char *) output_type_node
->name
,
1119 config_element_path
)) {
1121 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1122 if (!output
->path
) {
1123 ret
= -LTTNG_ERR_NOMEM
;
1128 ret
= get_net_output_uris(output_type_node
,
1129 &output
->control_uri
, &output
->data_uri
);
1141 free(output
->control_uri
);
1142 free(output
->data_uri
);
1143 memset(output
, 0, sizeof(struct consumer_output
));
1149 int create_session_net_output(const char *name
, const char *control_uri
,
1150 const char *data_uri
)
1153 struct lttng_handle
*handle
;
1154 const char *uri
= NULL
;
1158 handle
= lttng_create_handle(name
, NULL
);
1160 ret
= -LTTNG_ERR_NOMEM
;
1164 if (!control_uri
|| !data_uri
) {
1165 uri
= control_uri
? control_uri
: data_uri
;
1170 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1171 lttng_destroy_handle(handle
);
1177 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1178 const struct config_load_session_override_attr
*overrides
)
1181 xmlNodePtr node
= NULL
;
1182 xmlNodePtr snapshot_output_list_node
;
1183 xmlNodePtr snapshot_output_node
;
1185 LTTNG_ASSERT(session_name
);
1187 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1196 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1198 /* Parse and create snapshot outputs */
1200 for (snapshot_output_node
=
1201 xmlFirstElementChild(snapshot_output_list_node
);
1202 snapshot_output_node
; snapshot_output_node
=
1203 xmlNextElementSibling(snapshot_output_node
)) {
1205 uint64_t max_size
= UINT64_MAX
;
1206 struct consumer_output output
= { 0 };
1207 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1208 const char *control_uri
= NULL
;
1209 const char *data_uri
= NULL
;
1210 const char *path
= NULL
;
1212 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1213 node
= xmlNextElementSibling(node
)) {
1214 if (!strcmp((const char *) node
->name
,
1215 config_element_name
)) {
1217 name
= (char *) xmlNodeGetContent(node
);
1219 ret
= -LTTNG_ERR_NOMEM
;
1220 goto error_snapshot_output
;
1222 } else if (!strcmp((const char *) node
->name
,
1223 config_element_max_size
)) {
1224 xmlChar
*content
= xmlNodeGetContent(node
);
1228 ret
= -LTTNG_ERR_NOMEM
;
1229 goto error_snapshot_output
;
1231 ret
= parse_uint(content
, &max_size
);
1234 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1235 goto error_snapshot_output
;
1238 /* consumer_output */
1239 ret
= process_consumer_output(node
, &output
);
1241 goto error_snapshot_output
;
1246 control_uri
= output
.control_uri
;
1247 data_uri
= output
.data_uri
;
1251 if (overrides
->path_url
) {
1252 path
= overrides
->path_url
;
1253 /* Control/data_uri are null */
1257 if (overrides
->ctrl_url
) {
1258 control_uri
= overrides
->ctrl_url
;
1262 if (overrides
->data_url
) {
1263 data_uri
= overrides
->data_url
;
1270 snapshot_output
= lttng_snapshot_output_create();
1271 if (!snapshot_output
) {
1272 ret
= -LTTNG_ERR_NOMEM
;
1273 goto error_snapshot_output
;
1276 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1278 goto error_snapshot_output
;
1281 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1283 goto error_snapshot_output
;
1287 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1290 goto error_snapshot_output
;
1294 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1297 goto error_snapshot_output
;
1302 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1305 goto error_snapshot_output
;
1310 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1311 error_snapshot_output
:
1314 free(output
.control_uri
);
1315 free(output
.data_uri
);
1316 lttng_snapshot_output_destroy(snapshot_output
);
1326 int create_session(const char *name
,
1327 xmlNodePtr output_node
,
1328 uint64_t live_timer_interval
,
1329 const struct config_load_session_override_attr
*overrides
)
1332 struct consumer_output output
= { 0 };
1333 xmlNodePtr consumer_output_node
;
1334 const char *control_uri
= NULL
;
1335 const char *data_uri
= NULL
;
1336 const char *path
= NULL
;
1341 consumer_output_node
= xmlFirstElementChild(output_node
);
1342 if (!consumer_output_node
) {
1343 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1347 if (strcmp((const char *) consumer_output_node
->name
,
1348 config_element_consumer_output
)) {
1349 WARN("Invalid output type, expected %s node",
1350 config_element_consumer_output
);
1351 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1355 ret
= process_consumer_output(consumer_output_node
, &output
);
1361 control_uri
= output
.control_uri
;
1362 data_uri
= output
.data_uri
;
1365 /* Check for override and apply them */
1367 if (overrides
->path_url
) {
1368 path
= overrides
->path_url
;
1369 /* control/data_uri are null */;
1373 if (overrides
->ctrl_url
) {
1374 control_uri
= overrides
->ctrl_url
;
1378 if (overrides
->data_url
) {
1379 data_uri
= overrides
->data_url
;
1387 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1388 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1392 if (control_uri
|| data_uri
) {
1393 /* network destination */
1394 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1396 * URLs are provided for sure since the test above make sure that
1397 * with a live timer the data and control URIs are provided. So,
1398 * NULL is passed here and will be set right after.
1400 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1402 ret
= lttng_create_session(name
, NULL
);
1408 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1414 /* either local output or no output */
1415 ret
= lttng_create_session(name
, path
);
1422 free(output
.control_uri
);
1423 free(output
.data_uri
);
1428 struct lttng_userspace_probe_location
*
1429 process_userspace_probe_function_attribute_node(
1430 xmlNodePtr attribute_node
)
1432 xmlNodePtr function_attribute_node
;
1433 char *function_name
= NULL
, *binary_path
= NULL
;
1434 struct lttng_userspace_probe_location
*location
= NULL
;
1435 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1438 * Process userspace probe location function attributes. The order of
1439 * the fields are not guaranteed so we need to iterate over all fields
1440 * and check at the end if everything we need for this location type is
1443 for (function_attribute_node
=
1444 xmlFirstElementChild(attribute_node
);
1445 function_attribute_node
;
1446 function_attribute_node
= xmlNextElementSibling(
1447 function_attribute_node
)) {
1448 /* Handle function name, binary path and lookup method. */
1449 if (!strcmp((const char *) function_attribute_node
->name
,
1450 config_element_userspace_probe_function_location_function_name
)) {
1451 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1452 if (!function_name
) {
1455 } else if (!strcmp((const char *) function_attribute_node
->name
,
1456 config_element_userspace_probe_location_binary_path
)) {
1457 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1461 } else if (!strcmp((const char *) function_attribute_node
->name
,
1462 config_element_userspace_probe_lookup
)) {
1463 char *lookup_method_name
;
1465 lookup_method_name
= (char *) xmlNodeGetContent(
1466 function_attribute_node
);
1467 if (!lookup_method_name
) {
1472 * function_default lookup method defaults to
1473 * function_elf lookup method at the moment.
1475 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1476 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1477 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1478 if (!lookup_method
) {
1479 PERROR("Error creating function default/ELF lookup method");
1482 WARN("Unknown function lookup method");
1485 free(lookup_method_name
);
1486 if (!lookup_method
) {
1493 /* Check if all the necessary fields were found. */
1494 if (binary_path
&& function_name
&& lookup_method
) {
1495 /* Ownership of lookup_method is transferred. */
1497 lttng_userspace_probe_location_function_create(
1498 binary_path
, function_name
,
1500 lookup_method
= NULL
;
1505 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1507 free(function_name
);
1512 struct lttng_userspace_probe_location
*
1513 process_userspace_probe_tracepoint_attribute_node(
1514 xmlNodePtr attribute_node
)
1516 xmlNodePtr tracepoint_attribute_node
;
1517 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1518 struct lttng_userspace_probe_location
*location
= NULL
;
1519 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1522 * Process userspace probe location tracepoint attributes. The order of
1523 * the fields are not guaranteed so we need to iterate over all fields
1524 * and check at the end if everything we need for this location type is
1527 for (tracepoint_attribute_node
=
1528 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1529 tracepoint_attribute_node
= xmlNextElementSibling(
1530 tracepoint_attribute_node
)) {
1531 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1532 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1533 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1537 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1538 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1539 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1540 if (!provider_name
) {
1543 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1544 config_element_userspace_probe_location_binary_path
)) {
1545 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1549 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1550 config_element_userspace_probe_lookup
)) {
1551 char *lookup_method_name
;
1553 lookup_method_name
= (char *) xmlNodeGetContent(
1554 tracepoint_attribute_node
);
1555 if (!lookup_method_name
) {
1559 if (!strcmp(lookup_method_name
,
1560 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1562 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1563 if (!lookup_method
) {
1564 PERROR("Error creating tracepoint SDT lookup method");
1567 WARN("Unknown tracepoint lookup method");
1570 free(lookup_method_name
);
1571 if (!lookup_method
) {
1575 WARN("Unknown tracepoint attribute");
1579 /* Check if all the necessary fields were found. */
1580 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1581 /* Ownership of lookup_method is transferred. */
1583 lttng_userspace_probe_location_tracepoint_create(
1584 binary_path
, provider_name
,
1585 probe_name
, lookup_method
);
1586 lookup_method
= NULL
;
1591 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1593 free(provider_name
);
1599 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1600 struct lttng_event_probe_attr
*attr
)
1604 LTTNG_ASSERT(probe_attribute_node
);
1607 if (!strcmp((const char *) probe_attribute_node
->name
,
1608 config_element_address
)) {
1613 content
= xmlNodeGetContent(probe_attribute_node
);
1615 ret
= -LTTNG_ERR_NOMEM
;
1619 ret
= parse_uint(content
, &addr
);
1622 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1627 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1628 config_element_offset
)) {
1630 uint64_t offset
= 0;
1633 content
= xmlNodeGetContent(probe_attribute_node
);
1635 ret
= -LTTNG_ERR_NOMEM
;
1639 ret
= parse_uint(content
, &offset
);
1642 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1646 attr
->offset
= offset
;
1647 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1648 config_element_symbol_name
)) {
1652 content
= xmlNodeGetContent(probe_attribute_node
);
1654 ret
= -LTTNG_ERR_NOMEM
;
1658 ret
= lttng_strncpy(attr
->symbol_name
,
1659 (const char *) content
,
1660 LTTNG_SYMBOL_NAME_LEN
);
1662 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1663 (const char *) content
,
1664 strlen((const char *) content
),
1665 LTTNG_SYMBOL_NAME_LEN
);
1666 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1678 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1679 const char *channel_name
, const enum process_event_node_phase phase
)
1683 struct lttng_event
*event
;
1684 char **exclusions
= NULL
;
1685 unsigned long exclusion_count
= 0;
1686 char *filter_expression
= NULL
;
1688 LTTNG_ASSERT(event_node
);
1689 LTTNG_ASSERT(handle
);
1690 LTTNG_ASSERT(channel_name
);
1692 event
= lttng_event_create();
1694 ret
= -LTTNG_ERR_NOMEM
;
1698 /* Initialize default log level which varies by domain */
1699 switch (handle
->domain
.type
)
1701 case LTTNG_DOMAIN_JUL
:
1702 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1704 case LTTNG_DOMAIN_LOG4J
:
1705 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1707 case LTTNG_DOMAIN_PYTHON
:
1708 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1710 case LTTNG_DOMAIN_UST
:
1711 case LTTNG_DOMAIN_KERNEL
:
1712 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1718 for (node
= xmlFirstElementChild(event_node
); node
;
1719 node
= xmlNextElementSibling(node
)) {
1720 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1724 content
= xmlNodeGetContent(node
);
1726 ret
= -LTTNG_ERR_NOMEM
;
1730 ret
= lttng_strncpy(event
->name
,
1731 (const char *) content
,
1732 LTTNG_SYMBOL_NAME_LEN
);
1734 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1735 (const char *) content
,
1736 strlen((const char *) content
),
1737 LTTNG_SYMBOL_NAME_LEN
);
1738 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1743 } else if (!strcmp((const char *) node
->name
,
1744 config_element_enabled
)) {
1745 xmlChar
*content
= xmlNodeGetContent(node
);
1749 ret
= -LTTNG_ERR_NOMEM
;
1753 ret
= parse_bool(content
, &event
->enabled
);
1756 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1759 } else if (!strcmp((const char *) node
->name
,
1760 config_element_type
)) {
1761 xmlChar
*content
= xmlNodeGetContent(node
);
1765 ret
= -LTTNG_ERR_NOMEM
;
1769 ret
= get_event_type(content
);
1772 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1776 event
->type
= (lttng_event_type
) ret
;
1777 } else if (!strcmp((const char *) node
->name
,
1778 config_element_loglevel_type
)) {
1779 xmlChar
*content
= xmlNodeGetContent(node
);
1783 ret
= -LTTNG_ERR_NOMEM
;
1787 ret
= get_loglevel_type(content
);
1790 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1794 event
->loglevel_type
= (lttng_loglevel_type
) ret
;
1795 } else if (!strcmp((const char *) node
->name
,
1796 config_element_loglevel
)) {
1798 int64_t loglevel
= 0;
1801 content
= xmlNodeGetContent(node
);
1803 ret
= -LTTNG_ERR_NOMEM
;
1807 ret
= parse_int(content
, &loglevel
);
1810 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1814 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1815 WARN("loglevel out of range.");
1816 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1820 event
->loglevel
= loglevel
;
1821 } else if (!strcmp((const char *) node
->name
,
1822 config_element_filter
)) {
1824 xmlNodeGetContent(node
);
1828 ret
= -LTTNG_ERR_NOMEM
;
1832 free(filter_expression
);
1833 filter_expression
= strdup((char *) content
);
1835 if (!filter_expression
) {
1836 ret
= -LTTNG_ERR_NOMEM
;
1839 } else if (!strcmp((const char *) node
->name
,
1840 config_element_exclusions
)) {
1841 xmlNodePtr exclusion_node
;
1842 int exclusion_index
= 0;
1847 * Exclusions has already been initialized,
1850 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1854 exclusion_count
= xmlChildElementCount(node
);
1855 if (!exclusion_count
) {
1859 exclusions
= (char **) zmalloc(exclusion_count
* sizeof(char *));
1861 exclusion_count
= 0;
1862 ret
= -LTTNG_ERR_NOMEM
;
1866 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1867 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1869 xmlNodeGetContent(exclusion_node
);
1872 ret
= -LTTNG_ERR_NOMEM
;
1876 exclusions
[exclusion_index
] = strdup((const char *) content
);
1878 if (!exclusions
[exclusion_index
]) {
1879 ret
= -LTTNG_ERR_NOMEM
;
1885 event
->exclusion
= 1;
1886 } else if (!strcmp((const char *) node
->name
,
1887 config_element_attributes
)) {
1888 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1891 if (!attribute_node
) {
1892 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1896 if (!strcmp((const char *) attribute_node
->name
,
1897 config_element_probe_attributes
)) {
1898 xmlNodePtr probe_attribute_node
;
1900 /* probe_attributes */
1901 for (probe_attribute_node
=
1902 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1903 probe_attribute_node
= xmlNextElementSibling(
1904 probe_attribute_node
)) {
1906 ret
= process_probe_attribute_node(probe_attribute_node
,
1907 &event
->attr
.probe
);
1912 } else if (!strcmp((const char *) attribute_node
->name
,
1913 config_element_function_attributes
)) {
1916 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1918 /* function_attributes */
1919 content
= xmlNodeGetContent(symbol_node
);
1921 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1925 sym_len
= strlen((char *) content
);
1926 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1927 WARN("Function name too long.");
1928 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1933 ret
= lttng_strncpy(
1934 event
->attr
.ftrace
.symbol_name
,
1935 (char *) content
, sym_len
);
1937 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1942 } else if (!strcmp((const char *) attribute_node
->name
,
1943 config_element_userspace_probe_tracepoint_attributes
)) {
1944 struct lttng_userspace_probe_location
*location
;
1946 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
1948 WARN("Error processing userspace probe tracepoint attribute");
1949 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1952 ret
= lttng_event_set_userspace_probe_location(
1955 WARN("Error setting userspace probe location field");
1956 lttng_userspace_probe_location_destroy(
1958 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1961 } else if (!strcmp((const char *) attribute_node
->name
,
1962 config_element_userspace_probe_function_attributes
)) {
1963 struct lttng_userspace_probe_location
*location
;
1966 process_userspace_probe_function_attribute_node(
1969 WARN("Error processing userspace probe function attribute");
1970 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1974 ret
= lttng_event_set_userspace_probe_location(
1977 WARN("Error setting userspace probe location field");
1978 lttng_userspace_probe_location_destroy(
1980 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1984 /* Unknown event attribute. */
1985 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1991 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1992 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
1993 filter_expression
, exclusion_count
, exclusions
);
1995 WARN("Enabling event (name:%s) on load failed.", event
->name
);
1996 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2002 for (i
= 0; i
< exclusion_count
; i
++) {
2003 free(exclusions
[i
]);
2006 lttng_event_destroy(event
);
2008 free(filter_expression
);
2013 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2014 const char *channel_name
)
2017 struct lttng_event event
;
2020 LTTNG_ASSERT(events_node
);
2021 LTTNG_ASSERT(handle
);
2022 LTTNG_ASSERT(channel_name
);
2024 for (node
= xmlFirstElementChild(events_node
); node
;
2025 node
= xmlNextElementSibling(node
)) {
2026 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2033 * Disable all events to enable only the necessary events.
2034 * Limitations regarding lttng_disable_events and tuple descriptor
2035 * force this approach.
2037 memset(&event
, 0, sizeof(event
));
2038 event
.loglevel
= -1;
2039 event
.type
= LTTNG_EVENT_ALL
;
2040 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2045 for (node
= xmlFirstElementChild(events_node
); node
;
2046 node
= xmlNextElementSibling(node
)) {
2047 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2058 int process_channel_attr_node(xmlNodePtr attr_node
,
2059 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2060 xmlNodePtr
*events_node
)
2064 LTTNG_ASSERT(attr_node
);
2065 LTTNG_ASSERT(channel
);
2066 LTTNG_ASSERT(contexts_node
);
2067 LTTNG_ASSERT(events_node
);
2069 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2073 content
= xmlNodeGetContent(attr_node
);
2075 ret
= -LTTNG_ERR_NOMEM
;
2079 ret
= lttng_strncpy(channel
->name
,
2080 (const char *) content
,
2081 LTTNG_SYMBOL_NAME_LEN
);
2083 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2084 (const char *) content
,
2085 strlen((const char *) content
),
2086 LTTNG_SYMBOL_NAME_LEN
);
2087 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2092 } else if (!strcmp((const char *) attr_node
->name
,
2093 config_element_enabled
)) {
2098 content
= xmlNodeGetContent(attr_node
);
2100 ret
= -LTTNG_ERR_NOMEM
;
2104 ret
= parse_bool(content
, &enabled
);
2107 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2111 channel
->enabled
= enabled
;
2112 } else if (!strcmp((const char *) attr_node
->name
,
2113 config_element_overwrite_mode
)) {
2116 /* overwrite_mode */
2117 content
= xmlNodeGetContent(attr_node
);
2119 ret
= -LTTNG_ERR_NOMEM
;
2123 ret
= get_overwrite_mode(content
);
2126 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2130 channel
->attr
.overwrite
= ret
;
2131 } else if (!strcmp((const char *) attr_node
->name
,
2132 config_element_subbuf_size
)) {
2135 /* subbuffer_size */
2136 content
= xmlNodeGetContent(attr_node
);
2138 ret
= -LTTNG_ERR_NOMEM
;
2142 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2145 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2148 } else if (!strcmp((const char *) attr_node
->name
,
2149 config_element_num_subbuf
)) {
2152 /* subbuffer_count */
2153 content
= xmlNodeGetContent(attr_node
);
2155 ret
= -LTTNG_ERR_NOMEM
;
2159 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2162 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2165 } else if (!strcmp((const char *) attr_node
->name
,
2166 config_element_switch_timer_interval
)) {
2168 uint64_t switch_timer_interval
= 0;
2170 /* switch_timer_interval */
2171 content
= xmlNodeGetContent(attr_node
);
2173 ret
= -LTTNG_ERR_NOMEM
;
2177 ret
= parse_uint(content
, &switch_timer_interval
);
2180 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2184 if (switch_timer_interval
> UINT_MAX
) {
2185 WARN("switch_timer_interval out of range.");
2186 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2190 channel
->attr
.switch_timer_interval
=
2191 switch_timer_interval
;
2192 } else if (!strcmp((const char *) attr_node
->name
,
2193 config_element_read_timer_interval
)) {
2195 uint64_t read_timer_interval
= 0;
2197 /* read_timer_interval */
2198 content
= xmlNodeGetContent(attr_node
);
2200 ret
= -LTTNG_ERR_NOMEM
;
2204 ret
= parse_uint(content
, &read_timer_interval
);
2207 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2211 if (read_timer_interval
> UINT_MAX
) {
2212 WARN("read_timer_interval out of range.");
2213 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2217 channel
->attr
.read_timer_interval
=
2218 read_timer_interval
;
2219 } else if (!strcmp((const char *) attr_node
->name
,
2220 config_element_output_type
)) {
2224 content
= xmlNodeGetContent(attr_node
);
2226 ret
= -LTTNG_ERR_NOMEM
;
2230 ret
= get_output_type(content
);
2233 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2237 channel
->attr
.output
= (lttng_event_output
) ret
;
2238 } else if (!strcmp((const char *) attr_node
->name
,
2239 config_element_tracefile_size
)) {
2242 /* tracefile_size */
2243 content
= xmlNodeGetContent(attr_node
);
2245 ret
= -LTTNG_ERR_NOMEM
;
2249 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2252 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2255 } else if (!strcmp((const char *) attr_node
->name
,
2256 config_element_tracefile_count
)) {
2259 /* tracefile_count */
2260 content
= xmlNodeGetContent(attr_node
);
2262 ret
= -LTTNG_ERR_NOMEM
;
2266 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2269 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2272 } else if (!strcmp((const char *) attr_node
->name
,
2273 config_element_live_timer_interval
)) {
2275 uint64_t live_timer_interval
= 0;
2277 /* live_timer_interval */
2278 content
= xmlNodeGetContent(attr_node
);
2280 ret
= -LTTNG_ERR_NOMEM
;
2284 ret
= parse_uint(content
, &live_timer_interval
);
2287 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2291 if (live_timer_interval
> UINT_MAX
) {
2292 WARN("live_timer_interval out of range.");
2293 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2297 channel
->attr
.live_timer_interval
=
2298 live_timer_interval
;
2299 } else if (!strcmp((const char *) attr_node
->name
,
2300 config_element_monitor_timer_interval
)) {
2302 uint64_t monitor_timer_interval
= 0;
2304 /* monitor_timer_interval */
2305 content
= xmlNodeGetContent(attr_node
);
2307 ret
= -LTTNG_ERR_NOMEM
;
2311 ret
= parse_uint(content
, &monitor_timer_interval
);
2314 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2318 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2319 monitor_timer_interval
);
2321 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2324 } else if (!strcmp((const char *) attr_node
->name
,
2325 config_element_blocking_timeout
)) {
2327 int64_t blocking_timeout
= 0;
2329 /* blocking_timeout */
2330 content
= xmlNodeGetContent(attr_node
);
2332 ret
= -LTTNG_ERR_NOMEM
;
2336 ret
= parse_int(content
, &blocking_timeout
);
2339 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2343 ret
= lttng_channel_set_blocking_timeout(channel
,
2346 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2349 } else if (!strcmp((const char *) attr_node
->name
,
2350 config_element_events
)) {
2352 *events_node
= attr_node
;
2355 *contexts_node
= attr_node
;
2363 int process_context_node(xmlNodePtr context_node
,
2364 struct lttng_handle
*handle
, const char *channel_name
)
2367 struct lttng_event_context context
;
2368 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2370 LTTNG_ASSERT(handle
);
2371 LTTNG_ASSERT(channel_name
);
2373 if (!context_child_node
) {
2374 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2378 memset(&context
, 0, sizeof(context
));
2380 if (!strcmp((const char *) context_child_node
->name
,
2381 config_element_type
)) {
2383 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2386 ret
= -LTTNG_ERR_NOMEM
;
2390 ret
= get_context_type(content
);
2393 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2397 context
.ctx
= (lttng_event_context_type
) ret
;
2398 } else if (!strcmp((const char *) context_child_node
->name
,
2399 config_element_context_perf
)) {
2401 xmlNodePtr perf_attr_node
;
2403 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2404 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2405 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2406 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2407 perf_attr_node
; perf_attr_node
=
2408 xmlNextElementSibling(perf_attr_node
)) {
2409 if (!strcmp((const char *) perf_attr_node
->name
,
2410 config_element_type
)) {
2415 content
= xmlNodeGetContent(perf_attr_node
);
2417 ret
= -LTTNG_ERR_NOMEM
;
2421 ret
= parse_uint(content
, &type
);
2424 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2428 if (type
> UINT32_MAX
) {
2429 WARN("perf context type out of range.");
2430 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2434 context
.u
.perf_counter
.type
= type
;
2435 } else if (!strcmp((const char *) perf_attr_node
->name
,
2436 config_element_config
)) {
2438 uint64_t config
= 0;
2441 content
= xmlNodeGetContent(perf_attr_node
);
2443 ret
= -LTTNG_ERR_NOMEM
;
2447 ret
= parse_uint(content
, &config
);
2450 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2454 context
.u
.perf_counter
.config
= config
;
2455 } else if (!strcmp((const char *) perf_attr_node
->name
,
2456 config_element_name
)) {
2460 content
= xmlNodeGetContent(perf_attr_node
);
2462 ret
= -LTTNG_ERR_NOMEM
;
2466 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2467 (const char *) content
,
2468 LTTNG_SYMBOL_NAME_LEN
);
2470 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2471 (const char *) content
,
2472 strlen((const char *) content
),
2473 LTTNG_SYMBOL_NAME_LEN
);
2474 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2481 } else if (!strcmp((const char *) context_child_node
->name
,
2482 config_element_context_app
)) {
2483 /* application context */
2484 xmlNodePtr app_ctx_node
;
2486 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2487 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2488 app_ctx_node
; app_ctx_node
=
2489 xmlNextElementSibling(app_ctx_node
)) {
2491 char **target
= strcmp(
2492 (const char *) app_ctx_node
->name
,
2493 config_element_context_app_provider_name
) == 0 ?
2494 &context
.u
.app_ctx
.provider_name
:
2495 &context
.u
.app_ctx
.ctx_name
;
2497 content
= xmlNodeGetContent(app_ctx_node
);
2499 ret
= -LTTNG_ERR_NOMEM
;
2503 *target
= (char *) content
;
2506 /* Unrecognized context type */
2507 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2511 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2512 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2513 free(context
.u
.app_ctx
.provider_name
);
2514 free(context
.u
.app_ctx
.ctx_name
);
2521 int process_contexts_node(xmlNodePtr contexts_node
,
2522 struct lttng_handle
*handle
, const char *channel_name
)
2525 xmlNodePtr context_node
;
2527 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2528 context_node
= xmlNextElementSibling(context_node
)) {
2529 ret
= process_context_node(context_node
, handle
, channel_name
);
2538 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2539 const char **element_id_tracker
,
2540 const char **element_value_type
,
2541 const char **element_value
,
2542 const char **element_value_alias
,
2543 const char **element_name
)
2547 switch (process_attr
) {
2548 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2549 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2550 *element_value_type
= config_element_process_attr_pid_value
;
2551 *element_value
= config_element_process_attr_id
;
2552 *element_value_alias
= config_element_process_attr_id
;
2553 *element_name
= NULL
;
2555 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2556 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2557 *element_value_type
= config_element_process_attr_vpid_value
;
2558 *element_value
= config_element_process_attr_id
;
2559 *element_value_alias
= NULL
;
2560 *element_name
= NULL
;
2562 case LTTNG_PROCESS_ATTR_USER_ID
:
2563 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2564 *element_value_type
= config_element_process_attr_uid_value
;
2565 *element_value
= config_element_process_attr_id
;
2566 *element_value_alias
= NULL
;
2567 *element_name
= config_element_name
;
2569 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2570 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2571 *element_value_type
= config_element_process_attr_vuid_value
;
2572 *element_value
= config_element_process_attr_id
;
2573 *element_value_alias
= NULL
;
2574 *element_name
= config_element_name
;
2576 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2577 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2578 *element_value_type
= config_element_process_attr_gid_value
;
2579 *element_value
= config_element_process_attr_id
;
2580 *element_value_alias
= NULL
;
2581 *element_name
= config_element_name
;
2583 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2584 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2585 *element_value_type
= config_element_process_attr_vgid_value
;
2586 *element_value
= config_element_process_attr_id
;
2587 *element_value_alias
= NULL
;
2588 *element_name
= config_element_name
;
2591 ret
= LTTNG_ERR_INVALID
;
2596 static int process_legacy_pid_tracker_node(
2597 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2599 int ret
= 0, child_count
;
2600 xmlNodePtr targets_node
= NULL
;
2602 const char *element_id_tracker
;
2603 const char *element_target_id
;
2604 const char *element_id
;
2605 const char *element_id_alias
;
2606 const char *element_name
;
2607 enum lttng_error_code tracker_handle_ret_code
;
2608 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2609 enum lttng_process_attr_tracker_handle_status status
;
2610 const enum lttng_process_attr process_attr
=
2611 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2612 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2613 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2615 LTTNG_ASSERT(handle
);
2617 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2618 handle
->session_name
, handle
->domain
.type
,
2621 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2622 ret
= LTTNG_ERR_INVALID
;
2626 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2627 &element_target_id
, &element_id
, &element_id_alias
,
2633 /* Get the targets node */
2634 for (node
= xmlFirstElementChild(trackers_node
); node
;
2635 node
= xmlNextElementSibling(node
)) {
2636 if (!strcmp((const char *) node
->name
,
2637 config_element_tracker_targets_legacy
)) {
2638 targets_node
= node
;
2643 if (!targets_node
) {
2644 ret
= LTTNG_ERR_INVALID
;
2648 /* Go through all id target node */
2649 child_count
= xmlChildElementCount(targets_node
);
2650 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2652 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2653 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2654 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2655 ret
= LTTNG_ERR_UNK
;
2659 /* Add all tracked values. */
2660 for (node
= xmlFirstElementChild(targets_node
); node
;
2661 node
= xmlNextElementSibling(node
)) {
2662 xmlNodePtr pid_target_node
= node
;
2664 /* get pid_target node and track it */
2665 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2666 node
= xmlNextElementSibling(node
)) {
2667 if (!strcmp((const char *) node
->name
,
2668 config_element_tracker_pid_legacy
)) {
2670 xmlChar
*content
= xmlNodeGetContent(node
);
2673 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2677 ret
= parse_int(content
, &id
);
2680 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2684 switch (process_attr
) {
2685 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2686 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2690 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2691 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2696 ret
= LTTNG_ERR_INVALID
;
2701 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2703 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2704 ret
= LTTNG_ERR_INVALID
;
2706 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2707 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2709 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2710 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2712 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2713 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2715 ret
= LTTNG_ERR_UNK
;
2719 node
= pid_target_node
;
2723 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2727 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2728 struct lttng_handle
*handle
,
2729 enum lttng_process_attr process_attr
)
2731 int ret
= 0, child_count
;
2732 xmlNodePtr values_node
= NULL
;
2734 const char *element_id_tracker
;
2735 const char *element_target_id
;
2736 const char *element_id
;
2737 const char *element_id_alias
;
2738 const char *element_name
;
2739 enum lttng_error_code tracker_handle_ret_code
;
2740 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2741 enum lttng_process_attr_tracker_handle_status status
;
2743 LTTNG_ASSERT(handle
);
2744 LTTNG_ASSERT(id_tracker_node
);
2746 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2747 handle
->session_name
, handle
->domain
.type
, process_attr
,
2749 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2750 ret
= LTTNG_ERR_INVALID
;
2754 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2755 &element_target_id
, &element_id
, &element_id_alias
,
2761 /* get the values node */
2762 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2763 node
= xmlNextElementSibling(node
)) {
2764 if (!strcmp((const char *) node
->name
,
2765 config_element_process_attr_values
)) {
2772 ret
= LTTNG_ERR_INVALID
;
2776 /* Go through all id target node */
2777 child_count
= xmlChildElementCount(values_node
);
2778 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2780 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2781 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2782 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2783 ret
= LTTNG_ERR_UNK
;
2787 /* Add all tracked values. */
2788 for (node
= xmlFirstElementChild(values_node
); node
;
2789 node
= xmlNextElementSibling(node
)) {
2790 xmlNodePtr id_target_node
= node
;
2792 /* get id node and track it */
2793 for (node
= xmlFirstElementChild(id_target_node
); node
;
2794 node
= xmlNextElementSibling(node
)) {
2795 if (!strcmp((const char *) node
->name
, element_id
) ||
2796 (element_id_alias
&&
2797 !strcmp((const char *) node
->name
,
2798 element_id_alias
))) {
2800 xmlChar
*content
= xmlNodeGetContent(node
);
2803 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2807 ret
= parse_int(content
, &id
);
2810 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2814 switch (process_attr
) {
2815 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2816 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2820 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2821 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2825 case LTTNG_PROCESS_ATTR_USER_ID
:
2826 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2830 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2831 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2835 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2836 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2840 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2841 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2846 ret
= LTTNG_ERR_INVALID
;
2849 } else if (element_name
&&
2850 !strcmp((const char *) node
->name
,
2852 xmlChar
*content
= xmlNodeGetContent(node
);
2855 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2859 switch (process_attr
) {
2860 case LTTNG_PROCESS_ATTR_USER_ID
:
2861 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
2863 (const char *) content
);
2865 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2866 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
2868 (const char *) content
);
2870 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2871 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
2873 (const char *) content
);
2875 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2876 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
2878 (const char *) content
);
2882 ret
= LTTNG_ERR_INVALID
;
2888 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2890 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2891 ret
= LTTNG_ERR_INVALID
;
2893 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2894 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2896 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2897 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2899 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2900 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2902 ret
= LTTNG_ERR_UNK
;
2906 node
= id_target_node
;
2910 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2915 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2918 struct lttng_domain domain
{};
2919 struct lttng_handle
*handle
= NULL
;
2920 struct lttng_channel
*channel
= NULL
;
2921 xmlNodePtr channels_node
= NULL
;
2922 xmlNodePtr trackers_node
= NULL
;
2923 xmlNodePtr pid_tracker_node
= NULL
;
2924 xmlNodePtr vpid_tracker_node
= NULL
;
2925 xmlNodePtr uid_tracker_node
= NULL
;
2926 xmlNodePtr vuid_tracker_node
= NULL
;
2927 xmlNodePtr gid_tracker_node
= NULL
;
2928 xmlNodePtr vgid_tracker_node
= NULL
;
2931 LTTNG_ASSERT(session_name
);
2933 ret
= init_domain(domain_node
, &domain
);
2938 handle
= lttng_create_handle(session_name
, &domain
);
2940 ret
= -LTTNG_ERR_NOMEM
;
2944 /* get the channels node */
2945 for (node
= xmlFirstElementChild(domain_node
); node
;
2946 node
= xmlNextElementSibling(node
)) {
2947 if (!strcmp((const char *) node
->name
,
2948 config_element_channels
)) {
2949 channels_node
= node
;
2954 if (!channels_node
) {
2958 /* create all channels */
2959 for (node
= xmlFirstElementChild(channels_node
); node
;
2960 node
= xmlNextElementSibling(node
)) {
2961 const enum lttng_domain_type original_domain
= domain
.type
;
2962 xmlNodePtr contexts_node
= NULL
;
2963 xmlNodePtr events_node
= NULL
;
2964 xmlNodePtr channel_attr_node
;
2967 * Channels of the "agent" types cannot be created directly.
2968 * They are meant to be created implicitly through the
2969 * activation of events in their domain. However, a user
2970 * can override the default channel configuration attributes
2971 * by creating the underlying UST channel _before_ enabling
2972 * an agent domain event.
2974 * Hence, the channel's type is substituted before the creation
2975 * and restored by the time the events are created.
2977 switch (domain
.type
) {
2978 case LTTNG_DOMAIN_JUL
:
2979 case LTTNG_DOMAIN_LOG4J
:
2980 case LTTNG_DOMAIN_PYTHON
:
2981 domain
.type
= LTTNG_DOMAIN_UST
;
2986 channel
= lttng_channel_create(&domain
);
2992 for (channel_attr_node
= xmlFirstElementChild(node
);
2993 channel_attr_node
; channel_attr_node
=
2994 xmlNextElementSibling(channel_attr_node
)) {
2995 ret
= process_channel_attr_node(channel_attr_node
,
2996 channel
, &contexts_node
, &events_node
);
3002 ret
= lttng_enable_channel(handle
, channel
);
3007 /* Restore the original channel domain. */
3008 domain
.type
= original_domain
;
3010 ret
= process_events_node(events_node
, handle
, channel
->name
);
3015 ret
= process_contexts_node(contexts_node
, handle
,
3021 lttng_channel_destroy(channel
);
3025 /* get the trackers node */
3026 for (node
= xmlFirstElementChild(domain_node
); node
;
3027 node
= xmlNextElementSibling(node
)) {
3028 if (!strcmp((const char *) node
->name
,
3029 config_element_process_attr_trackers
) ||
3030 !strcmp((const char *) node
->name
,
3031 config_element_trackers_legacy
)) {
3032 if (trackers_node
) {
3033 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3034 config_element_process_attr_trackers
,
3035 config_element_trackers_legacy
);
3039 trackers_node
= node
;
3044 if (!trackers_node
) {
3048 for (node
= xmlFirstElementChild(trackers_node
); node
;
3049 node
= xmlNextElementSibling(node
)) {
3050 if (!strcmp((const char *) node
->name
,
3051 config_element_process_attr_tracker_pid
)) {
3052 pid_tracker_node
= node
;
3053 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3054 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3059 if (!strcmp((const char *) node
->name
,
3060 config_element_process_attr_tracker_vpid
)) {
3061 vpid_tracker_node
= node
;
3062 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3063 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3068 if (!strcmp((const char *) node
->name
,
3069 config_element_process_attr_tracker_uid
)) {
3070 uid_tracker_node
= node
;
3071 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3072 LTTNG_PROCESS_ATTR_USER_ID
);
3077 if (!strcmp((const char *) node
->name
,
3078 config_element_process_attr_tracker_vuid
)) {
3079 vuid_tracker_node
= node
;
3080 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3081 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3086 if (!strcmp((const char *) node
->name
,
3087 config_element_process_attr_tracker_gid
)) {
3088 gid_tracker_node
= node
;
3089 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3090 LTTNG_PROCESS_ATTR_GROUP_ID
);
3095 if (!strcmp((const char *) node
->name
,
3096 config_element_process_attr_tracker_vgid
)) {
3097 vgid_tracker_node
= node
;
3098 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3099 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3104 if (!strcmp((const char *) node
->name
,
3105 config_element_pid_tracker_legacy
)) {
3106 ret
= process_legacy_pid_tracker_node(node
, handle
);
3114 lttng_channel_destroy(channel
);
3115 lttng_destroy_handle(handle
);
3120 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3123 enum lttng_rotation_status status
;
3124 struct lttng_rotation_schedule
*periodic
=
3125 lttng_rotation_schedule_periodic_create();
3128 ret
= -LTTNG_ERR_NOMEM
;
3132 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3134 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3135 ret
= -LTTNG_ERR_INVALID
;
3139 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3141 case LTTNG_ROTATION_STATUS_OK
:
3144 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3145 case LTTNG_ROTATION_STATUS_INVALID
:
3146 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3149 ret
= -LTTNG_ERR_UNK
;
3153 lttng_rotation_schedule_destroy(periodic
);
3158 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3161 enum lttng_rotation_status status
;
3162 struct lttng_rotation_schedule
*size
=
3163 lttng_rotation_schedule_size_threshold_create();
3166 ret
= -LTTNG_ERR_NOMEM
;
3170 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3172 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3173 ret
= -LTTNG_ERR_INVALID
;
3177 status
= lttng_session_add_rotation_schedule(name
, size
);
3179 case LTTNG_ROTATION_STATUS_OK
:
3182 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3183 case LTTNG_ROTATION_STATUS_INVALID
:
3184 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3187 ret
= -LTTNG_ERR_UNK
;
3191 lttng_rotation_schedule_destroy(size
);
3196 int process_session_rotation_schedules_node(
3197 xmlNodePtr schedules_node
,
3198 uint64_t *rotation_timer_interval
,
3199 uint64_t *rotation_size
)
3204 for (child
= xmlFirstElementChild(schedules_node
);
3206 child
= xmlNextElementSibling(child
)) {
3207 if (!strcmp((const char *) child
->name
,
3208 config_element_rotation_schedule_periodic
)) {
3210 xmlNodePtr time_us_node
;
3212 /* periodic rotation schedule */
3213 time_us_node
= xmlFirstElementChild(child
);
3214 if (!time_us_node
||
3215 strcmp((const char *) time_us_node
->name
,
3216 config_element_rotation_schedule_periodic_time_us
)) {
3217 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3222 content
= xmlNodeGetContent(time_us_node
);
3224 ret
= -LTTNG_ERR_NOMEM
;
3227 ret
= parse_uint(content
, rotation_timer_interval
);
3230 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3233 } else if (!strcmp((const char *) child
->name
,
3234 config_element_rotation_schedule_size_threshold
)) {
3236 xmlNodePtr bytes_node
;
3238 /* size_threshold rotation schedule */
3239 bytes_node
= xmlFirstElementChild(child
);
3241 strcmp((const char *) bytes_node
->name
,
3242 config_element_rotation_schedule_size_threshold_bytes
)) {
3243 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3248 content
= xmlNodeGetContent(bytes_node
);
3250 ret
= -LTTNG_ERR_NOMEM
;
3253 ret
= parse_uint(content
, rotation_size
);
3256 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3267 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3269 const struct config_load_session_override_attr
*overrides
)
3271 int ret
, started
= -1, snapshot_mode
= -1;
3272 uint64_t live_timer_interval
= UINT64_MAX
,
3273 rotation_timer_interval
= 0,
3275 xmlChar
*name
= NULL
;
3276 xmlChar
*shm_path
= NULL
;
3277 xmlNodePtr domains_node
= NULL
;
3278 xmlNodePtr output_node
= NULL
;
3280 xmlNodePtr attributes_child
;
3281 struct lttng_domain
*kernel_domain
= NULL
;
3282 struct lttng_domain
*ust_domain
= NULL
;
3283 struct lttng_domain
*jul_domain
= NULL
;
3284 struct lttng_domain
*log4j_domain
= NULL
;
3285 struct lttng_domain
*python_domain
= NULL
;
3287 for (node
= xmlFirstElementChild(session_node
); node
;
3288 node
= xmlNextElementSibling(node
)) {
3289 if (!name
&& !strcmp((const char *) node
->name
,
3290 config_element_name
)) {
3292 xmlChar
*node_content
= xmlNodeGetContent(node
);
3293 if (!node_content
) {
3294 ret
= -LTTNG_ERR_NOMEM
;
3298 name
= node_content
;
3299 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3300 config_element_domains
)) {
3302 domains_node
= node
;
3303 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3304 config_element_started
)) {
3306 xmlChar
*node_content
= xmlNodeGetContent(node
);
3307 if (!node_content
) {
3308 ret
= -LTTNG_ERR_NOMEM
;
3312 ret
= parse_bool(node_content
, &started
);
3315 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3318 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3319 config_element_output
)) {
3322 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3323 config_element_shared_memory_path
)) {
3324 /* shared memory path */
3325 xmlChar
*node_content
= xmlNodeGetContent(node
);
3326 if (!node_content
) {
3327 ret
= -LTTNG_ERR_NOMEM
;
3331 shm_path
= node_content
;
3334 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3335 * rotation_timer_interval.
3337 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3338 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3339 if (!strcmp((const char *) attributes_child
->name
,
3340 config_element_snapshot_mode
)) {
3342 xmlChar
*snapshot_mode_content
=
3343 xmlNodeGetContent(attributes_child
);
3344 if (!snapshot_mode_content
) {
3345 ret
= -LTTNG_ERR_NOMEM
;
3349 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3350 free(snapshot_mode_content
);
3352 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3355 } else if (!strcmp((const char *) attributes_child
->name
,
3356 config_element_live_timer_interval
)) {
3357 /* live_timer_interval */
3358 xmlChar
*timer_interval_content
=
3359 xmlNodeGetContent(attributes_child
);
3360 if (!timer_interval_content
) {
3361 ret
= -LTTNG_ERR_NOMEM
;
3365 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3366 free(timer_interval_content
);
3368 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3371 } else if (!strcmp((const char *) attributes_child
->name
,
3372 config_element_rotation_schedules
)) {
3373 ret
= process_session_rotation_schedules_node(
3375 &rotation_timer_interval
,
3378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3388 /* Mandatory attribute, as defined in the session XSD */
3389 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3393 if (session_name
&& strcmp((char *) name
, session_name
)) {
3394 /* This is not the session we are looking for */
3395 ret
= -LTTNG_ERR_NO_SESSION
;
3399 /* Init domains to create the session handles */
3400 for (node
= xmlFirstElementChild(domains_node
); node
;
3401 node
= xmlNextElementSibling(node
)) {
3402 struct lttng_domain
*domain
;
3404 domain
= (lttng_domain
*) zmalloc(sizeof(*domain
));
3406 ret
= -LTTNG_ERR_NOMEM
;
3410 ret
= init_domain(node
, domain
);
3412 goto domain_init_error
;
3415 switch (domain
->type
) {
3416 case LTTNG_DOMAIN_KERNEL
:
3417 if (kernel_domain
) {
3418 /* Same domain seen twice, invalid! */
3419 goto domain_init_error
;
3421 kernel_domain
= domain
;
3423 case LTTNG_DOMAIN_UST
:
3425 /* Same domain seen twice, invalid! */
3426 goto domain_init_error
;
3428 ust_domain
= domain
;
3430 case LTTNG_DOMAIN_JUL
:
3432 /* Same domain seen twice, invalid! */
3433 goto domain_init_error
;
3435 jul_domain
= domain
;
3437 case LTTNG_DOMAIN_LOG4J
:
3439 /* Same domain seen twice, invalid! */
3440 goto domain_init_error
;
3442 log4j_domain
= domain
;
3444 case LTTNG_DOMAIN_PYTHON
:
3445 if (python_domain
) {
3446 /* Same domain seen twice, invalid! */
3447 goto domain_init_error
;
3449 python_domain
= domain
;
3452 WARN("Invalid domain type");
3453 goto domain_init_error
;
3458 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3462 /* Apply overrides */
3464 if (overrides
->session_name
) {
3465 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3466 if (!name_override
) {
3467 ret
= -LTTNG_ERR_NOMEM
;
3471 /* Overrides the session name to the provided name */
3473 name
= name_override
;
3478 /* Destroy session if it exists */
3479 ret
= lttng_destroy_session((const char *) name
);
3480 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3481 ERR("Failed to destroy existing session.");
3486 /* Create session type depending on output type */
3487 if (snapshot_mode
&& snapshot_mode
!= -1) {
3488 ret
= create_snapshot_session((const char *) name
, output_node
,
3490 } else if (live_timer_interval
&&
3491 live_timer_interval
!= UINT64_MAX
) {
3492 ret
= create_session((const char *) name
,
3493 output_node
, live_timer_interval
, overrides
);
3495 /* regular session */
3496 ret
= create_session((const char *) name
,
3497 output_node
, UINT64_MAX
, overrides
);
3504 ret
= lttng_set_session_shm_path((const char *) name
,
3505 (const char *) shm_path
);
3511 for (node
= xmlFirstElementChild(domains_node
); node
;
3512 node
= xmlNextElementSibling(node
)) {
3513 ret
= process_domain_node(node
, (const char *) name
);
3519 if (rotation_timer_interval
) {
3520 ret
= add_periodic_rotation((const char *) name
,
3521 rotation_timer_interval
);
3526 if (rotation_size
) {
3527 ret
= add_size_rotation((const char *) name
,
3535 ret
= lttng_start_tracing((const char *) name
);
3543 ERR("Failed to load session %s: %s", (const char *) name
,
3544 lttng_strerror(ret
));
3545 lttng_destroy_session((const char *) name
);
3549 free(kernel_domain
);
3553 free(python_domain
);
3560 * Return 1 if the given path is readable by the current UID or 0 if not.
3561 * Return -1 if the path is EPERM.
3563 static int validate_file_read_creds(const char *path
)
3569 /* Can we read the file. */
3570 ret
= access(path
, R_OK
);
3574 if (errno
== EACCES
) {
3585 int load_session_from_file(const char *path
, const char *session_name
,
3586 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3587 const struct config_load_session_override_attr
*overrides
)
3589 int ret
, session_found
= !session_name
;
3590 xmlDocPtr doc
= NULL
;
3591 xmlNodePtr sessions_node
;
3592 xmlNodePtr session_node
;
3595 LTTNG_ASSERT(validation_ctx
);
3597 ret
= validate_file_read_creds(path
);
3600 ret
= -LTTNG_ERR_EPERM
;
3602 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3607 doc
= xmlParseFile(path
);
3609 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3613 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3615 ERR("Session configuration file validation failed");
3616 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3620 sessions_node
= xmlDocGetRootElement(doc
);
3621 if (!sessions_node
) {
3622 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3626 for (session_node
= xmlFirstElementChild(sessions_node
);
3627 session_node
; session_node
=
3628 xmlNextElementSibling(session_node
)) {
3629 ret
= process_session_node(session_node
,
3630 session_name
, overwrite
, overrides
);
3631 if (!session_name
&& ret
) {
3632 /* Loading error occurred. */
3634 } else if (session_name
) {
3636 /* Target session found and loaded */
3639 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3641 * Ignore this error, we are looking for a
3646 /* Loading error occurred. */
3654 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3660 int load_session_from_path(const char *path
, const char *session_name
,
3661 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3662 const struct config_load_session_override_attr
*overrides
)
3664 int ret
, session_found
= !session_name
;
3665 DIR *directory
= NULL
;
3666 struct lttng_dynamic_buffer file_path
;
3670 LTTNG_ASSERT(validation_ctx
);
3671 path_len
= strlen(path
);
3672 lttng_dynamic_buffer_init(&file_path
);
3673 if (path_len
>= LTTNG_PATH_MAX
) {
3674 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3675 path
, path_len
, LTTNG_PATH_MAX
);
3676 ret
= -LTTNG_ERR_INVALID
;
3680 directory
= opendir(path
);
3684 /* Try the file loading. */
3687 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3690 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3695 size_t file_path_root_len
;
3697 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3700 ret
= -LTTNG_ERR_NOMEM
;
3704 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3706 ret
= -LTTNG_ERR_NOMEM
;
3710 if (file_path
.data
[file_path
.size
- 1] != '/') {
3711 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3713 ret
= -LTTNG_ERR_NOMEM
;
3717 file_path_root_len
= file_path
.size
;
3719 /* Search for *.lttng files */
3721 size_t file_name_len
;
3722 struct dirent
*result
;
3725 * When the end of the directory stream is reached, NULL
3726 * is returned and errno is kept unchanged. When an
3727 * error occurs, NULL is returned and errno is set
3728 * accordingly. To distinguish between the two, set
3729 * errno to zero before calling readdir().
3731 * On success, readdir() returns a pointer to a dirent
3732 * structure. This structure may be statically
3733 * allocated, do not attempt to free(3) it.
3736 result
= readdir(directory
);
3738 /* Reached end of dir stream or error out. */
3741 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3742 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3748 file_name_len
= strlen(result
->d_name
);
3750 if (file_name_len
<=
3751 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3755 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3756 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3758 /* +1 to account for NULL terminator. */
3759 file_path
.size
+ file_name_len
+ 1,
3764 /* Does the file end with .lttng? */
3765 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3766 result
->d_name
+ file_name_len
- sizeof(
3767 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3771 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3774 ret
= -LTTNG_ERR_NOMEM
;
3778 ret
= load_session_from_file(file_path
.data
, session_name
,
3779 validation_ctx
, overwrite
, overrides
);
3781 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3785 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3789 * Reset the buffer's size to the location of the
3790 * path's trailing '/'.
3792 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3793 file_path_root_len
);
3795 ret
= -LTTNG_ERR_UNK
;
3800 ret
= load_session_from_file(path
, session_name
,
3801 validation_ctx
, overwrite
, overrides
);
3811 if (closedir(directory
)) {
3815 if (!ret
&& !session_found
) {
3816 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3818 lttng_dynamic_buffer_reset(&file_path
);
3823 * Validate that the given path's credentials and the current process have the
3824 * same UID. If so, return 1 else return 0 if it does NOT match.
3826 static int validate_path_creds(const char *path
)
3828 int ret
, uid
= getuid();
3837 ret
= stat(path
, &buf
);
3839 if (errno
!= ENOENT
) {
3845 if (buf
.st_uid
!= uid
) {
3855 int config_load_session(const char *path
, const char *session_name
,
3856 int overwrite
, unsigned int autoload
,
3857 const struct config_load_session_override_attr
*overrides
)
3860 bool session_loaded
= false;
3861 const char *path_ptr
= NULL
;
3862 struct session_config_validation_ctx validation_ctx
= { 0 };
3864 ret
= init_session_config_validation_ctx(&validation_ctx
);
3870 const char *home_path
;
3871 const char *sys_path
;
3874 home_path
= utils_get_home_dir();
3876 char path_buf
[PATH_MAX
];
3879 * Try user session configuration path. Ignore error here so we can
3880 * continue loading the system wide sessions.
3883 ret
= snprintf(path_buf
, sizeof(path_buf
),
3884 DEFAULT_SESSION_HOME_CONFIGPATH
3885 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
3888 PERROR("snprintf session autoload home config path");
3889 ret
= -LTTNG_ERR_INVALID
;
3894 * Credentials are only validated for the autoload in order to
3895 * avoid any user session daemon to try to load kernel sessions
3896 * automatically and failing all the times.
3898 ret
= validate_path_creds(path_buf
);
3900 path_ptr
= path_buf
;
3903 ret
= snprintf(path_buf
, sizeof(path_buf
),
3904 DEFAULT_SESSION_HOME_CONFIGPATH
,
3907 PERROR("snprintf session home config path");
3908 ret
= -LTTNG_ERR_INVALID
;
3911 path_ptr
= path_buf
;
3914 ret
= load_session_from_path(path_ptr
, session_name
,
3915 &validation_ctx
, overwrite
, overrides
);
3916 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3920 * Continue even if the session was found since we have to try
3921 * the system wide sessions.
3923 session_loaded
= true;
3927 /* Reset path pointer for the system wide dir. */
3930 /* Try system wide configuration directory. */
3932 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3933 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3934 ret
= validate_path_creds(sys_path
);
3936 path_ptr
= sys_path
;
3939 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3940 path_ptr
= sys_path
;
3944 ret
= load_session_from_path(path_ptr
, session_name
,
3945 &validation_ctx
, overwrite
, overrides
);
3947 session_loaded
= true;
3953 ret
= access(path
, F_OK
);
3958 ret
= -LTTNG_ERR_INVALID
;
3959 WARN("Session configuration path does not exist.");
3962 ret
= -LTTNG_ERR_EPERM
;
3965 ret
= -LTTNG_ERR_UNK
;
3971 ret
= load_session_from_path(path
, session_name
,
3972 &validation_ctx
, overwrite
, overrides
);
3975 fini_session_config_validation_ctx(&validation_ctx
);
3976 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3978 * Don't report an error if no sessions are found when called
3979 * without a session_name or a search path.
3984 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3985 /* A matching session was found in one of the search paths. */
3992 void __attribute__((destructor
)) session_config_exit(void)