2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "lttng/tracker.h"
18 #include <sys/types.h>
22 #include <common/defaults.h>
23 #include <common/error.h>
24 #include <common/macros.h>
25 #include <common/utils.h>
26 #include <common/dynamic-buffer.h>
27 #include <common/compat/getenv.h>
28 #include <lttng/lttng-error.h>
29 #include <libxml/parser.h>
30 #include <libxml/valid.h>
31 #include <libxml/xmlschemas.h>
32 #include <libxml/tree.h>
33 #include <lttng/lttng.h>
34 #include <lttng/snapshot.h>
35 #include <lttng/rotation.h>
36 #include <lttng/userspace-probe.h>
38 #include "session-config.h"
39 #include "config-internal.h"
41 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
43 struct handler_filter_args
{
45 config_entry_handler_cb handler
;
49 struct session_config_validation_ctx
{
50 xmlSchemaParserCtxtPtr parser_ctx
;
52 xmlSchemaValidCtxtPtr schema_validation_ctx
;
55 LTTNG_HIDDEN
const char * const config_element_all
= "all";
56 const char * const config_str_yes
= "yes";
57 const char * const config_str_true
= "true";
58 const char * const config_str_on
= "on";
59 const char * const config_str_no
= "no";
60 const char * const config_str_false
= "false";
61 const char * const config_str_off
= "off";
62 const char * const config_xml_encoding
= "UTF-8";
63 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
64 const char * const config_xml_indent_string
= "\t";
65 const char * const config_xml_true
= "true";
66 const char * const config_xml_false
= "false";
68 const char * const config_element_channel
= "channel";
69 const char * const config_element_channels
= "channels";
70 const char * const config_element_domain
= "domain";
71 const char * const config_element_domains
= "domains";
72 const char * const config_element_event
= "event";
73 const char * const config_element_events
= "events";
74 const char * const config_element_context
= "context";
75 const char * const config_element_contexts
= "contexts";
76 const char * const config_element_attributes
= "attributes";
77 const char * const config_element_exclusion
= "exclusion";
78 const char * const config_element_exclusions
= "exclusions";
79 const char * const config_element_function_attributes
= "function_attributes";
80 const char * const config_element_probe_attributes
= "probe_attributes";
81 const char * const config_element_symbol_name
= "symbol_name";
82 const char * const config_element_address
= "address";
83 const char * const config_element_offset
= "offset";
85 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
86 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
87 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
88 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
89 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
90 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
91 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
92 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
93 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
96 const char * const config_element_name
= "name";
97 const char * const config_element_enabled
= "enabled";
98 const char * const config_element_overwrite_mode
= "overwrite_mode";
99 const char * const config_element_subbuf_size
= "subbuffer_size";
100 const char * const config_element_num_subbuf
= "subbuffer_count";
101 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
102 const char * const config_element_read_timer_interval
= "read_timer_interval";
103 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
104 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
105 const char * const config_element_output
= "output";
106 const char * const config_element_output_type
= "output_type";
107 const char * const config_element_tracefile_size
= "tracefile_size";
108 const char * const config_element_tracefile_count
= "tracefile_count";
109 const char * const config_element_live_timer_interval
= "live_timer_interval";
110 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
111 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
112 const char * const config_element_type
= "type";
113 const char * const config_element_buffer_type
= "buffer_type";
114 const char * const config_element_session
= "session";
115 const char * const config_element_sessions
= "sessions";
116 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
117 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
118 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
119 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
120 const char * const config_element_config
= "config";
121 const char * const config_element_started
= "started";
122 const char * const config_element_snapshot_mode
= "snapshot_mode";
123 const char * const config_element_loglevel
= "loglevel";
124 const char * const config_element_loglevel_type
= "loglevel_type";
125 const char * const config_element_filter
= "filter";
126 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
127 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
128 const char * const config_element_consumer_output
= "consumer_output";
129 const char * const config_element_destination
= "destination";
130 const char * const config_element_path
= "path";
131 const char * const config_element_net_output
= "net_output";
132 const char * const config_element_control_uri
= "control_uri";
133 const char * const config_element_data_uri
= "data_uri";
134 const char * const config_element_max_size
= "max_size";
135 const char * const config_element_pid
= "pid";
136 const char * const config_element_pids
= "pids";
137 const char * const config_element_shared_memory_path
= "shared_memory_path";
139 LTTNG_HIDDEN
const char * const config_element_process_attr_id
= "id";
140 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
141 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
142 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
143 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
144 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
145 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
146 LTTNG_HIDDEN
const char * const config_element_process_attr_trackers
= "process_attr_trackers";
147 LTTNG_HIDDEN
const char * const config_element_process_attr_values
= "process_attr_values";
148 LTTNG_HIDDEN
const char * const config_element_process_attr_value_type
= "process_attr_value_type";
149 LTTNG_HIDDEN
const char * const config_element_process_attr_pid_value
= "pid";
150 LTTNG_HIDDEN
const char * const config_element_process_attr_vpid_value
= "vpid";
151 LTTNG_HIDDEN
const char * const config_element_process_attr_uid_value
= "uid";
152 LTTNG_HIDDEN
const char * const config_element_process_attr_vuid_value
= "vuid";
153 LTTNG_HIDDEN
const char * const config_element_process_attr_gid_value
= "gid";
154 LTTNG_HIDDEN
const char * const config_element_process_attr_vgid_value
= "vgid";
155 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
157 /* Used for support of legacy tracker serialization (< 2.12). */
158 LTTNG_HIDDEN
const char * const config_element_trackers_legacy
= "trackers";
159 LTTNG_HIDDEN
const char * const config_element_pid_tracker_legacy
= "pid_tracker";
160 LTTNG_HIDDEN
const char * const config_element_tracker_targets_legacy
= "targets";
161 LTTNG_HIDDEN
const char * const config_element_tracker_pid_target_legacy
= "pid_target";
162 LTTNG_HIDDEN
const char * const config_element_tracker_pid_legacy
= "pid";
164 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
165 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
166 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
167 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
168 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
170 const char * const config_domain_type_kernel
= "KERNEL";
171 const char * const config_domain_type_ust
= "UST";
172 const char * const config_domain_type_jul
= "JUL";
173 const char * const config_domain_type_log4j
= "LOG4J";
174 const char * const config_domain_type_python
= "PYTHON";
176 const char * const config_buffer_type_per_pid
= "PER_PID";
177 const char * const config_buffer_type_per_uid
= "PER_UID";
178 const char * const config_buffer_type_global
= "GLOBAL";
180 const char * const config_overwrite_mode_discard
= "DISCARD";
181 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
183 const char * const config_output_type_splice
= "SPLICE";
184 const char * const config_output_type_mmap
= "MMAP";
186 const char * const config_loglevel_type_all
= "ALL";
187 const char * const config_loglevel_type_range
= "RANGE";
188 const char * const config_loglevel_type_single
= "SINGLE";
190 const char * const config_event_type_all
= "ALL";
191 const char * const config_event_type_tracepoint
= "TRACEPOINT";
192 const char * const config_event_type_probe
= "PROBE";
193 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
194 const char * const config_event_type_function
= "FUNCTION";
195 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
196 const char * const config_event_type_noop
= "NOOP";
197 const char * const config_event_type_syscall
= "SYSCALL";
198 const char * const config_event_type_kprobe
= "KPROBE";
199 const char * const config_event_type_kretprobe
= "KRETPROBE";
201 const char * const config_event_context_pid
= "PID";
202 const char * const config_event_context_procname
= "PROCNAME";
203 const char * const config_event_context_prio
= "PRIO";
204 const char * const config_event_context_nice
= "NICE";
205 const char * const config_event_context_vpid
= "VPID";
206 const char * const config_event_context_tid
= "TID";
207 const char * const config_event_context_vtid
= "VTID";
208 const char * const config_event_context_ppid
= "PPID";
209 const char * const config_event_context_vppid
= "VPPID";
210 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
211 const char * const config_event_context_hostname
= "HOSTNAME";
212 const char * const config_event_context_ip
= "IP";
213 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
214 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
215 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
216 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
217 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
218 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
219 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
220 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
221 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
222 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
223 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
224 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
225 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
226 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
227 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
228 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
229 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
230 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
231 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
232 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
233 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
234 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
235 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
236 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
237 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
238 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
239 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
241 /* Deprecated symbols */
242 const char * const config_element_perf
;
244 enum process_event_node_phase
{
249 struct consumer_output
{
256 static int config_entry_handler_filter(struct handler_filter_args
*args
,
257 const char *section
, const char *name
, const char *value
)
260 struct config_entry entry
= { section
, name
, value
};
264 if (!section
|| !name
|| !value
) {
270 if (strcmp(args
->section
, section
)) {
275 ret
= args
->handler(&entry
, args
->user_data
);
281 int config_get_section_entries(const char *override_path
, const char *section
,
282 config_entry_handler_cb handler
, void *user_data
)
286 FILE *config_file
= NULL
;
287 struct handler_filter_args filter
= { section
, handler
, user_data
};
289 /* First, try system-wide conf. file. */
290 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
292 config_file
= fopen(path
, "r");
294 DBG("Loading daemon conf file at %s", path
);
296 * Return value is not very important here since error or not, we
297 * continue and try the next possible conf. file.
299 (void) ini_parse_file(config_file
,
300 (ini_entry_handler
) config_entry_handler_filter
,
305 /* Second is the user local configuration. */
306 path
= utils_get_home_dir();
308 char fullpath
[PATH_MAX
];
310 ret
= snprintf(fullpath
, sizeof(fullpath
),
311 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
313 PERROR("snprintf user conf. path");
317 config_file
= fopen(fullpath
, "r");
319 DBG("Loading daemon user conf file at %s", path
);
321 * Return value is not very important here since error or not, we
322 * continue and try the next possible conf. file.
324 (void) ini_parse_file(config_file
,
325 (ini_entry_handler
) config_entry_handler_filter
,
331 /* Final path is the one that the user might have provided. */
333 config_file
= fopen(override_path
, "r");
335 DBG("Loading daemon command line conf file at %s", override_path
);
336 (void) ini_parse_file(config_file
,
337 (ini_entry_handler
) config_entry_handler_filter
,
341 ERR("Failed to open daemon configuration file at %s",
348 /* Everything went well. */
356 int config_parse_value(const char *value
)
359 char *endptr
, *lower_str
;
369 v
= strtoul(value
, &endptr
, 10);
370 if (endptr
!= value
) {
375 lower_str
= zmalloc(len
+ 1);
382 for (i
= 0; i
< len
; i
++) {
383 lower_str
[i
] = tolower(value
[i
]);
386 if (!strcmp(lower_str
, config_str_yes
) ||
387 !strcmp(lower_str
, config_str_true
) ||
388 !strcmp(lower_str
, config_str_on
)) {
390 } else if (!strcmp(lower_str
, config_str_no
) ||
391 !strcmp(lower_str
, config_str_false
) ||
392 !strcmp(lower_str
, config_str_off
)) {
404 * Returns a xmlChar string which must be released using xmlFree().
406 static xmlChar
*encode_string(const char *in_str
)
408 xmlChar
*out_str
= NULL
;
409 xmlCharEncodingHandlerPtr handler
;
410 int out_len
, ret
, in_len
;
414 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
416 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
420 in_len
= strlen(in_str
);
422 * Add 1 byte for the NULL terminted character. The factor 4 here is
423 * used because UTF-8 characters can take up to 4 bytes.
425 out_len
= (in_len
* 4) + 1;
426 out_str
= xmlMalloc(out_len
);
431 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
438 /* out_len is now the size of out_str */
439 out_str
[out_len
] = '\0';
445 struct config_writer
*config_writer_create(int fd_output
, int indent
)
448 struct config_writer
*writer
;
449 xmlOutputBufferPtr buffer
;
451 writer
= zmalloc(sizeof(struct config_writer
));
453 PERROR("zmalloc config_writer_create");
457 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
462 writer
->writer
= xmlNewTextWriter(buffer
);
463 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
464 config_xml_encoding
, NULL
);
469 ret
= xmlTextWriterSetIndentString(writer
->writer
,
470 BAD_CAST config_xml_indent_string
);
475 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
483 config_writer_destroy(writer
);
488 int config_writer_destroy(struct config_writer
*writer
)
497 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
498 WARN("Could not close XML document");
502 if (writer
->writer
) {
503 xmlFreeTextWriter(writer
->writer
);
512 int config_writer_open_element(struct config_writer
*writer
,
513 const char *element_name
)
516 xmlChar
*encoded_element_name
;
518 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
523 encoded_element_name
= encode_string(element_name
);
524 if (!encoded_element_name
) {
529 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
530 xmlFree(encoded_element_name
);
532 return ret
>= 0 ? 0 : ret
;
536 int config_writer_write_attribute(struct config_writer
*writer
,
537 const char *name
, const char *value
)
540 xmlChar
*encoded_name
= NULL
;
541 xmlChar
*encoded_value
= NULL
;
543 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
548 encoded_name
= encode_string(name
);
554 encoded_value
= encode_string(value
);
555 if (!encoded_value
) {
560 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
563 xmlFree(encoded_name
);
564 xmlFree(encoded_value
);
565 return ret
>= 0 ? 0 : ret
;
569 int config_writer_close_element(struct config_writer
*writer
)
573 if (!writer
|| !writer
->writer
) {
578 ret
= xmlTextWriterEndElement(writer
->writer
);
580 return ret
>= 0 ? 0 : ret
;
584 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
585 const char *element_name
, uint64_t value
)
588 xmlChar
*encoded_element_name
;
590 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
595 encoded_element_name
= encode_string(element_name
);
596 if (!encoded_element_name
) {
601 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
602 encoded_element_name
, "%" PRIu64
, value
);
603 xmlFree(encoded_element_name
);
605 return ret
>= 0 ? 0 : ret
;
609 int config_writer_write_element_signed_int(struct config_writer
*writer
,
610 const char *element_name
, int64_t value
)
613 xmlChar
*encoded_element_name
;
615 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
620 encoded_element_name
= encode_string(element_name
);
621 if (!encoded_element_name
) {
626 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
627 encoded_element_name
, "%" PRIi64
, value
);
628 xmlFree(encoded_element_name
);
630 return ret
>= 0 ? 0 : ret
;
634 int config_writer_write_element_bool(struct config_writer
*writer
,
635 const char *element_name
, int value
)
637 return config_writer_write_element_string(writer
, element_name
,
638 value
? config_xml_true
: config_xml_false
);
642 int config_writer_write_element_string(struct config_writer
*writer
,
643 const char *element_name
, const char *value
)
646 xmlChar
*encoded_element_name
= NULL
;
647 xmlChar
*encoded_value
= NULL
;
649 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
655 encoded_element_name
= encode_string(element_name
);
656 if (!encoded_element_name
) {
661 encoded_value
= encode_string(value
);
662 if (!encoded_value
) {
667 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
670 xmlFree(encoded_element_name
);
671 xmlFree(encoded_value
);
672 return ret
>= 0 ? 0 : ret
;
676 void xml_error_handler(void *ctx
, const char *format
, ...)
682 va_start(args
, format
);
683 ret
= vasprintf(&errMsg
, format
, args
);
686 ERR("String allocation failed in xml error handler");
690 fprintf(stderr
, "XML Error: %s", errMsg
);
695 void fini_session_config_validation_ctx(
696 struct session_config_validation_ctx
*ctx
)
698 if (ctx
->parser_ctx
) {
699 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
703 xmlSchemaFree(ctx
->schema
);
706 if (ctx
->schema_validation_ctx
) {
707 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
710 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
714 char *get_session_config_xsd_path()
717 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
718 size_t base_path_len
;
722 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
725 base_path_len
= strlen(base_path
);
726 max_path_len
= base_path_len
+
727 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
728 xsd_path
= zmalloc(max_path_len
);
733 strcpy(xsd_path
, base_path
);
734 if (xsd_path
[base_path_len
- 1] != '/') {
735 xsd_path
[base_path_len
++] = '/';
738 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
744 int init_session_config_validation_ctx(
745 struct session_config_validation_ctx
*ctx
)
748 char *xsd_path
= get_session_config_xsd_path();
751 ret
= -LTTNG_ERR_NOMEM
;
755 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
756 if (!ctx
->parser_ctx
) {
757 ERR("XSD parser context creation failed");
758 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
761 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
762 xml_error_handler
, NULL
);
764 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
766 ERR("XSD parsing failed");
767 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
771 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
772 if (!ctx
->schema_validation_ctx
) {
773 ERR("XSD validation context creation failed");
774 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
778 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
779 xml_error_handler
, NULL
);
784 fini_session_config_validation_ctx(ctx
);
792 int parse_uint(xmlChar
*str
, uint64_t *val
)
802 *val
= strtoull((const char *) str
, &endptr
, 10);
803 if (!endptr
|| *endptr
) {
814 int parse_int(xmlChar
*str
, int64_t *val
)
824 *val
= strtoll((const char *) str
, &endptr
, 10);
825 if (!endptr
|| *endptr
) {
836 int parse_bool(xmlChar
*str
, int *val
)
845 if (!strcmp((const char *) str
, config_xml_true
)) {
847 } else if (!strcmp((const char *) str
, config_xml_false
)) {
850 WARN("Invalid boolean value encoutered (%s).",
859 int get_domain_type(xmlChar
*domain
)
867 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
868 ret
= LTTNG_DOMAIN_KERNEL
;
869 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
870 ret
= LTTNG_DOMAIN_UST
;
871 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
872 ret
= LTTNG_DOMAIN_JUL
;
873 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
874 ret
= LTTNG_DOMAIN_LOG4J
;
875 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
876 ret
= LTTNG_DOMAIN_PYTHON
;
887 int get_buffer_type(xmlChar
*buffer_type
)
895 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
896 ret
= LTTNG_BUFFER_GLOBAL
;
897 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
898 ret
= LTTNG_BUFFER_PER_UID
;
899 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
900 ret
= LTTNG_BUFFER_PER_PID
;
911 int get_overwrite_mode(xmlChar
*overwrite_mode
)
915 if (!overwrite_mode
) {
919 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
921 } else if (!strcmp((char *) overwrite_mode
,
922 config_overwrite_mode_discard
)) {
934 int get_output_type(xmlChar
*output_type
)
942 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
943 ret
= LTTNG_EVENT_MMAP
;
944 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
945 ret
= LTTNG_EVENT_SPLICE
;
956 int get_event_type(xmlChar
*event_type
)
964 if (!strcmp((char *) event_type
, config_event_type_all
)) {
965 ret
= LTTNG_EVENT_ALL
;
966 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
967 ret
= LTTNG_EVENT_TRACEPOINT
;
968 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
969 ret
= LTTNG_EVENT_PROBE
;
970 } else if (!strcmp((char *) event_type
,
971 config_event_type_userspace_probe
)) {
972 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
973 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
974 ret
= LTTNG_EVENT_FUNCTION
;
975 } else if (!strcmp((char *) event_type
,
976 config_event_type_function_entry
)) {
977 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
978 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
979 ret
= LTTNG_EVENT_NOOP
;
980 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
981 ret
= LTTNG_EVENT_SYSCALL
;
992 int get_loglevel_type(xmlChar
*loglevel_type
)
996 if (!loglevel_type
) {
1000 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1001 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1002 } else if (!strcmp((char *) loglevel_type
,
1003 config_loglevel_type_range
)) {
1004 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1005 } else if (!strcmp((char *) loglevel_type
,
1006 config_loglevel_type_single
)) {
1007 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1018 * Return the context type or -1 on error.
1021 int get_context_type(xmlChar
*context_type
)
1025 if (!context_type
) {
1029 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1030 ret
= LTTNG_EVENT_CONTEXT_PID
;
1031 } else if (!strcmp((char *) context_type
,
1032 config_event_context_procname
)) {
1033 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1034 } else if (!strcmp((char *) context_type
,
1035 config_event_context_prio
)) {
1036 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1037 } else if (!strcmp((char *) context_type
,
1038 config_event_context_nice
)) {
1039 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1040 } else if (!strcmp((char *) context_type
,
1041 config_event_context_vpid
)) {
1042 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1043 } else if (!strcmp((char *) context_type
,
1044 config_event_context_tid
)) {
1045 ret
= LTTNG_EVENT_CONTEXT_TID
;
1046 } else if (!strcmp((char *) context_type
,
1047 config_event_context_vtid
)) {
1048 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1049 } else if (!strcmp((char *) context_type
,
1050 config_event_context_ppid
)) {
1051 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1052 } else if (!strcmp((char *) context_type
,
1053 config_event_context_vppid
)) {
1054 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1055 } else if (!strcmp((char *) context_type
,
1056 config_event_context_pthread_id
)) {
1057 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1058 } else if (!strcmp((char *) context_type
,
1059 config_event_context_hostname
)) {
1060 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1061 } else if (!strcmp((char *) context_type
,
1062 config_event_context_ip
)) {
1063 ret
= LTTNG_EVENT_CONTEXT_IP
;
1064 } else if (!strcmp((char *) context_type
,
1065 config_event_context_interruptible
)) {
1066 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1067 } else if (!strcmp((char *) context_type
,
1068 config_event_context_preemptible
)) {
1069 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1070 } else if (!strcmp((char *) context_type
,
1071 config_event_context_need_reschedule
)) {
1072 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1073 } else if (!strcmp((char *) context_type
,
1074 config_event_context_migratable
)) {
1075 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1076 } else if (!strcmp((char *) context_type
,
1077 config_event_context_callstack_user
)) {
1078 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1079 } else if (!strcmp((char *) context_type
,
1080 config_event_context_callstack_kernel
)) {
1081 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1082 } else if (!strcmp((char *) context_type
,
1083 config_event_context_cgroup_ns
)) {
1084 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1085 } else if (!strcmp((char *) context_type
,
1086 config_event_context_ipc_ns
)) {
1087 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1088 } else if (!strcmp((char *) context_type
,
1089 config_event_context_mnt_ns
)) {
1090 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1091 } else if (!strcmp((char *) context_type
,
1092 config_event_context_net_ns
)) {
1093 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1094 } else if (!strcmp((char *) context_type
,
1095 config_event_context_pid_ns
)) {
1096 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1097 } else if (!strcmp((char *) context_type
,
1098 config_event_context_user_ns
)) {
1099 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1100 } else if (!strcmp((char *) context_type
,
1101 config_event_context_uts_ns
)) {
1102 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1103 } else if (!strcmp((char *) context_type
,
1104 config_event_context_uid
)) {
1105 ret
= LTTNG_EVENT_CONTEXT_UID
;
1106 } else if (!strcmp((char *) context_type
,
1107 config_event_context_euid
)) {
1108 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1109 } else if (!strcmp((char *) context_type
,
1110 config_event_context_suid
)) {
1111 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1112 } else if (!strcmp((char *) context_type
,
1113 config_event_context_gid
)) {
1114 ret
= LTTNG_EVENT_CONTEXT_GID
;
1115 } else if (!strcmp((char *) context_type
,
1116 config_event_context_egid
)) {
1117 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1118 } else if (!strcmp((char *) context_type
,
1119 config_event_context_sgid
)) {
1120 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1121 } else if (!strcmp((char *) context_type
,
1122 config_event_context_vuid
)) {
1123 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1124 } else if (!strcmp((char *) context_type
,
1125 config_event_context_veuid
)) {
1126 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1127 } else if (!strcmp((char *) context_type
,
1128 config_event_context_vsuid
)) {
1129 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1130 } else if (!strcmp((char *) context_type
,
1131 config_event_context_vgid
)) {
1132 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1133 } else if (!strcmp((char *) context_type
,
1134 config_event_context_vegid
)) {
1135 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1136 } else if (!strcmp((char *) context_type
,
1137 config_event_context_vsgid
)) {
1138 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1149 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1154 for (node
= xmlFirstElementChild(domain_node
); node
;
1155 node
= xmlNextElementSibling(node
)) {
1156 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1158 xmlChar
*node_content
= xmlNodeGetContent(node
);
1159 if (!node_content
) {
1160 ret
= -LTTNG_ERR_NOMEM
;
1164 ret
= get_domain_type(node_content
);
1167 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1172 } else if (!strcmp((const char *) node
->name
,
1173 config_element_buffer_type
)) {
1175 xmlChar
*node_content
= xmlNodeGetContent(node
);
1176 if (!node_content
) {
1177 ret
= -LTTNG_ERR_NOMEM
;
1181 ret
= get_buffer_type(node_content
);
1184 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1188 domain
->buf_type
= ret
;
1197 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1202 for (node
= xmlFirstElementChild(net_output_node
); node
;
1203 node
= xmlNextElementSibling(node
)) {
1204 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1206 *control_uri
= (char *) xmlNodeGetContent(node
);
1207 if (!*control_uri
) {
1212 *data_uri
= (char *) xmlNodeGetContent(node
);
1219 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1223 int process_consumer_output(xmlNodePtr consumer_output_node
,
1224 struct consumer_output
*output
)
1231 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1232 node
= xmlNextElementSibling(node
)) {
1233 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1234 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1238 ret
= -LTTNG_ERR_NOMEM
;
1242 ret
= parse_bool(enabled_str
, &output
->enabled
);
1248 xmlNodePtr output_type_node
;
1251 output_type_node
= xmlFirstElementChild(node
);
1252 if (!output_type_node
) {
1253 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1257 if (!strcmp((const char *) output_type_node
->name
,
1258 config_element_path
)) {
1260 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1261 if (!output
->path
) {
1262 ret
= -LTTNG_ERR_NOMEM
;
1267 ret
= get_net_output_uris(output_type_node
,
1268 &output
->control_uri
, &output
->data_uri
);
1280 free(output
->control_uri
);
1281 free(output
->data_uri
);
1282 memset(output
, 0, sizeof(struct consumer_output
));
1288 int create_session_net_output(const char *name
, const char *control_uri
,
1289 const char *data_uri
)
1292 struct lttng_handle
*handle
;
1293 const char *uri
= NULL
;
1297 handle
= lttng_create_handle(name
, NULL
);
1299 ret
= -LTTNG_ERR_NOMEM
;
1303 if (!control_uri
|| !data_uri
) {
1304 uri
= control_uri
? control_uri
: data_uri
;
1309 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1310 lttng_destroy_handle(handle
);
1316 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1317 const struct config_load_session_override_attr
*overrides
)
1320 xmlNodePtr node
= NULL
;
1321 xmlNodePtr snapshot_output_list_node
;
1322 xmlNodePtr snapshot_output_node
;
1324 assert(session_name
);
1326 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1335 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1337 /* Parse and create snapshot outputs */
1339 for (snapshot_output_node
=
1340 xmlFirstElementChild(snapshot_output_list_node
);
1341 snapshot_output_node
; snapshot_output_node
=
1342 xmlNextElementSibling(snapshot_output_node
)) {
1344 uint64_t max_size
= UINT64_MAX
;
1345 struct consumer_output output
= { 0 };
1346 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1347 const char *control_uri
= NULL
;
1348 const char *data_uri
= NULL
;
1349 const char *path
= NULL
;
1351 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1352 node
= xmlNextElementSibling(node
)) {
1353 if (!strcmp((const char *) node
->name
,
1354 config_element_name
)) {
1356 name
= (char *) xmlNodeGetContent(node
);
1358 ret
= -LTTNG_ERR_NOMEM
;
1359 goto error_snapshot_output
;
1361 } else if (!strcmp((const char *) node
->name
,
1362 config_element_max_size
)) {
1363 xmlChar
*content
= xmlNodeGetContent(node
);
1367 ret
= -LTTNG_ERR_NOMEM
;
1368 goto error_snapshot_output
;
1370 ret
= parse_uint(content
, &max_size
);
1373 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1374 goto error_snapshot_output
;
1377 /* consumer_output */
1378 ret
= process_consumer_output(node
, &output
);
1380 goto error_snapshot_output
;
1385 control_uri
= output
.control_uri
;
1386 data_uri
= output
.data_uri
;
1390 if (overrides
->path_url
) {
1391 path
= overrides
->path_url
;
1392 /* Control/data_uri are null */
1396 if (overrides
->ctrl_url
) {
1397 control_uri
= overrides
->ctrl_url
;
1401 if (overrides
->data_url
) {
1402 data_uri
= overrides
->data_url
;
1409 snapshot_output
= lttng_snapshot_output_create();
1410 if (!snapshot_output
) {
1411 ret
= -LTTNG_ERR_NOMEM
;
1412 goto error_snapshot_output
;
1415 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1417 goto error_snapshot_output
;
1420 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1422 goto error_snapshot_output
;
1426 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1429 goto error_snapshot_output
;
1433 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1436 goto error_snapshot_output
;
1441 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1444 goto error_snapshot_output
;
1449 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1450 error_snapshot_output
:
1453 free(output
.control_uri
);
1454 free(output
.data_uri
);
1455 lttng_snapshot_output_destroy(snapshot_output
);
1465 int create_session(const char *name
,
1466 xmlNodePtr output_node
,
1467 uint64_t live_timer_interval
,
1468 const struct config_load_session_override_attr
*overrides
)
1471 struct consumer_output output
= { 0 };
1472 xmlNodePtr consumer_output_node
;
1473 const char *control_uri
= NULL
;
1474 const char *data_uri
= NULL
;
1475 const char *path
= NULL
;
1480 consumer_output_node
= xmlFirstElementChild(output_node
);
1481 if (!consumer_output_node
) {
1482 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1486 if (strcmp((const char *) consumer_output_node
->name
,
1487 config_element_consumer_output
)) {
1488 WARN("Invalid output type, expected %s node",
1489 config_element_consumer_output
);
1490 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1494 ret
= process_consumer_output(consumer_output_node
, &output
);
1500 control_uri
= output
.control_uri
;
1501 data_uri
= output
.data_uri
;
1504 /* Check for override and apply them */
1506 if (overrides
->path_url
) {
1507 path
= overrides
->path_url
;
1508 /* control/data_uri are null */;
1512 if (overrides
->ctrl_url
) {
1513 control_uri
= overrides
->ctrl_url
;
1517 if (overrides
->data_url
) {
1518 data_uri
= overrides
->data_url
;
1526 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1527 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1531 if (control_uri
|| data_uri
) {
1532 /* network destination */
1533 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1535 * URLs are provided for sure since the test above make sure that
1536 * with a live timer the data and control URIs are provided. So,
1537 * NULL is passed here and will be set right after.
1539 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1541 ret
= lttng_create_session(name
, NULL
);
1547 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1553 /* either local output or no output */
1554 ret
= lttng_create_session(name
, path
);
1561 free(output
.control_uri
);
1562 free(output
.data_uri
);
1567 struct lttng_userspace_probe_location
*
1568 process_userspace_probe_function_attribute_node(
1569 xmlNodePtr attribute_node
)
1571 xmlNodePtr function_attribute_node
;
1572 char *function_name
= NULL
, *binary_path
= NULL
;
1573 struct lttng_userspace_probe_location
*location
= NULL
;
1574 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1577 * Process userspace probe location function attributes. The order of
1578 * the fields are not guaranteed so we need to iterate over all fields
1579 * and check at the end if everything we need for this location type is
1582 for (function_attribute_node
=
1583 xmlFirstElementChild(attribute_node
);
1584 function_attribute_node
;
1585 function_attribute_node
= xmlNextElementSibling(
1586 function_attribute_node
)) {
1587 /* Handle function name, binary path and lookup method. */
1588 if (!strcmp((const char *) function_attribute_node
->name
,
1589 config_element_userspace_probe_function_location_function_name
)) {
1590 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1591 if (!function_name
) {
1594 } else if (!strcmp((const char *) function_attribute_node
->name
,
1595 config_element_userspace_probe_location_binary_path
)) {
1596 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1600 } else if (!strcmp((const char *) function_attribute_node
->name
,
1601 config_element_userspace_probe_lookup
)) {
1602 char *lookup_method_name
;
1604 lookup_method_name
= (char *) xmlNodeGetContent(
1605 function_attribute_node
);
1606 if (!lookup_method_name
) {
1611 * function_default lookup method defaults to
1612 * function_elf lookup method at the moment.
1614 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1615 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1616 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1617 if (!lookup_method
) {
1618 PERROR("Error creating function default/ELF lookup method");
1621 WARN("Unknown function lookup method");
1624 free(lookup_method_name
);
1625 if (!lookup_method
) {
1632 /* Check if all the necessary fields were found. */
1633 if (binary_path
&& function_name
&& lookup_method
) {
1634 /* Ownership of lookup_method is transferred. */
1636 lttng_userspace_probe_location_function_create(
1637 binary_path
, function_name
,
1639 lookup_method
= NULL
;
1644 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1646 free(function_name
);
1651 struct lttng_userspace_probe_location
*
1652 process_userspace_probe_tracepoint_attribute_node(
1653 xmlNodePtr attribute_node
)
1655 xmlNodePtr tracepoint_attribute_node
;
1656 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1657 struct lttng_userspace_probe_location
*location
= NULL
;
1658 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1661 * Process userspace probe location tracepoint attributes. The order of
1662 * the fields are not guaranteed so we need to iterate over all fields
1663 * and check at the end if everything we need for this location type is
1666 for (tracepoint_attribute_node
=
1667 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1668 tracepoint_attribute_node
= xmlNextElementSibling(
1669 tracepoint_attribute_node
)) {
1670 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1671 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1672 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1676 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1677 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1678 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1679 if (!provider_name
) {
1682 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1683 config_element_userspace_probe_location_binary_path
)) {
1684 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1688 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1689 config_element_userspace_probe_lookup
)) {
1690 char *lookup_method_name
;
1692 lookup_method_name
= (char *) xmlNodeGetContent(
1693 tracepoint_attribute_node
);
1694 if (!lookup_method_name
) {
1698 if (!strcmp(lookup_method_name
,
1699 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1701 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1702 if (!lookup_method
) {
1703 PERROR("Error creating tracepoint SDT lookup method");
1706 WARN("Unknown tracepoint lookup method");
1709 free(lookup_method_name
);
1710 if (!lookup_method
) {
1714 WARN("Unknown tracepoint attribute");
1718 /* Check if all the necessary fields were found. */
1719 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1720 /* Ownership of lookup_method is transferred. */
1722 lttng_userspace_probe_location_tracepoint_create(
1723 binary_path
, provider_name
,
1724 probe_name
, lookup_method
);
1725 lookup_method
= NULL
;
1730 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1732 free(provider_name
);
1738 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1739 struct lttng_event_probe_attr
*attr
)
1743 assert(probe_attribute_node
);
1746 if (!strcmp((const char *) probe_attribute_node
->name
,
1747 config_element_address
)) {
1752 content
= xmlNodeGetContent(probe_attribute_node
);
1754 ret
= -LTTNG_ERR_NOMEM
;
1758 ret
= parse_uint(content
, &addr
);
1761 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1766 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1767 config_element_offset
)) {
1769 uint64_t offset
= 0;
1772 content
= xmlNodeGetContent(probe_attribute_node
);
1774 ret
= -LTTNG_ERR_NOMEM
;
1778 ret
= parse_uint(content
, &offset
);
1781 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1785 attr
->offset
= offset
;
1786 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1787 config_element_symbol_name
)) {
1791 content
= xmlNodeGetContent(probe_attribute_node
);
1793 ret
= -LTTNG_ERR_NOMEM
;
1797 ret
= lttng_strncpy(attr
->symbol_name
,
1798 (const char *) content
,
1799 LTTNG_SYMBOL_NAME_LEN
);
1801 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1802 (const char *) content
,
1803 strlen((const char *) content
),
1804 LTTNG_SYMBOL_NAME_LEN
);
1805 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1817 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1818 const char *channel_name
, const enum process_event_node_phase phase
)
1822 struct lttng_event
*event
;
1823 char **exclusions
= NULL
;
1824 unsigned long exclusion_count
= 0;
1825 char *filter_expression
= NULL
;
1829 assert(channel_name
);
1831 event
= lttng_event_create();
1833 ret
= -LTTNG_ERR_NOMEM
;
1837 /* Initialize default log level which varies by domain */
1838 switch (handle
->domain
.type
)
1840 case LTTNG_DOMAIN_JUL
:
1841 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1843 case LTTNG_DOMAIN_LOG4J
:
1844 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1846 case LTTNG_DOMAIN_PYTHON
:
1847 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1849 case LTTNG_DOMAIN_UST
:
1850 case LTTNG_DOMAIN_KERNEL
:
1851 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1857 for (node
= xmlFirstElementChild(event_node
); node
;
1858 node
= xmlNextElementSibling(node
)) {
1859 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1863 content
= xmlNodeGetContent(node
);
1865 ret
= -LTTNG_ERR_NOMEM
;
1869 ret
= lttng_strncpy(event
->name
,
1870 (const char *) content
,
1871 LTTNG_SYMBOL_NAME_LEN
);
1873 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1874 (const char *) content
,
1875 strlen((const char *) content
),
1876 LTTNG_SYMBOL_NAME_LEN
);
1877 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1882 } else if (!strcmp((const char *) node
->name
,
1883 config_element_enabled
)) {
1884 xmlChar
*content
= xmlNodeGetContent(node
);
1888 ret
= -LTTNG_ERR_NOMEM
;
1892 ret
= parse_bool(content
, &event
->enabled
);
1895 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1898 } else if (!strcmp((const char *) node
->name
,
1899 config_element_type
)) {
1900 xmlChar
*content
= xmlNodeGetContent(node
);
1904 ret
= -LTTNG_ERR_NOMEM
;
1908 ret
= get_event_type(content
);
1911 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1916 } else if (!strcmp((const char *) node
->name
,
1917 config_element_loglevel_type
)) {
1918 xmlChar
*content
= xmlNodeGetContent(node
);
1922 ret
= -LTTNG_ERR_NOMEM
;
1926 ret
= get_loglevel_type(content
);
1929 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1933 event
->loglevel_type
= ret
;
1934 } else if (!strcmp((const char *) node
->name
,
1935 config_element_loglevel
)) {
1937 int64_t loglevel
= 0;
1940 content
= xmlNodeGetContent(node
);
1942 ret
= -LTTNG_ERR_NOMEM
;
1946 ret
= parse_int(content
, &loglevel
);
1949 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1953 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1954 WARN("loglevel out of range.");
1955 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1959 event
->loglevel
= loglevel
;
1960 } else if (!strcmp((const char *) node
->name
,
1961 config_element_filter
)) {
1963 xmlNodeGetContent(node
);
1967 ret
= -LTTNG_ERR_NOMEM
;
1971 free(filter_expression
);
1972 filter_expression
= strdup((char *) content
);
1974 if (!filter_expression
) {
1975 ret
= -LTTNG_ERR_NOMEM
;
1978 } else if (!strcmp((const char *) node
->name
,
1979 config_element_exclusions
)) {
1980 xmlNodePtr exclusion_node
;
1981 int exclusion_index
= 0;
1986 * Exclusions has already been initialized,
1989 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1993 exclusion_count
= xmlChildElementCount(node
);
1994 if (!exclusion_count
) {
1998 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2000 exclusion_count
= 0;
2001 ret
= -LTTNG_ERR_NOMEM
;
2005 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2006 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2008 xmlNodeGetContent(exclusion_node
);
2011 ret
= -LTTNG_ERR_NOMEM
;
2015 exclusions
[exclusion_index
] = strdup((const char *) content
);
2017 if (!exclusions
[exclusion_index
]) {
2018 ret
= -LTTNG_ERR_NOMEM
;
2024 event
->exclusion
= 1;
2025 } else if (!strcmp((const char *) node
->name
,
2026 config_element_attributes
)) {
2027 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2030 if (!attribute_node
) {
2031 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2035 if (!strcmp((const char *) attribute_node
->name
,
2036 config_element_probe_attributes
)) {
2037 xmlNodePtr probe_attribute_node
;
2039 /* probe_attributes */
2040 for (probe_attribute_node
=
2041 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2042 probe_attribute_node
= xmlNextElementSibling(
2043 probe_attribute_node
)) {
2045 ret
= process_probe_attribute_node(probe_attribute_node
,
2046 &event
->attr
.probe
);
2051 } else if (!strcmp((const char *) attribute_node
->name
,
2052 config_element_function_attributes
)) {
2055 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2057 /* function_attributes */
2058 content
= xmlNodeGetContent(symbol_node
);
2060 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2064 sym_len
= strlen((char *) content
);
2065 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2066 WARN("Function name too long.");
2067 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2072 ret
= lttng_strncpy(
2073 event
->attr
.ftrace
.symbol_name
,
2074 (char *) content
, sym_len
);
2076 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2081 } else if (!strcmp((const char *) attribute_node
->name
,
2082 config_element_userspace_probe_tracepoint_attributes
)) {
2083 struct lttng_userspace_probe_location
*location
;
2085 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2087 WARN("Error processing userspace probe tracepoint attribute");
2088 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2091 ret
= lttng_event_set_userspace_probe_location(
2094 WARN("Error setting userspace probe location field");
2095 lttng_userspace_probe_location_destroy(
2097 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2100 } else if (!strcmp((const char *) attribute_node
->name
,
2101 config_element_userspace_probe_function_attributes
)) {
2102 struct lttng_userspace_probe_location
*location
;
2105 process_userspace_probe_function_attribute_node(
2108 WARN("Error processing userspace probe function attribute");
2109 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2113 ret
= lttng_event_set_userspace_probe_location(
2116 WARN("Error setting userspace probe location field");
2117 lttng_userspace_probe_location_destroy(
2119 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2123 /* Unknown event attribute. */
2124 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2130 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2131 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2132 filter_expression
, exclusion_count
, exclusions
);
2134 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2135 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2141 for (i
= 0; i
< exclusion_count
; i
++) {
2142 free(exclusions
[i
]);
2145 lttng_event_destroy(event
);
2147 free(filter_expression
);
2152 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2153 const char *channel_name
)
2156 struct lttng_event event
;
2159 assert(events_node
);
2161 assert(channel_name
);
2163 for (node
= xmlFirstElementChild(events_node
); node
;
2164 node
= xmlNextElementSibling(node
)) {
2165 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2172 * Disable all events to enable only the necessary events.
2173 * Limitations regarding lttng_disable_events and tuple descriptor
2174 * force this approach.
2176 memset(&event
, 0, sizeof(event
));
2177 event
.loglevel
= -1;
2178 event
.type
= LTTNG_EVENT_ALL
;
2179 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2184 for (node
= xmlFirstElementChild(events_node
); node
;
2185 node
= xmlNextElementSibling(node
)) {
2186 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2197 int process_channel_attr_node(xmlNodePtr attr_node
,
2198 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2199 xmlNodePtr
*events_node
)
2205 assert(contexts_node
);
2206 assert(events_node
);
2208 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2212 content
= xmlNodeGetContent(attr_node
);
2214 ret
= -LTTNG_ERR_NOMEM
;
2218 ret
= lttng_strncpy(channel
->name
,
2219 (const char *) content
,
2220 LTTNG_SYMBOL_NAME_LEN
);
2222 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2223 (const char *) content
,
2224 strlen((const char *) content
),
2225 LTTNG_SYMBOL_NAME_LEN
);
2226 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2231 } else if (!strcmp((const char *) attr_node
->name
,
2232 config_element_enabled
)) {
2237 content
= xmlNodeGetContent(attr_node
);
2239 ret
= -LTTNG_ERR_NOMEM
;
2243 ret
= parse_bool(content
, &enabled
);
2246 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2250 channel
->enabled
= enabled
;
2251 } else if (!strcmp((const char *) attr_node
->name
,
2252 config_element_overwrite_mode
)) {
2255 /* overwrite_mode */
2256 content
= xmlNodeGetContent(attr_node
);
2258 ret
= -LTTNG_ERR_NOMEM
;
2262 ret
= get_overwrite_mode(content
);
2265 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2269 channel
->attr
.overwrite
= ret
;
2270 } else if (!strcmp((const char *) attr_node
->name
,
2271 config_element_subbuf_size
)) {
2274 /* subbuffer_size */
2275 content
= xmlNodeGetContent(attr_node
);
2277 ret
= -LTTNG_ERR_NOMEM
;
2281 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2284 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2287 } else if (!strcmp((const char *) attr_node
->name
,
2288 config_element_num_subbuf
)) {
2291 /* subbuffer_count */
2292 content
= xmlNodeGetContent(attr_node
);
2294 ret
= -LTTNG_ERR_NOMEM
;
2298 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2301 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2304 } else if (!strcmp((const char *) attr_node
->name
,
2305 config_element_switch_timer_interval
)) {
2307 uint64_t switch_timer_interval
= 0;
2309 /* switch_timer_interval */
2310 content
= xmlNodeGetContent(attr_node
);
2312 ret
= -LTTNG_ERR_NOMEM
;
2316 ret
= parse_uint(content
, &switch_timer_interval
);
2319 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2323 if (switch_timer_interval
> UINT_MAX
) {
2324 WARN("switch_timer_interval out of range.");
2325 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2329 channel
->attr
.switch_timer_interval
=
2330 switch_timer_interval
;
2331 } else if (!strcmp((const char *) attr_node
->name
,
2332 config_element_read_timer_interval
)) {
2334 uint64_t read_timer_interval
= 0;
2336 /* read_timer_interval */
2337 content
= xmlNodeGetContent(attr_node
);
2339 ret
= -LTTNG_ERR_NOMEM
;
2343 ret
= parse_uint(content
, &read_timer_interval
);
2346 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2350 if (read_timer_interval
> UINT_MAX
) {
2351 WARN("read_timer_interval out of range.");
2352 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2356 channel
->attr
.read_timer_interval
=
2357 read_timer_interval
;
2358 } else if (!strcmp((const char *) attr_node
->name
,
2359 config_element_output_type
)) {
2363 content
= xmlNodeGetContent(attr_node
);
2365 ret
= -LTTNG_ERR_NOMEM
;
2369 ret
= get_output_type(content
);
2372 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2376 channel
->attr
.output
= ret
;
2377 } else if (!strcmp((const char *) attr_node
->name
,
2378 config_element_tracefile_size
)) {
2381 /* tracefile_size */
2382 content
= xmlNodeGetContent(attr_node
);
2384 ret
= -LTTNG_ERR_NOMEM
;
2388 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2391 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2394 } else if (!strcmp((const char *) attr_node
->name
,
2395 config_element_tracefile_count
)) {
2398 /* tracefile_count */
2399 content
= xmlNodeGetContent(attr_node
);
2401 ret
= -LTTNG_ERR_NOMEM
;
2405 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2408 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2411 } else if (!strcmp((const char *) attr_node
->name
,
2412 config_element_live_timer_interval
)) {
2414 uint64_t live_timer_interval
= 0;
2416 /* live_timer_interval */
2417 content
= xmlNodeGetContent(attr_node
);
2419 ret
= -LTTNG_ERR_NOMEM
;
2423 ret
= parse_uint(content
, &live_timer_interval
);
2426 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2430 if (live_timer_interval
> UINT_MAX
) {
2431 WARN("live_timer_interval out of range.");
2432 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2436 channel
->attr
.live_timer_interval
=
2437 live_timer_interval
;
2438 } else if (!strcmp((const char *) attr_node
->name
,
2439 config_element_monitor_timer_interval
)) {
2441 uint64_t monitor_timer_interval
= 0;
2443 /* monitor_timer_interval */
2444 content
= xmlNodeGetContent(attr_node
);
2446 ret
= -LTTNG_ERR_NOMEM
;
2450 ret
= parse_uint(content
, &monitor_timer_interval
);
2453 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2457 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2458 monitor_timer_interval
);
2460 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2463 } else if (!strcmp((const char *) attr_node
->name
,
2464 config_element_blocking_timeout
)) {
2466 int64_t blocking_timeout
= 0;
2468 /* blocking_timeout */
2469 content
= xmlNodeGetContent(attr_node
);
2471 ret
= -LTTNG_ERR_NOMEM
;
2475 ret
= parse_int(content
, &blocking_timeout
);
2478 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2482 ret
= lttng_channel_set_blocking_timeout(channel
,
2485 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2488 } else if (!strcmp((const char *) attr_node
->name
,
2489 config_element_events
)) {
2491 *events_node
= attr_node
;
2494 *contexts_node
= attr_node
;
2502 int process_context_node(xmlNodePtr context_node
,
2503 struct lttng_handle
*handle
, const char *channel_name
)
2506 struct lttng_event_context context
;
2507 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2510 assert(channel_name
);
2512 if (!context_child_node
) {
2513 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2517 memset(&context
, 0, sizeof(context
));
2519 if (!strcmp((const char *) context_child_node
->name
,
2520 config_element_type
)) {
2522 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2525 ret
= -LTTNG_ERR_NOMEM
;
2529 ret
= get_context_type(content
);
2532 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2537 } else if (!strcmp((const char *) context_child_node
->name
,
2538 config_element_context_perf
)) {
2540 xmlNodePtr perf_attr_node
;
2542 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2543 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2544 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2545 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2546 perf_attr_node
; perf_attr_node
=
2547 xmlNextElementSibling(perf_attr_node
)) {
2548 if (!strcmp((const char *) perf_attr_node
->name
,
2549 config_element_type
)) {
2554 content
= xmlNodeGetContent(perf_attr_node
);
2556 ret
= -LTTNG_ERR_NOMEM
;
2560 ret
= parse_uint(content
, &type
);
2563 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2567 if (type
> UINT32_MAX
) {
2568 WARN("perf context type out of range.");
2569 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2573 context
.u
.perf_counter
.type
= type
;
2574 } else if (!strcmp((const char *) perf_attr_node
->name
,
2575 config_element_config
)) {
2577 uint64_t config
= 0;
2580 content
= xmlNodeGetContent(perf_attr_node
);
2582 ret
= -LTTNG_ERR_NOMEM
;
2586 ret
= parse_uint(content
, &config
);
2589 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2593 context
.u
.perf_counter
.config
= config
;
2594 } else if (!strcmp((const char *) perf_attr_node
->name
,
2595 config_element_name
)) {
2599 content
= xmlNodeGetContent(perf_attr_node
);
2601 ret
= -LTTNG_ERR_NOMEM
;
2605 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2606 (const char *) content
,
2607 LTTNG_SYMBOL_NAME_LEN
);
2609 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2610 (const char *) content
,
2611 strlen((const char *) content
),
2612 LTTNG_SYMBOL_NAME_LEN
);
2613 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2620 } else if (!strcmp((const char *) context_child_node
->name
,
2621 config_element_context_app
)) {
2622 /* application context */
2623 xmlNodePtr app_ctx_node
;
2625 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2626 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2627 app_ctx_node
; app_ctx_node
=
2628 xmlNextElementSibling(app_ctx_node
)) {
2630 char **target
= strcmp(
2631 (const char *) app_ctx_node
->name
,
2632 config_element_context_app_provider_name
) == 0 ?
2633 &context
.u
.app_ctx
.provider_name
:
2634 &context
.u
.app_ctx
.ctx_name
;
2636 content
= xmlNodeGetContent(app_ctx_node
);
2638 ret
= -LTTNG_ERR_NOMEM
;
2642 *target
= (char *) content
;
2645 /* Unrecognized context type */
2646 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2650 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2651 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2652 free(context
.u
.app_ctx
.provider_name
);
2653 free(context
.u
.app_ctx
.ctx_name
);
2660 int process_contexts_node(xmlNodePtr contexts_node
,
2661 struct lttng_handle
*handle
, const char *channel_name
)
2664 xmlNodePtr context_node
;
2666 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2667 context_node
= xmlNextElementSibling(context_node
)) {
2668 ret
= process_context_node(context_node
, handle
, channel_name
);
2677 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2678 const char **element_id_tracker
,
2679 const char **element_value_type
,
2680 const char **element_value
,
2681 const char **element_value_alias
,
2682 const char **element_name
)
2686 switch (process_attr
) {
2687 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2688 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2689 *element_value_type
= config_element_process_attr_pid_value
;
2690 *element_value
= config_element_process_attr_id
;
2691 *element_value_alias
= config_element_process_attr_id
;
2692 *element_name
= NULL
;
2694 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2695 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2696 *element_value_type
= config_element_process_attr_vpid_value
;
2697 *element_value
= config_element_process_attr_id
;
2698 *element_value_alias
= NULL
;
2699 *element_name
= NULL
;
2701 case LTTNG_PROCESS_ATTR_USER_ID
:
2702 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2703 *element_value_type
= config_element_process_attr_uid_value
;
2704 *element_value
= config_element_process_attr_id
;
2705 *element_value_alias
= NULL
;
2706 *element_name
= config_element_name
;
2708 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2709 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2710 *element_value_type
= config_element_process_attr_vuid_value
;
2711 *element_value
= config_element_process_attr_id
;
2712 *element_value_alias
= NULL
;
2713 *element_name
= config_element_name
;
2715 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2716 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2717 *element_value_type
= config_element_process_attr_gid_value
;
2718 *element_value
= config_element_process_attr_id
;
2719 *element_value_alias
= NULL
;
2720 *element_name
= config_element_name
;
2722 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2723 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2724 *element_value_type
= config_element_process_attr_vgid_value
;
2725 *element_value
= config_element_process_attr_id
;
2726 *element_value_alias
= NULL
;
2727 *element_name
= config_element_name
;
2730 ret
= LTTNG_ERR_INVALID
;
2735 static int process_legacy_pid_tracker_node(
2736 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2738 int ret
= 0, child_count
;
2739 xmlNodePtr targets_node
= NULL
;
2741 const char *element_id_tracker
;
2742 const char *element_target_id
;
2743 const char *element_id
;
2744 const char *element_id_alias
;
2745 const char *element_name
;
2746 enum lttng_error_code tracker_handle_ret_code
;
2747 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2748 enum lttng_process_attr_tracker_handle_status status
;
2749 const enum lttng_process_attr process_attr
=
2750 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2751 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2752 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2756 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2757 handle
->session_name
, handle
->domain
.type
,
2760 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2761 ret
= LTTNG_ERR_INVALID
;
2765 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2766 &element_target_id
, &element_id
, &element_id_alias
,
2772 /* Get the targets node */
2773 for (node
= xmlFirstElementChild(trackers_node
); node
;
2774 node
= xmlNextElementSibling(node
)) {
2775 if (!strcmp((const char *) node
->name
,
2776 config_element_tracker_targets_legacy
)) {
2777 targets_node
= node
;
2782 if (!targets_node
) {
2783 ret
= LTTNG_ERR_INVALID
;
2787 /* Go through all id target node */
2788 child_count
= xmlChildElementCount(targets_node
);
2789 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2791 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2792 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2793 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2794 ret
= LTTNG_ERR_UNK
;
2798 /* Add all tracked values. */
2799 for (node
= xmlFirstElementChild(targets_node
); node
;
2800 node
= xmlNextElementSibling(node
)) {
2801 xmlNodePtr pid_target_node
= node
;
2803 /* get pid_target node and track it */
2804 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2805 node
= xmlNextElementSibling(node
)) {
2806 if (!strcmp((const char *) node
->name
,
2807 config_element_tracker_pid_legacy
)) {
2809 xmlChar
*content
= xmlNodeGetContent(node
);
2812 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2816 ret
= parse_int(content
, &id
);
2819 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2823 switch (process_attr
) {
2824 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2825 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2829 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2830 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2835 ret
= LTTNG_ERR_INVALID
;
2840 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2842 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2843 ret
= LTTNG_ERR_INVALID
;
2845 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2846 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2848 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2849 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2851 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2852 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2854 ret
= LTTNG_ERR_UNK
;
2858 node
= pid_target_node
;
2862 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2866 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2867 struct lttng_handle
*handle
,
2868 enum lttng_process_attr process_attr
)
2870 int ret
= 0, child_count
;
2871 xmlNodePtr values_node
= NULL
;
2873 const char *element_id_tracker
;
2874 const char *element_target_id
;
2875 const char *element_id
;
2876 const char *element_id_alias
;
2877 const char *element_name
;
2878 enum lttng_error_code tracker_handle_ret_code
;
2879 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2880 enum lttng_process_attr_tracker_handle_status status
;
2883 assert(id_tracker_node
);
2885 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2886 handle
->session_name
, handle
->domain
.type
, process_attr
,
2888 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2889 ret
= LTTNG_ERR_INVALID
;
2893 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2894 &element_target_id
, &element_id
, &element_id_alias
,
2900 /* get the values node */
2901 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2902 node
= xmlNextElementSibling(node
)) {
2903 if (!strcmp((const char *) node
->name
,
2904 config_element_process_attr_values
)) {
2911 ret
= LTTNG_ERR_INVALID
;
2915 /* Go through all id target node */
2916 child_count
= xmlChildElementCount(values_node
);
2917 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2919 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2920 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2921 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2922 ret
= LTTNG_ERR_UNK
;
2926 /* Add all tracked values. */
2927 for (node
= xmlFirstElementChild(values_node
); node
;
2928 node
= xmlNextElementSibling(node
)) {
2929 xmlNodePtr id_target_node
= node
;
2931 /* get id node and track it */
2932 for (node
= xmlFirstElementChild(id_target_node
); node
;
2933 node
= xmlNextElementSibling(node
)) {
2934 if (!strcmp((const char *) node
->name
, element_id
) ||
2935 (element_id_alias
&&
2936 !strcmp((const char *) node
->name
,
2937 element_id_alias
))) {
2939 xmlChar
*content
= xmlNodeGetContent(node
);
2942 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2946 ret
= parse_int(content
, &id
);
2949 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2953 switch (process_attr
) {
2954 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2955 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2959 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2960 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2964 case LTTNG_PROCESS_ATTR_USER_ID
:
2965 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2969 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2970 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2974 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2975 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2979 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2980 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2985 ret
= LTTNG_ERR_INVALID
;
2988 } else if (element_name
&&
2989 !strcmp((const char *) node
->name
,
2991 xmlChar
*content
= xmlNodeGetContent(node
);
2994 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2998 switch (process_attr
) {
2999 case LTTNG_PROCESS_ATTR_USER_ID
:
3000 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3002 (const char *) content
);
3004 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3005 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3007 (const char *) content
);
3009 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3010 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3012 (const char *) content
);
3014 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3015 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3017 (const char *) content
);
3021 ret
= LTTNG_ERR_INVALID
;
3027 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3029 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3030 ret
= LTTNG_ERR_INVALID
;
3032 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3033 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3035 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3036 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3038 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3039 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3041 ret
= LTTNG_ERR_UNK
;
3045 node
= id_target_node
;
3049 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3054 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3057 struct lttng_domain domain
= { 0 };
3058 struct lttng_handle
*handle
= NULL
;
3059 struct lttng_channel
*channel
= NULL
;
3060 xmlNodePtr channels_node
= NULL
;
3061 xmlNodePtr trackers_node
= NULL
;
3062 xmlNodePtr pid_tracker_node
= NULL
;
3063 xmlNodePtr vpid_tracker_node
= NULL
;
3064 xmlNodePtr uid_tracker_node
= NULL
;
3065 xmlNodePtr vuid_tracker_node
= NULL
;
3066 xmlNodePtr gid_tracker_node
= NULL
;
3067 xmlNodePtr vgid_tracker_node
= NULL
;
3070 assert(session_name
);
3072 ret
= init_domain(domain_node
, &domain
);
3077 handle
= lttng_create_handle(session_name
, &domain
);
3079 ret
= -LTTNG_ERR_NOMEM
;
3083 /* get the channels node */
3084 for (node
= xmlFirstElementChild(domain_node
); node
;
3085 node
= xmlNextElementSibling(node
)) {
3086 if (!strcmp((const char *) node
->name
,
3087 config_element_channels
)) {
3088 channels_node
= node
;
3093 if (!channels_node
) {
3097 /* create all channels */
3098 for (node
= xmlFirstElementChild(channels_node
); node
;
3099 node
= xmlNextElementSibling(node
)) {
3100 const enum lttng_domain_type original_domain
= domain
.type
;
3101 xmlNodePtr contexts_node
= NULL
;
3102 xmlNodePtr events_node
= NULL
;
3103 xmlNodePtr channel_attr_node
;
3106 * Channels of the "agent" types cannot be created directly.
3107 * They are meant to be created implicitly through the
3108 * activation of events in their domain. However, a user
3109 * can override the default channel configuration attributes
3110 * by creating the underlying UST channel _before_ enabling
3111 * an agent domain event.
3113 * Hence, the channel's type is substituted before the creation
3114 * and restored by the time the events are created.
3116 switch (domain
.type
) {
3117 case LTTNG_DOMAIN_JUL
:
3118 case LTTNG_DOMAIN_LOG4J
:
3119 case LTTNG_DOMAIN_PYTHON
:
3120 domain
.type
= LTTNG_DOMAIN_UST
;
3125 channel
= lttng_channel_create(&domain
);
3131 for (channel_attr_node
= xmlFirstElementChild(node
);
3132 channel_attr_node
; channel_attr_node
=
3133 xmlNextElementSibling(channel_attr_node
)) {
3134 ret
= process_channel_attr_node(channel_attr_node
,
3135 channel
, &contexts_node
, &events_node
);
3141 ret
= lttng_enable_channel(handle
, channel
);
3146 /* Restore the original channel domain. */
3147 domain
.type
= original_domain
;
3149 ret
= process_events_node(events_node
, handle
, channel
->name
);
3154 ret
= process_contexts_node(contexts_node
, handle
,
3160 lttng_channel_destroy(channel
);
3164 /* get the trackers node */
3165 for (node
= xmlFirstElementChild(domain_node
); node
;
3166 node
= xmlNextElementSibling(node
)) {
3167 if (!strcmp((const char *) node
->name
,
3168 config_element_process_attr_trackers
) ||
3169 !strcmp((const char *) node
->name
,
3170 config_element_trackers_legacy
)) {
3171 if (trackers_node
) {
3172 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3173 config_element_process_attr_trackers
,
3174 config_element_trackers_legacy
);
3178 trackers_node
= node
;
3183 if (!trackers_node
) {
3187 for (node
= xmlFirstElementChild(trackers_node
); node
;
3188 node
= xmlNextElementSibling(node
)) {
3189 if (!strcmp((const char *) node
->name
,
3190 config_element_process_attr_tracker_pid
)) {
3191 pid_tracker_node
= node
;
3192 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3193 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3198 if (!strcmp((const char *) node
->name
,
3199 config_element_process_attr_tracker_vpid
)) {
3200 vpid_tracker_node
= node
;
3201 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3202 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3207 if (!strcmp((const char *) node
->name
,
3208 config_element_process_attr_tracker_uid
)) {
3209 uid_tracker_node
= node
;
3210 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3211 LTTNG_PROCESS_ATTR_USER_ID
);
3216 if (!strcmp((const char *) node
->name
,
3217 config_element_process_attr_tracker_vuid
)) {
3218 vuid_tracker_node
= node
;
3219 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3220 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3225 if (!strcmp((const char *) node
->name
,
3226 config_element_process_attr_tracker_gid
)) {
3227 gid_tracker_node
= node
;
3228 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3229 LTTNG_PROCESS_ATTR_GROUP_ID
);
3234 if (!strcmp((const char *) node
->name
,
3235 config_element_process_attr_tracker_vgid
)) {
3236 vgid_tracker_node
= node
;
3237 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3238 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3243 if (!strcmp((const char *) node
->name
,
3244 config_element_pid_tracker_legacy
)) {
3245 ret
= process_legacy_pid_tracker_node(node
, handle
);
3253 lttng_channel_destroy(channel
);
3254 lttng_destroy_handle(handle
);
3259 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3262 enum lttng_rotation_status status
;
3263 struct lttng_rotation_schedule
*periodic
=
3264 lttng_rotation_schedule_periodic_create();
3267 ret
= -LTTNG_ERR_NOMEM
;
3271 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3273 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3274 ret
= -LTTNG_ERR_INVALID
;
3278 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3280 case LTTNG_ROTATION_STATUS_OK
:
3283 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3284 case LTTNG_ROTATION_STATUS_INVALID
:
3285 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3288 ret
= -LTTNG_ERR_UNK
;
3292 lttng_rotation_schedule_destroy(periodic
);
3297 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3300 enum lttng_rotation_status status
;
3301 struct lttng_rotation_schedule
*size
=
3302 lttng_rotation_schedule_size_threshold_create();
3305 ret
= -LTTNG_ERR_NOMEM
;
3309 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3311 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3312 ret
= -LTTNG_ERR_INVALID
;
3316 status
= lttng_session_add_rotation_schedule(name
, size
);
3318 case LTTNG_ROTATION_STATUS_OK
:
3321 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3322 case LTTNG_ROTATION_STATUS_INVALID
:
3323 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3326 ret
= -LTTNG_ERR_UNK
;
3330 lttng_rotation_schedule_destroy(size
);
3335 int process_session_rotation_schedules_node(
3336 xmlNodePtr schedules_node
,
3337 uint64_t *rotation_timer_interval
,
3338 uint64_t *rotation_size
)
3343 for (child
= xmlFirstElementChild(schedules_node
);
3345 child
= xmlNextElementSibling(child
)) {
3346 if (!strcmp((const char *) child
->name
,
3347 config_element_rotation_schedule_periodic
)) {
3349 xmlNodePtr time_us_node
;
3351 /* periodic rotation schedule */
3352 time_us_node
= xmlFirstElementChild(child
);
3353 if (!time_us_node
||
3354 strcmp((const char *) time_us_node
->name
,
3355 config_element_rotation_schedule_periodic_time_us
)) {
3356 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3361 content
= xmlNodeGetContent(time_us_node
);
3363 ret
= -LTTNG_ERR_NOMEM
;
3366 ret
= parse_uint(content
, rotation_timer_interval
);
3369 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3372 } else if (!strcmp((const char *) child
->name
,
3373 config_element_rotation_schedule_size_threshold
)) {
3375 xmlNodePtr bytes_node
;
3377 /* size_threshold rotation schedule */
3378 bytes_node
= xmlFirstElementChild(child
);
3380 strcmp((const char *) bytes_node
->name
,
3381 config_element_rotation_schedule_size_threshold_bytes
)) {
3382 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3387 content
= xmlNodeGetContent(bytes_node
);
3389 ret
= -LTTNG_ERR_NOMEM
;
3392 ret
= parse_uint(content
, rotation_size
);
3395 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3406 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3408 const struct config_load_session_override_attr
*overrides
)
3410 int ret
, started
= -1, snapshot_mode
= -1;
3411 uint64_t live_timer_interval
= UINT64_MAX
,
3412 rotation_timer_interval
= 0,
3414 xmlChar
*name
= NULL
;
3415 xmlChar
*shm_path
= NULL
;
3416 xmlNodePtr domains_node
= NULL
;
3417 xmlNodePtr output_node
= NULL
;
3419 xmlNodePtr attributes_child
;
3420 struct lttng_domain
*kernel_domain
= NULL
;
3421 struct lttng_domain
*ust_domain
= NULL
;
3422 struct lttng_domain
*jul_domain
= NULL
;
3423 struct lttng_domain
*log4j_domain
= NULL
;
3424 struct lttng_domain
*python_domain
= NULL
;
3426 for (node
= xmlFirstElementChild(session_node
); node
;
3427 node
= xmlNextElementSibling(node
)) {
3428 if (!name
&& !strcmp((const char *) node
->name
,
3429 config_element_name
)) {
3431 xmlChar
*node_content
= xmlNodeGetContent(node
);
3432 if (!node_content
) {
3433 ret
= -LTTNG_ERR_NOMEM
;
3437 name
= node_content
;
3438 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3439 config_element_domains
)) {
3441 domains_node
= node
;
3442 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3443 config_element_started
)) {
3445 xmlChar
*node_content
= xmlNodeGetContent(node
);
3446 if (!node_content
) {
3447 ret
= -LTTNG_ERR_NOMEM
;
3451 ret
= parse_bool(node_content
, &started
);
3454 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3457 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3458 config_element_output
)) {
3461 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3462 config_element_shared_memory_path
)) {
3463 /* shared memory path */
3464 xmlChar
*node_content
= xmlNodeGetContent(node
);
3465 if (!node_content
) {
3466 ret
= -LTTNG_ERR_NOMEM
;
3470 shm_path
= node_content
;
3473 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3474 * rotation_timer_interval.
3476 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3477 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3478 if (!strcmp((const char *) attributes_child
->name
,
3479 config_element_snapshot_mode
)) {
3481 xmlChar
*snapshot_mode_content
=
3482 xmlNodeGetContent(attributes_child
);
3483 if (!snapshot_mode_content
) {
3484 ret
= -LTTNG_ERR_NOMEM
;
3488 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3489 free(snapshot_mode_content
);
3491 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3494 } else if (!strcmp((const char *) attributes_child
->name
,
3495 config_element_live_timer_interval
)) {
3496 /* live_timer_interval */
3497 xmlChar
*timer_interval_content
=
3498 xmlNodeGetContent(attributes_child
);
3499 if (!timer_interval_content
) {
3500 ret
= -LTTNG_ERR_NOMEM
;
3504 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3505 free(timer_interval_content
);
3507 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3510 } else if (!strcmp((const char *) attributes_child
->name
,
3511 config_element_rotation_schedules
)) {
3512 ret
= process_session_rotation_schedules_node(
3514 &rotation_timer_interval
,
3517 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3527 /* Mandatory attribute, as defined in the session XSD */
3528 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3532 if (session_name
&& strcmp((char *) name
, session_name
)) {
3533 /* This is not the session we are looking for */
3534 ret
= -LTTNG_ERR_NO_SESSION
;
3538 /* Init domains to create the session handles */
3539 for (node
= xmlFirstElementChild(domains_node
); node
;
3540 node
= xmlNextElementSibling(node
)) {
3541 struct lttng_domain
*domain
;
3543 domain
= zmalloc(sizeof(*domain
));
3545 ret
= -LTTNG_ERR_NOMEM
;
3549 ret
= init_domain(node
, domain
);
3551 goto domain_init_error
;
3554 switch (domain
->type
) {
3555 case LTTNG_DOMAIN_KERNEL
:
3556 if (kernel_domain
) {
3557 /* Same domain seen twice, invalid! */
3558 goto domain_init_error
;
3560 kernel_domain
= domain
;
3562 case LTTNG_DOMAIN_UST
:
3564 /* Same domain seen twice, invalid! */
3565 goto domain_init_error
;
3567 ust_domain
= domain
;
3569 case LTTNG_DOMAIN_JUL
:
3571 /* Same domain seen twice, invalid! */
3572 goto domain_init_error
;
3574 jul_domain
= domain
;
3576 case LTTNG_DOMAIN_LOG4J
:
3578 /* Same domain seen twice, invalid! */
3579 goto domain_init_error
;
3581 log4j_domain
= domain
;
3583 case LTTNG_DOMAIN_PYTHON
:
3584 if (python_domain
) {
3585 /* Same domain seen twice, invalid! */
3586 goto domain_init_error
;
3588 python_domain
= domain
;
3591 WARN("Invalid domain type");
3592 goto domain_init_error
;
3597 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3601 /* Apply overrides */
3603 if (overrides
->session_name
) {
3604 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3605 if (!name_override
) {
3606 ret
= -LTTNG_ERR_NOMEM
;
3610 /* Overrides the session name to the provided name */
3612 name
= name_override
;
3617 /* Destroy session if it exists */
3618 ret
= lttng_destroy_session((const char *) name
);
3619 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3620 ERR("Failed to destroy existing session.");
3625 /* Create session type depending on output type */
3626 if (snapshot_mode
&& snapshot_mode
!= -1) {
3627 ret
= create_snapshot_session((const char *) name
, output_node
,
3629 } else if (live_timer_interval
&&
3630 live_timer_interval
!= UINT64_MAX
) {
3631 ret
= create_session((const char *) name
,
3632 output_node
, live_timer_interval
, overrides
);
3634 /* regular session */
3635 ret
= create_session((const char *) name
,
3636 output_node
, UINT64_MAX
, overrides
);
3643 ret
= lttng_set_session_shm_path((const char *) name
,
3644 (const char *) shm_path
);
3650 for (node
= xmlFirstElementChild(domains_node
); node
;
3651 node
= xmlNextElementSibling(node
)) {
3652 ret
= process_domain_node(node
, (const char *) name
);
3658 if (rotation_timer_interval
) {
3659 ret
= add_periodic_rotation((const char *) name
,
3660 rotation_timer_interval
);
3665 if (rotation_size
) {
3666 ret
= add_size_rotation((const char *) name
,
3674 ret
= lttng_start_tracing((const char *) name
);
3682 ERR("Failed to load session %s: %s", (const char *) name
,
3683 lttng_strerror(ret
));
3684 lttng_destroy_session((const char *) name
);
3688 free(kernel_domain
);
3692 free(python_domain
);
3699 * Return 1 if the given path is readable by the current UID or 0 if not.
3700 * Return -1 if the path is EPERM.
3702 static int validate_file_read_creds(const char *path
)
3708 /* Can we read the file. */
3709 ret
= access(path
, R_OK
);
3713 if (errno
== EACCES
) {
3724 int load_session_from_file(const char *path
, const char *session_name
,
3725 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3726 const struct config_load_session_override_attr
*overrides
)
3728 int ret
, session_found
= !session_name
;
3729 xmlDocPtr doc
= NULL
;
3730 xmlNodePtr sessions_node
;
3731 xmlNodePtr session_node
;
3734 assert(validation_ctx
);
3736 ret
= validate_file_read_creds(path
);
3739 ret
= -LTTNG_ERR_EPERM
;
3741 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3746 doc
= xmlParseFile(path
);
3748 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3752 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3754 ERR("Session configuration file validation failed");
3755 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3759 sessions_node
= xmlDocGetRootElement(doc
);
3760 if (!sessions_node
) {
3761 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3765 for (session_node
= xmlFirstElementChild(sessions_node
);
3766 session_node
; session_node
=
3767 xmlNextElementSibling(session_node
)) {
3768 ret
= process_session_node(session_node
,
3769 session_name
, overwrite
, overrides
);
3770 if (!session_name
&& ret
) {
3771 /* Loading error occurred. */
3773 } else if (session_name
) {
3775 /* Target session found and loaded */
3778 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3780 * Ignore this error, we are looking for a
3785 /* Loading error occurred. */
3793 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3799 int load_session_from_path(const char *path
, const char *session_name
,
3800 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3801 const struct config_load_session_override_attr
*overrides
)
3803 int ret
, session_found
= !session_name
;
3804 DIR *directory
= NULL
;
3805 struct lttng_dynamic_buffer file_path
;
3809 assert(validation_ctx
);
3810 path_len
= strlen(path
);
3811 lttng_dynamic_buffer_init(&file_path
);
3812 if (path_len
>= LTTNG_PATH_MAX
) {
3813 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3814 path
, path_len
, LTTNG_PATH_MAX
);
3815 ret
= -LTTNG_ERR_INVALID
;
3819 directory
= opendir(path
);
3823 /* Try the file loading. */
3826 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3829 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3834 size_t file_path_root_len
;
3836 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3839 ret
= -LTTNG_ERR_NOMEM
;
3843 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3845 ret
= -LTTNG_ERR_NOMEM
;
3849 if (file_path
.data
[file_path
.size
- 1] != '/') {
3850 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3852 ret
= -LTTNG_ERR_NOMEM
;
3856 file_path_root_len
= file_path
.size
;
3858 /* Search for *.lttng files */
3860 size_t file_name_len
;
3861 struct dirent
*result
;
3864 * When the end of the directory stream is reached, NULL
3865 * is returned and errno is kept unchanged. When an
3866 * error occurs, NULL is returned and errno is set
3867 * accordingly. To distinguish between the two, set
3868 * errno to zero before calling readdir().
3870 * On success, readdir() returns a pointer to a dirent
3871 * structure. This structure may be statically
3872 * allocated, do not attempt to free(3) it.
3875 result
= readdir(directory
);
3877 /* Reached end of dir stream or error out. */
3880 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3881 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3887 file_name_len
= strlen(result
->d_name
);
3889 if (file_name_len
<=
3890 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3894 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3895 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3897 /* +1 to account for NULL terminator. */
3898 file_path
.size
+ file_name_len
+ 1,
3903 /* Does the file end with .lttng? */
3904 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3905 result
->d_name
+ file_name_len
- sizeof(
3906 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3910 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3913 ret
= -LTTNG_ERR_NOMEM
;
3917 ret
= load_session_from_file(file_path
.data
, session_name
,
3918 validation_ctx
, overwrite
, overrides
);
3920 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3924 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3928 * Reset the buffer's size to the location of the
3929 * path's trailing '/'.
3931 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3932 file_path_root_len
);
3934 ret
= -LTTNG_ERR_UNK
;
3939 ret
= load_session_from_file(path
, session_name
,
3940 validation_ctx
, overwrite
, overrides
);
3950 if (closedir(directory
)) {
3954 if (!ret
&& !session_found
) {
3955 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3957 lttng_dynamic_buffer_reset(&file_path
);
3962 * Validate that the given path's credentials and the current process have the
3963 * same UID. If so, return 1 else return 0 if it does NOT match.
3965 static int validate_path_creds(const char *path
)
3967 int ret
, uid
= getuid();
3976 ret
= stat(path
, &buf
);
3978 if (errno
!= ENOENT
) {
3984 if (buf
.st_uid
!= uid
) {
3995 int config_load_session(const char *path
, const char *session_name
,
3996 int overwrite
, unsigned int autoload
,
3997 const struct config_load_session_override_attr
*overrides
)
4000 bool session_loaded
= false;
4001 const char *path_ptr
= NULL
;
4002 struct session_config_validation_ctx validation_ctx
= { 0 };
4004 ret
= init_session_config_validation_ctx(&validation_ctx
);
4010 const char *home_path
;
4011 const char *sys_path
;
4014 home_path
= utils_get_home_dir();
4016 char path
[PATH_MAX
];
4019 * Try user session configuration path. Ignore error here so we can
4020 * continue loading the system wide sessions.
4023 ret
= snprintf(path
, sizeof(path
),
4024 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
4025 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
4027 PERROR("snprintf session autoload home config path");
4028 ret
= -LTTNG_ERR_INVALID
;
4033 * Credentials are only validated for the autoload in order to
4034 * avoid any user session daemon to try to load kernel sessions
4035 * automatically and failing all the times.
4037 ret
= validate_path_creds(path
);
4042 ret
= snprintf(path
, sizeof(path
),
4043 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
4045 PERROR("snprintf session home config path");
4046 ret
= -LTTNG_ERR_INVALID
;
4052 ret
= load_session_from_path(path_ptr
, session_name
,
4053 &validation_ctx
, overwrite
, overrides
);
4054 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4058 * Continue even if the session was found since we have to try
4059 * the system wide sessions.
4061 session_loaded
= true;
4065 /* Reset path pointer for the system wide dir. */
4068 /* Try system wide configuration directory. */
4070 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4071 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4072 ret
= validate_path_creds(sys_path
);
4074 path_ptr
= sys_path
;
4077 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4078 path_ptr
= sys_path
;
4082 ret
= load_session_from_path(path_ptr
, session_name
,
4083 &validation_ctx
, overwrite
, overrides
);
4085 session_loaded
= true;
4091 ret
= access(path
, F_OK
);
4096 ret
= -LTTNG_ERR_INVALID
;
4097 WARN("Session configuration path does not exist.");
4100 ret
= -LTTNG_ERR_EPERM
;
4103 ret
= -LTTNG_ERR_UNK
;
4109 ret
= load_session_from_path(path
, session_name
,
4110 &validation_ctx
, overwrite
, overrides
);
4113 fini_session_config_validation_ctx(&validation_ctx
);
4114 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4116 * Don't report an error if no sessions are found when called
4117 * without a session_name or a search path.
4122 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4123 /* A matching session was found in one of the search paths. */
4130 void __attribute__((destructor
)) session_config_exit(void)