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"
10 #include "config-internal.hpp"
11 #include "session-config.hpp"
13 #include <common/compat/getenv.hpp>
14 #include <common/defaults.hpp>
15 #include <common/dynamic-buffer.hpp>
16 #include <common/error.hpp>
17 #include <common/macros.hpp>
18 #include <common/utils.hpp>
20 #include <lttng/lttng-error.h>
21 #include <lttng/lttng.h>
22 #include <lttng/rotation.h>
23 #include <lttng/snapshot.h>
24 #include <lttng/userspace-probe.h>
29 #include <libxml/parser.h>
30 #include <libxml/tree.h>
31 #include <libxml/valid.h>
32 #include <libxml/xmlschemas.h>
38 #include <sys/types.h>
41 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
44 struct session_config_validation_ctx
{
45 xmlSchemaParserCtxtPtr parser_ctx
;
47 xmlSchemaValidCtxtPtr schema_validation_ctx
;
51 const char *const config_element_all
= "all";
52 LTTNG_EXPORT
const char *config_xml_encoding
= "UTF-8";
53 LTTNG_EXPORT
size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest
55 LTTNG_EXPORT
const char *config_xml_indent_string
= "\t";
56 LTTNG_EXPORT
const char *config_xml_true
= "true";
57 LTTNG_EXPORT
const char *config_xml_false
= "false";
59 const char *const config_element_channel
= "channel";
60 const char *const config_element_channels
= "channels";
61 const char *const config_element_domain
= "domain";
62 const char *const config_element_domains
= "domains";
63 const char *const config_element_event
= "event";
64 const char *const config_element_events
= "events";
65 const char *const config_element_context
= "context";
66 const char *const config_element_contexts
= "contexts";
67 const char *const config_element_attributes
= "attributes";
68 const char *const config_element_exclusion
= "exclusion";
69 const char *const config_element_exclusions
= "exclusions";
70 const char *const config_element_function_attributes
= "function_attributes";
71 const char *const config_element_probe_attributes
= "probe_attributes";
72 const char *const config_element_symbol_name
= "symbol_name";
73 const char *const config_element_address
= "address";
74 const char *const config_element_offset
= "offset";
76 const char *const config_element_userspace_probe_lookup
= "lookup_method";
77 const char *const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
78 const char *const config_element_userspace_probe_lookup_function_elf
= "ELF";
79 const char *const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
80 const char *const config_element_userspace_probe_location_binary_path
= "binary_path";
81 const char *const config_element_userspace_probe_function_attributes
=
82 "userspace_probe_function_attributes";
83 const char *const config_element_userspace_probe_function_location_function_name
= "function_name";
84 const char *const config_element_userspace_probe_tracepoint_attributes
=
85 "userspace_probe_tracepoint_attributes";
86 const char *const config_element_userspace_probe_tracepoint_location_provider_name
=
88 const char *const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
90 const char *const config_element_name
= "name";
91 const char *const config_element_enabled
= "enabled";
92 const char *const config_element_overwrite_mode
= "overwrite_mode";
93 const char *const config_element_subbuf_size
= "subbuffer_size";
94 const char *const config_element_num_subbuf
= "subbuffer_count";
95 const char *const config_element_switch_timer_interval
= "switch_timer_interval";
96 const char *const config_element_read_timer_interval
= "read_timer_interval";
97 const char *const config_element_monitor_timer_interval
= "monitor_timer_interval";
98 const char *const config_element_blocking_timeout
= "blocking_timeout";
99 const char *const config_element_output
= "output";
100 const char *const config_element_output_type
= "output_type";
101 const char *const config_element_tracefile_size
= "tracefile_size";
102 const char *const config_element_tracefile_count
= "tracefile_count";
103 const char *const config_element_live_timer_interval
= "live_timer_interval";
104 const char *const config_element_discarded_events
= "discarded_events";
105 const char *const config_element_lost_packets
= "lost_packets";
106 const char *const config_element_type
= "type";
107 const char *const config_element_buffer_type
= "buffer_type";
108 const char *const config_element_session
= "session";
109 const char *const config_element_sessions
= "sessions";
110 const char *const config_element_context_perf
= "perf";
111 const char *const config_element_context_app
= "app";
112 const char *const config_element_context_app_provider_name
= "provider_name";
113 const char *const config_element_context_app_ctx_name
= "ctx_name";
114 const char *const config_element_config
= "config";
115 const char *const config_element_started
= "started";
116 const char *const config_element_snapshot_mode
= "snapshot_mode";
117 const char *const config_element_loglevel
= "loglevel";
118 const char *const config_element_loglevel_type
= "loglevel_type";
119 const char *const config_element_filter
= "filter";
120 const char *const config_element_filter_expression
= "filter_expression";
121 const char *const config_element_snapshot_outputs
= "snapshot_outputs";
122 const char *const config_element_consumer_output
= "consumer_output";
123 const char *const config_element_destination
= "destination";
124 const char *const config_element_path
= "path";
125 const char *const config_element_net_output
= "net_output";
126 const char *const config_element_control_uri
= "control_uri";
127 const char *const config_element_data_uri
= "data_uri";
128 const char *const config_element_max_size
= "max_size";
129 const char *const config_element_pid
= "pid";
130 const char *const config_element_pids
= "pids";
131 const char *const config_element_shared_memory_path
= "shared_memory_path";
133 const char *const config_element_process_attr_id
= "id";
134 const char *const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
135 const char *const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
136 const char *const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
137 const char *const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
138 const char *const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
139 const char *const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
140 const char *const config_element_process_attr_trackers
= "process_attr_trackers";
141 const char *const config_element_process_attr_values
= "process_attr_values";
142 const char *const config_element_process_attr_value_type
= "process_attr_value_type";
143 const char *const config_element_process_attr_pid_value
= "pid";
144 const char *const config_element_process_attr_vpid_value
= "vpid";
145 const char *const config_element_process_attr_uid_value
= "uid";
146 const char *const config_element_process_attr_vuid_value
= "vuid";
147 const char *const config_element_process_attr_gid_value
= "gid";
148 const char *const config_element_process_attr_vgid_value
= "vgid";
149 const char *const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
151 /* Used for support of legacy tracker serialization (< 2.12). */
152 const char *const config_element_trackers_legacy
= "trackers";
153 const char *const config_element_pid_tracker_legacy
= "pid_tracker";
154 const char *const config_element_tracker_targets_legacy
= "targets";
155 const char *const config_element_tracker_pid_legacy
= "pid";
157 const char *const config_element_rotation_schedules
= "rotation_schedules";
158 const char *const config_element_rotation_schedule_periodic
= "periodic";
159 const char *const config_element_rotation_schedule_periodic_time_us
= "time_us";
160 const char *const config_element_rotation_schedule_size_threshold
= "size_threshold";
161 const char *const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
163 const char *const config_domain_type_kernel
= "KERNEL";
164 const char *const config_domain_type_ust
= "UST";
165 const char *const config_domain_type_jul
= "JUL";
166 const char *const config_domain_type_log4j
= "LOG4J";
167 const char *const config_domain_type_python
= "PYTHON";
169 const char *const config_buffer_type_per_pid
= "PER_PID";
170 const char *const config_buffer_type_per_uid
= "PER_UID";
171 const char *const config_buffer_type_global
= "GLOBAL";
173 const char *const config_overwrite_mode_discard
= "DISCARD";
174 const char *const config_overwrite_mode_overwrite
= "OVERWRITE";
176 const char *const config_output_type_splice
= "SPLICE";
177 const char *const config_output_type_mmap
= "MMAP";
179 const char *const config_loglevel_type_all
= "ALL";
180 const char *const config_loglevel_type_range
= "RANGE";
181 const char *const config_loglevel_type_single
= "SINGLE";
183 const char *const config_event_type_all
= "ALL";
184 const char *const config_event_type_tracepoint
= "TRACEPOINT";
185 const char *const config_event_type_probe
= "PROBE";
186 const char *const config_event_type_userspace_probe
= "USERSPACE_PROBE";
187 const char *const config_event_type_function
= "FUNCTION";
188 const char *const config_event_type_function_entry
= "FUNCTION_ENTRY";
189 const char *const config_event_type_noop
= "NOOP";
190 const char *const config_event_type_syscall
= "SYSCALL";
191 const char *const config_event_type_kprobe
= "KPROBE";
192 const char *const config_event_type_kretprobe
= "KRETPROBE";
194 const char *const config_event_context_pid
= "PID";
195 const char *const config_event_context_procname
= "PROCNAME";
196 const char *const config_event_context_prio
= "PRIO";
197 const char *const config_event_context_nice
= "NICE";
198 const char *const config_event_context_vpid
= "VPID";
199 const char *const config_event_context_tid
= "TID";
200 const char *const config_event_context_vtid
= "VTID";
201 const char *const config_event_context_ppid
= "PPID";
202 const char *const config_event_context_vppid
= "VPPID";
203 const char *const config_event_context_pthread_id
= "PTHREAD_ID";
204 const char *const config_event_context_hostname
= "HOSTNAME";
205 const char *const config_event_context_ip
= "IP";
206 const char *const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
207 const char *const config_event_context_app
= "APP";
208 const char *const config_event_context_interruptible
= "INTERRUPTIBLE";
209 const char *const config_event_context_preemptible
= "PREEMPTIBLE";
210 const char *const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
211 const char *const config_event_context_migratable
= "MIGRATABLE";
212 const char *const config_event_context_callstack_user
= "CALLSTACK_USER";
213 const char *const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
214 const char *const config_event_context_cgroup_ns
= "CGROUP_NS";
215 const char *const config_event_context_ipc_ns
= "IPC_NS";
216 const char *const config_event_context_mnt_ns
= "MNT_NS";
217 const char *const config_event_context_net_ns
= "NET_NS";
218 const char *const config_event_context_pid_ns
= "PID_NS";
219 const char *const config_event_context_time_ns
= "TIME_NS";
220 const char *const config_event_context_user_ns
= "USER_NS";
221 const char *const config_event_context_uts_ns
= "UTS_NS";
222 const char *const config_event_context_uid
= "UID";
223 const char *const config_event_context_euid
= "EUID";
224 const char *const config_event_context_suid
= "SUID";
225 const char *const config_event_context_gid
= "GID";
226 const char *const config_event_context_egid
= "EGID";
227 const char *const config_event_context_sgid
= "SGID";
228 const char *const config_event_context_vuid
= "VUID";
229 const char *const config_event_context_veuid
= "VEUID";
230 const char *const config_event_context_vsuid
= "VSUID";
231 const char *const config_event_context_vgid
= "VGID";
232 const char *const config_event_context_vegid
= "VEGID";
233 const char *const config_event_context_vsgid
= "VSGID";
235 /* Deprecated symbols */
236 LTTNG_EXPORT
const char *config_element_perf
;
238 enum process_event_node_phase
{
244 struct consumer_output
{
253 * Returns a xmlChar string which must be released using xmlFree().
255 static xmlChar
*encode_string(const char *in_str
)
257 xmlChar
*out_str
= nullptr;
258 xmlCharEncodingHandlerPtr handler
;
259 int out_len
, ret
, in_len
;
261 LTTNG_ASSERT(in_str
);
263 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
265 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
269 in_len
= strlen(in_str
);
271 * Add 1 byte for the NULL terminted character. The factor 4 here is
272 * used because UTF-8 characters can take up to 4 bytes.
274 out_len
= (in_len
* 4) + 1;
275 out_str
= (xmlChar
*) xmlMalloc(out_len
);
280 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
287 /* out_len is now the size of out_str */
288 out_str
[out_len
] = '\0';
293 struct config_writer
*config_writer_create(int fd_output
, int indent
)
296 struct config_writer
*writer
;
297 xmlOutputBufferPtr buffer
;
299 writer
= zmalloc
<config_writer
>();
301 PERROR("zmalloc config_writer_create");
305 buffer
= xmlOutputBufferCreateFd(fd_output
, nullptr);
310 writer
->writer
= xmlNewTextWriter(buffer
);
311 ret
= xmlTextWriterStartDocument(writer
->writer
, nullptr, config_xml_encoding
, nullptr);
316 ret
= xmlTextWriterSetIndentString(writer
->writer
, BAD_CAST config_xml_indent_string
);
321 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
329 config_writer_destroy(writer
);
333 int config_writer_destroy(struct config_writer
*writer
)
342 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
343 WARN("Could not close XML document");
347 if (writer
->writer
) {
348 xmlFreeTextWriter(writer
->writer
);
356 int config_writer_open_element(struct config_writer
*writer
, const char *element_name
)
359 xmlChar
*encoded_element_name
;
361 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
366 encoded_element_name
= encode_string(element_name
);
367 if (!encoded_element_name
) {
372 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
373 xmlFree(encoded_element_name
);
375 return ret
>= 0 ? 0 : ret
;
378 int config_writer_write_attribute(struct config_writer
*writer
, const char *name
, const char *value
)
381 xmlChar
*encoded_name
= nullptr;
382 xmlChar
*encoded_value
= nullptr;
384 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
389 encoded_name
= encode_string(name
);
395 encoded_value
= encode_string(value
);
396 if (!encoded_value
) {
401 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
, encoded_value
);
403 xmlFree(encoded_name
);
404 xmlFree(encoded_value
);
405 return ret
>= 0 ? 0 : ret
;
408 int config_writer_close_element(struct config_writer
*writer
)
412 if (!writer
|| !writer
->writer
) {
417 ret
= xmlTextWriterEndElement(writer
->writer
);
419 return ret
>= 0 ? 0 : ret
;
422 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
423 const char *element_name
,
427 xmlChar
*encoded_element_name
;
429 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
434 encoded_element_name
= encode_string(element_name
);
435 if (!encoded_element_name
) {
440 ret
= xmlTextWriterWriteFormatElement(
441 writer
->writer
, encoded_element_name
, "%" PRIu64
, value
);
442 xmlFree(encoded_element_name
);
444 return ret
>= 0 ? 0 : ret
;
447 int config_writer_write_element_signed_int(struct config_writer
*writer
,
448 const char *element_name
,
452 xmlChar
*encoded_element_name
;
454 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
459 encoded_element_name
= encode_string(element_name
);
460 if (!encoded_element_name
) {
465 ret
= xmlTextWriterWriteFormatElement(
466 writer
->writer
, encoded_element_name
, "%" PRIi64
, value
);
467 xmlFree(encoded_element_name
);
469 return ret
>= 0 ? 0 : ret
;
472 int config_writer_write_element_bool(struct config_writer
*writer
,
473 const char *element_name
,
476 return config_writer_write_element_string(
477 writer
, element_name
, value
? config_xml_true
: config_xml_false
);
480 int config_writer_write_element_double(struct config_writer
*writer
,
481 const char *element_name
,
485 xmlChar
*encoded_element_name
;
487 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
492 encoded_element_name
= encode_string(element_name
);
493 if (!encoded_element_name
) {
498 ret
= xmlTextWriterWriteFormatElement(writer
->writer
, encoded_element_name
, "%f", value
);
499 xmlFree(encoded_element_name
);
501 return ret
>= 0 ? 0 : ret
;
504 int config_writer_write_element_string(struct config_writer
*writer
,
505 const char *element_name
,
509 xmlChar
*encoded_element_name
= nullptr;
510 xmlChar
*encoded_value
= nullptr;
512 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] || !value
) {
517 encoded_element_name
= encode_string(element_name
);
518 if (!encoded_element_name
) {
523 encoded_value
= encode_string(value
);
524 if (!encoded_value
) {
529 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
, encoded_value
);
531 xmlFree(encoded_element_name
);
532 xmlFree(encoded_value
);
533 return ret
>= 0 ? 0 : ret
;
536 static ATTR_FORMAT_PRINTF(2, 3) void xml_error_handler(void *ctx
__attribute__((unused
)),
544 va_start(args
, format
);
545 ret
= vasprintf(&errMsg
, format
, args
);
548 ERR("String allocation failed in xml error handler");
552 fprintf(stderr
, "XML Error: %s", errMsg
);
556 static void fini_session_config_validation_ctx(struct session_config_validation_ctx
*ctx
)
558 if (ctx
->parser_ctx
) {
559 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
563 xmlSchemaFree(ctx
->schema
);
566 if (ctx
->schema_validation_ctx
) {
567 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
570 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
573 static char *get_session_config_xsd_path()
576 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
577 size_t base_path_len
;
581 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
584 base_path_len
= strlen(base_path
);
585 max_path_len
= base_path_len
+ sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
586 xsd_path
= zmalloc
<char>(max_path_len
);
591 strcpy(xsd_path
, base_path
);
592 if (xsd_path
[base_path_len
- 1] != '/') {
593 xsd_path
[base_path_len
++] = '/';
596 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
601 static int init_session_config_validation_ctx(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
, xml_error_handler
, nullptr);
619 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
621 ERR("XSD parsing failed");
622 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
626 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
627 if (!ctx
->schema_validation_ctx
) {
628 ERR("XSD validation context creation failed");
629 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
633 xmlSchemaSetValidErrors(
634 ctx
->schema_validation_ctx
, xml_error_handler
, xml_error_handler
, nullptr);
639 fini_session_config_validation_ctx(ctx
);
646 static int parse_uint(xmlChar
*str
, uint64_t *val
)
656 *val
= strtoull((const char *) str
, &endptr
, 10);
657 if (!endptr
|| *endptr
) {
667 static int parse_int(xmlChar
*str
, int64_t *val
)
677 *val
= strtoll((const char *) str
, &endptr
, 10);
678 if (!endptr
|| *endptr
) {
688 static int parse_bool(xmlChar
*str
, int *val
)
697 if (!strcmp((const char *) str
, config_xml_true
) || !strcmp((const char *) str
, "1")) {
699 } else if (!strcmp((const char *) str
, config_xml_false
) ||
700 !strcmp((const char *) str
, "0")) {
703 WARN("Invalid boolean value encountered (%s).", (const char *) str
);
710 static int get_domain_type(xmlChar
*domain
)
718 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
719 ret
= LTTNG_DOMAIN_KERNEL
;
720 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
721 ret
= LTTNG_DOMAIN_UST
;
722 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
723 ret
= LTTNG_DOMAIN_JUL
;
724 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
725 ret
= LTTNG_DOMAIN_LOG4J
;
726 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
727 ret
= LTTNG_DOMAIN_PYTHON
;
737 static int get_buffer_type(xmlChar
*buffer_type
)
745 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
746 ret
= LTTNG_BUFFER_GLOBAL
;
747 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
748 ret
= LTTNG_BUFFER_PER_UID
;
749 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
750 ret
= LTTNG_BUFFER_PER_PID
;
760 static int get_overwrite_mode(xmlChar
*overwrite_mode
)
764 if (!overwrite_mode
) {
768 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
770 } else if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_discard
)) {
781 static int get_output_type(xmlChar
*output_type
)
789 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
790 ret
= LTTNG_EVENT_MMAP
;
791 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
792 ret
= LTTNG_EVENT_SPLICE
;
802 static int get_event_type(xmlChar
*event_type
)
810 if (!strcmp((char *) event_type
, config_event_type_all
)) {
811 ret
= LTTNG_EVENT_ALL
;
812 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
813 ret
= LTTNG_EVENT_TRACEPOINT
;
814 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
815 ret
= LTTNG_EVENT_PROBE
;
816 } else if (!strcmp((char *) event_type
, config_event_type_userspace_probe
)) {
817 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
818 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
819 ret
= LTTNG_EVENT_FUNCTION
;
820 } else if (!strcmp((char *) event_type
, config_event_type_function_entry
)) {
821 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
822 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
823 ret
= LTTNG_EVENT_NOOP
;
824 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
825 ret
= LTTNG_EVENT_SYSCALL
;
835 static int get_loglevel_type(xmlChar
*loglevel_type
)
839 if (!loglevel_type
) {
843 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
844 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
845 } else if (!strcmp((char *) loglevel_type
, config_loglevel_type_range
)) {
846 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
847 } else if (!strcmp((char *) loglevel_type
, config_loglevel_type_single
)) {
848 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
859 * Return the context type or -1 on error.
861 static int get_context_type(xmlChar
*context_type
)
869 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
870 ret
= LTTNG_EVENT_CONTEXT_PID
;
871 } else if (!strcmp((char *) context_type
, config_event_context_procname
)) {
872 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
873 } else if (!strcmp((char *) context_type
, config_event_context_prio
)) {
874 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
875 } else if (!strcmp((char *) context_type
, config_event_context_nice
)) {
876 ret
= LTTNG_EVENT_CONTEXT_NICE
;
877 } else if (!strcmp((char *) context_type
, config_event_context_vpid
)) {
878 ret
= LTTNG_EVENT_CONTEXT_VPID
;
879 } else if (!strcmp((char *) context_type
, config_event_context_tid
)) {
880 ret
= LTTNG_EVENT_CONTEXT_TID
;
881 } else if (!strcmp((char *) context_type
, config_event_context_vtid
)) {
882 ret
= LTTNG_EVENT_CONTEXT_VTID
;
883 } else if (!strcmp((char *) context_type
, config_event_context_ppid
)) {
884 ret
= LTTNG_EVENT_CONTEXT_PPID
;
885 } else if (!strcmp((char *) context_type
, config_event_context_vppid
)) {
886 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
887 } else if (!strcmp((char *) context_type
, config_event_context_pthread_id
)) {
888 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
889 } else if (!strcmp((char *) context_type
, config_event_context_hostname
)) {
890 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
891 } else if (!strcmp((char *) context_type
, config_event_context_ip
)) {
892 ret
= LTTNG_EVENT_CONTEXT_IP
;
893 } else if (!strcmp((char *) context_type
, config_event_context_interruptible
)) {
894 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
895 } else if (!strcmp((char *) context_type
, config_event_context_preemptible
)) {
896 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
897 } else if (!strcmp((char *) context_type
, config_event_context_need_reschedule
)) {
898 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
899 } else if (!strcmp((char *) context_type
, config_event_context_migratable
)) {
900 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
901 } else if (!strcmp((char *) context_type
, config_event_context_callstack_user
)) {
902 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
903 } else if (!strcmp((char *) context_type
, config_event_context_callstack_kernel
)) {
904 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
905 } else if (!strcmp((char *) context_type
, config_event_context_cgroup_ns
)) {
906 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
907 } else if (!strcmp((char *) context_type
, config_event_context_ipc_ns
)) {
908 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
909 } else if (!strcmp((char *) context_type
, config_event_context_mnt_ns
)) {
910 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
911 } else if (!strcmp((char *) context_type
, config_event_context_net_ns
)) {
912 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
913 } else if (!strcmp((char *) context_type
, config_event_context_pid_ns
)) {
914 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
915 } else if (!strcmp((char *) context_type
, config_event_context_time_ns
)) {
916 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
917 } else if (!strcmp((char *) context_type
, config_event_context_user_ns
)) {
918 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
919 } else if (!strcmp((char *) context_type
, config_event_context_uts_ns
)) {
920 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
921 } else if (!strcmp((char *) context_type
, config_event_context_uid
)) {
922 ret
= LTTNG_EVENT_CONTEXT_UID
;
923 } else if (!strcmp((char *) context_type
, config_event_context_euid
)) {
924 ret
= LTTNG_EVENT_CONTEXT_EUID
;
925 } else if (!strcmp((char *) context_type
, config_event_context_suid
)) {
926 ret
= LTTNG_EVENT_CONTEXT_SUID
;
927 } else if (!strcmp((char *) context_type
, config_event_context_gid
)) {
928 ret
= LTTNG_EVENT_CONTEXT_GID
;
929 } else if (!strcmp((char *) context_type
, config_event_context_egid
)) {
930 ret
= LTTNG_EVENT_CONTEXT_EGID
;
931 } else if (!strcmp((char *) context_type
, config_event_context_sgid
)) {
932 ret
= LTTNG_EVENT_CONTEXT_SGID
;
933 } else if (!strcmp((char *) context_type
, config_event_context_vuid
)) {
934 ret
= LTTNG_EVENT_CONTEXT_VUID
;
935 } else if (!strcmp((char *) context_type
, config_event_context_veuid
)) {
936 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
937 } else if (!strcmp((char *) context_type
, config_event_context_vsuid
)) {
938 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
939 } else if (!strcmp((char *) context_type
, config_event_context_vgid
)) {
940 ret
= LTTNG_EVENT_CONTEXT_VGID
;
941 } else if (!strcmp((char *) context_type
, config_event_context_vegid
)) {
942 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
943 } else if (!strcmp((char *) context_type
, config_event_context_vsgid
)) {
944 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
954 static int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
959 for (node
= xmlFirstElementChild(domain_node
); node
; node
= xmlNextElementSibling(node
)) {
960 if (!strcmp((const char *) node
->name
, config_element_type
)) {
962 xmlChar
*node_content
= xmlNodeGetContent(node
);
964 ret
= -LTTNG_ERR_NOMEM
;
968 ret
= get_domain_type(node_content
);
971 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
975 domain
->type
= (lttng_domain_type
) ret
;
976 } else if (!strcmp((const char *) node
->name
, config_element_buffer_type
)) {
978 xmlChar
*node_content
= xmlNodeGetContent(node
);
980 ret
= -LTTNG_ERR_NOMEM
;
984 ret
= get_buffer_type(node_content
);
987 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
991 domain
->buf_type
= (lttng_buffer_type
) ret
;
999 static int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
, char **data_uri
)
1003 for (node
= xmlFirstElementChild(net_output_node
); node
;
1004 node
= xmlNextElementSibling(node
)) {
1005 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1007 *control_uri
= (char *) xmlNodeGetContent(node
);
1008 if (!*control_uri
) {
1013 *data_uri
= (char *) xmlNodeGetContent(node
);
1020 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1023 static int process_consumer_output(xmlNodePtr consumer_output_node
, struct consumer_output
*output
)
1028 LTTNG_ASSERT(output
);
1030 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1031 node
= xmlNextElementSibling(node
)) {
1032 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1033 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1037 ret
= -LTTNG_ERR_NOMEM
;
1041 ret
= parse_bool(enabled_str
, &output
->enabled
);
1047 xmlNodePtr output_type_node
;
1050 output_type_node
= xmlFirstElementChild(node
);
1051 if (!output_type_node
) {
1052 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1056 if (!strcmp((const char *) output_type_node
->name
, config_element_path
)) {
1058 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1059 if (!output
->path
) {
1060 ret
= -LTTNG_ERR_NOMEM
;
1065 ret
= get_net_output_uris(
1066 output_type_node
, &output
->control_uri
, &output
->data_uri
);
1078 free(output
->control_uri
);
1079 free(output
->data_uri
);
1080 memset(output
, 0, sizeof(struct consumer_output
));
1085 static int create_snapshot_session(const char *session_name
,
1086 xmlNodePtr output_node
,
1087 const struct config_load_session_override_attr
*overrides
)
1090 enum lttng_error_code ret_code
;
1091 xmlNodePtr node
= nullptr;
1092 xmlNodePtr snapshot_output_list_node
;
1093 xmlNodePtr snapshot_output_node
;
1094 struct lttng_session_descriptor
*session_descriptor
= nullptr;
1096 LTTNG_ASSERT(session_name
);
1097 LTTNG_ASSERT(output_node
);
1100 * Use a descriptor without output since consumer output size is not
1101 * exposed by the session descriptor api.
1103 session_descriptor
= lttng_session_descriptor_snapshot_create(session_name
);
1104 if (session_descriptor
== nullptr) {
1105 ret
= -LTTNG_ERR_NOMEM
;
1109 ret_code
= lttng_create_session_ext(session_descriptor
);
1110 if (ret_code
!= LTTNG_OK
) {
1115 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1117 /* Parse and create snapshot outputs */
1118 for (snapshot_output_node
= xmlFirstElementChild(snapshot_output_list_node
);
1119 snapshot_output_node
;
1120 snapshot_output_node
= xmlNextElementSibling(snapshot_output_node
)) {
1121 char *name
= nullptr;
1122 uint64_t max_size
= UINT64_MAX
;
1123 struct consumer_output output
= {};
1124 struct lttng_snapshot_output
*snapshot_output
= nullptr;
1125 const char *control_uri
= nullptr;
1126 const char *data_uri
= nullptr;
1127 const char *path
= nullptr;
1129 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1130 node
= xmlNextElementSibling(node
)) {
1131 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1133 name
= (char *) xmlNodeGetContent(node
);
1135 ret
= -LTTNG_ERR_NOMEM
;
1136 goto error_snapshot_output
;
1138 } else if (!strcmp((const char *) node
->name
, config_element_max_size
)) {
1139 xmlChar
*content
= xmlNodeGetContent(node
);
1143 ret
= -LTTNG_ERR_NOMEM
;
1144 goto error_snapshot_output
;
1146 ret
= parse_uint(content
, &max_size
);
1149 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1150 goto error_snapshot_output
;
1153 /* consumer_output */
1154 ret
= process_consumer_output(node
, &output
);
1156 goto error_snapshot_output
;
1161 control_uri
= output
.control_uri
;
1162 data_uri
= output
.data_uri
;
1166 if (overrides
->path_url
) {
1167 path
= overrides
->path_url
;
1168 /* Control/data_uri are null */
1169 control_uri
= nullptr;
1172 if (overrides
->ctrl_url
) {
1173 control_uri
= overrides
->ctrl_url
;
1177 if (overrides
->data_url
) {
1178 data_uri
= overrides
->data_url
;
1185 snapshot_output
= lttng_snapshot_output_create();
1186 if (!snapshot_output
) {
1187 ret
= -LTTNG_ERR_NOMEM
;
1188 goto error_snapshot_output
;
1191 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1193 goto error_snapshot_output
;
1196 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1198 goto error_snapshot_output
;
1202 ret
= lttng_snapshot_output_set_ctrl_url(path
, snapshot_output
);
1204 goto error_snapshot_output
;
1208 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1211 goto error_snapshot_output
;
1216 ret
= lttng_snapshot_output_set_data_url(data_uri
, snapshot_output
);
1218 goto error_snapshot_output
;
1223 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1224 error_snapshot_output
:
1227 free(output
.control_uri
);
1228 free(output
.data_uri
);
1229 lttng_snapshot_output_destroy(snapshot_output
);
1235 lttng_session_descriptor_destroy(session_descriptor
);
1239 static int create_session(const char *name
,
1240 xmlNodePtr output_node
,
1241 uint64_t live_timer_interval
,
1242 const struct config_load_session_override_attr
*overrides
)
1245 enum lttng_error_code ret_code
;
1246 struct consumer_output output
= {};
1247 xmlNodePtr consumer_output_node
;
1248 const char *control_uri
= nullptr;
1249 const char *data_uri
= nullptr;
1250 const char *path
= nullptr;
1251 struct lttng_session_descriptor
*session_descriptor
= nullptr;
1256 consumer_output_node
= xmlFirstElementChild(output_node
);
1257 if (!consumer_output_node
) {
1258 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1262 if (strcmp((const char *) consumer_output_node
->name
,
1263 config_element_consumer_output
) != 0) {
1264 WARN("Invalid output type, expected %s node",
1265 config_element_consumer_output
);
1266 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1270 ret
= process_consumer_output(consumer_output_node
, &output
);
1276 control_uri
= output
.control_uri
;
1277 data_uri
= output
.data_uri
;
1280 /* Check for override and apply them */
1282 if (overrides
->path_url
) {
1283 path
= overrides
->path_url
;
1284 /* control/data_uri are null */;
1285 control_uri
= nullptr;
1288 if (overrides
->ctrl_url
) {
1289 control_uri
= overrides
->ctrl_url
;
1293 if (overrides
->data_url
) {
1294 data_uri
= overrides
->data_url
;
1301 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1302 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1306 if (control_uri
|| data_uri
) {
1307 /* network destination */
1308 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1310 * URLs are provided for sure since the test above make sure that
1311 * with a live timer the data and control URIs are provided. So,
1312 * NULL is passed here and will be set right after.
1314 session_descriptor
= lttng_session_descriptor_live_network_create(
1315 name
, control_uri
, data_uri
, live_timer_interval
);
1317 session_descriptor
= lttng_session_descriptor_network_create(
1318 name
, control_uri
, data_uri
);
1321 } else if (path
!= nullptr) {
1322 session_descriptor
= lttng_session_descriptor_local_create(name
, path
);
1325 session_descriptor
= lttng_session_descriptor_create(name
);
1328 if (session_descriptor
== nullptr) {
1329 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1333 ret_code
= lttng_create_session_ext(session_descriptor
);
1334 if (ret_code
!= LTTNG_OK
) {
1341 free(output
.control_uri
);
1342 free(output
.data_uri
);
1343 lttng_session_descriptor_destroy(session_descriptor
);
1347 static struct lttng_userspace_probe_location
*
1348 process_userspace_probe_function_attribute_node(xmlNodePtr attribute_node
)
1350 xmlNodePtr function_attribute_node
;
1351 char *function_name
= nullptr, *binary_path
= nullptr;
1352 struct lttng_userspace_probe_location
*location
= nullptr;
1353 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= nullptr;
1356 * Process userspace probe location function attributes. The order of
1357 * the fields are not guaranteed so we need to iterate over all fields
1358 * and check at the end if everything we need for this location type is
1361 for (function_attribute_node
= xmlFirstElementChild(attribute_node
);
1362 function_attribute_node
;
1363 function_attribute_node
= xmlNextElementSibling(function_attribute_node
)) {
1364 /* Handle function name, binary path and lookup method. */
1365 if (!strcmp((const char *) function_attribute_node
->name
,
1366 config_element_userspace_probe_function_location_function_name
)) {
1367 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1368 if (!function_name
) {
1371 } else if (!strcmp((const char *) function_attribute_node
->name
,
1372 config_element_userspace_probe_location_binary_path
)) {
1373 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1377 } else if (!strcmp((const char *) function_attribute_node
->name
,
1378 config_element_userspace_probe_lookup
)) {
1379 char *lookup_method_name
;
1381 lookup_method_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1382 if (!lookup_method_name
) {
1387 * function_default lookup method defaults to
1388 * function_elf lookup method at the moment.
1390 if (!strcmp(lookup_method_name
,
1391 config_element_userspace_probe_lookup_function_elf
) ||
1392 !strcmp(lookup_method_name
,
1393 config_element_userspace_probe_lookup_function_default
)) {
1395 lttng_userspace_probe_location_lookup_method_function_elf_create();
1396 if (!lookup_method
) {
1397 PERROR("Error creating function default/ELF lookup method");
1400 WARN("Unknown function lookup method");
1403 free(lookup_method_name
);
1404 if (!lookup_method
) {
1411 /* Check if all the necessary fields were found. */
1412 if (binary_path
&& function_name
&& lookup_method
) {
1413 /* Ownership of lookup_method is transferred. */
1414 location
= lttng_userspace_probe_location_function_create(
1415 binary_path
, function_name
, lookup_method
);
1416 lookup_method
= nullptr;
1421 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1423 free(function_name
);
1427 static struct lttng_userspace_probe_location
*
1428 process_userspace_probe_tracepoint_attribute_node(xmlNodePtr attribute_node
)
1430 xmlNodePtr tracepoint_attribute_node
;
1431 char *probe_name
= nullptr, *provider_name
= nullptr, *binary_path
= nullptr;
1432 struct lttng_userspace_probe_location
*location
= nullptr;
1433 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= nullptr;
1436 * Process userspace probe location tracepoint attributes. The order of
1437 * the fields are not guaranteed so we need to iterate over all fields
1438 * and check at the end if everything we need for this location type is
1441 for (tracepoint_attribute_node
= xmlFirstElementChild(attribute_node
);
1442 tracepoint_attribute_node
;
1443 tracepoint_attribute_node
= xmlNextElementSibling(tracepoint_attribute_node
)) {
1444 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1445 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1446 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1450 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1451 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1452 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1453 if (!provider_name
) {
1456 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1457 config_element_userspace_probe_location_binary_path
)) {
1458 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1462 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1463 config_element_userspace_probe_lookup
)) {
1464 char *lookup_method_name
;
1466 lookup_method_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1467 if (!lookup_method_name
) {
1471 if (!strcmp(lookup_method_name
,
1472 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1474 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1475 if (!lookup_method
) {
1476 PERROR("Error creating tracepoint SDT lookup method");
1479 WARN("Unknown tracepoint lookup method");
1482 free(lookup_method_name
);
1483 if (!lookup_method
) {
1487 WARN("Unknown tracepoint attribute");
1491 /* Check if all the necessary fields were found. */
1492 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1493 /* Ownership of lookup_method is transferred. */
1494 location
= lttng_userspace_probe_location_tracepoint_create(
1495 binary_path
, provider_name
, probe_name
, lookup_method
);
1496 lookup_method
= nullptr;
1501 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1503 free(provider_name
);
1508 static int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1509 struct lttng_event_probe_attr
*attr
)
1513 LTTNG_ASSERT(probe_attribute_node
);
1516 if (!strcmp((const char *) probe_attribute_node
->name
, config_element_address
)) {
1521 content
= xmlNodeGetContent(probe_attribute_node
);
1523 ret
= -LTTNG_ERR_NOMEM
;
1527 ret
= parse_uint(content
, &addr
);
1530 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1535 } else if (!strcmp((const char *) probe_attribute_node
->name
, config_element_offset
)) {
1537 uint64_t offset
= 0;
1540 content
= xmlNodeGetContent(probe_attribute_node
);
1542 ret
= -LTTNG_ERR_NOMEM
;
1546 ret
= parse_uint(content
, &offset
);
1549 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1553 attr
->offset
= offset
;
1554 } else if (!strcmp((const char *) probe_attribute_node
->name
, config_element_symbol_name
)) {
1558 content
= xmlNodeGetContent(probe_attribute_node
);
1560 ret
= -LTTNG_ERR_NOMEM
;
1564 ret
= lttng_strncpy(
1565 attr
->symbol_name
, (const char *) content
, LTTNG_SYMBOL_NAME_LEN
);
1567 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1568 (const char *) content
,
1569 strlen((const char *) content
),
1570 LTTNG_SYMBOL_NAME_LEN
);
1571 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1582 static int process_event_node(xmlNodePtr event_node
,
1583 struct lttng_handle
*handle
,
1584 const char *channel_name
,
1585 const enum process_event_node_phase phase
)
1589 struct lttng_event
*event
;
1590 char **exclusions
= nullptr;
1591 unsigned long exclusion_count
= 0;
1592 char *filter_expression
= nullptr;
1594 LTTNG_ASSERT(event_node
);
1595 LTTNG_ASSERT(handle
);
1596 LTTNG_ASSERT(channel_name
);
1598 event
= lttng_event_create();
1600 ret
= -LTTNG_ERR_NOMEM
;
1604 /* Initialize default log level which varies by domain */
1605 switch (handle
->domain
.type
) {
1606 case LTTNG_DOMAIN_JUL
:
1607 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1609 case LTTNG_DOMAIN_LOG4J
:
1610 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1612 case LTTNG_DOMAIN_PYTHON
:
1613 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1615 case LTTNG_DOMAIN_UST
:
1616 case LTTNG_DOMAIN_KERNEL
:
1617 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1623 for (node
= xmlFirstElementChild(event_node
); node
; node
= xmlNextElementSibling(node
)) {
1624 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1628 content
= xmlNodeGetContent(node
);
1630 ret
= -LTTNG_ERR_NOMEM
;
1634 ret
= lttng_strncpy(
1635 event
->name
, (const char *) content
, LTTNG_SYMBOL_NAME_LEN
);
1637 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1638 (const char *) content
,
1639 strlen((const char *) content
),
1640 LTTNG_SYMBOL_NAME_LEN
);
1641 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1646 } else if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1647 xmlChar
*content
= xmlNodeGetContent(node
);
1651 ret
= -LTTNG_ERR_NOMEM
;
1655 ret
= parse_bool(content
, &event
->enabled
);
1658 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1661 } else if (!strcmp((const char *) node
->name
, config_element_type
)) {
1662 xmlChar
*content
= xmlNodeGetContent(node
);
1666 ret
= -LTTNG_ERR_NOMEM
;
1670 ret
= get_event_type(content
);
1673 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1677 event
->type
= (lttng_event_type
) ret
;
1678 } else if (!strcmp((const char *) node
->name
, config_element_loglevel_type
)) {
1679 xmlChar
*content
= xmlNodeGetContent(node
);
1683 ret
= -LTTNG_ERR_NOMEM
;
1687 ret
= get_loglevel_type(content
);
1690 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1694 event
->loglevel_type
= (lttng_loglevel_type
) ret
;
1695 } else if (!strcmp((const char *) node
->name
, config_element_loglevel
)) {
1697 int64_t loglevel
= 0;
1700 content
= xmlNodeGetContent(node
);
1702 ret
= -LTTNG_ERR_NOMEM
;
1706 ret
= parse_int(content
, &loglevel
);
1709 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1713 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1714 WARN("loglevel out of range.");
1715 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1719 event
->loglevel
= loglevel
;
1720 } else if (!strcmp((const char *) node
->name
, config_element_filter
)) {
1721 xmlChar
*content
= xmlNodeGetContent(node
);
1725 ret
= -LTTNG_ERR_NOMEM
;
1729 free(filter_expression
);
1730 filter_expression
= strdup((char *) content
);
1732 if (!filter_expression
) {
1733 ret
= -LTTNG_ERR_NOMEM
;
1736 } else if (!strcmp((const char *) node
->name
, config_element_exclusions
)) {
1737 xmlNodePtr exclusion_node
;
1738 int exclusion_index
= 0;
1743 * Exclusions has already been initialized,
1746 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1750 exclusion_count
= xmlChildElementCount(node
);
1751 if (!exclusion_count
) {
1755 exclusions
= calloc
<char *>(exclusion_count
);
1757 exclusion_count
= 0;
1758 ret
= -LTTNG_ERR_NOMEM
;
1762 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1763 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1764 xmlChar
*content
= xmlNodeGetContent(exclusion_node
);
1767 ret
= -LTTNG_ERR_NOMEM
;
1771 exclusions
[exclusion_index
] = strdup((const char *) content
);
1773 if (!exclusions
[exclusion_index
]) {
1774 ret
= -LTTNG_ERR_NOMEM
;
1780 event
->exclusion
= 1;
1781 } else if (!strcmp((const char *) node
->name
, config_element_attributes
)) {
1782 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1785 if (!attribute_node
) {
1786 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1790 if (!strcmp((const char *) attribute_node
->name
,
1791 config_element_probe_attributes
)) {
1792 xmlNodePtr probe_attribute_node
;
1794 /* probe_attributes */
1795 for (probe_attribute_node
= xmlFirstElementChild(attribute_node
);
1796 probe_attribute_node
;
1797 probe_attribute_node
=
1798 xmlNextElementSibling(probe_attribute_node
)) {
1799 ret
= process_probe_attribute_node(probe_attribute_node
,
1800 &event
->attr
.probe
);
1805 } else if (!strcmp((const char *) attribute_node
->name
,
1806 config_element_function_attributes
)) {
1809 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1811 /* function_attributes */
1812 content
= xmlNodeGetContent(symbol_node
);
1814 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1818 sym_len
= strlen((char *) content
);
1819 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1820 WARN("Function name too long.");
1821 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1826 ret
= lttng_strncpy(
1827 event
->attr
.ftrace
.symbol_name
, (char *) content
, sym_len
);
1829 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1834 } else if (!strcmp((const char *) attribute_node
->name
,
1835 config_element_userspace_probe_tracepoint_attributes
)) {
1836 struct lttng_userspace_probe_location
*location
;
1838 location
= process_userspace_probe_tracepoint_attribute_node(
1841 WARN("Error processing userspace probe tracepoint attribute");
1842 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1845 ret
= lttng_event_set_userspace_probe_location(event
, location
);
1847 WARN("Error setting userspace probe location field");
1848 lttng_userspace_probe_location_destroy(location
);
1849 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1852 } else if (!strcmp((const char *) attribute_node
->name
,
1853 config_element_userspace_probe_function_attributes
)) {
1854 struct lttng_userspace_probe_location
*location
;
1856 location
= process_userspace_probe_function_attribute_node(
1859 WARN("Error processing userspace probe function attribute");
1860 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1864 ret
= lttng_event_set_userspace_probe_location(event
, location
);
1866 WARN("Error setting userspace probe location field");
1867 lttng_userspace_probe_location_destroy(location
);
1868 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1872 /* Unknown event attribute. */
1873 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1879 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1880 ret
= lttng_enable_event_with_exclusions(
1881 handle
, event
, channel_name
, filter_expression
, exclusion_count
, exclusions
);
1883 WARN("Enabling event (name:%s) on load failed.", event
->name
);
1884 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1890 for (i
= 0; i
< exclusion_count
; i
++) {
1891 free(exclusions
[i
]);
1894 lttng_event_destroy(event
);
1896 free(filter_expression
);
1901 process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
, const char *channel_name
)
1904 struct lttng_event event
;
1907 LTTNG_ASSERT(events_node
);
1908 LTTNG_ASSERT(handle
);
1909 LTTNG_ASSERT(channel_name
);
1911 for (node
= xmlFirstElementChild(events_node
); node
; node
= xmlNextElementSibling(node
)) {
1912 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
1919 * Disable all events to enable only the necessary events.
1920 * Limitations regarding lttng_disable_events and tuple descriptor
1921 * force this approach.
1923 memset(&event
, 0, sizeof(event
));
1924 event
.loglevel
= -1;
1925 event
.type
= LTTNG_EVENT_ALL
;
1926 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, nullptr);
1931 for (node
= xmlFirstElementChild(events_node
); node
; node
= xmlNextElementSibling(node
)) {
1932 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
1942 static int process_channel_attr_node(xmlNodePtr attr_node
,
1943 struct lttng_channel
*channel
,
1944 xmlNodePtr
*contexts_node
,
1945 xmlNodePtr
*events_node
)
1949 LTTNG_ASSERT(attr_node
);
1950 LTTNG_ASSERT(channel
);
1951 LTTNG_ASSERT(contexts_node
);
1952 LTTNG_ASSERT(events_node
);
1954 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
1958 content
= xmlNodeGetContent(attr_node
);
1960 ret
= -LTTNG_ERR_NOMEM
;
1964 ret
= lttng_strncpy(channel
->name
, (const char *) content
, LTTNG_SYMBOL_NAME_LEN
);
1966 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1967 (const char *) content
,
1968 strlen((const char *) content
),
1969 LTTNG_SYMBOL_NAME_LEN
);
1970 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1975 } else if (!strcmp((const char *) attr_node
->name
, config_element_enabled
)) {
1980 content
= xmlNodeGetContent(attr_node
);
1982 ret
= -LTTNG_ERR_NOMEM
;
1986 ret
= parse_bool(content
, &enabled
);
1989 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1993 channel
->enabled
= enabled
;
1994 } else if (!strcmp((const char *) attr_node
->name
, config_element_overwrite_mode
)) {
1997 /* overwrite_mode */
1998 content
= xmlNodeGetContent(attr_node
);
2000 ret
= -LTTNG_ERR_NOMEM
;
2004 ret
= get_overwrite_mode(content
);
2007 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2011 channel
->attr
.overwrite
= ret
;
2012 } else if (!strcmp((const char *) attr_node
->name
, config_element_subbuf_size
)) {
2015 /* subbuffer_size */
2016 content
= xmlNodeGetContent(attr_node
);
2018 ret
= -LTTNG_ERR_NOMEM
;
2022 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2025 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2028 } else if (!strcmp((const char *) attr_node
->name
, config_element_num_subbuf
)) {
2031 /* subbuffer_count */
2032 content
= xmlNodeGetContent(attr_node
);
2034 ret
= -LTTNG_ERR_NOMEM
;
2038 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2041 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2044 } else if (!strcmp((const char *) attr_node
->name
, config_element_switch_timer_interval
)) {
2046 uint64_t switch_timer_interval
= 0;
2048 /* switch_timer_interval */
2049 content
= xmlNodeGetContent(attr_node
);
2051 ret
= -LTTNG_ERR_NOMEM
;
2055 ret
= parse_uint(content
, &switch_timer_interval
);
2058 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2062 if (switch_timer_interval
> UINT_MAX
) {
2063 WARN("switch_timer_interval out of range.");
2064 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2068 channel
->attr
.switch_timer_interval
= switch_timer_interval
;
2069 } else if (!strcmp((const char *) attr_node
->name
, config_element_read_timer_interval
)) {
2071 uint64_t read_timer_interval
= 0;
2073 /* read_timer_interval */
2074 content
= xmlNodeGetContent(attr_node
);
2076 ret
= -LTTNG_ERR_NOMEM
;
2080 ret
= parse_uint(content
, &read_timer_interval
);
2083 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2087 if (read_timer_interval
> UINT_MAX
) {
2088 WARN("read_timer_interval out of range.");
2089 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2093 channel
->attr
.read_timer_interval
= read_timer_interval
;
2094 } else if (!strcmp((const char *) attr_node
->name
, config_element_output_type
)) {
2098 content
= xmlNodeGetContent(attr_node
);
2100 ret
= -LTTNG_ERR_NOMEM
;
2104 ret
= get_output_type(content
);
2107 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2111 channel
->attr
.output
= (lttng_event_output
) ret
;
2112 } else if (!strcmp((const char *) attr_node
->name
, config_element_tracefile_size
)) {
2115 /* tracefile_size */
2116 content
= xmlNodeGetContent(attr_node
);
2118 ret
= -LTTNG_ERR_NOMEM
;
2122 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2125 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2128 } else if (!strcmp((const char *) attr_node
->name
, config_element_tracefile_count
)) {
2131 /* tracefile_count */
2132 content
= xmlNodeGetContent(attr_node
);
2134 ret
= -LTTNG_ERR_NOMEM
;
2138 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2141 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2144 } else if (!strcmp((const char *) attr_node
->name
, config_element_live_timer_interval
)) {
2146 uint64_t live_timer_interval
= 0;
2148 /* live_timer_interval */
2149 content
= xmlNodeGetContent(attr_node
);
2151 ret
= -LTTNG_ERR_NOMEM
;
2155 ret
= parse_uint(content
, &live_timer_interval
);
2158 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2162 if (live_timer_interval
> UINT_MAX
) {
2163 WARN("live_timer_interval out of range.");
2164 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2168 channel
->attr
.live_timer_interval
= live_timer_interval
;
2169 } else if (!strcmp((const char *) attr_node
->name
, config_element_monitor_timer_interval
)) {
2171 uint64_t monitor_timer_interval
= 0;
2173 /* monitor_timer_interval */
2174 content
= xmlNodeGetContent(attr_node
);
2176 ret
= -LTTNG_ERR_NOMEM
;
2180 ret
= parse_uint(content
, &monitor_timer_interval
);
2183 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2187 ret
= lttng_channel_set_monitor_timer_interval(channel
, monitor_timer_interval
);
2189 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2192 } else if (!strcmp((const char *) attr_node
->name
, config_element_blocking_timeout
)) {
2194 int64_t blocking_timeout
= 0;
2196 /* blocking_timeout */
2197 content
= xmlNodeGetContent(attr_node
);
2199 ret
= -LTTNG_ERR_NOMEM
;
2203 ret
= parse_int(content
, &blocking_timeout
);
2206 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2210 ret
= lttng_channel_set_blocking_timeout(channel
, blocking_timeout
);
2212 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2215 } else if (!strcmp((const char *) attr_node
->name
, config_element_events
)) {
2217 *events_node
= attr_node
;
2220 *contexts_node
= attr_node
;
2228 process_context_node(xmlNodePtr context_node
, struct lttng_handle
*handle
, const char *channel_name
)
2231 struct lttng_event_context context
;
2232 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2234 LTTNG_ASSERT(handle
);
2235 LTTNG_ASSERT(channel_name
);
2237 if (!context_child_node
) {
2238 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2242 memset(&context
, 0, sizeof(context
));
2244 if (!strcmp((const char *) context_child_node
->name
, config_element_type
)) {
2246 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2249 ret
= -LTTNG_ERR_NOMEM
;
2253 ret
= get_context_type(content
);
2256 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2260 context
.ctx
= (lttng_event_context_type
) ret
;
2261 } else if (!strcmp((const char *) context_child_node
->name
, config_element_context_perf
)) {
2263 xmlNodePtr perf_attr_node
;
2265 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2266 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2267 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2268 for (perf_attr_node
= xmlFirstElementChild(context_child_node
); perf_attr_node
;
2269 perf_attr_node
= xmlNextElementSibling(perf_attr_node
)) {
2270 if (!strcmp((const char *) perf_attr_node
->name
, config_element_type
)) {
2275 content
= xmlNodeGetContent(perf_attr_node
);
2277 ret
= -LTTNG_ERR_NOMEM
;
2281 ret
= parse_uint(content
, &type
);
2284 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2288 if (type
> UINT32_MAX
) {
2289 WARN("perf context type out of range.");
2290 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2294 context
.u
.perf_counter
.type
= type
;
2295 } else if (!strcmp((const char *) perf_attr_node
->name
,
2296 config_element_config
)) {
2298 uint64_t config
= 0;
2301 content
= xmlNodeGetContent(perf_attr_node
);
2303 ret
= -LTTNG_ERR_NOMEM
;
2307 ret
= parse_uint(content
, &config
);
2310 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2314 context
.u
.perf_counter
.config
= config
;
2315 } else if (!strcmp((const char *) perf_attr_node
->name
,
2316 config_element_name
)) {
2320 content
= xmlNodeGetContent(perf_attr_node
);
2322 ret
= -LTTNG_ERR_NOMEM
;
2326 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2327 (const char *) content
,
2328 LTTNG_SYMBOL_NAME_LEN
);
2330 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2331 (const char *) content
,
2332 strlen((const char *) content
),
2333 LTTNG_SYMBOL_NAME_LEN
);
2334 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2341 } else if (!strcmp((const char *) context_child_node
->name
, config_element_context_app
)) {
2342 /* application context */
2343 xmlNodePtr app_ctx_node
;
2345 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2346 for (app_ctx_node
= xmlFirstElementChild(context_child_node
); app_ctx_node
;
2347 app_ctx_node
= xmlNextElementSibling(app_ctx_node
)) {
2349 char **target
= strcmp((const char *) app_ctx_node
->name
,
2350 config_element_context_app_provider_name
) == 0 ?
2351 &context
.u
.app_ctx
.provider_name
:
2352 &context
.u
.app_ctx
.ctx_name
;
2354 content
= xmlNodeGetContent(app_ctx_node
);
2356 ret
= -LTTNG_ERR_NOMEM
;
2360 *target
= (char *) content
;
2363 /* Unrecognized context type */
2364 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2368 ret
= lttng_add_context(handle
, &context
, nullptr, channel_name
);
2369 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2370 free(context
.u
.app_ctx
.provider_name
);
2371 free(context
.u
.app_ctx
.ctx_name
);
2377 static int process_contexts_node(xmlNodePtr contexts_node
,
2378 struct lttng_handle
*handle
,
2379 const char *channel_name
)
2382 xmlNodePtr context_node
;
2384 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2385 context_node
= xmlNextElementSibling(context_node
)) {
2386 ret
= process_context_node(context_node
, handle
, channel_name
);
2395 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2396 const char **element_id_tracker
,
2397 const char **element_value_type
,
2398 const char **element_value
,
2399 const char **element_value_alias
,
2400 const char **element_name
)
2404 switch (process_attr
) {
2405 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2406 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2407 *element_value_type
= config_element_process_attr_pid_value
;
2408 *element_value
= config_element_process_attr_id
;
2409 *element_value_alias
= config_element_process_attr_id
;
2410 *element_name
= nullptr;
2412 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2413 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2414 *element_value_type
= config_element_process_attr_vpid_value
;
2415 *element_value
= config_element_process_attr_id
;
2416 *element_value_alias
= nullptr;
2417 *element_name
= nullptr;
2419 case LTTNG_PROCESS_ATTR_USER_ID
:
2420 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2421 *element_value_type
= config_element_process_attr_uid_value
;
2422 *element_value
= config_element_process_attr_id
;
2423 *element_value_alias
= nullptr;
2424 *element_name
= config_element_name
;
2426 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2427 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2428 *element_value_type
= config_element_process_attr_vuid_value
;
2429 *element_value
= config_element_process_attr_id
;
2430 *element_value_alias
= nullptr;
2431 *element_name
= config_element_name
;
2433 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2434 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2435 *element_value_type
= config_element_process_attr_gid_value
;
2436 *element_value
= config_element_process_attr_id
;
2437 *element_value_alias
= nullptr;
2438 *element_name
= config_element_name
;
2440 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2441 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2442 *element_value_type
= config_element_process_attr_vgid_value
;
2443 *element_value
= config_element_process_attr_id
;
2444 *element_value_alias
= nullptr;
2445 *element_name
= config_element_name
;
2448 ret
= LTTNG_ERR_INVALID
;
2453 static int process_legacy_pid_tracker_node(xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2455 int ret
= 0, child_count
;
2456 xmlNodePtr targets_node
= nullptr;
2458 const char *element_id_tracker
;
2459 const char *element_target_id
;
2460 const char *element_id
;
2461 const char *element_id_alias
;
2462 const char *element_name
;
2463 enum lttng_error_code tracker_handle_ret_code
;
2464 struct lttng_process_attr_tracker_handle
*tracker_handle
= nullptr;
2465 enum lttng_process_attr_tracker_handle_status status
;
2466 const enum lttng_process_attr process_attr
= handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2467 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2468 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2470 LTTNG_ASSERT(handle
);
2472 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2473 handle
->session_name
, handle
->domain
.type
, process_attr
, &tracker_handle
);
2474 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2475 ret
= LTTNG_ERR_INVALID
;
2479 ret
= get_tracker_elements(process_attr
,
2480 &element_id_tracker
,
2489 /* Get the targets node */
2490 for (node
= xmlFirstElementChild(trackers_node
); node
; node
= xmlNextElementSibling(node
)) {
2491 if (!strcmp((const char *) node
->name
, config_element_tracker_targets_legacy
)) {
2492 targets_node
= node
;
2497 if (!targets_node
) {
2498 ret
= LTTNG_ERR_INVALID
;
2502 /* Go through all id target node */
2503 child_count
= xmlChildElementCount(targets_node
);
2504 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2506 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2507 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2508 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2509 ret
= LTTNG_ERR_UNK
;
2513 /* Add all tracked values. */
2514 for (node
= xmlFirstElementChild(targets_node
); node
; node
= xmlNextElementSibling(node
)) {
2515 xmlNodePtr pid_target_node
= node
;
2517 /* get pid_target node and track it */
2518 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2519 node
= xmlNextElementSibling(node
)) {
2520 if (!strcmp((const char *) node
->name
, config_element_tracker_pid_legacy
)) {
2522 xmlChar
*content
= xmlNodeGetContent(node
);
2525 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2529 ret
= parse_int(content
, &id
);
2532 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2536 switch (process_attr
) {
2537 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2539 lttng_process_attr_process_id_tracker_handle_add_pid(
2540 tracker_handle
, (pid_t
) id
);
2542 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2544 lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2545 tracker_handle
, (pid_t
) id
);
2548 ret
= LTTNG_ERR_INVALID
;
2553 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2555 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2556 ret
= LTTNG_ERR_INVALID
;
2558 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2559 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2561 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2562 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2564 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2565 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2567 ret
= LTTNG_ERR_UNK
;
2571 node
= pid_target_node
;
2575 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2579 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2580 struct lttng_handle
*handle
,
2581 enum lttng_process_attr process_attr
)
2583 int ret
= 0, child_count
;
2584 xmlNodePtr values_node
= nullptr;
2586 const char *element_id_tracker
;
2587 const char *element_target_id
;
2588 const char *element_id
;
2589 const char *element_id_alias
;
2590 const char *element_name
;
2591 enum lttng_error_code tracker_handle_ret_code
;
2592 struct lttng_process_attr_tracker_handle
*tracker_handle
= nullptr;
2593 enum lttng_process_attr_tracker_handle_status status
;
2595 LTTNG_ASSERT(handle
);
2596 LTTNG_ASSERT(id_tracker_node
);
2598 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2599 handle
->session_name
, handle
->domain
.type
, process_attr
, &tracker_handle
);
2600 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2601 ret
= LTTNG_ERR_INVALID
;
2605 ret
= get_tracker_elements(process_attr
,
2606 &element_id_tracker
,
2615 /* get the values node */
2616 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2617 node
= xmlNextElementSibling(node
)) {
2618 if (!strcmp((const char *) node
->name
, config_element_process_attr_values
)) {
2625 ret
= LTTNG_ERR_INVALID
;
2629 /* Go through all id target node */
2630 child_count
= xmlChildElementCount(values_node
);
2631 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2633 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2634 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2635 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2636 ret
= LTTNG_ERR_UNK
;
2640 /* Add all tracked values. */
2641 for (node
= xmlFirstElementChild(values_node
); node
; node
= xmlNextElementSibling(node
)) {
2642 xmlNodePtr id_target_node
= node
;
2644 /* get id node and track it */
2645 for (node
= xmlFirstElementChild(id_target_node
); node
;
2646 node
= xmlNextElementSibling(node
)) {
2647 if (!strcmp((const char *) node
->name
, element_id
) ||
2648 (element_id_alias
&&
2649 !strcmp((const char *) node
->name
, element_id_alias
))) {
2651 xmlChar
*content
= xmlNodeGetContent(node
);
2654 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2658 ret
= parse_int(content
, &id
);
2661 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2665 switch (process_attr
) {
2666 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2668 lttng_process_attr_process_id_tracker_handle_add_pid(
2669 tracker_handle
, (pid_t
) id
);
2671 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2673 lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2674 tracker_handle
, (pid_t
) id
);
2676 case LTTNG_PROCESS_ATTR_USER_ID
:
2677 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2678 tracker_handle
, (uid_t
) id
);
2680 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2682 lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2683 tracker_handle
, (uid_t
) id
);
2685 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2686 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2687 tracker_handle
, (gid_t
) id
);
2689 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2691 lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2692 tracker_handle
, (gid_t
) id
);
2695 ret
= LTTNG_ERR_INVALID
;
2698 } else if (element_name
&&
2699 !strcmp((const char *) node
->name
, element_name
)) {
2700 xmlChar
*content
= xmlNodeGetContent(node
);
2703 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2707 switch (process_attr
) {
2708 case LTTNG_PROCESS_ATTR_USER_ID
:
2710 lttng_process_attr_user_id_tracker_handle_add_user_name(
2711 tracker_handle
, (const char *) content
);
2713 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2715 lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
2716 tracker_handle
, (const char *) content
);
2718 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2720 lttng_process_attr_group_id_tracker_handle_add_group_name(
2721 tracker_handle
, (const char *) content
);
2723 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2725 lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
2726 tracker_handle
, (const char *) content
);
2730 ret
= LTTNG_ERR_INVALID
;
2736 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2738 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2739 ret
= LTTNG_ERR_INVALID
;
2741 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2742 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2744 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2745 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2747 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2748 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2750 ret
= LTTNG_ERR_UNK
;
2754 node
= id_target_node
;
2758 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2762 static int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2765 struct lttng_domain domain
{};
2766 struct lttng_handle
*handle
= nullptr;
2767 struct lttng_channel
*channel
= nullptr;
2768 xmlNodePtr channels_node
= nullptr;
2769 xmlNodePtr trackers_node
= nullptr;
2770 xmlNodePtr pid_tracker_node
= nullptr;
2771 xmlNodePtr vpid_tracker_node
= nullptr;
2772 xmlNodePtr uid_tracker_node
= nullptr;
2773 xmlNodePtr vuid_tracker_node
= nullptr;
2774 xmlNodePtr gid_tracker_node
= nullptr;
2775 xmlNodePtr vgid_tracker_node
= nullptr;
2778 LTTNG_ASSERT(session_name
);
2780 ret
= init_domain(domain_node
, &domain
);
2785 handle
= lttng_create_handle(session_name
, &domain
);
2787 ret
= -LTTNG_ERR_NOMEM
;
2791 /* get the channels node */
2792 for (node
= xmlFirstElementChild(domain_node
); node
; node
= xmlNextElementSibling(node
)) {
2793 if (!strcmp((const char *) node
->name
, config_element_channels
)) {
2794 channels_node
= node
;
2799 if (!channels_node
) {
2803 /* create all channels */
2804 for (node
= xmlFirstElementChild(channels_node
); node
; node
= xmlNextElementSibling(node
)) {
2805 const enum lttng_domain_type original_domain
= domain
.type
;
2806 xmlNodePtr contexts_node
= nullptr;
2807 xmlNodePtr events_node
= nullptr;
2808 xmlNodePtr channel_attr_node
;
2811 * Channels of the "agent" types cannot be created directly.
2812 * They are meant to be created implicitly through the
2813 * activation of events in their domain. However, a user
2814 * can override the default channel configuration attributes
2815 * by creating the underlying UST channel _before_ enabling
2816 * an agent domain event.
2818 * Hence, the channel's type is substituted before the creation
2819 * and restored by the time the events are created.
2821 switch (domain
.type
) {
2822 case LTTNG_DOMAIN_JUL
:
2823 case LTTNG_DOMAIN_LOG4J
:
2824 case LTTNG_DOMAIN_PYTHON
:
2825 domain
.type
= LTTNG_DOMAIN_UST
;
2830 channel
= lttng_channel_create(&domain
);
2836 for (channel_attr_node
= xmlFirstElementChild(node
); channel_attr_node
;
2837 channel_attr_node
= xmlNextElementSibling(channel_attr_node
)) {
2838 ret
= process_channel_attr_node(
2839 channel_attr_node
, channel
, &contexts_node
, &events_node
);
2845 ret
= lttng_enable_channel(handle
, channel
);
2850 /* Restore the original channel domain. */
2851 domain
.type
= original_domain
;
2853 ret
= process_events_node(events_node
, handle
, channel
->name
);
2858 ret
= process_contexts_node(contexts_node
, handle
, channel
->name
);
2863 lttng_channel_destroy(channel
);
2867 /* get the trackers node */
2868 for (node
= xmlFirstElementChild(domain_node
); node
; node
= xmlNextElementSibling(node
)) {
2869 if (!strcmp((const char *) node
->name
, config_element_process_attr_trackers
) ||
2870 !strcmp((const char *) node
->name
, config_element_trackers_legacy
)) {
2871 if (trackers_node
) {
2872 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
2873 config_element_process_attr_trackers
,
2874 config_element_trackers_legacy
);
2878 trackers_node
= node
;
2883 if (!trackers_node
) {
2887 for (node
= xmlFirstElementChild(trackers_node
); node
; node
= xmlNextElementSibling(node
)) {
2888 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_pid
)) {
2889 pid_tracker_node
= node
;
2890 ret
= process_id_tracker_node(
2891 pid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_PROCESS_ID
);
2896 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_vpid
)) {
2897 vpid_tracker_node
= node
;
2898 ret
= process_id_tracker_node(
2899 vpid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2904 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_uid
)) {
2905 uid_tracker_node
= node
;
2906 ret
= process_id_tracker_node(
2907 uid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_USER_ID
);
2912 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_vuid
)) {
2913 vuid_tracker_node
= node
;
2914 ret
= process_id_tracker_node(
2915 vuid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2920 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_gid
)) {
2921 gid_tracker_node
= node
;
2922 ret
= process_id_tracker_node(
2923 gid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_GROUP_ID
);
2928 if (!strcmp((const char *) node
->name
, config_element_process_attr_tracker_vgid
)) {
2929 vgid_tracker_node
= node
;
2930 ret
= process_id_tracker_node(
2931 vgid_tracker_node
, handle
, LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2936 if (!strcmp((const char *) node
->name
, config_element_pid_tracker_legacy
)) {
2937 ret
= process_legacy_pid_tracker_node(node
, handle
);
2945 lttng_channel_destroy(channel
);
2946 lttng_destroy_handle(handle
);
2950 static int add_periodic_rotation(const char *name
, uint64_t time_us
)
2953 enum lttng_rotation_status status
;
2954 struct lttng_rotation_schedule
*periodic
= lttng_rotation_schedule_periodic_create();
2957 ret
= -LTTNG_ERR_NOMEM
;
2961 status
= lttng_rotation_schedule_periodic_set_period(periodic
, time_us
);
2962 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2963 ret
= -LTTNG_ERR_INVALID
;
2967 status
= lttng_session_add_rotation_schedule(name
, periodic
);
2969 case LTTNG_ROTATION_STATUS_OK
:
2972 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
2973 case LTTNG_ROTATION_STATUS_INVALID
:
2974 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2977 ret
= -LTTNG_ERR_UNK
;
2981 lttng_rotation_schedule_destroy(periodic
);
2985 static int add_size_rotation(const char *name
, uint64_t size_bytes
)
2988 enum lttng_rotation_status status
;
2989 struct lttng_rotation_schedule
*size
= lttng_rotation_schedule_size_threshold_create();
2992 ret
= -LTTNG_ERR_NOMEM
;
2996 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
, size_bytes
);
2997 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2998 ret
= -LTTNG_ERR_INVALID
;
3002 status
= lttng_session_add_rotation_schedule(name
, size
);
3004 case LTTNG_ROTATION_STATUS_OK
:
3007 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3008 case LTTNG_ROTATION_STATUS_INVALID
:
3009 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3012 ret
= -LTTNG_ERR_UNK
;
3016 lttng_rotation_schedule_destroy(size
);
3020 static int process_session_rotation_schedules_node(xmlNodePtr schedules_node
,
3021 uint64_t *rotation_timer_interval
,
3022 uint64_t *rotation_size
)
3027 for (child
= xmlFirstElementChild(schedules_node
); child
;
3028 child
= xmlNextElementSibling(child
)) {
3029 if (!strcmp((const char *) child
->name
,
3030 config_element_rotation_schedule_periodic
)) {
3032 xmlNodePtr time_us_node
;
3034 /* periodic rotation schedule */
3035 time_us_node
= xmlFirstElementChild(child
);
3036 if (!time_us_node
||
3037 strcmp((const char *) time_us_node
->name
,
3038 config_element_rotation_schedule_periodic_time_us
) != 0) {
3039 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3044 content
= xmlNodeGetContent(time_us_node
);
3046 ret
= -LTTNG_ERR_NOMEM
;
3049 ret
= parse_uint(content
, rotation_timer_interval
);
3052 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3055 } else if (!strcmp((const char *) child
->name
,
3056 config_element_rotation_schedule_size_threshold
)) {
3058 xmlNodePtr bytes_node
;
3060 /* size_threshold rotation schedule */
3061 bytes_node
= xmlFirstElementChild(child
);
3063 strcmp((const char *) bytes_node
->name
,
3064 config_element_rotation_schedule_size_threshold_bytes
) != 0) {
3065 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3070 content
= xmlNodeGetContent(bytes_node
);
3072 ret
= -LTTNG_ERR_NOMEM
;
3075 ret
= parse_uint(content
, rotation_size
);
3078 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3088 static int process_session_node(xmlNodePtr session_node
,
3089 const char *session_name
,
3091 const struct config_load_session_override_attr
*overrides
)
3093 int ret
, started
= -1, snapshot_mode
= -1;
3094 uint64_t live_timer_interval
= UINT64_MAX
, rotation_timer_interval
= 0, rotation_size
= 0;
3095 xmlChar
*name
= nullptr;
3096 xmlChar
*shm_path
= nullptr;
3097 xmlNodePtr domains_node
= nullptr;
3098 xmlNodePtr output_node
= nullptr;
3100 xmlNodePtr attributes_child
;
3101 struct lttng_domain
*kernel_domain
= nullptr;
3102 struct lttng_domain
*ust_domain
= nullptr;
3103 struct lttng_domain
*jul_domain
= nullptr;
3104 struct lttng_domain
*log4j_domain
= nullptr;
3105 struct lttng_domain
*python_domain
= nullptr;
3107 for (node
= xmlFirstElementChild(session_node
); node
; node
= xmlNextElementSibling(node
)) {
3108 if (!name
&& !strcmp((const char *) node
->name
, config_element_name
)) {
3110 xmlChar
*node_content
= xmlNodeGetContent(node
);
3111 if (!node_content
) {
3112 ret
= -LTTNG_ERR_NOMEM
;
3116 name
= node_content
;
3117 } else if (!domains_node
&&
3118 !strcmp((const char *) node
->name
, config_element_domains
)) {
3120 domains_node
= node
;
3121 } else if (started
== -1 &&
3122 !strcmp((const char *) node
->name
, config_element_started
)) {
3124 xmlChar
*node_content
= xmlNodeGetContent(node
);
3125 if (!node_content
) {
3126 ret
= -LTTNG_ERR_NOMEM
;
3130 ret
= parse_bool(node_content
, &started
);
3133 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3136 } else if (!output_node
&&
3137 !strcmp((const char *) node
->name
, config_element_output
)) {
3140 } else if (!shm_path
&&
3141 !strcmp((const char *) node
->name
, config_element_shared_memory_path
)) {
3142 /* shared memory path */
3143 xmlChar
*node_content
= xmlNodeGetContent(node
);
3144 if (!node_content
) {
3145 ret
= -LTTNG_ERR_NOMEM
;
3149 shm_path
= node_content
;
3152 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3153 * rotation_timer_interval.
3155 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3156 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3157 if (!strcmp((const char *) attributes_child
->name
,
3158 config_element_snapshot_mode
)) {
3160 xmlChar
*snapshot_mode_content
=
3161 xmlNodeGetContent(attributes_child
);
3162 if (!snapshot_mode_content
) {
3163 ret
= -LTTNG_ERR_NOMEM
;
3167 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3168 free(snapshot_mode_content
);
3170 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3173 } else if (!strcmp((const char *) attributes_child
->name
,
3174 config_element_live_timer_interval
)) {
3175 /* live_timer_interval */
3176 xmlChar
*timer_interval_content
=
3177 xmlNodeGetContent(attributes_child
);
3178 if (!timer_interval_content
) {
3179 ret
= -LTTNG_ERR_NOMEM
;
3183 ret
= parse_uint(timer_interval_content
,
3184 &live_timer_interval
);
3185 free(timer_interval_content
);
3187 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3190 } else if (!strcmp((const char *) attributes_child
->name
,
3191 config_element_rotation_schedules
)) {
3192 ret
= process_session_rotation_schedules_node(
3194 &rotation_timer_interval
,
3197 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3206 /* Mandatory attribute, as defined in the session XSD */
3207 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3211 if (session_name
&& strcmp((char *) name
, session_name
) != 0) {
3212 /* This is not the session we are looking for */
3213 ret
= -LTTNG_ERR_NO_SESSION
;
3217 /* Init domains to create the session handles */
3218 for (node
= xmlFirstElementChild(domains_node
); node
; node
= xmlNextElementSibling(node
)) {
3219 lttng_domain
*domain
= zmalloc
<lttng_domain
>();
3222 ret
= -LTTNG_ERR_NOMEM
;
3226 ret
= init_domain(node
, domain
);
3228 goto domain_init_error
;
3231 switch (domain
->type
) {
3232 case LTTNG_DOMAIN_KERNEL
:
3233 if (kernel_domain
) {
3234 /* Same domain seen twice, invalid! */
3235 goto domain_init_error
;
3237 kernel_domain
= domain
;
3239 case LTTNG_DOMAIN_UST
:
3241 /* Same domain seen twice, invalid! */
3242 goto domain_init_error
;
3244 ust_domain
= domain
;
3246 case LTTNG_DOMAIN_JUL
:
3248 /* Same domain seen twice, invalid! */
3249 goto domain_init_error
;
3251 jul_domain
= domain
;
3253 case LTTNG_DOMAIN_LOG4J
:
3255 /* Same domain seen twice, invalid! */
3256 goto domain_init_error
;
3258 log4j_domain
= domain
;
3260 case LTTNG_DOMAIN_PYTHON
:
3261 if (python_domain
) {
3262 /* Same domain seen twice, invalid! */
3263 goto domain_init_error
;
3265 python_domain
= domain
;
3268 WARN("Invalid domain type");
3269 goto domain_init_error
;
3274 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3278 /* Apply overrides */
3280 if (overrides
->session_name
) {
3281 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3282 if (!name_override
) {
3283 ret
= -LTTNG_ERR_NOMEM
;
3287 /* Overrides the session name to the provided name */
3289 name
= name_override
;
3294 /* Destroy session if it exists */
3295 ret
= lttng_destroy_session((const char *) name
);
3296 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3297 ERR("Failed to destroy existing session.");
3302 /* Create session type depending on output type */
3303 if (snapshot_mode
&& snapshot_mode
!= -1) {
3304 ret
= create_snapshot_session((const char *) name
, output_node
, overrides
);
3305 } else if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
3306 ret
= create_session(
3307 (const char *) name
, output_node
, live_timer_interval
, overrides
);
3309 /* regular session */
3310 ret
= create_session((const char *) name
, output_node
, UINT64_MAX
, overrides
);
3317 ret
= lttng_set_session_shm_path((const char *) name
, (const char *) shm_path
);
3323 for (node
= xmlFirstElementChild(domains_node
); node
; node
= xmlNextElementSibling(node
)) {
3324 ret
= process_domain_node(node
, (const char *) name
);
3330 if (rotation_timer_interval
) {
3331 ret
= add_periodic_rotation((const char *) name
, rotation_timer_interval
);
3336 if (rotation_size
) {
3337 ret
= add_size_rotation((const char *) name
, rotation_size
);
3344 ret
= lttng_start_tracing((const char *) name
);
3352 ERR("Failed to load session %s: %s", (const char *) name
, lttng_strerror(ret
));
3353 lttng_destroy_session((const char *) name
);
3357 free(kernel_domain
);
3361 free(python_domain
);
3368 * Return 1 if the given path is readable by the current UID or 0 if not.
3369 * Return -1 if the path is EPERM.
3371 static int validate_file_read_creds(const char *path
)
3377 /* Can we read the file. */
3378 ret
= access(path
, R_OK
);
3382 if (errno
== EACCES
) {
3392 static int load_session_from_file(const char *path
,
3393 const char *session_name
,
3394 struct session_config_validation_ctx
*validation_ctx
,
3396 const struct config_load_session_override_attr
*overrides
)
3398 int ret
, session_found
= !session_name
;
3399 xmlDocPtr doc
= nullptr;
3400 xmlNodePtr sessions_node
;
3401 xmlNodePtr session_node
;
3404 LTTNG_ASSERT(validation_ctx
);
3406 ret
= validate_file_read_creds(path
);
3409 ret
= -LTTNG_ERR_EPERM
;
3411 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3416 doc
= xmlParseFile(path
);
3418 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3422 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3424 ERR("Session configuration file validation failed");
3425 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3429 sessions_node
= xmlDocGetRootElement(doc
);
3430 if (!sessions_node
) {
3431 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3435 for (session_node
= xmlFirstElementChild(sessions_node
); session_node
;
3436 session_node
= xmlNextElementSibling(session_node
)) {
3437 ret
= process_session_node(session_node
, session_name
, overwrite
, overrides
);
3438 if (!session_name
&& ret
) {
3439 /* Loading error occurred. */
3441 } else if (session_name
) {
3443 /* Target session found and loaded */
3446 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3448 * Ignore this error, we are looking for a
3453 /* Loading error occurred. */
3461 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3466 static int load_session_from_path(const char *path
,
3467 const char *session_name
,
3468 struct session_config_validation_ctx
*validation_ctx
,
3470 const struct config_load_session_override_attr
*overrides
)
3472 int ret
, session_found
= !session_name
;
3473 DIR *directory
= nullptr;
3474 struct lttng_dynamic_buffer file_path
;
3478 LTTNG_ASSERT(validation_ctx
);
3479 path_len
= strlen(path
);
3480 lttng_dynamic_buffer_init(&file_path
);
3481 if (path_len
>= LTTNG_PATH_MAX
) {
3482 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3486 ret
= -LTTNG_ERR_INVALID
;
3490 directory
= opendir(path
);
3494 /* Try the file loading. */
3497 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3500 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3505 size_t file_path_root_len
;
3507 ret
= lttng_dynamic_buffer_set_capacity(&file_path
, LTTNG_PATH_MAX
);
3509 ret
= -LTTNG_ERR_NOMEM
;
3513 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3515 ret
= -LTTNG_ERR_NOMEM
;
3519 if (file_path
.data
[file_path
.size
- 1] != '/') {
3520 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3522 ret
= -LTTNG_ERR_NOMEM
;
3526 file_path_root_len
= file_path
.size
;
3528 /* Search for *.lttng files */
3530 size_t file_name_len
;
3531 struct dirent
*result
;
3534 * When the end of the directory stream is reached, NULL
3535 * is returned and errno is kept unchanged. When an
3536 * error occurs, NULL is returned and errno is set
3537 * accordingly. To distinguish between the two, set
3538 * errno to zero before calling readdir().
3540 * On success, readdir() returns a pointer to a dirent
3541 * structure. This structure may be statically
3542 * allocated, do not attempt to free(3) it.
3545 result
= readdir(directory
);
3547 /* Reached end of dir stream or error out. */
3550 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned",
3552 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3558 file_name_len
= strlen(result
->d_name
);
3560 if (file_name_len
<= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3564 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3565 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3567 /* +1 to account for NULL terminator. */
3568 file_path
.size
+ file_name_len
+ 1,
3573 /* Does the file end with .lttng? */
3574 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3575 result
->d_name
+ file_name_len
-
3576 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1) !=
3581 ret
= lttng_dynamic_buffer_append(
3582 &file_path
, result
->d_name
, file_name_len
+ 1);
3584 ret
= -LTTNG_ERR_NOMEM
;
3588 ret
= load_session_from_file(
3589 file_path
.data
, session_name
, validation_ctx
, overwrite
, overrides
);
3590 if (session_name
&& (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3594 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3598 * Reset the buffer's size to the location of the
3599 * path's trailing '/'.
3601 ret
= lttng_dynamic_buffer_set_size(&file_path
, file_path_root_len
);
3603 ret
= -LTTNG_ERR_UNK
;
3608 ret
= load_session_from_file(
3609 path
, session_name
, validation_ctx
, overwrite
, overrides
);
3619 if (closedir(directory
)) {
3623 if (!ret
&& !session_found
) {
3624 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3626 lttng_dynamic_buffer_reset(&file_path
);
3631 * Validate that the given path's credentials and the current process have the
3632 * same UID. If so, return 1 else return 0 if it does NOT match.
3634 static int validate_path_creds(const char *path
)
3636 int ret
, uid
= getuid();
3645 ret
= stat(path
, &buf
);
3647 if (errno
!= ENOENT
) {
3653 if (buf
.st_uid
!= uid
) {
3663 int config_load_session(const char *path
,
3664 const char *session_name
,
3666 unsigned int autoload
,
3667 const struct config_load_session_override_attr
*overrides
)
3670 bool session_loaded
= false;
3671 const char *path_ptr
= nullptr;
3672 struct session_config_validation_ctx validation_ctx
= {};
3674 ret
= init_session_config_validation_ctx(&validation_ctx
);
3680 const char *home_path
;
3681 const char *sys_path
;
3684 home_path
= utils_get_home_dir();
3686 char path_buf
[PATH_MAX
];
3689 * Try user session configuration path. Ignore error here so we can
3690 * continue loading the system wide sessions.
3693 ret
= snprintf(path_buf
,
3695 DEFAULT_SESSION_HOME_CONFIGPATH
3696 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
3699 PERROR("snprintf session autoload home config path");
3700 ret
= -LTTNG_ERR_INVALID
;
3705 * Credentials are only validated for the autoload in order to
3706 * avoid any user session daemon to try to load kernel sessions
3707 * automatically and failing all the times.
3709 ret
= validate_path_creds(path_buf
);
3711 path_ptr
= path_buf
;
3714 ret
= snprintf(path_buf
,
3716 DEFAULT_SESSION_HOME_CONFIGPATH
,
3719 PERROR("snprintf session home config path");
3720 ret
= -LTTNG_ERR_INVALID
;
3723 path_ptr
= path_buf
;
3726 ret
= load_session_from_path(path_ptr
,
3731 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3735 * Continue even if the session was found since we have to try
3736 * the system wide sessions.
3738 session_loaded
= true;
3742 /* Reset path pointer for the system wide dir. */
3745 /* Try system wide configuration directory. */
3747 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
3748 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3749 ret
= validate_path_creds(sys_path
);
3751 path_ptr
= sys_path
;
3754 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3755 path_ptr
= sys_path
;
3759 ret
= load_session_from_path(
3760 path_ptr
, session_name
, &validation_ctx
, overwrite
, overrides
);
3762 session_loaded
= true;
3768 ret
= access(path
, F_OK
);
3773 ret
= -LTTNG_ERR_INVALID
;
3774 WARN("Session configuration path does not exist.");
3777 ret
= -LTTNG_ERR_EPERM
;
3780 ret
= -LTTNG_ERR_UNK
;
3786 ret
= load_session_from_path(
3787 path
, session_name
, &validation_ctx
, overwrite
, overrides
);
3790 fini_session_config_validation_ctx(&validation_ctx
);
3791 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3793 * Don't report an error if no sessions are found when called
3794 * without a session_name or a search path.
3799 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3800 /* A matching session was found in one of the search paths. */
3806 static void __attribute__((destructor
)) session_config_exit()