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.hpp>
22 #include <common/error.hpp>
23 #include <common/macros.hpp>
24 #include <common/utils.hpp>
25 #include <common/dynamic-buffer.hpp>
26 #include <common/compat/getenv.hpp>
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.hpp"
38 #include "config-internal.hpp"
40 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
43 struct session_config_validation_ctx
{
44 xmlSchemaParserCtxtPtr parser_ctx
;
46 xmlSchemaValidCtxtPtr schema_validation_ctx
;
50 const char * const config_element_all
= "all";
51 LTTNG_EXPORT
const char *config_xml_encoding
= "UTF-8";
52 LTTNG_EXPORT
size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
53 LTTNG_EXPORT
const char *config_xml_indent_string
= "\t";
54 LTTNG_EXPORT
const char *config_xml_true
= "true";
55 LTTNG_EXPORT
const char *config_xml_false
= "false";
57 const char * const config_element_channel
= "channel";
58 const char * const config_element_channels
= "channels";
59 const char * const config_element_domain
= "domain";
60 const char * const config_element_domains
= "domains";
61 const char * const config_element_event
= "event";
62 const char * const config_element_events
= "events";
63 const char * const config_element_context
= "context";
64 const char * const config_element_contexts
= "contexts";
65 const char * const config_element_attributes
= "attributes";
66 const char * const config_element_exclusion
= "exclusion";
67 const char * const config_element_exclusions
= "exclusions";
68 const char * const config_element_function_attributes
= "function_attributes";
69 const char * const config_element_probe_attributes
= "probe_attributes";
70 const char * const config_element_symbol_name
= "symbol_name";
71 const char * const config_element_address
= "address";
72 const char * const config_element_offset
= "offset";
74 const char * const config_element_userspace_probe_lookup
= "lookup_method";
75 const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
76 const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
77 const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
78 const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
79 const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
80 const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
81 const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
82 const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
83 const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
85 const char * const config_element_name
= "name";
86 const char * const config_element_enabled
= "enabled";
87 const char * const config_element_overwrite_mode
= "overwrite_mode";
88 const char * const config_element_subbuf_size
= "subbuffer_size";
89 const char * const config_element_num_subbuf
= "subbuffer_count";
90 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
91 const char * const config_element_read_timer_interval
= "read_timer_interval";
92 const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
93 const char * const config_element_blocking_timeout
= "blocking_timeout";
94 const char * const config_element_output
= "output";
95 const char * const config_element_output_type
= "output_type";
96 const char * const config_element_tracefile_size
= "tracefile_size";
97 const char * const config_element_tracefile_count
= "tracefile_count";
98 const char * const config_element_live_timer_interval
= "live_timer_interval";
99 const char * const config_element_discarded_events
= "discarded_events";
100 const char * const config_element_lost_packets
= "lost_packets";
101 const char * const config_element_type
= "type";
102 const char * const config_element_buffer_type
= "buffer_type";
103 const char * const config_element_session
= "session";
104 const char * const config_element_sessions
= "sessions";
105 const char * const config_element_context_perf
= "perf";
106 const char * const config_element_context_app
= "app";
107 const char * const config_element_context_app_provider_name
= "provider_name";
108 const char * const config_element_context_app_ctx_name
= "ctx_name";
109 const char * const config_element_config
= "config";
110 const char * const config_element_started
= "started";
111 const char * const config_element_snapshot_mode
= "snapshot_mode";
112 const char * const config_element_loglevel
= "loglevel";
113 const char * const config_element_loglevel_type
= "loglevel_type";
114 const char * const config_element_filter
= "filter";
115 const char * const config_element_filter_expression
= "filter_expression";
116 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
117 const char * const config_element_consumer_output
= "consumer_output";
118 const char * const config_element_destination
= "destination";
119 const char * const config_element_path
= "path";
120 const char * const config_element_net_output
= "net_output";
121 const char * const config_element_control_uri
= "control_uri";
122 const char * const config_element_data_uri
= "data_uri";
123 const char * const config_element_max_size
= "max_size";
124 const char * const config_element_pid
= "pid";
125 const char * const config_element_pids
= "pids";
126 const char * const config_element_shared_memory_path
= "shared_memory_path";
128 const char * const config_element_process_attr_id
= "id";
129 const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
130 const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
131 const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
132 const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
133 const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
134 const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
135 const char * const config_element_process_attr_trackers
= "process_attr_trackers";
136 const char * const config_element_process_attr_values
= "process_attr_values";
137 const char * const config_element_process_attr_value_type
= "process_attr_value_type";
138 const char * const config_element_process_attr_pid_value
= "pid";
139 const char * const config_element_process_attr_vpid_value
= "vpid";
140 const char * const config_element_process_attr_uid_value
= "uid";
141 const char * const config_element_process_attr_vuid_value
= "vuid";
142 const char * const config_element_process_attr_gid_value
= "gid";
143 const char * const config_element_process_attr_vgid_value
= "vgid";
144 const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
146 /* Used for support of legacy tracker serialization (< 2.12). */
147 const char * const config_element_trackers_legacy
= "trackers";
148 const char * const config_element_pid_tracker_legacy
= "pid_tracker";
149 const char * const config_element_tracker_targets_legacy
= "targets";
150 const char * const config_element_tracker_pid_legacy
= "pid";
152 const char * const config_element_rotation_schedules
= "rotation_schedules";
153 const char * const config_element_rotation_schedule_periodic
= "periodic";
154 const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
155 const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
156 const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
158 const char * const config_domain_type_kernel
= "KERNEL";
159 const char * const config_domain_type_ust
= "UST";
160 const char * const config_domain_type_jul
= "JUL";
161 const char * const config_domain_type_log4j
= "LOG4J";
162 const char * const config_domain_type_python
= "PYTHON";
164 const char * const config_buffer_type_per_pid
= "PER_PID";
165 const char * const config_buffer_type_per_uid
= "PER_UID";
166 const char * const config_buffer_type_global
= "GLOBAL";
168 const char * const config_overwrite_mode_discard
= "DISCARD";
169 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
171 const char * const config_output_type_splice
= "SPLICE";
172 const char * const config_output_type_mmap
= "MMAP";
174 const char * const config_loglevel_type_all
= "ALL";
175 const char * const config_loglevel_type_range
= "RANGE";
176 const char * const config_loglevel_type_single
= "SINGLE";
178 const char * const config_event_type_all
= "ALL";
179 const char * const config_event_type_tracepoint
= "TRACEPOINT";
180 const char * const config_event_type_probe
= "PROBE";
181 const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
182 const char * const config_event_type_function
= "FUNCTION";
183 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
184 const char * const config_event_type_noop
= "NOOP";
185 const char * const config_event_type_syscall
= "SYSCALL";
186 const char * const config_event_type_kprobe
= "KPROBE";
187 const char * const config_event_type_kretprobe
= "KRETPROBE";
189 const char * const config_event_context_pid
= "PID";
190 const char * const config_event_context_procname
= "PROCNAME";
191 const char * const config_event_context_prio
= "PRIO";
192 const char * const config_event_context_nice
= "NICE";
193 const char * const config_event_context_vpid
= "VPID";
194 const char * const config_event_context_tid
= "TID";
195 const char * const config_event_context_vtid
= "VTID";
196 const char * const config_event_context_ppid
= "PPID";
197 const char * const config_event_context_vppid
= "VPPID";
198 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
199 const char * const config_event_context_hostname
= "HOSTNAME";
200 const char * const config_event_context_ip
= "IP";
201 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
202 const char * const config_event_context_app
= "APP";
203 const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
204 const char * const config_event_context_preemptible
= "PREEMPTIBLE";
205 const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
206 const char * const config_event_context_migratable
= "MIGRATABLE";
207 const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
208 const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
209 const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
210 const char * const config_event_context_ipc_ns
= "IPC_NS";
211 const char * const config_event_context_mnt_ns
= "MNT_NS";
212 const char * const config_event_context_net_ns
= "NET_NS";
213 const char * const config_event_context_pid_ns
= "PID_NS";
214 const char * const config_event_context_time_ns
= "TIME_NS";
215 const char * const config_event_context_user_ns
= "USER_NS";
216 const char * const config_event_context_uts_ns
= "UTS_NS";
217 const char * const config_event_context_uid
= "UID";
218 const char * const config_event_context_euid
= "EUID";
219 const char * const config_event_context_suid
= "SUID";
220 const char * const config_event_context_gid
= "GID";
221 const char * const config_event_context_egid
= "EGID";
222 const char * const config_event_context_sgid
= "SGID";
223 const char * const config_event_context_vuid
= "VUID";
224 const char * const config_event_context_veuid
= "VEUID";
225 const char * const config_event_context_vsuid
= "VSUID";
226 const char * const config_event_context_vgid
= "VGID";
227 const char * const config_event_context_vegid
= "VEGID";
228 const char * const config_event_context_vsgid
= "VSGID";
230 /* Deprecated symbols */
231 LTTNG_EXPORT
const char *config_element_perf
;
233 enum process_event_node_phase
{
239 struct consumer_output
{
248 * Returns a xmlChar string which must be released using xmlFree().
250 static xmlChar
*encode_string(const char *in_str
)
252 xmlChar
*out_str
= NULL
;
253 xmlCharEncodingHandlerPtr handler
;
254 int out_len
, ret
, in_len
;
256 LTTNG_ASSERT(in_str
);
258 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
260 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
264 in_len
= strlen(in_str
);
266 * Add 1 byte for the NULL terminted character. The factor 4 here is
267 * used because UTF-8 characters can take up to 4 bytes.
269 out_len
= (in_len
* 4) + 1;
270 out_str
= (xmlChar
*) xmlMalloc(out_len
);
275 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
282 /* out_len is now the size of out_str */
283 out_str
[out_len
] = '\0';
288 struct config_writer
*config_writer_create(int fd_output
, int indent
)
291 struct config_writer
*writer
;
292 xmlOutputBufferPtr buffer
;
294 writer
= zmalloc
<config_writer
>();
296 PERROR("zmalloc config_writer_create");
300 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
305 writer
->writer
= xmlNewTextWriter(buffer
);
306 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
307 config_xml_encoding
, NULL
);
312 ret
= xmlTextWriterSetIndentString(writer
->writer
,
313 BAD_CAST config_xml_indent_string
);
318 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
326 config_writer_destroy(writer
);
330 int config_writer_destroy(struct config_writer
*writer
)
339 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
340 WARN("Could not close XML document");
344 if (writer
->writer
) {
345 xmlFreeTextWriter(writer
->writer
);
353 int config_writer_open_element(struct config_writer
*writer
,
354 const char *element_name
)
357 xmlChar
*encoded_element_name
;
359 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
364 encoded_element_name
= encode_string(element_name
);
365 if (!encoded_element_name
) {
370 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
371 xmlFree(encoded_element_name
);
373 return ret
>= 0 ? 0 : ret
;
376 int config_writer_write_attribute(struct config_writer
*writer
,
377 const char *name
, const char *value
)
380 xmlChar
*encoded_name
= NULL
;
381 xmlChar
*encoded_value
= NULL
;
383 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
388 encoded_name
= encode_string(name
);
394 encoded_value
= encode_string(value
);
395 if (!encoded_value
) {
400 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
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
, uint64_t value
)
426 xmlChar
*encoded_element_name
;
428 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
433 encoded_element_name
= encode_string(element_name
);
434 if (!encoded_element_name
) {
439 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
440 encoded_element_name
, "%" PRIu64
, value
);
441 xmlFree(encoded_element_name
);
443 return ret
>= 0 ? 0 : ret
;
446 int config_writer_write_element_signed_int(struct config_writer
*writer
,
447 const char *element_name
, int64_t value
)
450 xmlChar
*encoded_element_name
;
452 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
457 encoded_element_name
= encode_string(element_name
);
458 if (!encoded_element_name
) {
463 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
464 encoded_element_name
, "%" PRIi64
, value
);
465 xmlFree(encoded_element_name
);
467 return ret
>= 0 ? 0 : ret
;
470 int config_writer_write_element_bool(struct config_writer
*writer
,
471 const char *element_name
, int value
)
473 return config_writer_write_element_string(writer
, element_name
,
474 value
? config_xml_true
: config_xml_false
);
477 int config_writer_write_element_double(struct config_writer
*writer
,
478 const char *element_name
,
482 xmlChar
*encoded_element_name
;
484 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
489 encoded_element_name
= encode_string(element_name
);
490 if (!encoded_element_name
) {
495 ret
= xmlTextWriterWriteFormatElement(
496 writer
->writer
, encoded_element_name
, "%f", value
);
497 xmlFree(encoded_element_name
);
499 return ret
>= 0 ? 0 : ret
;
502 int config_writer_write_element_string(struct config_writer
*writer
,
503 const char *element_name
, const char *value
)
506 xmlChar
*encoded_element_name
= NULL
;
507 xmlChar
*encoded_value
= NULL
;
509 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
515 encoded_element_name
= encode_string(element_name
);
516 if (!encoded_element_name
) {
521 encoded_value
= encode_string(value
);
522 if (!encoded_value
) {
527 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
530 xmlFree(encoded_element_name
);
531 xmlFree(encoded_value
);
532 return ret
>= 0 ? 0 : ret
;
535 static ATTR_FORMAT_PRINTF(2, 3)
536 void xml_error_handler(void *ctx
__attribute__((unused
)), const char *format
, ...)
542 va_start(args
, format
);
543 ret
= vasprintf(&errMsg
, format
, args
);
546 ERR("String allocation failed in xml error handler");
550 fprintf(stderr
, "XML Error: %s", errMsg
);
555 void fini_session_config_validation_ctx(
556 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
));
574 char *get_session_config_xsd_path(void)
577 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
578 size_t base_path_len
;
582 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
585 base_path_len
= strlen(base_path
);
586 max_path_len
= base_path_len
+
587 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
588 xsd_path
= zmalloc
<char>(max_path_len
);
593 strcpy(xsd_path
, base_path
);
594 if (xsd_path
[base_path_len
- 1] != '/') {
595 xsd_path
[base_path_len
++] = '/';
598 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
604 int init_session_config_validation_ctx(
605 struct session_config_validation_ctx
*ctx
)
608 char *xsd_path
= get_session_config_xsd_path();
611 ret
= -LTTNG_ERR_NOMEM
;
615 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
616 if (!ctx
->parser_ctx
) {
617 ERR("XSD parser context creation failed");
618 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
621 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
622 xml_error_handler
, NULL
);
624 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
626 ERR("XSD parsing failed");
627 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
631 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
632 if (!ctx
->schema_validation_ctx
) {
633 ERR("XSD validation context creation failed");
634 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
638 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
639 xml_error_handler
, NULL
);
644 fini_session_config_validation_ctx(ctx
);
652 int parse_uint(xmlChar
*str
, uint64_t *val
)
662 *val
= strtoull((const char *) str
, &endptr
, 10);
663 if (!endptr
|| *endptr
) {
674 int parse_int(xmlChar
*str
, int64_t *val
)
684 *val
= strtoll((const char *) str
, &endptr
, 10);
685 if (!endptr
|| *endptr
) {
696 int parse_bool(xmlChar
*str
, int *val
)
705 if (!strcmp((const char *) str
, config_xml_true
) ||
706 !strcmp((const char *) str
, "1")) {
708 } else if (!strcmp((const char *) str
, config_xml_false
) ||
709 !strcmp((const char *) str
, "0")) {
712 WARN("Invalid boolean value encountered (%s).",
721 int get_domain_type(xmlChar
*domain
)
729 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
730 ret
= LTTNG_DOMAIN_KERNEL
;
731 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
732 ret
= LTTNG_DOMAIN_UST
;
733 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
734 ret
= LTTNG_DOMAIN_JUL
;
735 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
736 ret
= LTTNG_DOMAIN_LOG4J
;
737 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
738 ret
= LTTNG_DOMAIN_PYTHON
;
749 int get_buffer_type(xmlChar
*buffer_type
)
757 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
758 ret
= LTTNG_BUFFER_GLOBAL
;
759 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
760 ret
= LTTNG_BUFFER_PER_UID
;
761 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
762 ret
= LTTNG_BUFFER_PER_PID
;
773 int get_overwrite_mode(xmlChar
*overwrite_mode
)
777 if (!overwrite_mode
) {
781 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
783 } else if (!strcmp((char *) overwrite_mode
,
784 config_overwrite_mode_discard
)) {
796 int get_output_type(xmlChar
*output_type
)
804 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
805 ret
= LTTNG_EVENT_MMAP
;
806 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
807 ret
= LTTNG_EVENT_SPLICE
;
818 int get_event_type(xmlChar
*event_type
)
826 if (!strcmp((char *) event_type
, config_event_type_all
)) {
827 ret
= LTTNG_EVENT_ALL
;
828 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
829 ret
= LTTNG_EVENT_TRACEPOINT
;
830 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
831 ret
= LTTNG_EVENT_PROBE
;
832 } else if (!strcmp((char *) event_type
,
833 config_event_type_userspace_probe
)) {
834 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
835 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
836 ret
= LTTNG_EVENT_FUNCTION
;
837 } else if (!strcmp((char *) event_type
,
838 config_event_type_function_entry
)) {
839 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
840 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
841 ret
= LTTNG_EVENT_NOOP
;
842 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
843 ret
= LTTNG_EVENT_SYSCALL
;
854 int get_loglevel_type(xmlChar
*loglevel_type
)
858 if (!loglevel_type
) {
862 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
863 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
864 } else if (!strcmp((char *) loglevel_type
,
865 config_loglevel_type_range
)) {
866 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
867 } else if (!strcmp((char *) loglevel_type
,
868 config_loglevel_type_single
)) {
869 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
880 * Return the context type or -1 on error.
883 int get_context_type(xmlChar
*context_type
)
891 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
892 ret
= LTTNG_EVENT_CONTEXT_PID
;
893 } else if (!strcmp((char *) context_type
,
894 config_event_context_procname
)) {
895 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
896 } else if (!strcmp((char *) context_type
,
897 config_event_context_prio
)) {
898 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
899 } else if (!strcmp((char *) context_type
,
900 config_event_context_nice
)) {
901 ret
= LTTNG_EVENT_CONTEXT_NICE
;
902 } else if (!strcmp((char *) context_type
,
903 config_event_context_vpid
)) {
904 ret
= LTTNG_EVENT_CONTEXT_VPID
;
905 } else if (!strcmp((char *) context_type
,
906 config_event_context_tid
)) {
907 ret
= LTTNG_EVENT_CONTEXT_TID
;
908 } else if (!strcmp((char *) context_type
,
909 config_event_context_vtid
)) {
910 ret
= LTTNG_EVENT_CONTEXT_VTID
;
911 } else if (!strcmp((char *) context_type
,
912 config_event_context_ppid
)) {
913 ret
= LTTNG_EVENT_CONTEXT_PPID
;
914 } else if (!strcmp((char *) context_type
,
915 config_event_context_vppid
)) {
916 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
917 } else if (!strcmp((char *) context_type
,
918 config_event_context_pthread_id
)) {
919 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
920 } else if (!strcmp((char *) context_type
,
921 config_event_context_hostname
)) {
922 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
923 } else if (!strcmp((char *) context_type
,
924 config_event_context_ip
)) {
925 ret
= LTTNG_EVENT_CONTEXT_IP
;
926 } else if (!strcmp((char *) context_type
,
927 config_event_context_interruptible
)) {
928 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
929 } else if (!strcmp((char *) context_type
,
930 config_event_context_preemptible
)) {
931 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
932 } else if (!strcmp((char *) context_type
,
933 config_event_context_need_reschedule
)) {
934 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
935 } else if (!strcmp((char *) context_type
,
936 config_event_context_migratable
)) {
937 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
938 } else if (!strcmp((char *) context_type
,
939 config_event_context_callstack_user
)) {
940 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
941 } else if (!strcmp((char *) context_type
,
942 config_event_context_callstack_kernel
)) {
943 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
944 } else if (!strcmp((char *) context_type
,
945 config_event_context_cgroup_ns
)) {
946 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
947 } else if (!strcmp((char *) context_type
,
948 config_event_context_ipc_ns
)) {
949 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
950 } else if (!strcmp((char *) context_type
,
951 config_event_context_mnt_ns
)) {
952 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
953 } else if (!strcmp((char *) context_type
,
954 config_event_context_net_ns
)) {
955 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
956 } else if (!strcmp((char *) context_type
,
957 config_event_context_pid_ns
)) {
958 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
959 } else if (!strcmp((char *) context_type
,
960 config_event_context_time_ns
)) {
961 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
962 } else if (!strcmp((char *) context_type
,
963 config_event_context_user_ns
)) {
964 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
965 } else if (!strcmp((char *) context_type
,
966 config_event_context_uts_ns
)) {
967 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
968 } else if (!strcmp((char *) context_type
,
969 config_event_context_uid
)) {
970 ret
= LTTNG_EVENT_CONTEXT_UID
;
971 } else if (!strcmp((char *) context_type
,
972 config_event_context_euid
)) {
973 ret
= LTTNG_EVENT_CONTEXT_EUID
;
974 } else if (!strcmp((char *) context_type
,
975 config_event_context_suid
)) {
976 ret
= LTTNG_EVENT_CONTEXT_SUID
;
977 } else if (!strcmp((char *) context_type
,
978 config_event_context_gid
)) {
979 ret
= LTTNG_EVENT_CONTEXT_GID
;
980 } else if (!strcmp((char *) context_type
,
981 config_event_context_egid
)) {
982 ret
= LTTNG_EVENT_CONTEXT_EGID
;
983 } else if (!strcmp((char *) context_type
,
984 config_event_context_sgid
)) {
985 ret
= LTTNG_EVENT_CONTEXT_SGID
;
986 } else if (!strcmp((char *) context_type
,
987 config_event_context_vuid
)) {
988 ret
= LTTNG_EVENT_CONTEXT_VUID
;
989 } else if (!strcmp((char *) context_type
,
990 config_event_context_veuid
)) {
991 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
992 } else if (!strcmp((char *) context_type
,
993 config_event_context_vsuid
)) {
994 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
995 } else if (!strcmp((char *) context_type
,
996 config_event_context_vgid
)) {
997 ret
= LTTNG_EVENT_CONTEXT_VGID
;
998 } else if (!strcmp((char *) context_type
,
999 config_event_context_vegid
)) {
1000 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1001 } else if (!strcmp((char *) context_type
,
1002 config_event_context_vsgid
)) {
1003 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1014 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1019 for (node
= xmlFirstElementChild(domain_node
); node
;
1020 node
= xmlNextElementSibling(node
)) {
1021 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1023 xmlChar
*node_content
= xmlNodeGetContent(node
);
1024 if (!node_content
) {
1025 ret
= -LTTNG_ERR_NOMEM
;
1029 ret
= get_domain_type(node_content
);
1032 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1036 domain
->type
= (lttng_domain_type
) ret
;
1037 } else if (!strcmp((const char *) node
->name
,
1038 config_element_buffer_type
)) {
1040 xmlChar
*node_content
= xmlNodeGetContent(node
);
1041 if (!node_content
) {
1042 ret
= -LTTNG_ERR_NOMEM
;
1046 ret
= get_buffer_type(node_content
);
1049 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1053 domain
->buf_type
= (lttng_buffer_type
) ret
;
1062 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1067 for (node
= xmlFirstElementChild(net_output_node
); node
;
1068 node
= xmlNextElementSibling(node
)) {
1069 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1071 *control_uri
= (char *) xmlNodeGetContent(node
);
1072 if (!*control_uri
) {
1077 *data_uri
= (char *) xmlNodeGetContent(node
);
1084 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1088 int process_consumer_output(xmlNodePtr consumer_output_node
,
1089 struct consumer_output
*output
)
1094 LTTNG_ASSERT(output
);
1096 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1097 node
= xmlNextElementSibling(node
)) {
1098 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1099 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1103 ret
= -LTTNG_ERR_NOMEM
;
1107 ret
= parse_bool(enabled_str
, &output
->enabled
);
1113 xmlNodePtr output_type_node
;
1116 output_type_node
= xmlFirstElementChild(node
);
1117 if (!output_type_node
) {
1118 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1122 if (!strcmp((const char *) output_type_node
->name
,
1123 config_element_path
)) {
1125 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1126 if (!output
->path
) {
1127 ret
= -LTTNG_ERR_NOMEM
;
1132 ret
= get_net_output_uris(output_type_node
,
1133 &output
->control_uri
, &output
->data_uri
);
1145 free(output
->control_uri
);
1146 free(output
->data_uri
);
1147 memset(output
, 0, sizeof(struct consumer_output
));
1153 int create_session_net_output(const char *name
, const char *control_uri
,
1154 const char *data_uri
)
1157 struct lttng_handle
*handle
;
1158 const char *uri
= NULL
;
1162 handle
= lttng_create_handle(name
, NULL
);
1164 ret
= -LTTNG_ERR_NOMEM
;
1168 if (!control_uri
|| !data_uri
) {
1169 uri
= control_uri
? control_uri
: data_uri
;
1174 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1175 lttng_destroy_handle(handle
);
1181 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1182 const struct config_load_session_override_attr
*overrides
)
1185 xmlNodePtr node
= NULL
;
1186 xmlNodePtr snapshot_output_list_node
;
1187 xmlNodePtr snapshot_output_node
;
1189 LTTNG_ASSERT(session_name
);
1191 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1200 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1202 /* Parse and create snapshot outputs */
1204 for (snapshot_output_node
=
1205 xmlFirstElementChild(snapshot_output_list_node
);
1206 snapshot_output_node
; snapshot_output_node
=
1207 xmlNextElementSibling(snapshot_output_node
)) {
1209 uint64_t max_size
= UINT64_MAX
;
1210 struct consumer_output output
= {};
1211 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1212 const char *control_uri
= NULL
;
1213 const char *data_uri
= NULL
;
1214 const char *path
= NULL
;
1216 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1217 node
= xmlNextElementSibling(node
)) {
1218 if (!strcmp((const char *) node
->name
,
1219 config_element_name
)) {
1221 name
= (char *) xmlNodeGetContent(node
);
1223 ret
= -LTTNG_ERR_NOMEM
;
1224 goto error_snapshot_output
;
1226 } else if (!strcmp((const char *) node
->name
,
1227 config_element_max_size
)) {
1228 xmlChar
*content
= xmlNodeGetContent(node
);
1232 ret
= -LTTNG_ERR_NOMEM
;
1233 goto error_snapshot_output
;
1235 ret
= parse_uint(content
, &max_size
);
1238 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1239 goto error_snapshot_output
;
1242 /* consumer_output */
1243 ret
= process_consumer_output(node
, &output
);
1245 goto error_snapshot_output
;
1250 control_uri
= output
.control_uri
;
1251 data_uri
= output
.data_uri
;
1255 if (overrides
->path_url
) {
1256 path
= overrides
->path_url
;
1257 /* Control/data_uri are null */
1261 if (overrides
->ctrl_url
) {
1262 control_uri
= overrides
->ctrl_url
;
1266 if (overrides
->data_url
) {
1267 data_uri
= overrides
->data_url
;
1274 snapshot_output
= lttng_snapshot_output_create();
1275 if (!snapshot_output
) {
1276 ret
= -LTTNG_ERR_NOMEM
;
1277 goto error_snapshot_output
;
1280 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1282 goto error_snapshot_output
;
1285 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1287 goto error_snapshot_output
;
1291 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1294 goto error_snapshot_output
;
1298 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1301 goto error_snapshot_output
;
1306 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1309 goto error_snapshot_output
;
1314 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1315 error_snapshot_output
:
1318 free(output
.control_uri
);
1319 free(output
.data_uri
);
1320 lttng_snapshot_output_destroy(snapshot_output
);
1330 int create_session(const char *name
,
1331 xmlNodePtr output_node
,
1332 uint64_t live_timer_interval
,
1333 const struct config_load_session_override_attr
*overrides
)
1336 struct consumer_output output
= {};
1337 xmlNodePtr consumer_output_node
;
1338 const char *control_uri
= NULL
;
1339 const char *data_uri
= NULL
;
1340 const char *path
= NULL
;
1345 consumer_output_node
= xmlFirstElementChild(output_node
);
1346 if (!consumer_output_node
) {
1347 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1351 if (strcmp((const char *) consumer_output_node
->name
,
1352 config_element_consumer_output
)) {
1353 WARN("Invalid output type, expected %s node",
1354 config_element_consumer_output
);
1355 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1359 ret
= process_consumer_output(consumer_output_node
, &output
);
1365 control_uri
= output
.control_uri
;
1366 data_uri
= output
.data_uri
;
1369 /* Check for override and apply them */
1371 if (overrides
->path_url
) {
1372 path
= overrides
->path_url
;
1373 /* control/data_uri are null */;
1377 if (overrides
->ctrl_url
) {
1378 control_uri
= overrides
->ctrl_url
;
1382 if (overrides
->data_url
) {
1383 data_uri
= overrides
->data_url
;
1391 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1392 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1396 if (control_uri
|| data_uri
) {
1397 /* network destination */
1398 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1400 * URLs are provided for sure since the test above make sure that
1401 * with a live timer the data and control URIs are provided. So,
1402 * NULL is passed here and will be set right after.
1404 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1406 ret
= lttng_create_session(name
, NULL
);
1412 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1418 /* either local output or no output */
1419 ret
= lttng_create_session(name
, path
);
1426 free(output
.control_uri
);
1427 free(output
.data_uri
);
1432 struct lttng_userspace_probe_location
*
1433 process_userspace_probe_function_attribute_node(
1434 xmlNodePtr attribute_node
)
1436 xmlNodePtr function_attribute_node
;
1437 char *function_name
= NULL
, *binary_path
= NULL
;
1438 struct lttng_userspace_probe_location
*location
= NULL
;
1439 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1442 * Process userspace probe location function attributes. The order of
1443 * the fields are not guaranteed so we need to iterate over all fields
1444 * and check at the end if everything we need for this location type is
1447 for (function_attribute_node
=
1448 xmlFirstElementChild(attribute_node
);
1449 function_attribute_node
;
1450 function_attribute_node
= xmlNextElementSibling(
1451 function_attribute_node
)) {
1452 /* Handle function name, binary path and lookup method. */
1453 if (!strcmp((const char *) function_attribute_node
->name
,
1454 config_element_userspace_probe_function_location_function_name
)) {
1455 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1456 if (!function_name
) {
1459 } else if (!strcmp((const char *) function_attribute_node
->name
,
1460 config_element_userspace_probe_location_binary_path
)) {
1461 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1465 } else if (!strcmp((const char *) function_attribute_node
->name
,
1466 config_element_userspace_probe_lookup
)) {
1467 char *lookup_method_name
;
1469 lookup_method_name
= (char *) xmlNodeGetContent(
1470 function_attribute_node
);
1471 if (!lookup_method_name
) {
1476 * function_default lookup method defaults to
1477 * function_elf lookup method at the moment.
1479 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1480 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1481 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1482 if (!lookup_method
) {
1483 PERROR("Error creating function default/ELF lookup method");
1486 WARN("Unknown function lookup method");
1489 free(lookup_method_name
);
1490 if (!lookup_method
) {
1497 /* Check if all the necessary fields were found. */
1498 if (binary_path
&& function_name
&& lookup_method
) {
1499 /* Ownership of lookup_method is transferred. */
1501 lttng_userspace_probe_location_function_create(
1502 binary_path
, function_name
,
1504 lookup_method
= NULL
;
1509 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1511 free(function_name
);
1516 struct lttng_userspace_probe_location
*
1517 process_userspace_probe_tracepoint_attribute_node(
1518 xmlNodePtr attribute_node
)
1520 xmlNodePtr tracepoint_attribute_node
;
1521 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1522 struct lttng_userspace_probe_location
*location
= NULL
;
1523 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1526 * Process userspace probe location tracepoint attributes. The order of
1527 * the fields are not guaranteed so we need to iterate over all fields
1528 * and check at the end if everything we need for this location type is
1531 for (tracepoint_attribute_node
=
1532 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1533 tracepoint_attribute_node
= xmlNextElementSibling(
1534 tracepoint_attribute_node
)) {
1535 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1536 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1537 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1541 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1542 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1543 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1544 if (!provider_name
) {
1547 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1548 config_element_userspace_probe_location_binary_path
)) {
1549 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1553 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1554 config_element_userspace_probe_lookup
)) {
1555 char *lookup_method_name
;
1557 lookup_method_name
= (char *) xmlNodeGetContent(
1558 tracepoint_attribute_node
);
1559 if (!lookup_method_name
) {
1563 if (!strcmp(lookup_method_name
,
1564 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1566 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1567 if (!lookup_method
) {
1568 PERROR("Error creating tracepoint SDT lookup method");
1571 WARN("Unknown tracepoint lookup method");
1574 free(lookup_method_name
);
1575 if (!lookup_method
) {
1579 WARN("Unknown tracepoint attribute");
1583 /* Check if all the necessary fields were found. */
1584 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1585 /* Ownership of lookup_method is transferred. */
1587 lttng_userspace_probe_location_tracepoint_create(
1588 binary_path
, provider_name
,
1589 probe_name
, lookup_method
);
1590 lookup_method
= NULL
;
1595 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1597 free(provider_name
);
1603 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1604 struct lttng_event_probe_attr
*attr
)
1608 LTTNG_ASSERT(probe_attribute_node
);
1611 if (!strcmp((const char *) probe_attribute_node
->name
,
1612 config_element_address
)) {
1617 content
= xmlNodeGetContent(probe_attribute_node
);
1619 ret
= -LTTNG_ERR_NOMEM
;
1623 ret
= parse_uint(content
, &addr
);
1626 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1631 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1632 config_element_offset
)) {
1634 uint64_t offset
= 0;
1637 content
= xmlNodeGetContent(probe_attribute_node
);
1639 ret
= -LTTNG_ERR_NOMEM
;
1643 ret
= parse_uint(content
, &offset
);
1646 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1650 attr
->offset
= offset
;
1651 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1652 config_element_symbol_name
)) {
1656 content
= xmlNodeGetContent(probe_attribute_node
);
1658 ret
= -LTTNG_ERR_NOMEM
;
1662 ret
= lttng_strncpy(attr
->symbol_name
,
1663 (const char *) content
,
1664 LTTNG_SYMBOL_NAME_LEN
);
1666 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1667 (const char *) content
,
1668 strlen((const char *) content
),
1669 LTTNG_SYMBOL_NAME_LEN
);
1670 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1682 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1683 const char *channel_name
, const enum process_event_node_phase phase
)
1687 struct lttng_event
*event
;
1688 char **exclusions
= NULL
;
1689 unsigned long exclusion_count
= 0;
1690 char *filter_expression
= NULL
;
1692 LTTNG_ASSERT(event_node
);
1693 LTTNG_ASSERT(handle
);
1694 LTTNG_ASSERT(channel_name
);
1696 event
= lttng_event_create();
1698 ret
= -LTTNG_ERR_NOMEM
;
1702 /* Initialize default log level which varies by domain */
1703 switch (handle
->domain
.type
)
1705 case LTTNG_DOMAIN_JUL
:
1706 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1708 case LTTNG_DOMAIN_LOG4J
:
1709 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1711 case LTTNG_DOMAIN_PYTHON
:
1712 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1714 case LTTNG_DOMAIN_UST
:
1715 case LTTNG_DOMAIN_KERNEL
:
1716 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1722 for (node
= xmlFirstElementChild(event_node
); node
;
1723 node
= xmlNextElementSibling(node
)) {
1724 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1728 content
= xmlNodeGetContent(node
);
1730 ret
= -LTTNG_ERR_NOMEM
;
1734 ret
= lttng_strncpy(event
->name
,
1735 (const char *) content
,
1736 LTTNG_SYMBOL_NAME_LEN
);
1738 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1739 (const char *) content
,
1740 strlen((const char *) content
),
1741 LTTNG_SYMBOL_NAME_LEN
);
1742 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1747 } else if (!strcmp((const char *) node
->name
,
1748 config_element_enabled
)) {
1749 xmlChar
*content
= xmlNodeGetContent(node
);
1753 ret
= -LTTNG_ERR_NOMEM
;
1757 ret
= parse_bool(content
, &event
->enabled
);
1760 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1763 } else if (!strcmp((const char *) node
->name
,
1764 config_element_type
)) {
1765 xmlChar
*content
= xmlNodeGetContent(node
);
1769 ret
= -LTTNG_ERR_NOMEM
;
1773 ret
= get_event_type(content
);
1776 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1780 event
->type
= (lttng_event_type
) ret
;
1781 } else if (!strcmp((const char *) node
->name
,
1782 config_element_loglevel_type
)) {
1783 xmlChar
*content
= xmlNodeGetContent(node
);
1787 ret
= -LTTNG_ERR_NOMEM
;
1791 ret
= get_loglevel_type(content
);
1794 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1798 event
->loglevel_type
= (lttng_loglevel_type
) ret
;
1799 } else if (!strcmp((const char *) node
->name
,
1800 config_element_loglevel
)) {
1802 int64_t loglevel
= 0;
1805 content
= xmlNodeGetContent(node
);
1807 ret
= -LTTNG_ERR_NOMEM
;
1811 ret
= parse_int(content
, &loglevel
);
1814 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1818 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1819 WARN("loglevel out of range.");
1820 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1824 event
->loglevel
= loglevel
;
1825 } else if (!strcmp((const char *) node
->name
,
1826 config_element_filter
)) {
1828 xmlNodeGetContent(node
);
1832 ret
= -LTTNG_ERR_NOMEM
;
1836 free(filter_expression
);
1837 filter_expression
= strdup((char *) content
);
1839 if (!filter_expression
) {
1840 ret
= -LTTNG_ERR_NOMEM
;
1843 } else if (!strcmp((const char *) node
->name
,
1844 config_element_exclusions
)) {
1845 xmlNodePtr exclusion_node
;
1846 int exclusion_index
= 0;
1851 * Exclusions has already been initialized,
1854 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1858 exclusion_count
= xmlChildElementCount(node
);
1859 if (!exclusion_count
) {
1863 exclusions
= calloc
<char *>(exclusion_count
);
1865 exclusion_count
= 0;
1866 ret
= -LTTNG_ERR_NOMEM
;
1870 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1871 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1873 xmlNodeGetContent(exclusion_node
);
1876 ret
= -LTTNG_ERR_NOMEM
;
1880 exclusions
[exclusion_index
] = strdup((const char *) content
);
1882 if (!exclusions
[exclusion_index
]) {
1883 ret
= -LTTNG_ERR_NOMEM
;
1889 event
->exclusion
= 1;
1890 } else if (!strcmp((const char *) node
->name
,
1891 config_element_attributes
)) {
1892 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1895 if (!attribute_node
) {
1896 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1900 if (!strcmp((const char *) attribute_node
->name
,
1901 config_element_probe_attributes
)) {
1902 xmlNodePtr probe_attribute_node
;
1904 /* probe_attributes */
1905 for (probe_attribute_node
=
1906 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1907 probe_attribute_node
= xmlNextElementSibling(
1908 probe_attribute_node
)) {
1910 ret
= process_probe_attribute_node(probe_attribute_node
,
1911 &event
->attr
.probe
);
1916 } else if (!strcmp((const char *) attribute_node
->name
,
1917 config_element_function_attributes
)) {
1920 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1922 /* function_attributes */
1923 content
= xmlNodeGetContent(symbol_node
);
1925 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1929 sym_len
= strlen((char *) content
);
1930 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1931 WARN("Function name too long.");
1932 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1937 ret
= lttng_strncpy(
1938 event
->attr
.ftrace
.symbol_name
,
1939 (char *) content
, sym_len
);
1941 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1946 } else if (!strcmp((const char *) attribute_node
->name
,
1947 config_element_userspace_probe_tracepoint_attributes
)) {
1948 struct lttng_userspace_probe_location
*location
;
1950 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
1952 WARN("Error processing userspace probe tracepoint attribute");
1953 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1956 ret
= lttng_event_set_userspace_probe_location(
1959 WARN("Error setting userspace probe location field");
1960 lttng_userspace_probe_location_destroy(
1962 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1965 } else if (!strcmp((const char *) attribute_node
->name
,
1966 config_element_userspace_probe_function_attributes
)) {
1967 struct lttng_userspace_probe_location
*location
;
1970 process_userspace_probe_function_attribute_node(
1973 WARN("Error processing userspace probe function attribute");
1974 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1978 ret
= lttng_event_set_userspace_probe_location(
1981 WARN("Error setting userspace probe location field");
1982 lttng_userspace_probe_location_destroy(
1984 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1988 /* Unknown event attribute. */
1989 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1995 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1996 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
1997 filter_expression
, exclusion_count
, exclusions
);
1999 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2000 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2006 for (i
= 0; i
< exclusion_count
; i
++) {
2007 free(exclusions
[i
]);
2010 lttng_event_destroy(event
);
2012 free(filter_expression
);
2017 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2018 const char *channel_name
)
2021 struct lttng_event event
;
2024 LTTNG_ASSERT(events_node
);
2025 LTTNG_ASSERT(handle
);
2026 LTTNG_ASSERT(channel_name
);
2028 for (node
= xmlFirstElementChild(events_node
); node
;
2029 node
= xmlNextElementSibling(node
)) {
2030 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2037 * Disable all events to enable only the necessary events.
2038 * Limitations regarding lttng_disable_events and tuple descriptor
2039 * force this approach.
2041 memset(&event
, 0, sizeof(event
));
2042 event
.loglevel
= -1;
2043 event
.type
= LTTNG_EVENT_ALL
;
2044 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2049 for (node
= xmlFirstElementChild(events_node
); node
;
2050 node
= xmlNextElementSibling(node
)) {
2051 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2062 int process_channel_attr_node(xmlNodePtr attr_node
,
2063 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2064 xmlNodePtr
*events_node
)
2068 LTTNG_ASSERT(attr_node
);
2069 LTTNG_ASSERT(channel
);
2070 LTTNG_ASSERT(contexts_node
);
2071 LTTNG_ASSERT(events_node
);
2073 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2077 content
= xmlNodeGetContent(attr_node
);
2079 ret
= -LTTNG_ERR_NOMEM
;
2083 ret
= lttng_strncpy(channel
->name
,
2084 (const char *) content
,
2085 LTTNG_SYMBOL_NAME_LEN
);
2087 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2088 (const char *) content
,
2089 strlen((const char *) content
),
2090 LTTNG_SYMBOL_NAME_LEN
);
2091 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2096 } else if (!strcmp((const char *) attr_node
->name
,
2097 config_element_enabled
)) {
2102 content
= xmlNodeGetContent(attr_node
);
2104 ret
= -LTTNG_ERR_NOMEM
;
2108 ret
= parse_bool(content
, &enabled
);
2111 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2115 channel
->enabled
= enabled
;
2116 } else if (!strcmp((const char *) attr_node
->name
,
2117 config_element_overwrite_mode
)) {
2120 /* overwrite_mode */
2121 content
= xmlNodeGetContent(attr_node
);
2123 ret
= -LTTNG_ERR_NOMEM
;
2127 ret
= get_overwrite_mode(content
);
2130 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2134 channel
->attr
.overwrite
= ret
;
2135 } else if (!strcmp((const char *) attr_node
->name
,
2136 config_element_subbuf_size
)) {
2139 /* subbuffer_size */
2140 content
= xmlNodeGetContent(attr_node
);
2142 ret
= -LTTNG_ERR_NOMEM
;
2146 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2149 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2152 } else if (!strcmp((const char *) attr_node
->name
,
2153 config_element_num_subbuf
)) {
2156 /* subbuffer_count */
2157 content
= xmlNodeGetContent(attr_node
);
2159 ret
= -LTTNG_ERR_NOMEM
;
2163 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2166 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2169 } else if (!strcmp((const char *) attr_node
->name
,
2170 config_element_switch_timer_interval
)) {
2172 uint64_t switch_timer_interval
= 0;
2174 /* switch_timer_interval */
2175 content
= xmlNodeGetContent(attr_node
);
2177 ret
= -LTTNG_ERR_NOMEM
;
2181 ret
= parse_uint(content
, &switch_timer_interval
);
2184 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2188 if (switch_timer_interval
> UINT_MAX
) {
2189 WARN("switch_timer_interval out of range.");
2190 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2194 channel
->attr
.switch_timer_interval
=
2195 switch_timer_interval
;
2196 } else if (!strcmp((const char *) attr_node
->name
,
2197 config_element_read_timer_interval
)) {
2199 uint64_t read_timer_interval
= 0;
2201 /* read_timer_interval */
2202 content
= xmlNodeGetContent(attr_node
);
2204 ret
= -LTTNG_ERR_NOMEM
;
2208 ret
= parse_uint(content
, &read_timer_interval
);
2211 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2215 if (read_timer_interval
> UINT_MAX
) {
2216 WARN("read_timer_interval out of range.");
2217 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2221 channel
->attr
.read_timer_interval
=
2222 read_timer_interval
;
2223 } else if (!strcmp((const char *) attr_node
->name
,
2224 config_element_output_type
)) {
2228 content
= xmlNodeGetContent(attr_node
);
2230 ret
= -LTTNG_ERR_NOMEM
;
2234 ret
= get_output_type(content
);
2237 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2241 channel
->attr
.output
= (lttng_event_output
) ret
;
2242 } else if (!strcmp((const char *) attr_node
->name
,
2243 config_element_tracefile_size
)) {
2246 /* tracefile_size */
2247 content
= xmlNodeGetContent(attr_node
);
2249 ret
= -LTTNG_ERR_NOMEM
;
2253 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2256 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2259 } else if (!strcmp((const char *) attr_node
->name
,
2260 config_element_tracefile_count
)) {
2263 /* tracefile_count */
2264 content
= xmlNodeGetContent(attr_node
);
2266 ret
= -LTTNG_ERR_NOMEM
;
2270 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2273 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2276 } else if (!strcmp((const char *) attr_node
->name
,
2277 config_element_live_timer_interval
)) {
2279 uint64_t live_timer_interval
= 0;
2281 /* live_timer_interval */
2282 content
= xmlNodeGetContent(attr_node
);
2284 ret
= -LTTNG_ERR_NOMEM
;
2288 ret
= parse_uint(content
, &live_timer_interval
);
2291 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2295 if (live_timer_interval
> UINT_MAX
) {
2296 WARN("live_timer_interval out of range.");
2297 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2301 channel
->attr
.live_timer_interval
=
2302 live_timer_interval
;
2303 } else if (!strcmp((const char *) attr_node
->name
,
2304 config_element_monitor_timer_interval
)) {
2306 uint64_t monitor_timer_interval
= 0;
2308 /* monitor_timer_interval */
2309 content
= xmlNodeGetContent(attr_node
);
2311 ret
= -LTTNG_ERR_NOMEM
;
2315 ret
= parse_uint(content
, &monitor_timer_interval
);
2318 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2322 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2323 monitor_timer_interval
);
2325 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2328 } else if (!strcmp((const char *) attr_node
->name
,
2329 config_element_blocking_timeout
)) {
2331 int64_t blocking_timeout
= 0;
2333 /* blocking_timeout */
2334 content
= xmlNodeGetContent(attr_node
);
2336 ret
= -LTTNG_ERR_NOMEM
;
2340 ret
= parse_int(content
, &blocking_timeout
);
2343 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2347 ret
= lttng_channel_set_blocking_timeout(channel
,
2350 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2353 } else if (!strcmp((const char *) attr_node
->name
,
2354 config_element_events
)) {
2356 *events_node
= attr_node
;
2359 *contexts_node
= attr_node
;
2367 int process_context_node(xmlNodePtr context_node
,
2368 struct lttng_handle
*handle
, const char *channel_name
)
2371 struct lttng_event_context context
;
2372 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2374 LTTNG_ASSERT(handle
);
2375 LTTNG_ASSERT(channel_name
);
2377 if (!context_child_node
) {
2378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2382 memset(&context
, 0, sizeof(context
));
2384 if (!strcmp((const char *) context_child_node
->name
,
2385 config_element_type
)) {
2387 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2390 ret
= -LTTNG_ERR_NOMEM
;
2394 ret
= get_context_type(content
);
2397 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2401 context
.ctx
= (lttng_event_context_type
) ret
;
2402 } else if (!strcmp((const char *) context_child_node
->name
,
2403 config_element_context_perf
)) {
2405 xmlNodePtr perf_attr_node
;
2407 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2408 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2409 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2410 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2411 perf_attr_node
; perf_attr_node
=
2412 xmlNextElementSibling(perf_attr_node
)) {
2413 if (!strcmp((const char *) perf_attr_node
->name
,
2414 config_element_type
)) {
2419 content
= xmlNodeGetContent(perf_attr_node
);
2421 ret
= -LTTNG_ERR_NOMEM
;
2425 ret
= parse_uint(content
, &type
);
2428 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2432 if (type
> UINT32_MAX
) {
2433 WARN("perf context type out of range.");
2434 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2438 context
.u
.perf_counter
.type
= type
;
2439 } else if (!strcmp((const char *) perf_attr_node
->name
,
2440 config_element_config
)) {
2442 uint64_t config
= 0;
2445 content
= xmlNodeGetContent(perf_attr_node
);
2447 ret
= -LTTNG_ERR_NOMEM
;
2451 ret
= parse_uint(content
, &config
);
2454 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2458 context
.u
.perf_counter
.config
= config
;
2459 } else if (!strcmp((const char *) perf_attr_node
->name
,
2460 config_element_name
)) {
2464 content
= xmlNodeGetContent(perf_attr_node
);
2466 ret
= -LTTNG_ERR_NOMEM
;
2470 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2471 (const char *) content
,
2472 LTTNG_SYMBOL_NAME_LEN
);
2474 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2475 (const char *) content
,
2476 strlen((const char *) content
),
2477 LTTNG_SYMBOL_NAME_LEN
);
2478 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2485 } else if (!strcmp((const char *) context_child_node
->name
,
2486 config_element_context_app
)) {
2487 /* application context */
2488 xmlNodePtr app_ctx_node
;
2490 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2491 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2492 app_ctx_node
; app_ctx_node
=
2493 xmlNextElementSibling(app_ctx_node
)) {
2495 char **target
= strcmp(
2496 (const char *) app_ctx_node
->name
,
2497 config_element_context_app_provider_name
) == 0 ?
2498 &context
.u
.app_ctx
.provider_name
:
2499 &context
.u
.app_ctx
.ctx_name
;
2501 content
= xmlNodeGetContent(app_ctx_node
);
2503 ret
= -LTTNG_ERR_NOMEM
;
2507 *target
= (char *) content
;
2510 /* Unrecognized context type */
2511 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2515 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2516 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2517 free(context
.u
.app_ctx
.provider_name
);
2518 free(context
.u
.app_ctx
.ctx_name
);
2525 int process_contexts_node(xmlNodePtr contexts_node
,
2526 struct lttng_handle
*handle
, const char *channel_name
)
2529 xmlNodePtr context_node
;
2531 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2532 context_node
= xmlNextElementSibling(context_node
)) {
2533 ret
= process_context_node(context_node
, handle
, channel_name
);
2542 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2543 const char **element_id_tracker
,
2544 const char **element_value_type
,
2545 const char **element_value
,
2546 const char **element_value_alias
,
2547 const char **element_name
)
2551 switch (process_attr
) {
2552 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2553 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2554 *element_value_type
= config_element_process_attr_pid_value
;
2555 *element_value
= config_element_process_attr_id
;
2556 *element_value_alias
= config_element_process_attr_id
;
2557 *element_name
= NULL
;
2559 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2560 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2561 *element_value_type
= config_element_process_attr_vpid_value
;
2562 *element_value
= config_element_process_attr_id
;
2563 *element_value_alias
= NULL
;
2564 *element_name
= NULL
;
2566 case LTTNG_PROCESS_ATTR_USER_ID
:
2567 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2568 *element_value_type
= config_element_process_attr_uid_value
;
2569 *element_value
= config_element_process_attr_id
;
2570 *element_value_alias
= NULL
;
2571 *element_name
= config_element_name
;
2573 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2574 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2575 *element_value_type
= config_element_process_attr_vuid_value
;
2576 *element_value
= config_element_process_attr_id
;
2577 *element_value_alias
= NULL
;
2578 *element_name
= config_element_name
;
2580 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2581 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2582 *element_value_type
= config_element_process_attr_gid_value
;
2583 *element_value
= config_element_process_attr_id
;
2584 *element_value_alias
= NULL
;
2585 *element_name
= config_element_name
;
2587 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2588 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2589 *element_value_type
= config_element_process_attr_vgid_value
;
2590 *element_value
= config_element_process_attr_id
;
2591 *element_value_alias
= NULL
;
2592 *element_name
= config_element_name
;
2595 ret
= LTTNG_ERR_INVALID
;
2600 static int process_legacy_pid_tracker_node(
2601 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2603 int ret
= 0, child_count
;
2604 xmlNodePtr targets_node
= NULL
;
2606 const char *element_id_tracker
;
2607 const char *element_target_id
;
2608 const char *element_id
;
2609 const char *element_id_alias
;
2610 const char *element_name
;
2611 enum lttng_error_code tracker_handle_ret_code
;
2612 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2613 enum lttng_process_attr_tracker_handle_status status
;
2614 const enum lttng_process_attr process_attr
=
2615 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2616 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2617 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2619 LTTNG_ASSERT(handle
);
2621 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2622 handle
->session_name
, handle
->domain
.type
,
2625 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2626 ret
= LTTNG_ERR_INVALID
;
2630 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2631 &element_target_id
, &element_id
, &element_id_alias
,
2637 /* Get the targets node */
2638 for (node
= xmlFirstElementChild(trackers_node
); node
;
2639 node
= xmlNextElementSibling(node
)) {
2640 if (!strcmp((const char *) node
->name
,
2641 config_element_tracker_targets_legacy
)) {
2642 targets_node
= node
;
2647 if (!targets_node
) {
2648 ret
= LTTNG_ERR_INVALID
;
2652 /* Go through all id target node */
2653 child_count
= xmlChildElementCount(targets_node
);
2654 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2656 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2657 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2658 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2659 ret
= LTTNG_ERR_UNK
;
2663 /* Add all tracked values. */
2664 for (node
= xmlFirstElementChild(targets_node
); node
;
2665 node
= xmlNextElementSibling(node
)) {
2666 xmlNodePtr pid_target_node
= node
;
2668 /* get pid_target node and track it */
2669 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2670 node
= xmlNextElementSibling(node
)) {
2671 if (!strcmp((const char *) node
->name
,
2672 config_element_tracker_pid_legacy
)) {
2674 xmlChar
*content
= xmlNodeGetContent(node
);
2677 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2681 ret
= parse_int(content
, &id
);
2684 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2688 switch (process_attr
) {
2689 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2690 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2694 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2695 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2700 ret
= LTTNG_ERR_INVALID
;
2705 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2707 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2708 ret
= LTTNG_ERR_INVALID
;
2710 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2711 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2713 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2714 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2716 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2717 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2719 ret
= LTTNG_ERR_UNK
;
2723 node
= pid_target_node
;
2727 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2731 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2732 struct lttng_handle
*handle
,
2733 enum lttng_process_attr process_attr
)
2735 int ret
= 0, child_count
;
2736 xmlNodePtr values_node
= NULL
;
2738 const char *element_id_tracker
;
2739 const char *element_target_id
;
2740 const char *element_id
;
2741 const char *element_id_alias
;
2742 const char *element_name
;
2743 enum lttng_error_code tracker_handle_ret_code
;
2744 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2745 enum lttng_process_attr_tracker_handle_status status
;
2747 LTTNG_ASSERT(handle
);
2748 LTTNG_ASSERT(id_tracker_node
);
2750 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2751 handle
->session_name
, handle
->domain
.type
, process_attr
,
2753 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2754 ret
= LTTNG_ERR_INVALID
;
2758 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2759 &element_target_id
, &element_id
, &element_id_alias
,
2765 /* get the values node */
2766 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2767 node
= xmlNextElementSibling(node
)) {
2768 if (!strcmp((const char *) node
->name
,
2769 config_element_process_attr_values
)) {
2776 ret
= LTTNG_ERR_INVALID
;
2780 /* Go through all id target node */
2781 child_count
= xmlChildElementCount(values_node
);
2782 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2784 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2785 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2786 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2787 ret
= LTTNG_ERR_UNK
;
2791 /* Add all tracked values. */
2792 for (node
= xmlFirstElementChild(values_node
); node
;
2793 node
= xmlNextElementSibling(node
)) {
2794 xmlNodePtr id_target_node
= node
;
2796 /* get id node and track it */
2797 for (node
= xmlFirstElementChild(id_target_node
); node
;
2798 node
= xmlNextElementSibling(node
)) {
2799 if (!strcmp((const char *) node
->name
, element_id
) ||
2800 (element_id_alias
&&
2801 !strcmp((const char *) node
->name
,
2802 element_id_alias
))) {
2804 xmlChar
*content
= xmlNodeGetContent(node
);
2807 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2811 ret
= parse_int(content
, &id
);
2814 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2818 switch (process_attr
) {
2819 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2820 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2824 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2825 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2829 case LTTNG_PROCESS_ATTR_USER_ID
:
2830 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2834 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2835 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2839 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2840 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2844 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2845 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2850 ret
= LTTNG_ERR_INVALID
;
2853 } else if (element_name
&&
2854 !strcmp((const char *) node
->name
,
2856 xmlChar
*content
= xmlNodeGetContent(node
);
2859 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2863 switch (process_attr
) {
2864 case LTTNG_PROCESS_ATTR_USER_ID
:
2865 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
2867 (const char *) content
);
2869 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2870 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
2872 (const char *) content
);
2874 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2875 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
2877 (const char *) content
);
2879 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2880 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
2882 (const char *) content
);
2886 ret
= LTTNG_ERR_INVALID
;
2892 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2894 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2895 ret
= LTTNG_ERR_INVALID
;
2897 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2898 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2900 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2901 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2903 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2904 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2906 ret
= LTTNG_ERR_UNK
;
2910 node
= id_target_node
;
2914 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2919 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2922 struct lttng_domain domain
{};
2923 struct lttng_handle
*handle
= NULL
;
2924 struct lttng_channel
*channel
= NULL
;
2925 xmlNodePtr channels_node
= NULL
;
2926 xmlNodePtr trackers_node
= NULL
;
2927 xmlNodePtr pid_tracker_node
= NULL
;
2928 xmlNodePtr vpid_tracker_node
= NULL
;
2929 xmlNodePtr uid_tracker_node
= NULL
;
2930 xmlNodePtr vuid_tracker_node
= NULL
;
2931 xmlNodePtr gid_tracker_node
= NULL
;
2932 xmlNodePtr vgid_tracker_node
= NULL
;
2935 LTTNG_ASSERT(session_name
);
2937 ret
= init_domain(domain_node
, &domain
);
2942 handle
= lttng_create_handle(session_name
, &domain
);
2944 ret
= -LTTNG_ERR_NOMEM
;
2948 /* get the channels node */
2949 for (node
= xmlFirstElementChild(domain_node
); node
;
2950 node
= xmlNextElementSibling(node
)) {
2951 if (!strcmp((const char *) node
->name
,
2952 config_element_channels
)) {
2953 channels_node
= node
;
2958 if (!channels_node
) {
2962 /* create all channels */
2963 for (node
= xmlFirstElementChild(channels_node
); node
;
2964 node
= xmlNextElementSibling(node
)) {
2965 const enum lttng_domain_type original_domain
= domain
.type
;
2966 xmlNodePtr contexts_node
= NULL
;
2967 xmlNodePtr events_node
= NULL
;
2968 xmlNodePtr channel_attr_node
;
2971 * Channels of the "agent" types cannot be created directly.
2972 * They are meant to be created implicitly through the
2973 * activation of events in their domain. However, a user
2974 * can override the default channel configuration attributes
2975 * by creating the underlying UST channel _before_ enabling
2976 * an agent domain event.
2978 * Hence, the channel's type is substituted before the creation
2979 * and restored by the time the events are created.
2981 switch (domain
.type
) {
2982 case LTTNG_DOMAIN_JUL
:
2983 case LTTNG_DOMAIN_LOG4J
:
2984 case LTTNG_DOMAIN_PYTHON
:
2985 domain
.type
= LTTNG_DOMAIN_UST
;
2990 channel
= lttng_channel_create(&domain
);
2996 for (channel_attr_node
= xmlFirstElementChild(node
);
2997 channel_attr_node
; channel_attr_node
=
2998 xmlNextElementSibling(channel_attr_node
)) {
2999 ret
= process_channel_attr_node(channel_attr_node
,
3000 channel
, &contexts_node
, &events_node
);
3006 ret
= lttng_enable_channel(handle
, channel
);
3011 /* Restore the original channel domain. */
3012 domain
.type
= original_domain
;
3014 ret
= process_events_node(events_node
, handle
, channel
->name
);
3019 ret
= process_contexts_node(contexts_node
, handle
,
3025 lttng_channel_destroy(channel
);
3029 /* get the trackers node */
3030 for (node
= xmlFirstElementChild(domain_node
); node
;
3031 node
= xmlNextElementSibling(node
)) {
3032 if (!strcmp((const char *) node
->name
,
3033 config_element_process_attr_trackers
) ||
3034 !strcmp((const char *) node
->name
,
3035 config_element_trackers_legacy
)) {
3036 if (trackers_node
) {
3037 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3038 config_element_process_attr_trackers
,
3039 config_element_trackers_legacy
);
3043 trackers_node
= node
;
3048 if (!trackers_node
) {
3052 for (node
= xmlFirstElementChild(trackers_node
); node
;
3053 node
= xmlNextElementSibling(node
)) {
3054 if (!strcmp((const char *) node
->name
,
3055 config_element_process_attr_tracker_pid
)) {
3056 pid_tracker_node
= node
;
3057 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3058 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3063 if (!strcmp((const char *) node
->name
,
3064 config_element_process_attr_tracker_vpid
)) {
3065 vpid_tracker_node
= node
;
3066 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3067 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3072 if (!strcmp((const char *) node
->name
,
3073 config_element_process_attr_tracker_uid
)) {
3074 uid_tracker_node
= node
;
3075 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3076 LTTNG_PROCESS_ATTR_USER_ID
);
3081 if (!strcmp((const char *) node
->name
,
3082 config_element_process_attr_tracker_vuid
)) {
3083 vuid_tracker_node
= node
;
3084 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3085 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3090 if (!strcmp((const char *) node
->name
,
3091 config_element_process_attr_tracker_gid
)) {
3092 gid_tracker_node
= node
;
3093 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3094 LTTNG_PROCESS_ATTR_GROUP_ID
);
3099 if (!strcmp((const char *) node
->name
,
3100 config_element_process_attr_tracker_vgid
)) {
3101 vgid_tracker_node
= node
;
3102 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3103 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3108 if (!strcmp((const char *) node
->name
,
3109 config_element_pid_tracker_legacy
)) {
3110 ret
= process_legacy_pid_tracker_node(node
, handle
);
3118 lttng_channel_destroy(channel
);
3119 lttng_destroy_handle(handle
);
3124 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3127 enum lttng_rotation_status status
;
3128 struct lttng_rotation_schedule
*periodic
=
3129 lttng_rotation_schedule_periodic_create();
3132 ret
= -LTTNG_ERR_NOMEM
;
3136 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3138 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3139 ret
= -LTTNG_ERR_INVALID
;
3143 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3145 case LTTNG_ROTATION_STATUS_OK
:
3148 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3149 case LTTNG_ROTATION_STATUS_INVALID
:
3150 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3153 ret
= -LTTNG_ERR_UNK
;
3157 lttng_rotation_schedule_destroy(periodic
);
3162 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3165 enum lttng_rotation_status status
;
3166 struct lttng_rotation_schedule
*size
=
3167 lttng_rotation_schedule_size_threshold_create();
3170 ret
= -LTTNG_ERR_NOMEM
;
3174 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3176 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3177 ret
= -LTTNG_ERR_INVALID
;
3181 status
= lttng_session_add_rotation_schedule(name
, size
);
3183 case LTTNG_ROTATION_STATUS_OK
:
3186 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3187 case LTTNG_ROTATION_STATUS_INVALID
:
3188 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3191 ret
= -LTTNG_ERR_UNK
;
3195 lttng_rotation_schedule_destroy(size
);
3200 int process_session_rotation_schedules_node(
3201 xmlNodePtr schedules_node
,
3202 uint64_t *rotation_timer_interval
,
3203 uint64_t *rotation_size
)
3208 for (child
= xmlFirstElementChild(schedules_node
);
3210 child
= xmlNextElementSibling(child
)) {
3211 if (!strcmp((const char *) child
->name
,
3212 config_element_rotation_schedule_periodic
)) {
3214 xmlNodePtr time_us_node
;
3216 /* periodic rotation schedule */
3217 time_us_node
= xmlFirstElementChild(child
);
3218 if (!time_us_node
||
3219 strcmp((const char *) time_us_node
->name
,
3220 config_element_rotation_schedule_periodic_time_us
)) {
3221 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3226 content
= xmlNodeGetContent(time_us_node
);
3228 ret
= -LTTNG_ERR_NOMEM
;
3231 ret
= parse_uint(content
, rotation_timer_interval
);
3234 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3237 } else if (!strcmp((const char *) child
->name
,
3238 config_element_rotation_schedule_size_threshold
)) {
3240 xmlNodePtr bytes_node
;
3242 /* size_threshold rotation schedule */
3243 bytes_node
= xmlFirstElementChild(child
);
3245 strcmp((const char *) bytes_node
->name
,
3246 config_element_rotation_schedule_size_threshold_bytes
)) {
3247 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3252 content
= xmlNodeGetContent(bytes_node
);
3254 ret
= -LTTNG_ERR_NOMEM
;
3257 ret
= parse_uint(content
, rotation_size
);
3260 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3271 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3273 const struct config_load_session_override_attr
*overrides
)
3275 int ret
, started
= -1, snapshot_mode
= -1;
3276 uint64_t live_timer_interval
= UINT64_MAX
,
3277 rotation_timer_interval
= 0,
3279 xmlChar
*name
= NULL
;
3280 xmlChar
*shm_path
= NULL
;
3281 xmlNodePtr domains_node
= NULL
;
3282 xmlNodePtr output_node
= NULL
;
3284 xmlNodePtr attributes_child
;
3285 struct lttng_domain
*kernel_domain
= NULL
;
3286 struct lttng_domain
*ust_domain
= NULL
;
3287 struct lttng_domain
*jul_domain
= NULL
;
3288 struct lttng_domain
*log4j_domain
= NULL
;
3289 struct lttng_domain
*python_domain
= NULL
;
3291 for (node
= xmlFirstElementChild(session_node
); node
;
3292 node
= xmlNextElementSibling(node
)) {
3293 if (!name
&& !strcmp((const char *) node
->name
,
3294 config_element_name
)) {
3296 xmlChar
*node_content
= xmlNodeGetContent(node
);
3297 if (!node_content
) {
3298 ret
= -LTTNG_ERR_NOMEM
;
3302 name
= node_content
;
3303 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3304 config_element_domains
)) {
3306 domains_node
= node
;
3307 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3308 config_element_started
)) {
3310 xmlChar
*node_content
= xmlNodeGetContent(node
);
3311 if (!node_content
) {
3312 ret
= -LTTNG_ERR_NOMEM
;
3316 ret
= parse_bool(node_content
, &started
);
3319 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3322 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3323 config_element_output
)) {
3326 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3327 config_element_shared_memory_path
)) {
3328 /* shared memory path */
3329 xmlChar
*node_content
= xmlNodeGetContent(node
);
3330 if (!node_content
) {
3331 ret
= -LTTNG_ERR_NOMEM
;
3335 shm_path
= node_content
;
3338 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3339 * rotation_timer_interval.
3341 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3342 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3343 if (!strcmp((const char *) attributes_child
->name
,
3344 config_element_snapshot_mode
)) {
3346 xmlChar
*snapshot_mode_content
=
3347 xmlNodeGetContent(attributes_child
);
3348 if (!snapshot_mode_content
) {
3349 ret
= -LTTNG_ERR_NOMEM
;
3353 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3354 free(snapshot_mode_content
);
3356 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3359 } else if (!strcmp((const char *) attributes_child
->name
,
3360 config_element_live_timer_interval
)) {
3361 /* live_timer_interval */
3362 xmlChar
*timer_interval_content
=
3363 xmlNodeGetContent(attributes_child
);
3364 if (!timer_interval_content
) {
3365 ret
= -LTTNG_ERR_NOMEM
;
3369 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3370 free(timer_interval_content
);
3372 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3375 } else if (!strcmp((const char *) attributes_child
->name
,
3376 config_element_rotation_schedules
)) {
3377 ret
= process_session_rotation_schedules_node(
3379 &rotation_timer_interval
,
3382 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3392 /* Mandatory attribute, as defined in the session XSD */
3393 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3397 if (session_name
&& strcmp((char *) name
, session_name
)) {
3398 /* This is not the session we are looking for */
3399 ret
= -LTTNG_ERR_NO_SESSION
;
3403 /* Init domains to create the session handles */
3404 for (node
= xmlFirstElementChild(domains_node
); node
;
3405 node
= xmlNextElementSibling(node
)) {
3406 lttng_domain
*domain
= zmalloc
<lttng_domain
>();
3409 ret
= -LTTNG_ERR_NOMEM
;
3413 ret
= init_domain(node
, domain
);
3415 goto domain_init_error
;
3418 switch (domain
->type
) {
3419 case LTTNG_DOMAIN_KERNEL
:
3420 if (kernel_domain
) {
3421 /* Same domain seen twice, invalid! */
3422 goto domain_init_error
;
3424 kernel_domain
= domain
;
3426 case LTTNG_DOMAIN_UST
:
3428 /* Same domain seen twice, invalid! */
3429 goto domain_init_error
;
3431 ust_domain
= domain
;
3433 case LTTNG_DOMAIN_JUL
:
3435 /* Same domain seen twice, invalid! */
3436 goto domain_init_error
;
3438 jul_domain
= domain
;
3440 case LTTNG_DOMAIN_LOG4J
:
3442 /* Same domain seen twice, invalid! */
3443 goto domain_init_error
;
3445 log4j_domain
= domain
;
3447 case LTTNG_DOMAIN_PYTHON
:
3448 if (python_domain
) {
3449 /* Same domain seen twice, invalid! */
3450 goto domain_init_error
;
3452 python_domain
= domain
;
3455 WARN("Invalid domain type");
3456 goto domain_init_error
;
3461 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3465 /* Apply overrides */
3467 if (overrides
->session_name
) {
3468 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3469 if (!name_override
) {
3470 ret
= -LTTNG_ERR_NOMEM
;
3474 /* Overrides the session name to the provided name */
3476 name
= name_override
;
3481 /* Destroy session if it exists */
3482 ret
= lttng_destroy_session((const char *) name
);
3483 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3484 ERR("Failed to destroy existing session.");
3489 /* Create session type depending on output type */
3490 if (snapshot_mode
&& snapshot_mode
!= -1) {
3491 ret
= create_snapshot_session((const char *) name
, output_node
,
3493 } else if (live_timer_interval
&&
3494 live_timer_interval
!= UINT64_MAX
) {
3495 ret
= create_session((const char *) name
,
3496 output_node
, live_timer_interval
, overrides
);
3498 /* regular session */
3499 ret
= create_session((const char *) name
,
3500 output_node
, UINT64_MAX
, overrides
);
3507 ret
= lttng_set_session_shm_path((const char *) name
,
3508 (const char *) shm_path
);
3514 for (node
= xmlFirstElementChild(domains_node
); node
;
3515 node
= xmlNextElementSibling(node
)) {
3516 ret
= process_domain_node(node
, (const char *) name
);
3522 if (rotation_timer_interval
) {
3523 ret
= add_periodic_rotation((const char *) name
,
3524 rotation_timer_interval
);
3529 if (rotation_size
) {
3530 ret
= add_size_rotation((const char *) name
,
3538 ret
= lttng_start_tracing((const char *) name
);
3546 ERR("Failed to load session %s: %s", (const char *) name
,
3547 lttng_strerror(ret
));
3548 lttng_destroy_session((const char *) name
);
3552 free(kernel_domain
);
3556 free(python_domain
);
3563 * Return 1 if the given path is readable by the current UID or 0 if not.
3564 * Return -1 if the path is EPERM.
3566 static int validate_file_read_creds(const char *path
)
3572 /* Can we read the file. */
3573 ret
= access(path
, R_OK
);
3577 if (errno
== EACCES
) {
3588 int load_session_from_file(const char *path
, const char *session_name
,
3589 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3590 const struct config_load_session_override_attr
*overrides
)
3592 int ret
, session_found
= !session_name
;
3593 xmlDocPtr doc
= NULL
;
3594 xmlNodePtr sessions_node
;
3595 xmlNodePtr session_node
;
3598 LTTNG_ASSERT(validation_ctx
);
3600 ret
= validate_file_read_creds(path
);
3603 ret
= -LTTNG_ERR_EPERM
;
3605 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3610 doc
= xmlParseFile(path
);
3612 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3616 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3618 ERR("Session configuration file validation failed");
3619 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3623 sessions_node
= xmlDocGetRootElement(doc
);
3624 if (!sessions_node
) {
3625 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3629 for (session_node
= xmlFirstElementChild(sessions_node
);
3630 session_node
; session_node
=
3631 xmlNextElementSibling(session_node
)) {
3632 ret
= process_session_node(session_node
,
3633 session_name
, overwrite
, overrides
);
3634 if (!session_name
&& ret
) {
3635 /* Loading error occurred. */
3637 } else if (session_name
) {
3639 /* Target session found and loaded */
3642 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3644 * Ignore this error, we are looking for a
3649 /* Loading error occurred. */
3657 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3663 int load_session_from_path(const char *path
, const char *session_name
,
3664 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3665 const struct config_load_session_override_attr
*overrides
)
3667 int ret
, session_found
= !session_name
;
3668 DIR *directory
= NULL
;
3669 struct lttng_dynamic_buffer file_path
;
3673 LTTNG_ASSERT(validation_ctx
);
3674 path_len
= strlen(path
);
3675 lttng_dynamic_buffer_init(&file_path
);
3676 if (path_len
>= LTTNG_PATH_MAX
) {
3677 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3678 path
, path_len
, LTTNG_PATH_MAX
);
3679 ret
= -LTTNG_ERR_INVALID
;
3683 directory
= opendir(path
);
3687 /* Try the file loading. */
3690 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3693 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3698 size_t file_path_root_len
;
3700 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3703 ret
= -LTTNG_ERR_NOMEM
;
3707 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3709 ret
= -LTTNG_ERR_NOMEM
;
3713 if (file_path
.data
[file_path
.size
- 1] != '/') {
3714 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3716 ret
= -LTTNG_ERR_NOMEM
;
3720 file_path_root_len
= file_path
.size
;
3722 /* Search for *.lttng files */
3724 size_t file_name_len
;
3725 struct dirent
*result
;
3728 * When the end of the directory stream is reached, NULL
3729 * is returned and errno is kept unchanged. When an
3730 * error occurs, NULL is returned and errno is set
3731 * accordingly. To distinguish between the two, set
3732 * errno to zero before calling readdir().
3734 * On success, readdir() returns a pointer to a dirent
3735 * structure. This structure may be statically
3736 * allocated, do not attempt to free(3) it.
3739 result
= readdir(directory
);
3741 /* Reached end of dir stream or error out. */
3744 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3745 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3751 file_name_len
= strlen(result
->d_name
);
3753 if (file_name_len
<=
3754 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3758 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3759 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3761 /* +1 to account for NULL terminator. */
3762 file_path
.size
+ file_name_len
+ 1,
3767 /* Does the file end with .lttng? */
3768 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3769 result
->d_name
+ file_name_len
- sizeof(
3770 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3774 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3777 ret
= -LTTNG_ERR_NOMEM
;
3781 ret
= load_session_from_file(file_path
.data
, session_name
,
3782 validation_ctx
, overwrite
, overrides
);
3784 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3788 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3792 * Reset the buffer's size to the location of the
3793 * path's trailing '/'.
3795 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3796 file_path_root_len
);
3798 ret
= -LTTNG_ERR_UNK
;
3803 ret
= load_session_from_file(path
, session_name
,
3804 validation_ctx
, overwrite
, overrides
);
3814 if (closedir(directory
)) {
3818 if (!ret
&& !session_found
) {
3819 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3821 lttng_dynamic_buffer_reset(&file_path
);
3826 * Validate that the given path's credentials and the current process have the
3827 * same UID. If so, return 1 else return 0 if it does NOT match.
3829 static int validate_path_creds(const char *path
)
3831 int ret
, uid
= getuid();
3840 ret
= stat(path
, &buf
);
3842 if (errno
!= ENOENT
) {
3848 if (buf
.st_uid
!= uid
) {
3858 int config_load_session(const char *path
, const char *session_name
,
3859 int overwrite
, unsigned int autoload
,
3860 const struct config_load_session_override_attr
*overrides
)
3863 bool session_loaded
= false;
3864 const char *path_ptr
= NULL
;
3865 struct session_config_validation_ctx validation_ctx
= {};
3867 ret
= init_session_config_validation_ctx(&validation_ctx
);
3873 const char *home_path
;
3874 const char *sys_path
;
3877 home_path
= utils_get_home_dir();
3879 char path_buf
[PATH_MAX
];
3882 * Try user session configuration path. Ignore error here so we can
3883 * continue loading the system wide sessions.
3886 ret
= snprintf(path_buf
, sizeof(path_buf
),
3887 DEFAULT_SESSION_HOME_CONFIGPATH
3888 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
3891 PERROR("snprintf session autoload home config path");
3892 ret
= -LTTNG_ERR_INVALID
;
3897 * Credentials are only validated for the autoload in order to
3898 * avoid any user session daemon to try to load kernel sessions
3899 * automatically and failing all the times.
3901 ret
= validate_path_creds(path_buf
);
3903 path_ptr
= path_buf
;
3906 ret
= snprintf(path_buf
, sizeof(path_buf
),
3907 DEFAULT_SESSION_HOME_CONFIGPATH
,
3910 PERROR("snprintf session home config path");
3911 ret
= -LTTNG_ERR_INVALID
;
3914 path_ptr
= path_buf
;
3917 ret
= load_session_from_path(path_ptr
, session_name
,
3918 &validation_ctx
, overwrite
, overrides
);
3919 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3923 * Continue even if the session was found since we have to try
3924 * the system wide sessions.
3926 session_loaded
= true;
3930 /* Reset path pointer for the system wide dir. */
3933 /* Try system wide configuration directory. */
3935 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3936 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3937 ret
= validate_path_creds(sys_path
);
3939 path_ptr
= sys_path
;
3942 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3943 path_ptr
= sys_path
;
3947 ret
= load_session_from_path(path_ptr
, session_name
,
3948 &validation_ctx
, overwrite
, overrides
);
3950 session_loaded
= true;
3956 ret
= access(path
, F_OK
);
3961 ret
= -LTTNG_ERR_INVALID
;
3962 WARN("Session configuration path does not exist.");
3965 ret
= -LTTNG_ERR_EPERM
;
3968 ret
= -LTTNG_ERR_UNK
;
3974 ret
= load_session_from_path(path
, session_name
,
3975 &validation_ctx
, overwrite
, overrides
);
3978 fini_session_config_validation_ctx(&validation_ctx
);
3979 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3981 * Don't report an error if no sessions are found when called
3982 * without a session_name or a search path.
3987 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3988 /* A matching session was found in one of the search paths. */
3995 void __attribute__((destructor
)) session_config_exit(void)