2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "lttng/tracker.h"
18 #include <sys/types.h>
22 #include <common/defaults.h>
23 #include <common/error.h>
24 #include <common/macros.h>
25 #include <common/utils.h>
26 #include <common/dynamic-buffer.h>
27 #include <common/compat/getenv.h>
28 #include <lttng/lttng-error.h>
29 #include <libxml/parser.h>
30 #include <libxml/valid.h>
31 #include <libxml/xmlschemas.h>
32 #include <libxml/tree.h>
33 #include <lttng/lttng.h>
34 #include <lttng/snapshot.h>
35 #include <lttng/rotation.h>
36 #include <lttng/userspace-probe.h>
38 #include "session-config.h"
39 #include "config-internal.h"
41 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
43 struct handler_filter_args
{
45 config_entry_handler_cb handler
;
49 struct session_config_validation_ctx
{
50 xmlSchemaParserCtxtPtr parser_ctx
;
52 xmlSchemaValidCtxtPtr schema_validation_ctx
;
55 LTTNG_HIDDEN
const char * const config_element_all
= "all";
56 const char * const config_str_yes
= "yes";
57 const char * const config_str_true
= "true";
58 const char * const config_str_on
= "on";
59 const char * const config_str_no
= "no";
60 const char * const config_str_false
= "false";
61 const char * const config_str_off
= "off";
62 const char * const config_xml_encoding
= "UTF-8";
63 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
64 const char * const config_xml_indent_string
= "\t";
65 const char * const config_xml_true
= "true";
66 const char * const config_xml_false
= "false";
68 const char * const config_element_channel
= "channel";
69 const char * const config_element_channels
= "channels";
70 const char * const config_element_domain
= "domain";
71 const char * const config_element_domains
= "domains";
72 const char * const config_element_event
= "event";
73 const char * const config_element_events
= "events";
74 const char * const config_element_context
= "context";
75 const char * const config_element_contexts
= "contexts";
76 const char * const config_element_attributes
= "attributes";
77 const char * const config_element_exclusion
= "exclusion";
78 const char * const config_element_exclusions
= "exclusions";
79 const char * const config_element_function_attributes
= "function_attributes";
80 const char * const config_element_probe_attributes
= "probe_attributes";
81 const char * const config_element_symbol_name
= "symbol_name";
82 const char * const config_element_address
= "address";
83 const char * const config_element_offset
= "offset";
85 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
86 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
87 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
88 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
89 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
90 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
91 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
92 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
93 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
96 const char * const config_element_name
= "name";
97 const char * const config_element_enabled
= "enabled";
98 const char * const config_element_overwrite_mode
= "overwrite_mode";
99 const char * const config_element_subbuf_size
= "subbuffer_size";
100 const char * const config_element_num_subbuf
= "subbuffer_count";
101 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
102 const char * const config_element_read_timer_interval
= "read_timer_interval";
103 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
104 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
105 const char * const config_element_output
= "output";
106 const char * const config_element_output_type
= "output_type";
107 const char * const config_element_tracefile_size
= "tracefile_size";
108 const char * const config_element_tracefile_count
= "tracefile_count";
109 const char * const config_element_live_timer_interval
= "live_timer_interval";
110 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
111 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
112 const char * const config_element_type
= "type";
113 const char * const config_element_buffer_type
= "buffer_type";
114 const char * const config_element_session
= "session";
115 const char * const config_element_sessions
= "sessions";
116 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
117 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
118 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
119 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
120 const char * const config_element_config
= "config";
121 const char * const config_element_started
= "started";
122 const char * const config_element_snapshot_mode
= "snapshot_mode";
123 const char * const config_element_loglevel
= "loglevel";
124 const char * const config_element_loglevel_type
= "loglevel_type";
125 const char * const config_element_filter
= "filter";
126 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
127 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
128 const char * const config_element_consumer_output
= "consumer_output";
129 const char * const config_element_destination
= "destination";
130 const char * const config_element_path
= "path";
131 const char * const config_element_net_output
= "net_output";
132 const char * const config_element_control_uri
= "control_uri";
133 const char * const config_element_data_uri
= "data_uri";
134 const char * const config_element_max_size
= "max_size";
135 const char * const config_element_pid
= "pid";
136 const char * const config_element_pids
= "pids";
137 const char * const config_element_shared_memory_path
= "shared_memory_path";
139 LTTNG_HIDDEN
const char * const config_element_process_attr_id
= "id";
140 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
141 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
142 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
143 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
144 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
145 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
146 LTTNG_HIDDEN
const char * const config_element_process_attr_trackers
= "process_attr_trackers";
147 LTTNG_HIDDEN
const char * const config_element_process_attr_values
= "process_attr_values";
148 LTTNG_HIDDEN
const char * const config_element_process_attr_value_type
= "process_attr_value_type";
149 LTTNG_HIDDEN
const char * const config_element_process_attr_pid_value
= "pid";
150 LTTNG_HIDDEN
const char * const config_element_process_attr_vpid_value
= "vpid";
151 LTTNG_HIDDEN
const char * const config_element_process_attr_uid_value
= "uid";
152 LTTNG_HIDDEN
const char * const config_element_process_attr_vuid_value
= "vuid";
153 LTTNG_HIDDEN
const char * const config_element_process_attr_gid_value
= "gid";
154 LTTNG_HIDDEN
const char * const config_element_process_attr_vgid_value
= "vgid";
155 LTTNG_HIDDEN
const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
157 /* Used for support of legacy tracker serialization (< 2.12). */
158 LTTNG_HIDDEN
const char * const config_element_trackers_legacy
= "trackers";
159 LTTNG_HIDDEN
const char * const config_element_pid_tracker_legacy
= "pid_tracker";
160 LTTNG_HIDDEN
const char * const config_element_tracker_targets_legacy
= "targets";
161 LTTNG_HIDDEN
const char * const config_element_tracker_pid_target_legacy
= "pid_target";
162 LTTNG_HIDDEN
const char * const config_element_tracker_pid_legacy
= "pid";
164 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
165 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
166 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
167 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
168 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
170 const char * const config_domain_type_kernel
= "KERNEL";
171 const char * const config_domain_type_ust
= "UST";
172 const char * const config_domain_type_jul
= "JUL";
173 const char * const config_domain_type_log4j
= "LOG4J";
174 const char * const config_domain_type_python
= "PYTHON";
176 const char * const config_buffer_type_per_pid
= "PER_PID";
177 const char * const config_buffer_type_per_uid
= "PER_UID";
178 const char * const config_buffer_type_global
= "GLOBAL";
180 const char * const config_overwrite_mode_discard
= "DISCARD";
181 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
183 const char * const config_output_type_splice
= "SPLICE";
184 const char * const config_output_type_mmap
= "MMAP";
186 const char * const config_loglevel_type_all
= "ALL";
187 const char * const config_loglevel_type_range
= "RANGE";
188 const char * const config_loglevel_type_single
= "SINGLE";
190 const char * const config_event_type_all
= "ALL";
191 const char * const config_event_type_tracepoint
= "TRACEPOINT";
192 const char * const config_event_type_probe
= "PROBE";
193 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
194 const char * const config_event_type_function
= "FUNCTION";
195 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
196 const char * const config_event_type_noop
= "NOOP";
197 const char * const config_event_type_syscall
= "SYSCALL";
198 const char * const config_event_type_kprobe
= "KPROBE";
199 const char * const config_event_type_kretprobe
= "KRETPROBE";
201 const char * const config_event_context_pid
= "PID";
202 const char * const config_event_context_procname
= "PROCNAME";
203 const char * const config_event_context_prio
= "PRIO";
204 const char * const config_event_context_nice
= "NICE";
205 const char * const config_event_context_vpid
= "VPID";
206 const char * const config_event_context_tid
= "TID";
207 const char * const config_event_context_vtid
= "VTID";
208 const char * const config_event_context_ppid
= "PPID";
209 const char * const config_event_context_vppid
= "VPPID";
210 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
211 const char * const config_event_context_hostname
= "HOSTNAME";
212 const char * const config_event_context_ip
= "IP";
213 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
214 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
215 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
216 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
217 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
218 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
219 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
220 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
221 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
222 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
223 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
224 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
225 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
226 LTTNG_HIDDEN
const char * const config_event_context_time_ns
= "TIME_NS";
227 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
228 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
229 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
230 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
231 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
232 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
233 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
234 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
235 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
236 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
237 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
238 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
239 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
240 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
242 /* Deprecated symbols */
243 const char * const config_element_perf
;
245 enum process_event_node_phase
{
250 struct consumer_output
{
257 static int config_entry_handler_filter(struct handler_filter_args
*args
,
258 const char *section
, const char *name
, const char *value
)
261 struct config_entry entry
= { section
, name
, value
};
265 if (!section
|| !name
|| !value
) {
271 if (strcmp(args
->section
, section
)) {
276 ret
= args
->handler(&entry
, args
->user_data
);
282 int config_get_section_entries(const char *override_path
, const char *section
,
283 config_entry_handler_cb handler
, void *user_data
)
287 FILE *config_file
= NULL
;
288 struct handler_filter_args filter
= { section
, handler
, user_data
};
290 /* First, try system-wide conf. file. */
291 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
293 config_file
= fopen(path
, "r");
295 DBG("Loading daemon conf file at %s", path
);
297 * Return value is not very important here since error or not, we
298 * continue and try the next possible conf. file.
300 (void) ini_parse_file(config_file
,
301 (ini_entry_handler
) config_entry_handler_filter
,
306 /* Second is the user local configuration. */
307 path
= utils_get_home_dir();
309 char fullpath
[PATH_MAX
];
311 ret
= snprintf(fullpath
, sizeof(fullpath
),
312 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
314 PERROR("snprintf user conf. path");
318 config_file
= fopen(fullpath
, "r");
320 DBG("Loading daemon user conf file at %s", path
);
322 * Return value is not very important here since error or not, we
323 * continue and try the next possible conf. file.
325 (void) ini_parse_file(config_file
,
326 (ini_entry_handler
) config_entry_handler_filter
,
332 /* Final path is the one that the user might have provided. */
334 config_file
= fopen(override_path
, "r");
336 DBG("Loading daemon command line conf file at %s", override_path
);
337 (void) ini_parse_file(config_file
,
338 (ini_entry_handler
) config_entry_handler_filter
,
342 ERR("Failed to open daemon configuration file at %s",
349 /* Everything went well. */
357 int config_parse_value(const char *value
)
360 char *endptr
, *lower_str
;
370 v
= strtoul(value
, &endptr
, 10);
371 if (endptr
!= value
) {
376 lower_str
= zmalloc(len
+ 1);
383 for (i
= 0; i
< len
; i
++) {
384 lower_str
[i
] = tolower(value
[i
]);
387 if (!strcmp(lower_str
, config_str_yes
) ||
388 !strcmp(lower_str
, config_str_true
) ||
389 !strcmp(lower_str
, config_str_on
)) {
391 } else if (!strcmp(lower_str
, config_str_no
) ||
392 !strcmp(lower_str
, config_str_false
) ||
393 !strcmp(lower_str
, config_str_off
)) {
405 * Returns a xmlChar string which must be released using xmlFree().
407 static xmlChar
*encode_string(const char *in_str
)
409 xmlChar
*out_str
= NULL
;
410 xmlCharEncodingHandlerPtr handler
;
411 int out_len
, ret
, in_len
;
415 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
417 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
421 in_len
= strlen(in_str
);
423 * Add 1 byte for the NULL terminted character. The factor 4 here is
424 * used because UTF-8 characters can take up to 4 bytes.
426 out_len
= (in_len
* 4) + 1;
427 out_str
= xmlMalloc(out_len
);
432 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
439 /* out_len is now the size of out_str */
440 out_str
[out_len
] = '\0';
446 struct config_writer
*config_writer_create(int fd_output
, int indent
)
449 struct config_writer
*writer
;
450 xmlOutputBufferPtr buffer
;
452 writer
= zmalloc(sizeof(struct config_writer
));
454 PERROR("zmalloc config_writer_create");
458 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
463 writer
->writer
= xmlNewTextWriter(buffer
);
464 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
465 config_xml_encoding
, NULL
);
470 ret
= xmlTextWriterSetIndentString(writer
->writer
,
471 BAD_CAST config_xml_indent_string
);
476 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
484 config_writer_destroy(writer
);
489 int config_writer_destroy(struct config_writer
*writer
)
498 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
499 WARN("Could not close XML document");
503 if (writer
->writer
) {
504 xmlFreeTextWriter(writer
->writer
);
513 int config_writer_open_element(struct config_writer
*writer
,
514 const char *element_name
)
517 xmlChar
*encoded_element_name
;
519 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
524 encoded_element_name
= encode_string(element_name
);
525 if (!encoded_element_name
) {
530 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
531 xmlFree(encoded_element_name
);
533 return ret
>= 0 ? 0 : ret
;
537 int config_writer_write_attribute(struct config_writer
*writer
,
538 const char *name
, const char *value
)
541 xmlChar
*encoded_name
= NULL
;
542 xmlChar
*encoded_value
= NULL
;
544 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
549 encoded_name
= encode_string(name
);
555 encoded_value
= encode_string(value
);
556 if (!encoded_value
) {
561 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
564 xmlFree(encoded_name
);
565 xmlFree(encoded_value
);
566 return ret
>= 0 ? 0 : ret
;
570 int config_writer_close_element(struct config_writer
*writer
)
574 if (!writer
|| !writer
->writer
) {
579 ret
= xmlTextWriterEndElement(writer
->writer
);
581 return ret
>= 0 ? 0 : ret
;
585 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
586 const char *element_name
, uint64_t value
)
589 xmlChar
*encoded_element_name
;
591 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
596 encoded_element_name
= encode_string(element_name
);
597 if (!encoded_element_name
) {
602 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
603 encoded_element_name
, "%" PRIu64
, value
);
604 xmlFree(encoded_element_name
);
606 return ret
>= 0 ? 0 : ret
;
610 int config_writer_write_element_signed_int(struct config_writer
*writer
,
611 const char *element_name
, int64_t value
)
614 xmlChar
*encoded_element_name
;
616 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
621 encoded_element_name
= encode_string(element_name
);
622 if (!encoded_element_name
) {
627 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
628 encoded_element_name
, "%" PRIi64
, value
);
629 xmlFree(encoded_element_name
);
631 return ret
>= 0 ? 0 : ret
;
635 int config_writer_write_element_bool(struct config_writer
*writer
,
636 const char *element_name
, int value
)
638 return config_writer_write_element_string(writer
, element_name
,
639 value
? config_xml_true
: config_xml_false
);
643 int config_writer_write_element_string(struct config_writer
*writer
,
644 const char *element_name
, const char *value
)
647 xmlChar
*encoded_element_name
= NULL
;
648 xmlChar
*encoded_value
= NULL
;
650 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
656 encoded_element_name
= encode_string(element_name
);
657 if (!encoded_element_name
) {
662 encoded_value
= encode_string(value
);
663 if (!encoded_value
) {
668 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
671 xmlFree(encoded_element_name
);
672 xmlFree(encoded_value
);
673 return ret
>= 0 ? 0 : ret
;
677 void xml_error_handler(void *ctx
, const char *format
, ...)
683 va_start(args
, format
);
684 ret
= vasprintf(&errMsg
, format
, args
);
687 ERR("String allocation failed in xml error handler");
691 fprintf(stderr
, "XML Error: %s", errMsg
);
696 void fini_session_config_validation_ctx(
697 struct session_config_validation_ctx
*ctx
)
699 if (ctx
->parser_ctx
) {
700 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
704 xmlSchemaFree(ctx
->schema
);
707 if (ctx
->schema_validation_ctx
) {
708 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
711 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
715 char *get_session_config_xsd_path(void)
718 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
719 size_t base_path_len
;
723 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
726 base_path_len
= strlen(base_path
);
727 max_path_len
= base_path_len
+
728 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
729 xsd_path
= zmalloc(max_path_len
);
734 strcpy(xsd_path
, base_path
);
735 if (xsd_path
[base_path_len
- 1] != '/') {
736 xsd_path
[base_path_len
++] = '/';
739 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
745 int init_session_config_validation_ctx(
746 struct session_config_validation_ctx
*ctx
)
749 char *xsd_path
= get_session_config_xsd_path();
752 ret
= -LTTNG_ERR_NOMEM
;
756 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
757 if (!ctx
->parser_ctx
) {
758 ERR("XSD parser context creation failed");
759 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
762 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
763 xml_error_handler
, NULL
);
765 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
767 ERR("XSD parsing failed");
768 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
772 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
773 if (!ctx
->schema_validation_ctx
) {
774 ERR("XSD validation context creation failed");
775 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
779 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
780 xml_error_handler
, NULL
);
785 fini_session_config_validation_ctx(ctx
);
793 int parse_uint(xmlChar
*str
, uint64_t *val
)
803 *val
= strtoull((const char *) str
, &endptr
, 10);
804 if (!endptr
|| *endptr
) {
815 int parse_int(xmlChar
*str
, int64_t *val
)
825 *val
= strtoll((const char *) str
, &endptr
, 10);
826 if (!endptr
|| *endptr
) {
837 int parse_bool(xmlChar
*str
, int *val
)
846 if (!strcmp((const char *) str
, config_xml_true
) ||
847 !strcmp((const char *) str
, "1")) {
849 } else if (!strcmp((const char *) str
, config_xml_false
) ||
850 !strcmp((const char *) str
, "0")) {
853 WARN("Invalid boolean value encountered (%s).",
862 int get_domain_type(xmlChar
*domain
)
870 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
871 ret
= LTTNG_DOMAIN_KERNEL
;
872 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
873 ret
= LTTNG_DOMAIN_UST
;
874 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
875 ret
= LTTNG_DOMAIN_JUL
;
876 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
877 ret
= LTTNG_DOMAIN_LOG4J
;
878 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
879 ret
= LTTNG_DOMAIN_PYTHON
;
890 int get_buffer_type(xmlChar
*buffer_type
)
898 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
899 ret
= LTTNG_BUFFER_GLOBAL
;
900 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
901 ret
= LTTNG_BUFFER_PER_UID
;
902 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
903 ret
= LTTNG_BUFFER_PER_PID
;
914 int get_overwrite_mode(xmlChar
*overwrite_mode
)
918 if (!overwrite_mode
) {
922 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
924 } else if (!strcmp((char *) overwrite_mode
,
925 config_overwrite_mode_discard
)) {
937 int get_output_type(xmlChar
*output_type
)
945 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
946 ret
= LTTNG_EVENT_MMAP
;
947 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
948 ret
= LTTNG_EVENT_SPLICE
;
959 int get_event_type(xmlChar
*event_type
)
967 if (!strcmp((char *) event_type
, config_event_type_all
)) {
968 ret
= LTTNG_EVENT_ALL
;
969 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
970 ret
= LTTNG_EVENT_TRACEPOINT
;
971 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
972 ret
= LTTNG_EVENT_PROBE
;
973 } else if (!strcmp((char *) event_type
,
974 config_event_type_userspace_probe
)) {
975 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
976 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
977 ret
= LTTNG_EVENT_FUNCTION
;
978 } else if (!strcmp((char *) event_type
,
979 config_event_type_function_entry
)) {
980 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
981 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
982 ret
= LTTNG_EVENT_NOOP
;
983 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
984 ret
= LTTNG_EVENT_SYSCALL
;
995 int get_loglevel_type(xmlChar
*loglevel_type
)
999 if (!loglevel_type
) {
1003 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1004 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1005 } else if (!strcmp((char *) loglevel_type
,
1006 config_loglevel_type_range
)) {
1007 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1008 } else if (!strcmp((char *) loglevel_type
,
1009 config_loglevel_type_single
)) {
1010 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1021 * Return the context type or -1 on error.
1024 int get_context_type(xmlChar
*context_type
)
1028 if (!context_type
) {
1032 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1033 ret
= LTTNG_EVENT_CONTEXT_PID
;
1034 } else if (!strcmp((char *) context_type
,
1035 config_event_context_procname
)) {
1036 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1037 } else if (!strcmp((char *) context_type
,
1038 config_event_context_prio
)) {
1039 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1040 } else if (!strcmp((char *) context_type
,
1041 config_event_context_nice
)) {
1042 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1043 } else if (!strcmp((char *) context_type
,
1044 config_event_context_vpid
)) {
1045 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1046 } else if (!strcmp((char *) context_type
,
1047 config_event_context_tid
)) {
1048 ret
= LTTNG_EVENT_CONTEXT_TID
;
1049 } else if (!strcmp((char *) context_type
,
1050 config_event_context_vtid
)) {
1051 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1052 } else if (!strcmp((char *) context_type
,
1053 config_event_context_ppid
)) {
1054 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1055 } else if (!strcmp((char *) context_type
,
1056 config_event_context_vppid
)) {
1057 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1058 } else if (!strcmp((char *) context_type
,
1059 config_event_context_pthread_id
)) {
1060 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1061 } else if (!strcmp((char *) context_type
,
1062 config_event_context_hostname
)) {
1063 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1064 } else if (!strcmp((char *) context_type
,
1065 config_event_context_ip
)) {
1066 ret
= LTTNG_EVENT_CONTEXT_IP
;
1067 } else if (!strcmp((char *) context_type
,
1068 config_event_context_interruptible
)) {
1069 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1070 } else if (!strcmp((char *) context_type
,
1071 config_event_context_preemptible
)) {
1072 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1073 } else if (!strcmp((char *) context_type
,
1074 config_event_context_need_reschedule
)) {
1075 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1076 } else if (!strcmp((char *) context_type
,
1077 config_event_context_migratable
)) {
1078 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1079 } else if (!strcmp((char *) context_type
,
1080 config_event_context_callstack_user
)) {
1081 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1082 } else if (!strcmp((char *) context_type
,
1083 config_event_context_callstack_kernel
)) {
1084 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1085 } else if (!strcmp((char *) context_type
,
1086 config_event_context_cgroup_ns
)) {
1087 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1088 } else if (!strcmp((char *) context_type
,
1089 config_event_context_ipc_ns
)) {
1090 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1091 } else if (!strcmp((char *) context_type
,
1092 config_event_context_mnt_ns
)) {
1093 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1094 } else if (!strcmp((char *) context_type
,
1095 config_event_context_net_ns
)) {
1096 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1097 } else if (!strcmp((char *) context_type
,
1098 config_event_context_pid_ns
)) {
1099 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1100 } else if (!strcmp((char *) context_type
,
1101 config_event_context_time_ns
)) {
1102 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1103 } else if (!strcmp((char *) context_type
,
1104 config_event_context_user_ns
)) {
1105 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1106 } else if (!strcmp((char *) context_type
,
1107 config_event_context_uts_ns
)) {
1108 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1109 } else if (!strcmp((char *) context_type
,
1110 config_event_context_uid
)) {
1111 ret
= LTTNG_EVENT_CONTEXT_UID
;
1112 } else if (!strcmp((char *) context_type
,
1113 config_event_context_euid
)) {
1114 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1115 } else if (!strcmp((char *) context_type
,
1116 config_event_context_suid
)) {
1117 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1118 } else if (!strcmp((char *) context_type
,
1119 config_event_context_gid
)) {
1120 ret
= LTTNG_EVENT_CONTEXT_GID
;
1121 } else if (!strcmp((char *) context_type
,
1122 config_event_context_egid
)) {
1123 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1124 } else if (!strcmp((char *) context_type
,
1125 config_event_context_sgid
)) {
1126 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1127 } else if (!strcmp((char *) context_type
,
1128 config_event_context_vuid
)) {
1129 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1130 } else if (!strcmp((char *) context_type
,
1131 config_event_context_veuid
)) {
1132 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1133 } else if (!strcmp((char *) context_type
,
1134 config_event_context_vsuid
)) {
1135 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1136 } else if (!strcmp((char *) context_type
,
1137 config_event_context_vgid
)) {
1138 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1139 } else if (!strcmp((char *) context_type
,
1140 config_event_context_vegid
)) {
1141 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1142 } else if (!strcmp((char *) context_type
,
1143 config_event_context_vsgid
)) {
1144 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1155 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1160 for (node
= xmlFirstElementChild(domain_node
); node
;
1161 node
= xmlNextElementSibling(node
)) {
1162 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1164 xmlChar
*node_content
= xmlNodeGetContent(node
);
1165 if (!node_content
) {
1166 ret
= -LTTNG_ERR_NOMEM
;
1170 ret
= get_domain_type(node_content
);
1173 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1178 } else if (!strcmp((const char *) node
->name
,
1179 config_element_buffer_type
)) {
1181 xmlChar
*node_content
= xmlNodeGetContent(node
);
1182 if (!node_content
) {
1183 ret
= -LTTNG_ERR_NOMEM
;
1187 ret
= get_buffer_type(node_content
);
1190 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1194 domain
->buf_type
= ret
;
1203 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1208 for (node
= xmlFirstElementChild(net_output_node
); node
;
1209 node
= xmlNextElementSibling(node
)) {
1210 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1212 *control_uri
= (char *) xmlNodeGetContent(node
);
1213 if (!*control_uri
) {
1218 *data_uri
= (char *) xmlNodeGetContent(node
);
1225 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1229 int process_consumer_output(xmlNodePtr consumer_output_node
,
1230 struct consumer_output
*output
)
1237 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1238 node
= xmlNextElementSibling(node
)) {
1239 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1240 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1244 ret
= -LTTNG_ERR_NOMEM
;
1248 ret
= parse_bool(enabled_str
, &output
->enabled
);
1254 xmlNodePtr output_type_node
;
1257 output_type_node
= xmlFirstElementChild(node
);
1258 if (!output_type_node
) {
1259 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1263 if (!strcmp((const char *) output_type_node
->name
,
1264 config_element_path
)) {
1266 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1267 if (!output
->path
) {
1268 ret
= -LTTNG_ERR_NOMEM
;
1273 ret
= get_net_output_uris(output_type_node
,
1274 &output
->control_uri
, &output
->data_uri
);
1286 free(output
->control_uri
);
1287 free(output
->data_uri
);
1288 memset(output
, 0, sizeof(struct consumer_output
));
1294 int create_session_net_output(const char *name
, const char *control_uri
,
1295 const char *data_uri
)
1298 struct lttng_handle
*handle
;
1299 const char *uri
= NULL
;
1303 handle
= lttng_create_handle(name
, NULL
);
1305 ret
= -LTTNG_ERR_NOMEM
;
1309 if (!control_uri
|| !data_uri
) {
1310 uri
= control_uri
? control_uri
: data_uri
;
1315 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1316 lttng_destroy_handle(handle
);
1322 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1323 const struct config_load_session_override_attr
*overrides
)
1326 xmlNodePtr node
= NULL
;
1327 xmlNodePtr snapshot_output_list_node
;
1328 xmlNodePtr snapshot_output_node
;
1330 assert(session_name
);
1332 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1341 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1343 /* Parse and create snapshot outputs */
1345 for (snapshot_output_node
=
1346 xmlFirstElementChild(snapshot_output_list_node
);
1347 snapshot_output_node
; snapshot_output_node
=
1348 xmlNextElementSibling(snapshot_output_node
)) {
1350 uint64_t max_size
= UINT64_MAX
;
1351 struct consumer_output output
= { 0 };
1352 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1353 const char *control_uri
= NULL
;
1354 const char *data_uri
= NULL
;
1355 const char *path
= NULL
;
1357 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1358 node
= xmlNextElementSibling(node
)) {
1359 if (!strcmp((const char *) node
->name
,
1360 config_element_name
)) {
1362 name
= (char *) xmlNodeGetContent(node
);
1364 ret
= -LTTNG_ERR_NOMEM
;
1365 goto error_snapshot_output
;
1367 } else if (!strcmp((const char *) node
->name
,
1368 config_element_max_size
)) {
1369 xmlChar
*content
= xmlNodeGetContent(node
);
1373 ret
= -LTTNG_ERR_NOMEM
;
1374 goto error_snapshot_output
;
1376 ret
= parse_uint(content
, &max_size
);
1379 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1380 goto error_snapshot_output
;
1383 /* consumer_output */
1384 ret
= process_consumer_output(node
, &output
);
1386 goto error_snapshot_output
;
1391 control_uri
= output
.control_uri
;
1392 data_uri
= output
.data_uri
;
1396 if (overrides
->path_url
) {
1397 path
= overrides
->path_url
;
1398 /* Control/data_uri are null */
1402 if (overrides
->ctrl_url
) {
1403 control_uri
= overrides
->ctrl_url
;
1407 if (overrides
->data_url
) {
1408 data_uri
= overrides
->data_url
;
1415 snapshot_output
= lttng_snapshot_output_create();
1416 if (!snapshot_output
) {
1417 ret
= -LTTNG_ERR_NOMEM
;
1418 goto error_snapshot_output
;
1421 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1423 goto error_snapshot_output
;
1426 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1428 goto error_snapshot_output
;
1432 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1435 goto error_snapshot_output
;
1439 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1442 goto error_snapshot_output
;
1447 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1450 goto error_snapshot_output
;
1455 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1456 error_snapshot_output
:
1459 free(output
.control_uri
);
1460 free(output
.data_uri
);
1461 lttng_snapshot_output_destroy(snapshot_output
);
1471 int create_session(const char *name
,
1472 xmlNodePtr output_node
,
1473 uint64_t live_timer_interval
,
1474 const struct config_load_session_override_attr
*overrides
)
1477 struct consumer_output output
= { 0 };
1478 xmlNodePtr consumer_output_node
;
1479 const char *control_uri
= NULL
;
1480 const char *data_uri
= NULL
;
1481 const char *path
= NULL
;
1486 consumer_output_node
= xmlFirstElementChild(output_node
);
1487 if (!consumer_output_node
) {
1488 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1492 if (strcmp((const char *) consumer_output_node
->name
,
1493 config_element_consumer_output
)) {
1494 WARN("Invalid output type, expected %s node",
1495 config_element_consumer_output
);
1496 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1500 ret
= process_consumer_output(consumer_output_node
, &output
);
1506 control_uri
= output
.control_uri
;
1507 data_uri
= output
.data_uri
;
1510 /* Check for override and apply them */
1512 if (overrides
->path_url
) {
1513 path
= overrides
->path_url
;
1514 /* control/data_uri are null */;
1518 if (overrides
->ctrl_url
) {
1519 control_uri
= overrides
->ctrl_url
;
1523 if (overrides
->data_url
) {
1524 data_uri
= overrides
->data_url
;
1532 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1533 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1537 if (control_uri
|| data_uri
) {
1538 /* network destination */
1539 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1541 * URLs are provided for sure since the test above make sure that
1542 * with a live timer the data and control URIs are provided. So,
1543 * NULL is passed here and will be set right after.
1545 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1547 ret
= lttng_create_session(name
, NULL
);
1553 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1559 /* either local output or no output */
1560 ret
= lttng_create_session(name
, path
);
1567 free(output
.control_uri
);
1568 free(output
.data_uri
);
1573 struct lttng_userspace_probe_location
*
1574 process_userspace_probe_function_attribute_node(
1575 xmlNodePtr attribute_node
)
1577 xmlNodePtr function_attribute_node
;
1578 char *function_name
= NULL
, *binary_path
= NULL
;
1579 struct lttng_userspace_probe_location
*location
= NULL
;
1580 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1583 * Process userspace probe location function attributes. The order of
1584 * the fields are not guaranteed so we need to iterate over all fields
1585 * and check at the end if everything we need for this location type is
1588 for (function_attribute_node
=
1589 xmlFirstElementChild(attribute_node
);
1590 function_attribute_node
;
1591 function_attribute_node
= xmlNextElementSibling(
1592 function_attribute_node
)) {
1593 /* Handle function name, binary path and lookup method. */
1594 if (!strcmp((const char *) function_attribute_node
->name
,
1595 config_element_userspace_probe_function_location_function_name
)) {
1596 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1597 if (!function_name
) {
1600 } else if (!strcmp((const char *) function_attribute_node
->name
,
1601 config_element_userspace_probe_location_binary_path
)) {
1602 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1606 } else if (!strcmp((const char *) function_attribute_node
->name
,
1607 config_element_userspace_probe_lookup
)) {
1608 char *lookup_method_name
;
1610 lookup_method_name
= (char *) xmlNodeGetContent(
1611 function_attribute_node
);
1612 if (!lookup_method_name
) {
1617 * function_default lookup method defaults to
1618 * function_elf lookup method at the moment.
1620 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1621 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1622 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1623 if (!lookup_method
) {
1624 PERROR("Error creating function default/ELF lookup method");
1627 WARN("Unknown function lookup method");
1630 free(lookup_method_name
);
1631 if (!lookup_method
) {
1638 /* Check if all the necessary fields were found. */
1639 if (binary_path
&& function_name
&& lookup_method
) {
1640 /* Ownership of lookup_method is transferred. */
1642 lttng_userspace_probe_location_function_create(
1643 binary_path
, function_name
,
1645 lookup_method
= NULL
;
1650 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1652 free(function_name
);
1657 struct lttng_userspace_probe_location
*
1658 process_userspace_probe_tracepoint_attribute_node(
1659 xmlNodePtr attribute_node
)
1661 xmlNodePtr tracepoint_attribute_node
;
1662 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1663 struct lttng_userspace_probe_location
*location
= NULL
;
1664 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1667 * Process userspace probe location tracepoint attributes. The order of
1668 * the fields are not guaranteed so we need to iterate over all fields
1669 * and check at the end if everything we need for this location type is
1672 for (tracepoint_attribute_node
=
1673 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1674 tracepoint_attribute_node
= xmlNextElementSibling(
1675 tracepoint_attribute_node
)) {
1676 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1677 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1678 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1682 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1683 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1684 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1685 if (!provider_name
) {
1688 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1689 config_element_userspace_probe_location_binary_path
)) {
1690 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1694 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1695 config_element_userspace_probe_lookup
)) {
1696 char *lookup_method_name
;
1698 lookup_method_name
= (char *) xmlNodeGetContent(
1699 tracepoint_attribute_node
);
1700 if (!lookup_method_name
) {
1704 if (!strcmp(lookup_method_name
,
1705 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1707 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1708 if (!lookup_method
) {
1709 PERROR("Error creating tracepoint SDT lookup method");
1712 WARN("Unknown tracepoint lookup method");
1715 free(lookup_method_name
);
1716 if (!lookup_method
) {
1720 WARN("Unknown tracepoint attribute");
1724 /* Check if all the necessary fields were found. */
1725 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1726 /* Ownership of lookup_method is transferred. */
1728 lttng_userspace_probe_location_tracepoint_create(
1729 binary_path
, provider_name
,
1730 probe_name
, lookup_method
);
1731 lookup_method
= NULL
;
1736 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1738 free(provider_name
);
1744 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1745 struct lttng_event_probe_attr
*attr
)
1749 assert(probe_attribute_node
);
1752 if (!strcmp((const char *) probe_attribute_node
->name
,
1753 config_element_address
)) {
1758 content
= xmlNodeGetContent(probe_attribute_node
);
1760 ret
= -LTTNG_ERR_NOMEM
;
1764 ret
= parse_uint(content
, &addr
);
1767 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1772 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1773 config_element_offset
)) {
1775 uint64_t offset
= 0;
1778 content
= xmlNodeGetContent(probe_attribute_node
);
1780 ret
= -LTTNG_ERR_NOMEM
;
1784 ret
= parse_uint(content
, &offset
);
1787 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1791 attr
->offset
= offset
;
1792 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1793 config_element_symbol_name
)) {
1797 content
= xmlNodeGetContent(probe_attribute_node
);
1799 ret
= -LTTNG_ERR_NOMEM
;
1803 ret
= lttng_strncpy(attr
->symbol_name
,
1804 (const char *) content
,
1805 LTTNG_SYMBOL_NAME_LEN
);
1807 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1808 (const char *) content
,
1809 strlen((const char *) content
),
1810 LTTNG_SYMBOL_NAME_LEN
);
1811 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1823 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1824 const char *channel_name
, const enum process_event_node_phase phase
)
1828 struct lttng_event
*event
;
1829 char **exclusions
= NULL
;
1830 unsigned long exclusion_count
= 0;
1831 char *filter_expression
= NULL
;
1835 assert(channel_name
);
1837 event
= lttng_event_create();
1839 ret
= -LTTNG_ERR_NOMEM
;
1843 /* Initialize default log level which varies by domain */
1844 switch (handle
->domain
.type
)
1846 case LTTNG_DOMAIN_JUL
:
1847 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1849 case LTTNG_DOMAIN_LOG4J
:
1850 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1852 case LTTNG_DOMAIN_PYTHON
:
1853 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1855 case LTTNG_DOMAIN_UST
:
1856 case LTTNG_DOMAIN_KERNEL
:
1857 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1863 for (node
= xmlFirstElementChild(event_node
); node
;
1864 node
= xmlNextElementSibling(node
)) {
1865 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1869 content
= xmlNodeGetContent(node
);
1871 ret
= -LTTNG_ERR_NOMEM
;
1875 ret
= lttng_strncpy(event
->name
,
1876 (const char *) content
,
1877 LTTNG_SYMBOL_NAME_LEN
);
1879 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1880 (const char *) content
,
1881 strlen((const char *) content
),
1882 LTTNG_SYMBOL_NAME_LEN
);
1883 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1888 } else if (!strcmp((const char *) node
->name
,
1889 config_element_enabled
)) {
1890 xmlChar
*content
= xmlNodeGetContent(node
);
1894 ret
= -LTTNG_ERR_NOMEM
;
1898 ret
= parse_bool(content
, &event
->enabled
);
1901 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1904 } else if (!strcmp((const char *) node
->name
,
1905 config_element_type
)) {
1906 xmlChar
*content
= xmlNodeGetContent(node
);
1910 ret
= -LTTNG_ERR_NOMEM
;
1914 ret
= get_event_type(content
);
1917 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1922 } else if (!strcmp((const char *) node
->name
,
1923 config_element_loglevel_type
)) {
1924 xmlChar
*content
= xmlNodeGetContent(node
);
1928 ret
= -LTTNG_ERR_NOMEM
;
1932 ret
= get_loglevel_type(content
);
1935 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1939 event
->loglevel_type
= ret
;
1940 } else if (!strcmp((const char *) node
->name
,
1941 config_element_loglevel
)) {
1943 int64_t loglevel
= 0;
1946 content
= xmlNodeGetContent(node
);
1948 ret
= -LTTNG_ERR_NOMEM
;
1952 ret
= parse_int(content
, &loglevel
);
1955 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1959 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1960 WARN("loglevel out of range.");
1961 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1965 event
->loglevel
= loglevel
;
1966 } else if (!strcmp((const char *) node
->name
,
1967 config_element_filter
)) {
1969 xmlNodeGetContent(node
);
1973 ret
= -LTTNG_ERR_NOMEM
;
1977 free(filter_expression
);
1978 filter_expression
= strdup((char *) content
);
1980 if (!filter_expression
) {
1981 ret
= -LTTNG_ERR_NOMEM
;
1984 } else if (!strcmp((const char *) node
->name
,
1985 config_element_exclusions
)) {
1986 xmlNodePtr exclusion_node
;
1987 int exclusion_index
= 0;
1992 * Exclusions has already been initialized,
1995 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1999 exclusion_count
= xmlChildElementCount(node
);
2000 if (!exclusion_count
) {
2004 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2006 exclusion_count
= 0;
2007 ret
= -LTTNG_ERR_NOMEM
;
2011 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2012 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2014 xmlNodeGetContent(exclusion_node
);
2017 ret
= -LTTNG_ERR_NOMEM
;
2021 exclusions
[exclusion_index
] = strdup((const char *) content
);
2023 if (!exclusions
[exclusion_index
]) {
2024 ret
= -LTTNG_ERR_NOMEM
;
2030 event
->exclusion
= 1;
2031 } else if (!strcmp((const char *) node
->name
,
2032 config_element_attributes
)) {
2033 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2036 if (!attribute_node
) {
2037 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2041 if (!strcmp((const char *) attribute_node
->name
,
2042 config_element_probe_attributes
)) {
2043 xmlNodePtr probe_attribute_node
;
2045 /* probe_attributes */
2046 for (probe_attribute_node
=
2047 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2048 probe_attribute_node
= xmlNextElementSibling(
2049 probe_attribute_node
)) {
2051 ret
= process_probe_attribute_node(probe_attribute_node
,
2052 &event
->attr
.probe
);
2057 } else if (!strcmp((const char *) attribute_node
->name
,
2058 config_element_function_attributes
)) {
2061 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2063 /* function_attributes */
2064 content
= xmlNodeGetContent(symbol_node
);
2066 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2070 sym_len
= strlen((char *) content
);
2071 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2072 WARN("Function name too long.");
2073 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2078 ret
= lttng_strncpy(
2079 event
->attr
.ftrace
.symbol_name
,
2080 (char *) content
, sym_len
);
2082 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2087 } else if (!strcmp((const char *) attribute_node
->name
,
2088 config_element_userspace_probe_tracepoint_attributes
)) {
2089 struct lttng_userspace_probe_location
*location
;
2091 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2093 WARN("Error processing userspace probe tracepoint attribute");
2094 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2097 ret
= lttng_event_set_userspace_probe_location(
2100 WARN("Error setting userspace probe location field");
2101 lttng_userspace_probe_location_destroy(
2103 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2106 } else if (!strcmp((const char *) attribute_node
->name
,
2107 config_element_userspace_probe_function_attributes
)) {
2108 struct lttng_userspace_probe_location
*location
;
2111 process_userspace_probe_function_attribute_node(
2114 WARN("Error processing userspace probe function attribute");
2115 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2119 ret
= lttng_event_set_userspace_probe_location(
2122 WARN("Error setting userspace probe location field");
2123 lttng_userspace_probe_location_destroy(
2125 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2129 /* Unknown event attribute. */
2130 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2136 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2137 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2138 filter_expression
, exclusion_count
, exclusions
);
2140 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2141 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2147 for (i
= 0; i
< exclusion_count
; i
++) {
2148 free(exclusions
[i
]);
2151 lttng_event_destroy(event
);
2153 free(filter_expression
);
2158 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2159 const char *channel_name
)
2162 struct lttng_event event
;
2165 assert(events_node
);
2167 assert(channel_name
);
2169 for (node
= xmlFirstElementChild(events_node
); node
;
2170 node
= xmlNextElementSibling(node
)) {
2171 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2178 * Disable all events to enable only the necessary events.
2179 * Limitations regarding lttng_disable_events and tuple descriptor
2180 * force this approach.
2182 memset(&event
, 0, sizeof(event
));
2183 event
.loglevel
= -1;
2184 event
.type
= LTTNG_EVENT_ALL
;
2185 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2190 for (node
= xmlFirstElementChild(events_node
); node
;
2191 node
= xmlNextElementSibling(node
)) {
2192 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2203 int process_channel_attr_node(xmlNodePtr attr_node
,
2204 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2205 xmlNodePtr
*events_node
)
2211 assert(contexts_node
);
2212 assert(events_node
);
2214 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2218 content
= xmlNodeGetContent(attr_node
);
2220 ret
= -LTTNG_ERR_NOMEM
;
2224 ret
= lttng_strncpy(channel
->name
,
2225 (const char *) content
,
2226 LTTNG_SYMBOL_NAME_LEN
);
2228 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2229 (const char *) content
,
2230 strlen((const char *) content
),
2231 LTTNG_SYMBOL_NAME_LEN
);
2232 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2237 } else if (!strcmp((const char *) attr_node
->name
,
2238 config_element_enabled
)) {
2243 content
= xmlNodeGetContent(attr_node
);
2245 ret
= -LTTNG_ERR_NOMEM
;
2249 ret
= parse_bool(content
, &enabled
);
2252 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2256 channel
->enabled
= enabled
;
2257 } else if (!strcmp((const char *) attr_node
->name
,
2258 config_element_overwrite_mode
)) {
2261 /* overwrite_mode */
2262 content
= xmlNodeGetContent(attr_node
);
2264 ret
= -LTTNG_ERR_NOMEM
;
2268 ret
= get_overwrite_mode(content
);
2271 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2275 channel
->attr
.overwrite
= ret
;
2276 } else if (!strcmp((const char *) attr_node
->name
,
2277 config_element_subbuf_size
)) {
2280 /* subbuffer_size */
2281 content
= xmlNodeGetContent(attr_node
);
2283 ret
= -LTTNG_ERR_NOMEM
;
2287 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2290 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2293 } else if (!strcmp((const char *) attr_node
->name
,
2294 config_element_num_subbuf
)) {
2297 /* subbuffer_count */
2298 content
= xmlNodeGetContent(attr_node
);
2300 ret
= -LTTNG_ERR_NOMEM
;
2304 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2307 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2310 } else if (!strcmp((const char *) attr_node
->name
,
2311 config_element_switch_timer_interval
)) {
2313 uint64_t switch_timer_interval
= 0;
2315 /* switch_timer_interval */
2316 content
= xmlNodeGetContent(attr_node
);
2318 ret
= -LTTNG_ERR_NOMEM
;
2322 ret
= parse_uint(content
, &switch_timer_interval
);
2325 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2329 if (switch_timer_interval
> UINT_MAX
) {
2330 WARN("switch_timer_interval out of range.");
2331 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2335 channel
->attr
.switch_timer_interval
=
2336 switch_timer_interval
;
2337 } else if (!strcmp((const char *) attr_node
->name
,
2338 config_element_read_timer_interval
)) {
2340 uint64_t read_timer_interval
= 0;
2342 /* read_timer_interval */
2343 content
= xmlNodeGetContent(attr_node
);
2345 ret
= -LTTNG_ERR_NOMEM
;
2349 ret
= parse_uint(content
, &read_timer_interval
);
2352 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2356 if (read_timer_interval
> UINT_MAX
) {
2357 WARN("read_timer_interval out of range.");
2358 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2362 channel
->attr
.read_timer_interval
=
2363 read_timer_interval
;
2364 } else if (!strcmp((const char *) attr_node
->name
,
2365 config_element_output_type
)) {
2369 content
= xmlNodeGetContent(attr_node
);
2371 ret
= -LTTNG_ERR_NOMEM
;
2375 ret
= get_output_type(content
);
2378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2382 channel
->attr
.output
= ret
;
2383 } else if (!strcmp((const char *) attr_node
->name
,
2384 config_element_tracefile_size
)) {
2387 /* tracefile_size */
2388 content
= xmlNodeGetContent(attr_node
);
2390 ret
= -LTTNG_ERR_NOMEM
;
2394 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2397 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2400 } else if (!strcmp((const char *) attr_node
->name
,
2401 config_element_tracefile_count
)) {
2404 /* tracefile_count */
2405 content
= xmlNodeGetContent(attr_node
);
2407 ret
= -LTTNG_ERR_NOMEM
;
2411 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2414 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2417 } else if (!strcmp((const char *) attr_node
->name
,
2418 config_element_live_timer_interval
)) {
2420 uint64_t live_timer_interval
= 0;
2422 /* live_timer_interval */
2423 content
= xmlNodeGetContent(attr_node
);
2425 ret
= -LTTNG_ERR_NOMEM
;
2429 ret
= parse_uint(content
, &live_timer_interval
);
2432 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2436 if (live_timer_interval
> UINT_MAX
) {
2437 WARN("live_timer_interval out of range.");
2438 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2442 channel
->attr
.live_timer_interval
=
2443 live_timer_interval
;
2444 } else if (!strcmp((const char *) attr_node
->name
,
2445 config_element_monitor_timer_interval
)) {
2447 uint64_t monitor_timer_interval
= 0;
2449 /* monitor_timer_interval */
2450 content
= xmlNodeGetContent(attr_node
);
2452 ret
= -LTTNG_ERR_NOMEM
;
2456 ret
= parse_uint(content
, &monitor_timer_interval
);
2459 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2463 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2464 monitor_timer_interval
);
2466 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2469 } else if (!strcmp((const char *) attr_node
->name
,
2470 config_element_blocking_timeout
)) {
2472 int64_t blocking_timeout
= 0;
2474 /* blocking_timeout */
2475 content
= xmlNodeGetContent(attr_node
);
2477 ret
= -LTTNG_ERR_NOMEM
;
2481 ret
= parse_int(content
, &blocking_timeout
);
2484 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2488 ret
= lttng_channel_set_blocking_timeout(channel
,
2491 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2494 } else if (!strcmp((const char *) attr_node
->name
,
2495 config_element_events
)) {
2497 *events_node
= attr_node
;
2500 *contexts_node
= attr_node
;
2508 int process_context_node(xmlNodePtr context_node
,
2509 struct lttng_handle
*handle
, const char *channel_name
)
2512 struct lttng_event_context context
;
2513 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2516 assert(channel_name
);
2518 if (!context_child_node
) {
2519 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2523 memset(&context
, 0, sizeof(context
));
2525 if (!strcmp((const char *) context_child_node
->name
,
2526 config_element_type
)) {
2528 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2531 ret
= -LTTNG_ERR_NOMEM
;
2535 ret
= get_context_type(content
);
2538 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2543 } else if (!strcmp((const char *) context_child_node
->name
,
2544 config_element_context_perf
)) {
2546 xmlNodePtr perf_attr_node
;
2548 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2549 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2550 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2551 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2552 perf_attr_node
; perf_attr_node
=
2553 xmlNextElementSibling(perf_attr_node
)) {
2554 if (!strcmp((const char *) perf_attr_node
->name
,
2555 config_element_type
)) {
2560 content
= xmlNodeGetContent(perf_attr_node
);
2562 ret
= -LTTNG_ERR_NOMEM
;
2566 ret
= parse_uint(content
, &type
);
2569 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2573 if (type
> UINT32_MAX
) {
2574 WARN("perf context type out of range.");
2575 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2579 context
.u
.perf_counter
.type
= type
;
2580 } else if (!strcmp((const char *) perf_attr_node
->name
,
2581 config_element_config
)) {
2583 uint64_t config
= 0;
2586 content
= xmlNodeGetContent(perf_attr_node
);
2588 ret
= -LTTNG_ERR_NOMEM
;
2592 ret
= parse_uint(content
, &config
);
2595 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2599 context
.u
.perf_counter
.config
= config
;
2600 } else if (!strcmp((const char *) perf_attr_node
->name
,
2601 config_element_name
)) {
2605 content
= xmlNodeGetContent(perf_attr_node
);
2607 ret
= -LTTNG_ERR_NOMEM
;
2611 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2612 (const char *) content
,
2613 LTTNG_SYMBOL_NAME_LEN
);
2615 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2616 (const char *) content
,
2617 strlen((const char *) content
),
2618 LTTNG_SYMBOL_NAME_LEN
);
2619 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2626 } else if (!strcmp((const char *) context_child_node
->name
,
2627 config_element_context_app
)) {
2628 /* application context */
2629 xmlNodePtr app_ctx_node
;
2631 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2632 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2633 app_ctx_node
; app_ctx_node
=
2634 xmlNextElementSibling(app_ctx_node
)) {
2636 char **target
= strcmp(
2637 (const char *) app_ctx_node
->name
,
2638 config_element_context_app_provider_name
) == 0 ?
2639 &context
.u
.app_ctx
.provider_name
:
2640 &context
.u
.app_ctx
.ctx_name
;
2642 content
= xmlNodeGetContent(app_ctx_node
);
2644 ret
= -LTTNG_ERR_NOMEM
;
2648 *target
= (char *) content
;
2651 /* Unrecognized context type */
2652 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2656 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2657 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2658 free(context
.u
.app_ctx
.provider_name
);
2659 free(context
.u
.app_ctx
.ctx_name
);
2666 int process_contexts_node(xmlNodePtr contexts_node
,
2667 struct lttng_handle
*handle
, const char *channel_name
)
2670 xmlNodePtr context_node
;
2672 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2673 context_node
= xmlNextElementSibling(context_node
)) {
2674 ret
= process_context_node(context_node
, handle
, channel_name
);
2683 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2684 const char **element_id_tracker
,
2685 const char **element_value_type
,
2686 const char **element_value
,
2687 const char **element_value_alias
,
2688 const char **element_name
)
2692 switch (process_attr
) {
2693 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2694 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2695 *element_value_type
= config_element_process_attr_pid_value
;
2696 *element_value
= config_element_process_attr_id
;
2697 *element_value_alias
= config_element_process_attr_id
;
2698 *element_name
= NULL
;
2700 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2701 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2702 *element_value_type
= config_element_process_attr_vpid_value
;
2703 *element_value
= config_element_process_attr_id
;
2704 *element_value_alias
= NULL
;
2705 *element_name
= NULL
;
2707 case LTTNG_PROCESS_ATTR_USER_ID
:
2708 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2709 *element_value_type
= config_element_process_attr_uid_value
;
2710 *element_value
= config_element_process_attr_id
;
2711 *element_value_alias
= NULL
;
2712 *element_name
= config_element_name
;
2714 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2715 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2716 *element_value_type
= config_element_process_attr_vuid_value
;
2717 *element_value
= config_element_process_attr_id
;
2718 *element_value_alias
= NULL
;
2719 *element_name
= config_element_name
;
2721 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2722 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2723 *element_value_type
= config_element_process_attr_gid_value
;
2724 *element_value
= config_element_process_attr_id
;
2725 *element_value_alias
= NULL
;
2726 *element_name
= config_element_name
;
2728 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2729 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2730 *element_value_type
= config_element_process_attr_vgid_value
;
2731 *element_value
= config_element_process_attr_id
;
2732 *element_value_alias
= NULL
;
2733 *element_name
= config_element_name
;
2736 ret
= LTTNG_ERR_INVALID
;
2741 static int process_legacy_pid_tracker_node(
2742 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2744 int ret
= 0, child_count
;
2745 xmlNodePtr targets_node
= NULL
;
2747 const char *element_id_tracker
;
2748 const char *element_target_id
;
2749 const char *element_id
;
2750 const char *element_id_alias
;
2751 const char *element_name
;
2752 enum lttng_error_code tracker_handle_ret_code
;
2753 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2754 enum lttng_process_attr_tracker_handle_status status
;
2755 const enum lttng_process_attr process_attr
=
2756 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2757 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2758 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2762 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2763 handle
->session_name
, handle
->domain
.type
,
2766 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2767 ret
= LTTNG_ERR_INVALID
;
2771 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2772 &element_target_id
, &element_id
, &element_id_alias
,
2778 /* Get the targets node */
2779 for (node
= xmlFirstElementChild(trackers_node
); node
;
2780 node
= xmlNextElementSibling(node
)) {
2781 if (!strcmp((const char *) node
->name
,
2782 config_element_tracker_targets_legacy
)) {
2783 targets_node
= node
;
2788 if (!targets_node
) {
2789 ret
= LTTNG_ERR_INVALID
;
2793 /* Go through all id target node */
2794 child_count
= xmlChildElementCount(targets_node
);
2795 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2797 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2798 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2799 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2800 ret
= LTTNG_ERR_UNK
;
2804 /* Add all tracked values. */
2805 for (node
= xmlFirstElementChild(targets_node
); node
;
2806 node
= xmlNextElementSibling(node
)) {
2807 xmlNodePtr pid_target_node
= node
;
2809 /* get pid_target node and track it */
2810 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2811 node
= xmlNextElementSibling(node
)) {
2812 if (!strcmp((const char *) node
->name
,
2813 config_element_tracker_pid_legacy
)) {
2815 xmlChar
*content
= xmlNodeGetContent(node
);
2818 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2822 ret
= parse_int(content
, &id
);
2825 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2829 switch (process_attr
) {
2830 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2831 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2835 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2836 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2841 ret
= LTTNG_ERR_INVALID
;
2846 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2848 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2849 ret
= LTTNG_ERR_INVALID
;
2851 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2852 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2854 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2855 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2857 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2858 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2860 ret
= LTTNG_ERR_UNK
;
2864 node
= pid_target_node
;
2868 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2872 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2873 struct lttng_handle
*handle
,
2874 enum lttng_process_attr process_attr
)
2876 int ret
= 0, child_count
;
2877 xmlNodePtr values_node
= NULL
;
2879 const char *element_id_tracker
;
2880 const char *element_target_id
;
2881 const char *element_id
;
2882 const char *element_id_alias
;
2883 const char *element_name
;
2884 enum lttng_error_code tracker_handle_ret_code
;
2885 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2886 enum lttng_process_attr_tracker_handle_status status
;
2889 assert(id_tracker_node
);
2891 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2892 handle
->session_name
, handle
->domain
.type
, process_attr
,
2894 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2895 ret
= LTTNG_ERR_INVALID
;
2899 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2900 &element_target_id
, &element_id
, &element_id_alias
,
2906 /* get the values node */
2907 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2908 node
= xmlNextElementSibling(node
)) {
2909 if (!strcmp((const char *) node
->name
,
2910 config_element_process_attr_values
)) {
2917 ret
= LTTNG_ERR_INVALID
;
2921 /* Go through all id target node */
2922 child_count
= xmlChildElementCount(values_node
);
2923 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2925 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2926 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2927 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2928 ret
= LTTNG_ERR_UNK
;
2932 /* Add all tracked values. */
2933 for (node
= xmlFirstElementChild(values_node
); node
;
2934 node
= xmlNextElementSibling(node
)) {
2935 xmlNodePtr id_target_node
= node
;
2937 /* get id node and track it */
2938 for (node
= xmlFirstElementChild(id_target_node
); node
;
2939 node
= xmlNextElementSibling(node
)) {
2940 if (!strcmp((const char *) node
->name
, element_id
) ||
2941 (element_id_alias
&&
2942 !strcmp((const char *) node
->name
,
2943 element_id_alias
))) {
2945 xmlChar
*content
= xmlNodeGetContent(node
);
2948 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2952 ret
= parse_int(content
, &id
);
2955 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2959 switch (process_attr
) {
2960 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2961 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2965 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2966 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2970 case LTTNG_PROCESS_ATTR_USER_ID
:
2971 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2975 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2976 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2980 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2981 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2985 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2986 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2991 ret
= LTTNG_ERR_INVALID
;
2994 } else if (element_name
&&
2995 !strcmp((const char *) node
->name
,
2997 xmlChar
*content
= xmlNodeGetContent(node
);
3000 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3004 switch (process_attr
) {
3005 case LTTNG_PROCESS_ATTR_USER_ID
:
3006 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3008 (const char *) content
);
3010 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3011 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3013 (const char *) content
);
3015 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3016 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3018 (const char *) content
);
3020 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3021 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3023 (const char *) content
);
3027 ret
= LTTNG_ERR_INVALID
;
3033 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3035 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3036 ret
= LTTNG_ERR_INVALID
;
3038 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3039 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3041 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3042 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3044 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3045 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3047 ret
= LTTNG_ERR_UNK
;
3051 node
= id_target_node
;
3055 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3060 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3063 struct lttng_domain domain
= { 0 };
3064 struct lttng_handle
*handle
= NULL
;
3065 struct lttng_channel
*channel
= NULL
;
3066 xmlNodePtr channels_node
= NULL
;
3067 xmlNodePtr trackers_node
= NULL
;
3068 xmlNodePtr pid_tracker_node
= NULL
;
3069 xmlNodePtr vpid_tracker_node
= NULL
;
3070 xmlNodePtr uid_tracker_node
= NULL
;
3071 xmlNodePtr vuid_tracker_node
= NULL
;
3072 xmlNodePtr gid_tracker_node
= NULL
;
3073 xmlNodePtr vgid_tracker_node
= NULL
;
3076 assert(session_name
);
3078 ret
= init_domain(domain_node
, &domain
);
3083 handle
= lttng_create_handle(session_name
, &domain
);
3085 ret
= -LTTNG_ERR_NOMEM
;
3089 /* get the channels node */
3090 for (node
= xmlFirstElementChild(domain_node
); node
;
3091 node
= xmlNextElementSibling(node
)) {
3092 if (!strcmp((const char *) node
->name
,
3093 config_element_channels
)) {
3094 channels_node
= node
;
3099 if (!channels_node
) {
3103 /* create all channels */
3104 for (node
= xmlFirstElementChild(channels_node
); node
;
3105 node
= xmlNextElementSibling(node
)) {
3106 const enum lttng_domain_type original_domain
= domain
.type
;
3107 xmlNodePtr contexts_node
= NULL
;
3108 xmlNodePtr events_node
= NULL
;
3109 xmlNodePtr channel_attr_node
;
3112 * Channels of the "agent" types cannot be created directly.
3113 * They are meant to be created implicitly through the
3114 * activation of events in their domain. However, a user
3115 * can override the default channel configuration attributes
3116 * by creating the underlying UST channel _before_ enabling
3117 * an agent domain event.
3119 * Hence, the channel's type is substituted before the creation
3120 * and restored by the time the events are created.
3122 switch (domain
.type
) {
3123 case LTTNG_DOMAIN_JUL
:
3124 case LTTNG_DOMAIN_LOG4J
:
3125 case LTTNG_DOMAIN_PYTHON
:
3126 domain
.type
= LTTNG_DOMAIN_UST
;
3131 channel
= lttng_channel_create(&domain
);
3137 for (channel_attr_node
= xmlFirstElementChild(node
);
3138 channel_attr_node
; channel_attr_node
=
3139 xmlNextElementSibling(channel_attr_node
)) {
3140 ret
= process_channel_attr_node(channel_attr_node
,
3141 channel
, &contexts_node
, &events_node
);
3147 ret
= lttng_enable_channel(handle
, channel
);
3152 /* Restore the original channel domain. */
3153 domain
.type
= original_domain
;
3155 ret
= process_events_node(events_node
, handle
, channel
->name
);
3160 ret
= process_contexts_node(contexts_node
, handle
,
3166 lttng_channel_destroy(channel
);
3170 /* get the trackers node */
3171 for (node
= xmlFirstElementChild(domain_node
); node
;
3172 node
= xmlNextElementSibling(node
)) {
3173 if (!strcmp((const char *) node
->name
,
3174 config_element_process_attr_trackers
) ||
3175 !strcmp((const char *) node
->name
,
3176 config_element_trackers_legacy
)) {
3177 if (trackers_node
) {
3178 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3179 config_element_process_attr_trackers
,
3180 config_element_trackers_legacy
);
3184 trackers_node
= node
;
3189 if (!trackers_node
) {
3193 for (node
= xmlFirstElementChild(trackers_node
); node
;
3194 node
= xmlNextElementSibling(node
)) {
3195 if (!strcmp((const char *) node
->name
,
3196 config_element_process_attr_tracker_pid
)) {
3197 pid_tracker_node
= node
;
3198 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3199 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3204 if (!strcmp((const char *) node
->name
,
3205 config_element_process_attr_tracker_vpid
)) {
3206 vpid_tracker_node
= node
;
3207 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3208 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3213 if (!strcmp((const char *) node
->name
,
3214 config_element_process_attr_tracker_uid
)) {
3215 uid_tracker_node
= node
;
3216 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3217 LTTNG_PROCESS_ATTR_USER_ID
);
3222 if (!strcmp((const char *) node
->name
,
3223 config_element_process_attr_tracker_vuid
)) {
3224 vuid_tracker_node
= node
;
3225 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3226 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3231 if (!strcmp((const char *) node
->name
,
3232 config_element_process_attr_tracker_gid
)) {
3233 gid_tracker_node
= node
;
3234 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3235 LTTNG_PROCESS_ATTR_GROUP_ID
);
3240 if (!strcmp((const char *) node
->name
,
3241 config_element_process_attr_tracker_vgid
)) {
3242 vgid_tracker_node
= node
;
3243 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3244 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3249 if (!strcmp((const char *) node
->name
,
3250 config_element_pid_tracker_legacy
)) {
3251 ret
= process_legacy_pid_tracker_node(node
, handle
);
3259 lttng_channel_destroy(channel
);
3260 lttng_destroy_handle(handle
);
3265 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3268 enum lttng_rotation_status status
;
3269 struct lttng_rotation_schedule
*periodic
=
3270 lttng_rotation_schedule_periodic_create();
3273 ret
= -LTTNG_ERR_NOMEM
;
3277 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3279 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3280 ret
= -LTTNG_ERR_INVALID
;
3284 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3286 case LTTNG_ROTATION_STATUS_OK
:
3289 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3290 case LTTNG_ROTATION_STATUS_INVALID
:
3291 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3294 ret
= -LTTNG_ERR_UNK
;
3298 lttng_rotation_schedule_destroy(periodic
);
3303 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3306 enum lttng_rotation_status status
;
3307 struct lttng_rotation_schedule
*size
=
3308 lttng_rotation_schedule_size_threshold_create();
3311 ret
= -LTTNG_ERR_NOMEM
;
3315 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3317 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3318 ret
= -LTTNG_ERR_INVALID
;
3322 status
= lttng_session_add_rotation_schedule(name
, size
);
3324 case LTTNG_ROTATION_STATUS_OK
:
3327 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3328 case LTTNG_ROTATION_STATUS_INVALID
:
3329 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3332 ret
= -LTTNG_ERR_UNK
;
3336 lttng_rotation_schedule_destroy(size
);
3341 int process_session_rotation_schedules_node(
3342 xmlNodePtr schedules_node
,
3343 uint64_t *rotation_timer_interval
,
3344 uint64_t *rotation_size
)
3349 for (child
= xmlFirstElementChild(schedules_node
);
3351 child
= xmlNextElementSibling(child
)) {
3352 if (!strcmp((const char *) child
->name
,
3353 config_element_rotation_schedule_periodic
)) {
3355 xmlNodePtr time_us_node
;
3357 /* periodic rotation schedule */
3358 time_us_node
= xmlFirstElementChild(child
);
3359 if (!time_us_node
||
3360 strcmp((const char *) time_us_node
->name
,
3361 config_element_rotation_schedule_periodic_time_us
)) {
3362 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3367 content
= xmlNodeGetContent(time_us_node
);
3369 ret
= -LTTNG_ERR_NOMEM
;
3372 ret
= parse_uint(content
, rotation_timer_interval
);
3375 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3378 } else if (!strcmp((const char *) child
->name
,
3379 config_element_rotation_schedule_size_threshold
)) {
3381 xmlNodePtr bytes_node
;
3383 /* size_threshold rotation schedule */
3384 bytes_node
= xmlFirstElementChild(child
);
3386 strcmp((const char *) bytes_node
->name
,
3387 config_element_rotation_schedule_size_threshold_bytes
)) {
3388 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3393 content
= xmlNodeGetContent(bytes_node
);
3395 ret
= -LTTNG_ERR_NOMEM
;
3398 ret
= parse_uint(content
, rotation_size
);
3401 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3412 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3414 const struct config_load_session_override_attr
*overrides
)
3416 int ret
, started
= -1, snapshot_mode
= -1;
3417 uint64_t live_timer_interval
= UINT64_MAX
,
3418 rotation_timer_interval
= 0,
3420 xmlChar
*name
= NULL
;
3421 xmlChar
*shm_path
= NULL
;
3422 xmlNodePtr domains_node
= NULL
;
3423 xmlNodePtr output_node
= NULL
;
3425 xmlNodePtr attributes_child
;
3426 struct lttng_domain
*kernel_domain
= NULL
;
3427 struct lttng_domain
*ust_domain
= NULL
;
3428 struct lttng_domain
*jul_domain
= NULL
;
3429 struct lttng_domain
*log4j_domain
= NULL
;
3430 struct lttng_domain
*python_domain
= NULL
;
3432 for (node
= xmlFirstElementChild(session_node
); node
;
3433 node
= xmlNextElementSibling(node
)) {
3434 if (!name
&& !strcmp((const char *) node
->name
,
3435 config_element_name
)) {
3437 xmlChar
*node_content
= xmlNodeGetContent(node
);
3438 if (!node_content
) {
3439 ret
= -LTTNG_ERR_NOMEM
;
3443 name
= node_content
;
3444 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3445 config_element_domains
)) {
3447 domains_node
= node
;
3448 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3449 config_element_started
)) {
3451 xmlChar
*node_content
= xmlNodeGetContent(node
);
3452 if (!node_content
) {
3453 ret
= -LTTNG_ERR_NOMEM
;
3457 ret
= parse_bool(node_content
, &started
);
3460 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3463 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3464 config_element_output
)) {
3467 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3468 config_element_shared_memory_path
)) {
3469 /* shared memory path */
3470 xmlChar
*node_content
= xmlNodeGetContent(node
);
3471 if (!node_content
) {
3472 ret
= -LTTNG_ERR_NOMEM
;
3476 shm_path
= node_content
;
3479 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3480 * rotation_timer_interval.
3482 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3483 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3484 if (!strcmp((const char *) attributes_child
->name
,
3485 config_element_snapshot_mode
)) {
3487 xmlChar
*snapshot_mode_content
=
3488 xmlNodeGetContent(attributes_child
);
3489 if (!snapshot_mode_content
) {
3490 ret
= -LTTNG_ERR_NOMEM
;
3494 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3495 free(snapshot_mode_content
);
3497 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3500 } else if (!strcmp((const char *) attributes_child
->name
,
3501 config_element_live_timer_interval
)) {
3502 /* live_timer_interval */
3503 xmlChar
*timer_interval_content
=
3504 xmlNodeGetContent(attributes_child
);
3505 if (!timer_interval_content
) {
3506 ret
= -LTTNG_ERR_NOMEM
;
3510 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3511 free(timer_interval_content
);
3513 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3516 } else if (!strcmp((const char *) attributes_child
->name
,
3517 config_element_rotation_schedules
)) {
3518 ret
= process_session_rotation_schedules_node(
3520 &rotation_timer_interval
,
3523 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3533 /* Mandatory attribute, as defined in the session XSD */
3534 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3538 if (session_name
&& strcmp((char *) name
, session_name
)) {
3539 /* This is not the session we are looking for */
3540 ret
= -LTTNG_ERR_NO_SESSION
;
3544 /* Init domains to create the session handles */
3545 for (node
= xmlFirstElementChild(domains_node
); node
;
3546 node
= xmlNextElementSibling(node
)) {
3547 struct lttng_domain
*domain
;
3549 domain
= zmalloc(sizeof(*domain
));
3551 ret
= -LTTNG_ERR_NOMEM
;
3555 ret
= init_domain(node
, domain
);
3557 goto domain_init_error
;
3560 switch (domain
->type
) {
3561 case LTTNG_DOMAIN_KERNEL
:
3562 if (kernel_domain
) {
3563 /* Same domain seen twice, invalid! */
3564 goto domain_init_error
;
3566 kernel_domain
= domain
;
3568 case LTTNG_DOMAIN_UST
:
3570 /* Same domain seen twice, invalid! */
3571 goto domain_init_error
;
3573 ust_domain
= domain
;
3575 case LTTNG_DOMAIN_JUL
:
3577 /* Same domain seen twice, invalid! */
3578 goto domain_init_error
;
3580 jul_domain
= domain
;
3582 case LTTNG_DOMAIN_LOG4J
:
3584 /* Same domain seen twice, invalid! */
3585 goto domain_init_error
;
3587 log4j_domain
= domain
;
3589 case LTTNG_DOMAIN_PYTHON
:
3590 if (python_domain
) {
3591 /* Same domain seen twice, invalid! */
3592 goto domain_init_error
;
3594 python_domain
= domain
;
3597 WARN("Invalid domain type");
3598 goto domain_init_error
;
3603 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3607 /* Apply overrides */
3609 if (overrides
->session_name
) {
3610 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3611 if (!name_override
) {
3612 ret
= -LTTNG_ERR_NOMEM
;
3616 /* Overrides the session name to the provided name */
3618 name
= name_override
;
3623 /* Destroy session if it exists */
3624 ret
= lttng_destroy_session((const char *) name
);
3625 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3626 ERR("Failed to destroy existing session.");
3631 /* Create session type depending on output type */
3632 if (snapshot_mode
&& snapshot_mode
!= -1) {
3633 ret
= create_snapshot_session((const char *) name
, output_node
,
3635 } else if (live_timer_interval
&&
3636 live_timer_interval
!= UINT64_MAX
) {
3637 ret
= create_session((const char *) name
,
3638 output_node
, live_timer_interval
, overrides
);
3640 /* regular session */
3641 ret
= create_session((const char *) name
,
3642 output_node
, UINT64_MAX
, overrides
);
3649 ret
= lttng_set_session_shm_path((const char *) name
,
3650 (const char *) shm_path
);
3656 for (node
= xmlFirstElementChild(domains_node
); node
;
3657 node
= xmlNextElementSibling(node
)) {
3658 ret
= process_domain_node(node
, (const char *) name
);
3664 if (rotation_timer_interval
) {
3665 ret
= add_periodic_rotation((const char *) name
,
3666 rotation_timer_interval
);
3671 if (rotation_size
) {
3672 ret
= add_size_rotation((const char *) name
,
3680 ret
= lttng_start_tracing((const char *) name
);
3688 ERR("Failed to load session %s: %s", (const char *) name
,
3689 lttng_strerror(ret
));
3690 lttng_destroy_session((const char *) name
);
3694 free(kernel_domain
);
3698 free(python_domain
);
3705 * Return 1 if the given path is readable by the current UID or 0 if not.
3706 * Return -1 if the path is EPERM.
3708 static int validate_file_read_creds(const char *path
)
3714 /* Can we read the file. */
3715 ret
= access(path
, R_OK
);
3719 if (errno
== EACCES
) {
3730 int load_session_from_file(const char *path
, const char *session_name
,
3731 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3732 const struct config_load_session_override_attr
*overrides
)
3734 int ret
, session_found
= !session_name
;
3735 xmlDocPtr doc
= NULL
;
3736 xmlNodePtr sessions_node
;
3737 xmlNodePtr session_node
;
3740 assert(validation_ctx
);
3742 ret
= validate_file_read_creds(path
);
3745 ret
= -LTTNG_ERR_EPERM
;
3747 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3752 doc
= xmlParseFile(path
);
3754 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3758 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3760 ERR("Session configuration file validation failed");
3761 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3765 sessions_node
= xmlDocGetRootElement(doc
);
3766 if (!sessions_node
) {
3767 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3771 for (session_node
= xmlFirstElementChild(sessions_node
);
3772 session_node
; session_node
=
3773 xmlNextElementSibling(session_node
)) {
3774 ret
= process_session_node(session_node
,
3775 session_name
, overwrite
, overrides
);
3776 if (!session_name
&& ret
) {
3777 /* Loading error occurred. */
3779 } else if (session_name
) {
3781 /* Target session found and loaded */
3784 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3786 * Ignore this error, we are looking for a
3791 /* Loading error occurred. */
3799 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3805 int load_session_from_path(const char *path
, const char *session_name
,
3806 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3807 const struct config_load_session_override_attr
*overrides
)
3809 int ret
, session_found
= !session_name
;
3810 DIR *directory
= NULL
;
3811 struct lttng_dynamic_buffer file_path
;
3815 assert(validation_ctx
);
3816 path_len
= strlen(path
);
3817 lttng_dynamic_buffer_init(&file_path
);
3818 if (path_len
>= LTTNG_PATH_MAX
) {
3819 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3820 path
, path_len
, LTTNG_PATH_MAX
);
3821 ret
= -LTTNG_ERR_INVALID
;
3825 directory
= opendir(path
);
3829 /* Try the file loading. */
3832 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3835 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3840 size_t file_path_root_len
;
3842 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3845 ret
= -LTTNG_ERR_NOMEM
;
3849 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3851 ret
= -LTTNG_ERR_NOMEM
;
3855 if (file_path
.data
[file_path
.size
- 1] != '/') {
3856 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3858 ret
= -LTTNG_ERR_NOMEM
;
3862 file_path_root_len
= file_path
.size
;
3864 /* Search for *.lttng files */
3866 size_t file_name_len
;
3867 struct dirent
*result
;
3870 * When the end of the directory stream is reached, NULL
3871 * is returned and errno is kept unchanged. When an
3872 * error occurs, NULL is returned and errno is set
3873 * accordingly. To distinguish between the two, set
3874 * errno to zero before calling readdir().
3876 * On success, readdir() returns a pointer to a dirent
3877 * structure. This structure may be statically
3878 * allocated, do not attempt to free(3) it.
3881 result
= readdir(directory
);
3883 /* Reached end of dir stream or error out. */
3886 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3887 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3893 file_name_len
= strlen(result
->d_name
);
3895 if (file_name_len
<=
3896 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3900 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3901 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3903 /* +1 to account for NULL terminator. */
3904 file_path
.size
+ file_name_len
+ 1,
3909 /* Does the file end with .lttng? */
3910 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3911 result
->d_name
+ file_name_len
- sizeof(
3912 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3916 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3919 ret
= -LTTNG_ERR_NOMEM
;
3923 ret
= load_session_from_file(file_path
.data
, session_name
,
3924 validation_ctx
, overwrite
, overrides
);
3926 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3930 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3934 * Reset the buffer's size to the location of the
3935 * path's trailing '/'.
3937 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3938 file_path_root_len
);
3940 ret
= -LTTNG_ERR_UNK
;
3945 ret
= load_session_from_file(path
, session_name
,
3946 validation_ctx
, overwrite
, overrides
);
3956 if (closedir(directory
)) {
3960 if (!ret
&& !session_found
) {
3961 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3963 lttng_dynamic_buffer_reset(&file_path
);
3968 * Validate that the given path's credentials and the current process have the
3969 * same UID. If so, return 1 else return 0 if it does NOT match.
3971 static int validate_path_creds(const char *path
)
3973 int ret
, uid
= getuid();
3982 ret
= stat(path
, &buf
);
3984 if (errno
!= ENOENT
) {
3990 if (buf
.st_uid
!= uid
) {
4001 int config_load_session(const char *path
, const char *session_name
,
4002 int overwrite
, unsigned int autoload
,
4003 const struct config_load_session_override_attr
*overrides
)
4006 bool session_loaded
= false;
4007 const char *path_ptr
= NULL
;
4008 struct session_config_validation_ctx validation_ctx
= { 0 };
4010 ret
= init_session_config_validation_ctx(&validation_ctx
);
4016 const char *home_path
;
4017 const char *sys_path
;
4020 home_path
= utils_get_home_dir();
4022 char path_buf
[PATH_MAX
];
4025 * Try user session configuration path. Ignore error here so we can
4026 * continue loading the system wide sessions.
4029 ret
= snprintf(path_buf
, sizeof(path_buf
),
4030 DEFAULT_SESSION_HOME_CONFIGPATH
4031 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
4034 PERROR("snprintf session autoload home config path");
4035 ret
= -LTTNG_ERR_INVALID
;
4040 * Credentials are only validated for the autoload in order to
4041 * avoid any user session daemon to try to load kernel sessions
4042 * automatically and failing all the times.
4044 ret
= validate_path_creds(path_buf
);
4046 path_ptr
= path_buf
;
4049 ret
= snprintf(path_buf
, sizeof(path_buf
),
4050 DEFAULT_SESSION_HOME_CONFIGPATH
,
4053 PERROR("snprintf session home config path");
4054 ret
= -LTTNG_ERR_INVALID
;
4057 path_ptr
= path_buf
;
4060 ret
= load_session_from_path(path_ptr
, session_name
,
4061 &validation_ctx
, overwrite
, overrides
);
4062 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4066 * Continue even if the session was found since we have to try
4067 * the system wide sessions.
4069 session_loaded
= true;
4073 /* Reset path pointer for the system wide dir. */
4076 /* Try system wide configuration directory. */
4078 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4079 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4080 ret
= validate_path_creds(sys_path
);
4082 path_ptr
= sys_path
;
4085 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4086 path_ptr
= sys_path
;
4090 ret
= load_session_from_path(path_ptr
, session_name
,
4091 &validation_ctx
, overwrite
, overrides
);
4093 session_loaded
= true;
4099 ret
= access(path
, F_OK
);
4104 ret
= -LTTNG_ERR_INVALID
;
4105 WARN("Session configuration path does not exist.");
4108 ret
= -LTTNG_ERR_EPERM
;
4111 ret
= -LTTNG_ERR_UNK
;
4117 ret
= load_session_from_path(path
, session_name
,
4118 &validation_ctx
, overwrite
, overrides
);
4121 fini_session_config_validation_ctx(&validation_ctx
);
4122 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4124 * Don't report an error if no sessions are found when called
4125 * without a session_name or a search path.
4130 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4131 /* A matching session was found in one of the search paths. */
4138 void __attribute__((destructor
)) session_config_exit(void)