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
)) {
848 } else if (!strcmp((const char *) str
, config_xml_false
)) {
851 WARN("Invalid boolean value encountered (%s).",
860 int get_domain_type(xmlChar
*domain
)
868 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
869 ret
= LTTNG_DOMAIN_KERNEL
;
870 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
871 ret
= LTTNG_DOMAIN_UST
;
872 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
873 ret
= LTTNG_DOMAIN_JUL
;
874 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
875 ret
= LTTNG_DOMAIN_LOG4J
;
876 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
877 ret
= LTTNG_DOMAIN_PYTHON
;
888 int get_buffer_type(xmlChar
*buffer_type
)
896 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
897 ret
= LTTNG_BUFFER_GLOBAL
;
898 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
899 ret
= LTTNG_BUFFER_PER_UID
;
900 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
901 ret
= LTTNG_BUFFER_PER_PID
;
912 int get_overwrite_mode(xmlChar
*overwrite_mode
)
916 if (!overwrite_mode
) {
920 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
922 } else if (!strcmp((char *) overwrite_mode
,
923 config_overwrite_mode_discard
)) {
935 int get_output_type(xmlChar
*output_type
)
943 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
944 ret
= LTTNG_EVENT_MMAP
;
945 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
946 ret
= LTTNG_EVENT_SPLICE
;
957 int get_event_type(xmlChar
*event_type
)
965 if (!strcmp((char *) event_type
, config_event_type_all
)) {
966 ret
= LTTNG_EVENT_ALL
;
967 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
968 ret
= LTTNG_EVENT_TRACEPOINT
;
969 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
970 ret
= LTTNG_EVENT_PROBE
;
971 } else if (!strcmp((char *) event_type
,
972 config_event_type_userspace_probe
)) {
973 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
974 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
975 ret
= LTTNG_EVENT_FUNCTION
;
976 } else if (!strcmp((char *) event_type
,
977 config_event_type_function_entry
)) {
978 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
979 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
980 ret
= LTTNG_EVENT_NOOP
;
981 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
982 ret
= LTTNG_EVENT_SYSCALL
;
993 int get_loglevel_type(xmlChar
*loglevel_type
)
997 if (!loglevel_type
) {
1001 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1002 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1003 } else if (!strcmp((char *) loglevel_type
,
1004 config_loglevel_type_range
)) {
1005 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1006 } else if (!strcmp((char *) loglevel_type
,
1007 config_loglevel_type_single
)) {
1008 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1019 * Return the context type or -1 on error.
1022 int get_context_type(xmlChar
*context_type
)
1026 if (!context_type
) {
1030 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1031 ret
= LTTNG_EVENT_CONTEXT_PID
;
1032 } else if (!strcmp((char *) context_type
,
1033 config_event_context_procname
)) {
1034 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1035 } else if (!strcmp((char *) context_type
,
1036 config_event_context_prio
)) {
1037 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1038 } else if (!strcmp((char *) context_type
,
1039 config_event_context_nice
)) {
1040 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1041 } else if (!strcmp((char *) context_type
,
1042 config_event_context_vpid
)) {
1043 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1044 } else if (!strcmp((char *) context_type
,
1045 config_event_context_tid
)) {
1046 ret
= LTTNG_EVENT_CONTEXT_TID
;
1047 } else if (!strcmp((char *) context_type
,
1048 config_event_context_vtid
)) {
1049 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1050 } else if (!strcmp((char *) context_type
,
1051 config_event_context_ppid
)) {
1052 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1053 } else if (!strcmp((char *) context_type
,
1054 config_event_context_vppid
)) {
1055 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1056 } else if (!strcmp((char *) context_type
,
1057 config_event_context_pthread_id
)) {
1058 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1059 } else if (!strcmp((char *) context_type
,
1060 config_event_context_hostname
)) {
1061 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1062 } else if (!strcmp((char *) context_type
,
1063 config_event_context_ip
)) {
1064 ret
= LTTNG_EVENT_CONTEXT_IP
;
1065 } else if (!strcmp((char *) context_type
,
1066 config_event_context_interruptible
)) {
1067 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1068 } else if (!strcmp((char *) context_type
,
1069 config_event_context_preemptible
)) {
1070 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1071 } else if (!strcmp((char *) context_type
,
1072 config_event_context_need_reschedule
)) {
1073 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1074 } else if (!strcmp((char *) context_type
,
1075 config_event_context_migratable
)) {
1076 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1077 } else if (!strcmp((char *) context_type
,
1078 config_event_context_callstack_user
)) {
1079 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1080 } else if (!strcmp((char *) context_type
,
1081 config_event_context_callstack_kernel
)) {
1082 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1083 } else if (!strcmp((char *) context_type
,
1084 config_event_context_cgroup_ns
)) {
1085 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1086 } else if (!strcmp((char *) context_type
,
1087 config_event_context_ipc_ns
)) {
1088 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1089 } else if (!strcmp((char *) context_type
,
1090 config_event_context_mnt_ns
)) {
1091 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1092 } else if (!strcmp((char *) context_type
,
1093 config_event_context_net_ns
)) {
1094 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1095 } else if (!strcmp((char *) context_type
,
1096 config_event_context_pid_ns
)) {
1097 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1098 } else if (!strcmp((char *) context_type
,
1099 config_event_context_time_ns
)) {
1100 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1101 } else if (!strcmp((char *) context_type
,
1102 config_event_context_user_ns
)) {
1103 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1104 } else if (!strcmp((char *) context_type
,
1105 config_event_context_uts_ns
)) {
1106 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1107 } else if (!strcmp((char *) context_type
,
1108 config_event_context_uid
)) {
1109 ret
= LTTNG_EVENT_CONTEXT_UID
;
1110 } else if (!strcmp((char *) context_type
,
1111 config_event_context_euid
)) {
1112 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1113 } else if (!strcmp((char *) context_type
,
1114 config_event_context_suid
)) {
1115 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1116 } else if (!strcmp((char *) context_type
,
1117 config_event_context_gid
)) {
1118 ret
= LTTNG_EVENT_CONTEXT_GID
;
1119 } else if (!strcmp((char *) context_type
,
1120 config_event_context_egid
)) {
1121 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1122 } else if (!strcmp((char *) context_type
,
1123 config_event_context_sgid
)) {
1124 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1125 } else if (!strcmp((char *) context_type
,
1126 config_event_context_vuid
)) {
1127 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1128 } else if (!strcmp((char *) context_type
,
1129 config_event_context_veuid
)) {
1130 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1131 } else if (!strcmp((char *) context_type
,
1132 config_event_context_vsuid
)) {
1133 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1134 } else if (!strcmp((char *) context_type
,
1135 config_event_context_vgid
)) {
1136 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1137 } else if (!strcmp((char *) context_type
,
1138 config_event_context_vegid
)) {
1139 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1140 } else if (!strcmp((char *) context_type
,
1141 config_event_context_vsgid
)) {
1142 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1153 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1158 for (node
= xmlFirstElementChild(domain_node
); node
;
1159 node
= xmlNextElementSibling(node
)) {
1160 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1162 xmlChar
*node_content
= xmlNodeGetContent(node
);
1163 if (!node_content
) {
1164 ret
= -LTTNG_ERR_NOMEM
;
1168 ret
= get_domain_type(node_content
);
1171 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1176 } else if (!strcmp((const char *) node
->name
,
1177 config_element_buffer_type
)) {
1179 xmlChar
*node_content
= xmlNodeGetContent(node
);
1180 if (!node_content
) {
1181 ret
= -LTTNG_ERR_NOMEM
;
1185 ret
= get_buffer_type(node_content
);
1188 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1192 domain
->buf_type
= ret
;
1201 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1206 for (node
= xmlFirstElementChild(net_output_node
); node
;
1207 node
= xmlNextElementSibling(node
)) {
1208 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1210 *control_uri
= (char *) xmlNodeGetContent(node
);
1211 if (!*control_uri
) {
1216 *data_uri
= (char *) xmlNodeGetContent(node
);
1223 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1227 int process_consumer_output(xmlNodePtr consumer_output_node
,
1228 struct consumer_output
*output
)
1235 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1236 node
= xmlNextElementSibling(node
)) {
1237 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1238 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1242 ret
= -LTTNG_ERR_NOMEM
;
1246 ret
= parse_bool(enabled_str
, &output
->enabled
);
1252 xmlNodePtr output_type_node
;
1255 output_type_node
= xmlFirstElementChild(node
);
1256 if (!output_type_node
) {
1257 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1261 if (!strcmp((const char *) output_type_node
->name
,
1262 config_element_path
)) {
1264 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1265 if (!output
->path
) {
1266 ret
= -LTTNG_ERR_NOMEM
;
1271 ret
= get_net_output_uris(output_type_node
,
1272 &output
->control_uri
, &output
->data_uri
);
1284 free(output
->control_uri
);
1285 free(output
->data_uri
);
1286 memset(output
, 0, sizeof(struct consumer_output
));
1292 int create_session_net_output(const char *name
, const char *control_uri
,
1293 const char *data_uri
)
1296 struct lttng_handle
*handle
;
1297 const char *uri
= NULL
;
1301 handle
= lttng_create_handle(name
, NULL
);
1303 ret
= -LTTNG_ERR_NOMEM
;
1307 if (!control_uri
|| !data_uri
) {
1308 uri
= control_uri
? control_uri
: data_uri
;
1313 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1314 lttng_destroy_handle(handle
);
1320 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1321 const struct config_load_session_override_attr
*overrides
)
1324 xmlNodePtr node
= NULL
;
1325 xmlNodePtr snapshot_output_list_node
;
1326 xmlNodePtr snapshot_output_node
;
1328 assert(session_name
);
1330 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1339 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1341 /* Parse and create snapshot outputs */
1343 for (snapshot_output_node
=
1344 xmlFirstElementChild(snapshot_output_list_node
);
1345 snapshot_output_node
; snapshot_output_node
=
1346 xmlNextElementSibling(snapshot_output_node
)) {
1348 uint64_t max_size
= UINT64_MAX
;
1349 struct consumer_output output
= { 0 };
1350 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1351 const char *control_uri
= NULL
;
1352 const char *data_uri
= NULL
;
1353 const char *path
= NULL
;
1355 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1356 node
= xmlNextElementSibling(node
)) {
1357 if (!strcmp((const char *) node
->name
,
1358 config_element_name
)) {
1360 name
= (char *) xmlNodeGetContent(node
);
1362 ret
= -LTTNG_ERR_NOMEM
;
1363 goto error_snapshot_output
;
1365 } else if (!strcmp((const char *) node
->name
,
1366 config_element_max_size
)) {
1367 xmlChar
*content
= xmlNodeGetContent(node
);
1371 ret
= -LTTNG_ERR_NOMEM
;
1372 goto error_snapshot_output
;
1374 ret
= parse_uint(content
, &max_size
);
1377 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1378 goto error_snapshot_output
;
1381 /* consumer_output */
1382 ret
= process_consumer_output(node
, &output
);
1384 goto error_snapshot_output
;
1389 control_uri
= output
.control_uri
;
1390 data_uri
= output
.data_uri
;
1394 if (overrides
->path_url
) {
1395 path
= overrides
->path_url
;
1396 /* Control/data_uri are null */
1400 if (overrides
->ctrl_url
) {
1401 control_uri
= overrides
->ctrl_url
;
1405 if (overrides
->data_url
) {
1406 data_uri
= overrides
->data_url
;
1413 snapshot_output
= lttng_snapshot_output_create();
1414 if (!snapshot_output
) {
1415 ret
= -LTTNG_ERR_NOMEM
;
1416 goto error_snapshot_output
;
1419 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1421 goto error_snapshot_output
;
1424 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1426 goto error_snapshot_output
;
1430 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1433 goto error_snapshot_output
;
1437 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1440 goto error_snapshot_output
;
1445 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1448 goto error_snapshot_output
;
1453 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1454 error_snapshot_output
:
1457 free(output
.control_uri
);
1458 free(output
.data_uri
);
1459 lttng_snapshot_output_destroy(snapshot_output
);
1469 int create_session(const char *name
,
1470 xmlNodePtr output_node
,
1471 uint64_t live_timer_interval
,
1472 const struct config_load_session_override_attr
*overrides
)
1475 struct consumer_output output
= { 0 };
1476 xmlNodePtr consumer_output_node
;
1477 const char *control_uri
= NULL
;
1478 const char *data_uri
= NULL
;
1479 const char *path
= NULL
;
1484 consumer_output_node
= xmlFirstElementChild(output_node
);
1485 if (!consumer_output_node
) {
1486 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1490 if (strcmp((const char *) consumer_output_node
->name
,
1491 config_element_consumer_output
)) {
1492 WARN("Invalid output type, expected %s node",
1493 config_element_consumer_output
);
1494 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1498 ret
= process_consumer_output(consumer_output_node
, &output
);
1504 control_uri
= output
.control_uri
;
1505 data_uri
= output
.data_uri
;
1508 /* Check for override and apply them */
1510 if (overrides
->path_url
) {
1511 path
= overrides
->path_url
;
1512 /* control/data_uri are null */;
1516 if (overrides
->ctrl_url
) {
1517 control_uri
= overrides
->ctrl_url
;
1521 if (overrides
->data_url
) {
1522 data_uri
= overrides
->data_url
;
1530 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1531 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1535 if (control_uri
|| data_uri
) {
1536 /* network destination */
1537 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1539 * URLs are provided for sure since the test above make sure that
1540 * with a live timer the data and control URIs are provided. So,
1541 * NULL is passed here and will be set right after.
1543 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1545 ret
= lttng_create_session(name
, NULL
);
1551 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1557 /* either local output or no output */
1558 ret
= lttng_create_session(name
, path
);
1565 free(output
.control_uri
);
1566 free(output
.data_uri
);
1571 struct lttng_userspace_probe_location
*
1572 process_userspace_probe_function_attribute_node(
1573 xmlNodePtr attribute_node
)
1575 xmlNodePtr function_attribute_node
;
1576 char *function_name
= NULL
, *binary_path
= NULL
;
1577 struct lttng_userspace_probe_location
*location
= NULL
;
1578 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1581 * Process userspace probe location function attributes. The order of
1582 * the fields are not guaranteed so we need to iterate over all fields
1583 * and check at the end if everything we need for this location type is
1586 for (function_attribute_node
=
1587 xmlFirstElementChild(attribute_node
);
1588 function_attribute_node
;
1589 function_attribute_node
= xmlNextElementSibling(
1590 function_attribute_node
)) {
1591 /* Handle function name, binary path and lookup method. */
1592 if (!strcmp((const char *) function_attribute_node
->name
,
1593 config_element_userspace_probe_function_location_function_name
)) {
1594 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1595 if (!function_name
) {
1598 } else if (!strcmp((const char *) function_attribute_node
->name
,
1599 config_element_userspace_probe_location_binary_path
)) {
1600 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1604 } else if (!strcmp((const char *) function_attribute_node
->name
,
1605 config_element_userspace_probe_lookup
)) {
1606 char *lookup_method_name
;
1608 lookup_method_name
= (char *) xmlNodeGetContent(
1609 function_attribute_node
);
1610 if (!lookup_method_name
) {
1615 * function_default lookup method defaults to
1616 * function_elf lookup method at the moment.
1618 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1619 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1620 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1621 if (!lookup_method
) {
1622 PERROR("Error creating function default/ELF lookup method");
1625 WARN("Unknown function lookup method");
1628 free(lookup_method_name
);
1629 if (!lookup_method
) {
1636 /* Check if all the necessary fields were found. */
1637 if (binary_path
&& function_name
&& lookup_method
) {
1638 /* Ownership of lookup_method is transferred. */
1640 lttng_userspace_probe_location_function_create(
1641 binary_path
, function_name
,
1643 lookup_method
= NULL
;
1648 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1650 free(function_name
);
1655 struct lttng_userspace_probe_location
*
1656 process_userspace_probe_tracepoint_attribute_node(
1657 xmlNodePtr attribute_node
)
1659 xmlNodePtr tracepoint_attribute_node
;
1660 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1661 struct lttng_userspace_probe_location
*location
= NULL
;
1662 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1665 * Process userspace probe location tracepoint attributes. The order of
1666 * the fields are not guaranteed so we need to iterate over all fields
1667 * and check at the end if everything we need for this location type is
1670 for (tracepoint_attribute_node
=
1671 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1672 tracepoint_attribute_node
= xmlNextElementSibling(
1673 tracepoint_attribute_node
)) {
1674 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1675 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1676 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1680 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1681 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1682 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1683 if (!provider_name
) {
1686 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1687 config_element_userspace_probe_location_binary_path
)) {
1688 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1692 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1693 config_element_userspace_probe_lookup
)) {
1694 char *lookup_method_name
;
1696 lookup_method_name
= (char *) xmlNodeGetContent(
1697 tracepoint_attribute_node
);
1698 if (!lookup_method_name
) {
1702 if (!strcmp(lookup_method_name
,
1703 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1705 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1706 if (!lookup_method
) {
1707 PERROR("Error creating tracepoint SDT lookup method");
1710 WARN("Unknown tracepoint lookup method");
1713 free(lookup_method_name
);
1714 if (!lookup_method
) {
1718 WARN("Unknown tracepoint attribute");
1722 /* Check if all the necessary fields were found. */
1723 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1724 /* Ownership of lookup_method is transferred. */
1726 lttng_userspace_probe_location_tracepoint_create(
1727 binary_path
, provider_name
,
1728 probe_name
, lookup_method
);
1729 lookup_method
= NULL
;
1734 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1736 free(provider_name
);
1742 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1743 struct lttng_event_probe_attr
*attr
)
1747 assert(probe_attribute_node
);
1750 if (!strcmp((const char *) probe_attribute_node
->name
,
1751 config_element_address
)) {
1756 content
= xmlNodeGetContent(probe_attribute_node
);
1758 ret
= -LTTNG_ERR_NOMEM
;
1762 ret
= parse_uint(content
, &addr
);
1765 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1770 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1771 config_element_offset
)) {
1773 uint64_t offset
= 0;
1776 content
= xmlNodeGetContent(probe_attribute_node
);
1778 ret
= -LTTNG_ERR_NOMEM
;
1782 ret
= parse_uint(content
, &offset
);
1785 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1789 attr
->offset
= offset
;
1790 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1791 config_element_symbol_name
)) {
1795 content
= xmlNodeGetContent(probe_attribute_node
);
1797 ret
= -LTTNG_ERR_NOMEM
;
1801 ret
= lttng_strncpy(attr
->symbol_name
,
1802 (const char *) content
,
1803 LTTNG_SYMBOL_NAME_LEN
);
1805 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1806 (const char *) content
,
1807 strlen((const char *) content
),
1808 LTTNG_SYMBOL_NAME_LEN
);
1809 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1821 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1822 const char *channel_name
, const enum process_event_node_phase phase
)
1826 struct lttng_event
*event
;
1827 char **exclusions
= NULL
;
1828 unsigned long exclusion_count
= 0;
1829 char *filter_expression
= NULL
;
1833 assert(channel_name
);
1835 event
= lttng_event_create();
1837 ret
= -LTTNG_ERR_NOMEM
;
1841 /* Initialize default log level which varies by domain */
1842 switch (handle
->domain
.type
)
1844 case LTTNG_DOMAIN_JUL
:
1845 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1847 case LTTNG_DOMAIN_LOG4J
:
1848 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1850 case LTTNG_DOMAIN_PYTHON
:
1851 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1853 case LTTNG_DOMAIN_UST
:
1854 case LTTNG_DOMAIN_KERNEL
:
1855 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1861 for (node
= xmlFirstElementChild(event_node
); node
;
1862 node
= xmlNextElementSibling(node
)) {
1863 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1867 content
= xmlNodeGetContent(node
);
1869 ret
= -LTTNG_ERR_NOMEM
;
1873 ret
= lttng_strncpy(event
->name
,
1874 (const char *) content
,
1875 LTTNG_SYMBOL_NAME_LEN
);
1877 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1878 (const char *) content
,
1879 strlen((const char *) content
),
1880 LTTNG_SYMBOL_NAME_LEN
);
1881 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1886 } else if (!strcmp((const char *) node
->name
,
1887 config_element_enabled
)) {
1888 xmlChar
*content
= xmlNodeGetContent(node
);
1892 ret
= -LTTNG_ERR_NOMEM
;
1896 ret
= parse_bool(content
, &event
->enabled
);
1899 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1902 } else if (!strcmp((const char *) node
->name
,
1903 config_element_type
)) {
1904 xmlChar
*content
= xmlNodeGetContent(node
);
1908 ret
= -LTTNG_ERR_NOMEM
;
1912 ret
= get_event_type(content
);
1915 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1920 } else if (!strcmp((const char *) node
->name
,
1921 config_element_loglevel_type
)) {
1922 xmlChar
*content
= xmlNodeGetContent(node
);
1926 ret
= -LTTNG_ERR_NOMEM
;
1930 ret
= get_loglevel_type(content
);
1933 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1937 event
->loglevel_type
= ret
;
1938 } else if (!strcmp((const char *) node
->name
,
1939 config_element_loglevel
)) {
1941 int64_t loglevel
= 0;
1944 content
= xmlNodeGetContent(node
);
1946 ret
= -LTTNG_ERR_NOMEM
;
1950 ret
= parse_int(content
, &loglevel
);
1953 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1957 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1958 WARN("loglevel out of range.");
1959 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1963 event
->loglevel
= loglevel
;
1964 } else if (!strcmp((const char *) node
->name
,
1965 config_element_filter
)) {
1967 xmlNodeGetContent(node
);
1971 ret
= -LTTNG_ERR_NOMEM
;
1975 free(filter_expression
);
1976 filter_expression
= strdup((char *) content
);
1978 if (!filter_expression
) {
1979 ret
= -LTTNG_ERR_NOMEM
;
1982 } else if (!strcmp((const char *) node
->name
,
1983 config_element_exclusions
)) {
1984 xmlNodePtr exclusion_node
;
1985 int exclusion_index
= 0;
1990 * Exclusions has already been initialized,
1993 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1997 exclusion_count
= xmlChildElementCount(node
);
1998 if (!exclusion_count
) {
2002 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2004 exclusion_count
= 0;
2005 ret
= -LTTNG_ERR_NOMEM
;
2009 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2010 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2012 xmlNodeGetContent(exclusion_node
);
2015 ret
= -LTTNG_ERR_NOMEM
;
2019 exclusions
[exclusion_index
] = strdup((const char *) content
);
2021 if (!exclusions
[exclusion_index
]) {
2022 ret
= -LTTNG_ERR_NOMEM
;
2028 event
->exclusion
= 1;
2029 } else if (!strcmp((const char *) node
->name
,
2030 config_element_attributes
)) {
2031 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2034 if (!attribute_node
) {
2035 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2039 if (!strcmp((const char *) attribute_node
->name
,
2040 config_element_probe_attributes
)) {
2041 xmlNodePtr probe_attribute_node
;
2043 /* probe_attributes */
2044 for (probe_attribute_node
=
2045 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2046 probe_attribute_node
= xmlNextElementSibling(
2047 probe_attribute_node
)) {
2049 ret
= process_probe_attribute_node(probe_attribute_node
,
2050 &event
->attr
.probe
);
2055 } else if (!strcmp((const char *) attribute_node
->name
,
2056 config_element_function_attributes
)) {
2059 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2061 /* function_attributes */
2062 content
= xmlNodeGetContent(symbol_node
);
2064 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2068 sym_len
= strlen((char *) content
);
2069 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2070 WARN("Function name too long.");
2071 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2076 ret
= lttng_strncpy(
2077 event
->attr
.ftrace
.symbol_name
,
2078 (char *) content
, sym_len
);
2080 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2085 } else if (!strcmp((const char *) attribute_node
->name
,
2086 config_element_userspace_probe_tracepoint_attributes
)) {
2087 struct lttng_userspace_probe_location
*location
;
2089 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2091 WARN("Error processing userspace probe tracepoint attribute");
2092 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2095 ret
= lttng_event_set_userspace_probe_location(
2098 WARN("Error setting userspace probe location field");
2099 lttng_userspace_probe_location_destroy(
2101 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2104 } else if (!strcmp((const char *) attribute_node
->name
,
2105 config_element_userspace_probe_function_attributes
)) {
2106 struct lttng_userspace_probe_location
*location
;
2109 process_userspace_probe_function_attribute_node(
2112 WARN("Error processing userspace probe function attribute");
2113 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2117 ret
= lttng_event_set_userspace_probe_location(
2120 WARN("Error setting userspace probe location field");
2121 lttng_userspace_probe_location_destroy(
2123 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2127 /* Unknown event attribute. */
2128 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2134 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2135 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2136 filter_expression
, exclusion_count
, exclusions
);
2138 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2139 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2145 for (i
= 0; i
< exclusion_count
; i
++) {
2146 free(exclusions
[i
]);
2149 lttng_event_destroy(event
);
2151 free(filter_expression
);
2156 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2157 const char *channel_name
)
2160 struct lttng_event event
;
2163 assert(events_node
);
2165 assert(channel_name
);
2167 for (node
= xmlFirstElementChild(events_node
); node
;
2168 node
= xmlNextElementSibling(node
)) {
2169 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2176 * Disable all events to enable only the necessary events.
2177 * Limitations regarding lttng_disable_events and tuple descriptor
2178 * force this approach.
2180 memset(&event
, 0, sizeof(event
));
2181 event
.loglevel
= -1;
2182 event
.type
= LTTNG_EVENT_ALL
;
2183 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2188 for (node
= xmlFirstElementChild(events_node
); node
;
2189 node
= xmlNextElementSibling(node
)) {
2190 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2201 int process_channel_attr_node(xmlNodePtr attr_node
,
2202 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2203 xmlNodePtr
*events_node
)
2209 assert(contexts_node
);
2210 assert(events_node
);
2212 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2216 content
= xmlNodeGetContent(attr_node
);
2218 ret
= -LTTNG_ERR_NOMEM
;
2222 ret
= lttng_strncpy(channel
->name
,
2223 (const char *) content
,
2224 LTTNG_SYMBOL_NAME_LEN
);
2226 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2227 (const char *) content
,
2228 strlen((const char *) content
),
2229 LTTNG_SYMBOL_NAME_LEN
);
2230 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2235 } else if (!strcmp((const char *) attr_node
->name
,
2236 config_element_enabled
)) {
2241 content
= xmlNodeGetContent(attr_node
);
2243 ret
= -LTTNG_ERR_NOMEM
;
2247 ret
= parse_bool(content
, &enabled
);
2250 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2254 channel
->enabled
= enabled
;
2255 } else if (!strcmp((const char *) attr_node
->name
,
2256 config_element_overwrite_mode
)) {
2259 /* overwrite_mode */
2260 content
= xmlNodeGetContent(attr_node
);
2262 ret
= -LTTNG_ERR_NOMEM
;
2266 ret
= get_overwrite_mode(content
);
2269 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2273 channel
->attr
.overwrite
= ret
;
2274 } else if (!strcmp((const char *) attr_node
->name
,
2275 config_element_subbuf_size
)) {
2278 /* subbuffer_size */
2279 content
= xmlNodeGetContent(attr_node
);
2281 ret
= -LTTNG_ERR_NOMEM
;
2285 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2288 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2291 } else if (!strcmp((const char *) attr_node
->name
,
2292 config_element_num_subbuf
)) {
2295 /* subbuffer_count */
2296 content
= xmlNodeGetContent(attr_node
);
2298 ret
= -LTTNG_ERR_NOMEM
;
2302 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2305 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2308 } else if (!strcmp((const char *) attr_node
->name
,
2309 config_element_switch_timer_interval
)) {
2311 uint64_t switch_timer_interval
= 0;
2313 /* switch_timer_interval */
2314 content
= xmlNodeGetContent(attr_node
);
2316 ret
= -LTTNG_ERR_NOMEM
;
2320 ret
= parse_uint(content
, &switch_timer_interval
);
2323 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2327 if (switch_timer_interval
> UINT_MAX
) {
2328 WARN("switch_timer_interval out of range.");
2329 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2333 channel
->attr
.switch_timer_interval
=
2334 switch_timer_interval
;
2335 } else if (!strcmp((const char *) attr_node
->name
,
2336 config_element_read_timer_interval
)) {
2338 uint64_t read_timer_interval
= 0;
2340 /* read_timer_interval */
2341 content
= xmlNodeGetContent(attr_node
);
2343 ret
= -LTTNG_ERR_NOMEM
;
2347 ret
= parse_uint(content
, &read_timer_interval
);
2350 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2354 if (read_timer_interval
> UINT_MAX
) {
2355 WARN("read_timer_interval out of range.");
2356 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2360 channel
->attr
.read_timer_interval
=
2361 read_timer_interval
;
2362 } else if (!strcmp((const char *) attr_node
->name
,
2363 config_element_output_type
)) {
2367 content
= xmlNodeGetContent(attr_node
);
2369 ret
= -LTTNG_ERR_NOMEM
;
2373 ret
= get_output_type(content
);
2376 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2380 channel
->attr
.output
= ret
;
2381 } else if (!strcmp((const char *) attr_node
->name
,
2382 config_element_tracefile_size
)) {
2385 /* tracefile_size */
2386 content
= xmlNodeGetContent(attr_node
);
2388 ret
= -LTTNG_ERR_NOMEM
;
2392 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2395 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2398 } else if (!strcmp((const char *) attr_node
->name
,
2399 config_element_tracefile_count
)) {
2402 /* tracefile_count */
2403 content
= xmlNodeGetContent(attr_node
);
2405 ret
= -LTTNG_ERR_NOMEM
;
2409 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2412 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2415 } else if (!strcmp((const char *) attr_node
->name
,
2416 config_element_live_timer_interval
)) {
2418 uint64_t live_timer_interval
= 0;
2420 /* live_timer_interval */
2421 content
= xmlNodeGetContent(attr_node
);
2423 ret
= -LTTNG_ERR_NOMEM
;
2427 ret
= parse_uint(content
, &live_timer_interval
);
2430 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2434 if (live_timer_interval
> UINT_MAX
) {
2435 WARN("live_timer_interval out of range.");
2436 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2440 channel
->attr
.live_timer_interval
=
2441 live_timer_interval
;
2442 } else if (!strcmp((const char *) attr_node
->name
,
2443 config_element_monitor_timer_interval
)) {
2445 uint64_t monitor_timer_interval
= 0;
2447 /* monitor_timer_interval */
2448 content
= xmlNodeGetContent(attr_node
);
2450 ret
= -LTTNG_ERR_NOMEM
;
2454 ret
= parse_uint(content
, &monitor_timer_interval
);
2457 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2461 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2462 monitor_timer_interval
);
2464 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2467 } else if (!strcmp((const char *) attr_node
->name
,
2468 config_element_blocking_timeout
)) {
2470 int64_t blocking_timeout
= 0;
2472 /* blocking_timeout */
2473 content
= xmlNodeGetContent(attr_node
);
2475 ret
= -LTTNG_ERR_NOMEM
;
2479 ret
= parse_int(content
, &blocking_timeout
);
2482 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2486 ret
= lttng_channel_set_blocking_timeout(channel
,
2489 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2492 } else if (!strcmp((const char *) attr_node
->name
,
2493 config_element_events
)) {
2495 *events_node
= attr_node
;
2498 *contexts_node
= attr_node
;
2506 int process_context_node(xmlNodePtr context_node
,
2507 struct lttng_handle
*handle
, const char *channel_name
)
2510 struct lttng_event_context context
;
2511 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2514 assert(channel_name
);
2516 if (!context_child_node
) {
2517 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2521 memset(&context
, 0, sizeof(context
));
2523 if (!strcmp((const char *) context_child_node
->name
,
2524 config_element_type
)) {
2526 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2529 ret
= -LTTNG_ERR_NOMEM
;
2533 ret
= get_context_type(content
);
2536 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2541 } else if (!strcmp((const char *) context_child_node
->name
,
2542 config_element_context_perf
)) {
2544 xmlNodePtr perf_attr_node
;
2546 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2547 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2548 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2549 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2550 perf_attr_node
; perf_attr_node
=
2551 xmlNextElementSibling(perf_attr_node
)) {
2552 if (!strcmp((const char *) perf_attr_node
->name
,
2553 config_element_type
)) {
2558 content
= xmlNodeGetContent(perf_attr_node
);
2560 ret
= -LTTNG_ERR_NOMEM
;
2564 ret
= parse_uint(content
, &type
);
2567 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2571 if (type
> UINT32_MAX
) {
2572 WARN("perf context type out of range.");
2573 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2577 context
.u
.perf_counter
.type
= type
;
2578 } else if (!strcmp((const char *) perf_attr_node
->name
,
2579 config_element_config
)) {
2581 uint64_t config
= 0;
2584 content
= xmlNodeGetContent(perf_attr_node
);
2586 ret
= -LTTNG_ERR_NOMEM
;
2590 ret
= parse_uint(content
, &config
);
2593 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2597 context
.u
.perf_counter
.config
= config
;
2598 } else if (!strcmp((const char *) perf_attr_node
->name
,
2599 config_element_name
)) {
2603 content
= xmlNodeGetContent(perf_attr_node
);
2605 ret
= -LTTNG_ERR_NOMEM
;
2609 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2610 (const char *) content
,
2611 LTTNG_SYMBOL_NAME_LEN
);
2613 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2614 (const char *) content
,
2615 strlen((const char *) content
),
2616 LTTNG_SYMBOL_NAME_LEN
);
2617 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2624 } else if (!strcmp((const char *) context_child_node
->name
,
2625 config_element_context_app
)) {
2626 /* application context */
2627 xmlNodePtr app_ctx_node
;
2629 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2630 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2631 app_ctx_node
; app_ctx_node
=
2632 xmlNextElementSibling(app_ctx_node
)) {
2634 char **target
= strcmp(
2635 (const char *) app_ctx_node
->name
,
2636 config_element_context_app_provider_name
) == 0 ?
2637 &context
.u
.app_ctx
.provider_name
:
2638 &context
.u
.app_ctx
.ctx_name
;
2640 content
= xmlNodeGetContent(app_ctx_node
);
2642 ret
= -LTTNG_ERR_NOMEM
;
2646 *target
= (char *) content
;
2649 /* Unrecognized context type */
2650 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2654 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2655 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2656 free(context
.u
.app_ctx
.provider_name
);
2657 free(context
.u
.app_ctx
.ctx_name
);
2664 int process_contexts_node(xmlNodePtr contexts_node
,
2665 struct lttng_handle
*handle
, const char *channel_name
)
2668 xmlNodePtr context_node
;
2670 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2671 context_node
= xmlNextElementSibling(context_node
)) {
2672 ret
= process_context_node(context_node
, handle
, channel_name
);
2681 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2682 const char **element_id_tracker
,
2683 const char **element_value_type
,
2684 const char **element_value
,
2685 const char **element_value_alias
,
2686 const char **element_name
)
2690 switch (process_attr
) {
2691 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2692 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2693 *element_value_type
= config_element_process_attr_pid_value
;
2694 *element_value
= config_element_process_attr_id
;
2695 *element_value_alias
= config_element_process_attr_id
;
2696 *element_name
= NULL
;
2698 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2699 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2700 *element_value_type
= config_element_process_attr_vpid_value
;
2701 *element_value
= config_element_process_attr_id
;
2702 *element_value_alias
= NULL
;
2703 *element_name
= NULL
;
2705 case LTTNG_PROCESS_ATTR_USER_ID
:
2706 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2707 *element_value_type
= config_element_process_attr_uid_value
;
2708 *element_value
= config_element_process_attr_id
;
2709 *element_value_alias
= NULL
;
2710 *element_name
= config_element_name
;
2712 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2713 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2714 *element_value_type
= config_element_process_attr_vuid_value
;
2715 *element_value
= config_element_process_attr_id
;
2716 *element_value_alias
= NULL
;
2717 *element_name
= config_element_name
;
2719 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2720 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2721 *element_value_type
= config_element_process_attr_gid_value
;
2722 *element_value
= config_element_process_attr_id
;
2723 *element_value_alias
= NULL
;
2724 *element_name
= config_element_name
;
2726 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2727 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2728 *element_value_type
= config_element_process_attr_vgid_value
;
2729 *element_value
= config_element_process_attr_id
;
2730 *element_value_alias
= NULL
;
2731 *element_name
= config_element_name
;
2734 ret
= LTTNG_ERR_INVALID
;
2739 static int process_legacy_pid_tracker_node(
2740 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2742 int ret
= 0, child_count
;
2743 xmlNodePtr targets_node
= NULL
;
2745 const char *element_id_tracker
;
2746 const char *element_target_id
;
2747 const char *element_id
;
2748 const char *element_id_alias
;
2749 const char *element_name
;
2750 enum lttng_error_code tracker_handle_ret_code
;
2751 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2752 enum lttng_process_attr_tracker_handle_status status
;
2753 const enum lttng_process_attr process_attr
=
2754 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2755 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2756 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2760 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2761 handle
->session_name
, handle
->domain
.type
,
2764 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2765 ret
= LTTNG_ERR_INVALID
;
2769 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2770 &element_target_id
, &element_id
, &element_id_alias
,
2776 /* Get the targets node */
2777 for (node
= xmlFirstElementChild(trackers_node
); node
;
2778 node
= xmlNextElementSibling(node
)) {
2779 if (!strcmp((const char *) node
->name
,
2780 config_element_tracker_targets_legacy
)) {
2781 targets_node
= node
;
2786 if (!targets_node
) {
2787 ret
= LTTNG_ERR_INVALID
;
2791 /* Go through all id target node */
2792 child_count
= xmlChildElementCount(targets_node
);
2793 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2795 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2796 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2797 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2798 ret
= LTTNG_ERR_UNK
;
2802 /* Add all tracked values. */
2803 for (node
= xmlFirstElementChild(targets_node
); node
;
2804 node
= xmlNextElementSibling(node
)) {
2805 xmlNodePtr pid_target_node
= node
;
2807 /* get pid_target node and track it */
2808 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2809 node
= xmlNextElementSibling(node
)) {
2810 if (!strcmp((const char *) node
->name
,
2811 config_element_tracker_pid_legacy
)) {
2813 xmlChar
*content
= xmlNodeGetContent(node
);
2816 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2820 ret
= parse_int(content
, &id
);
2823 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2827 switch (process_attr
) {
2828 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2829 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2833 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2834 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2839 ret
= LTTNG_ERR_INVALID
;
2844 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2846 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2847 ret
= LTTNG_ERR_INVALID
;
2849 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2850 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2852 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2853 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2855 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2856 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2858 ret
= LTTNG_ERR_UNK
;
2862 node
= pid_target_node
;
2866 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2870 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2871 struct lttng_handle
*handle
,
2872 enum lttng_process_attr process_attr
)
2874 int ret
= 0, child_count
;
2875 xmlNodePtr values_node
= NULL
;
2877 const char *element_id_tracker
;
2878 const char *element_target_id
;
2879 const char *element_id
;
2880 const char *element_id_alias
;
2881 const char *element_name
;
2882 enum lttng_error_code tracker_handle_ret_code
;
2883 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2884 enum lttng_process_attr_tracker_handle_status status
;
2887 assert(id_tracker_node
);
2889 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2890 handle
->session_name
, handle
->domain
.type
, process_attr
,
2892 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2893 ret
= LTTNG_ERR_INVALID
;
2897 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2898 &element_target_id
, &element_id
, &element_id_alias
,
2904 /* get the values node */
2905 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2906 node
= xmlNextElementSibling(node
)) {
2907 if (!strcmp((const char *) node
->name
,
2908 config_element_process_attr_values
)) {
2915 ret
= LTTNG_ERR_INVALID
;
2919 /* Go through all id target node */
2920 child_count
= xmlChildElementCount(values_node
);
2921 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2923 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2924 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2925 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2926 ret
= LTTNG_ERR_UNK
;
2930 /* Add all tracked values. */
2931 for (node
= xmlFirstElementChild(values_node
); node
;
2932 node
= xmlNextElementSibling(node
)) {
2933 xmlNodePtr id_target_node
= node
;
2935 /* get id node and track it */
2936 for (node
= xmlFirstElementChild(id_target_node
); node
;
2937 node
= xmlNextElementSibling(node
)) {
2938 if (!strcmp((const char *) node
->name
, element_id
) ||
2939 (element_id_alias
&&
2940 !strcmp((const char *) node
->name
,
2941 element_id_alias
))) {
2943 xmlChar
*content
= xmlNodeGetContent(node
);
2946 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2950 ret
= parse_int(content
, &id
);
2953 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2957 switch (process_attr
) {
2958 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2959 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2963 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2964 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2968 case LTTNG_PROCESS_ATTR_USER_ID
:
2969 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2973 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2974 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2978 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2979 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2983 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2984 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2989 ret
= LTTNG_ERR_INVALID
;
2992 } else if (element_name
&&
2993 !strcmp((const char *) node
->name
,
2995 xmlChar
*content
= xmlNodeGetContent(node
);
2998 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3002 switch (process_attr
) {
3003 case LTTNG_PROCESS_ATTR_USER_ID
:
3004 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3006 (const char *) content
);
3008 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3009 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3011 (const char *) content
);
3013 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3014 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3016 (const char *) content
);
3018 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3019 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3021 (const char *) content
);
3025 ret
= LTTNG_ERR_INVALID
;
3031 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3033 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3034 ret
= LTTNG_ERR_INVALID
;
3036 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3037 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3039 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3040 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3042 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3043 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3045 ret
= LTTNG_ERR_UNK
;
3049 node
= id_target_node
;
3053 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3058 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3061 struct lttng_domain domain
= { 0 };
3062 struct lttng_handle
*handle
= NULL
;
3063 struct lttng_channel
*channel
= NULL
;
3064 xmlNodePtr channels_node
= NULL
;
3065 xmlNodePtr trackers_node
= NULL
;
3066 xmlNodePtr pid_tracker_node
= NULL
;
3067 xmlNodePtr vpid_tracker_node
= NULL
;
3068 xmlNodePtr uid_tracker_node
= NULL
;
3069 xmlNodePtr vuid_tracker_node
= NULL
;
3070 xmlNodePtr gid_tracker_node
= NULL
;
3071 xmlNodePtr vgid_tracker_node
= NULL
;
3074 assert(session_name
);
3076 ret
= init_domain(domain_node
, &domain
);
3081 handle
= lttng_create_handle(session_name
, &domain
);
3083 ret
= -LTTNG_ERR_NOMEM
;
3087 /* get the channels node */
3088 for (node
= xmlFirstElementChild(domain_node
); node
;
3089 node
= xmlNextElementSibling(node
)) {
3090 if (!strcmp((const char *) node
->name
,
3091 config_element_channels
)) {
3092 channels_node
= node
;
3097 if (!channels_node
) {
3101 /* create all channels */
3102 for (node
= xmlFirstElementChild(channels_node
); node
;
3103 node
= xmlNextElementSibling(node
)) {
3104 const enum lttng_domain_type original_domain
= domain
.type
;
3105 xmlNodePtr contexts_node
= NULL
;
3106 xmlNodePtr events_node
= NULL
;
3107 xmlNodePtr channel_attr_node
;
3110 * Channels of the "agent" types cannot be created directly.
3111 * They are meant to be created implicitly through the
3112 * activation of events in their domain. However, a user
3113 * can override the default channel configuration attributes
3114 * by creating the underlying UST channel _before_ enabling
3115 * an agent domain event.
3117 * Hence, the channel's type is substituted before the creation
3118 * and restored by the time the events are created.
3120 switch (domain
.type
) {
3121 case LTTNG_DOMAIN_JUL
:
3122 case LTTNG_DOMAIN_LOG4J
:
3123 case LTTNG_DOMAIN_PYTHON
:
3124 domain
.type
= LTTNG_DOMAIN_UST
;
3129 channel
= lttng_channel_create(&domain
);
3135 for (channel_attr_node
= xmlFirstElementChild(node
);
3136 channel_attr_node
; channel_attr_node
=
3137 xmlNextElementSibling(channel_attr_node
)) {
3138 ret
= process_channel_attr_node(channel_attr_node
,
3139 channel
, &contexts_node
, &events_node
);
3145 ret
= lttng_enable_channel(handle
, channel
);
3150 /* Restore the original channel domain. */
3151 domain
.type
= original_domain
;
3153 ret
= process_events_node(events_node
, handle
, channel
->name
);
3158 ret
= process_contexts_node(contexts_node
, handle
,
3164 lttng_channel_destroy(channel
);
3168 /* get the trackers node */
3169 for (node
= xmlFirstElementChild(domain_node
); node
;
3170 node
= xmlNextElementSibling(node
)) {
3171 if (!strcmp((const char *) node
->name
,
3172 config_element_process_attr_trackers
) ||
3173 !strcmp((const char *) node
->name
,
3174 config_element_trackers_legacy
)) {
3175 if (trackers_node
) {
3176 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3177 config_element_process_attr_trackers
,
3178 config_element_trackers_legacy
);
3182 trackers_node
= node
;
3187 if (!trackers_node
) {
3191 for (node
= xmlFirstElementChild(trackers_node
); node
;
3192 node
= xmlNextElementSibling(node
)) {
3193 if (!strcmp((const char *) node
->name
,
3194 config_element_process_attr_tracker_pid
)) {
3195 pid_tracker_node
= node
;
3196 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3197 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3202 if (!strcmp((const char *) node
->name
,
3203 config_element_process_attr_tracker_vpid
)) {
3204 vpid_tracker_node
= node
;
3205 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3206 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3211 if (!strcmp((const char *) node
->name
,
3212 config_element_process_attr_tracker_uid
)) {
3213 uid_tracker_node
= node
;
3214 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3215 LTTNG_PROCESS_ATTR_USER_ID
);
3220 if (!strcmp((const char *) node
->name
,
3221 config_element_process_attr_tracker_vuid
)) {
3222 vuid_tracker_node
= node
;
3223 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3224 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3229 if (!strcmp((const char *) node
->name
,
3230 config_element_process_attr_tracker_gid
)) {
3231 gid_tracker_node
= node
;
3232 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3233 LTTNG_PROCESS_ATTR_GROUP_ID
);
3238 if (!strcmp((const char *) node
->name
,
3239 config_element_process_attr_tracker_vgid
)) {
3240 vgid_tracker_node
= node
;
3241 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3242 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3247 if (!strcmp((const char *) node
->name
,
3248 config_element_pid_tracker_legacy
)) {
3249 ret
= process_legacy_pid_tracker_node(node
, handle
);
3257 lttng_channel_destroy(channel
);
3258 lttng_destroy_handle(handle
);
3263 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3266 enum lttng_rotation_status status
;
3267 struct lttng_rotation_schedule
*periodic
=
3268 lttng_rotation_schedule_periodic_create();
3271 ret
= -LTTNG_ERR_NOMEM
;
3275 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3277 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3278 ret
= -LTTNG_ERR_INVALID
;
3282 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3284 case LTTNG_ROTATION_STATUS_OK
:
3287 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3288 case LTTNG_ROTATION_STATUS_INVALID
:
3289 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3292 ret
= -LTTNG_ERR_UNK
;
3296 lttng_rotation_schedule_destroy(periodic
);
3301 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3304 enum lttng_rotation_status status
;
3305 struct lttng_rotation_schedule
*size
=
3306 lttng_rotation_schedule_size_threshold_create();
3309 ret
= -LTTNG_ERR_NOMEM
;
3313 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3315 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3316 ret
= -LTTNG_ERR_INVALID
;
3320 status
= lttng_session_add_rotation_schedule(name
, size
);
3322 case LTTNG_ROTATION_STATUS_OK
:
3325 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3326 case LTTNG_ROTATION_STATUS_INVALID
:
3327 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3330 ret
= -LTTNG_ERR_UNK
;
3334 lttng_rotation_schedule_destroy(size
);
3339 int process_session_rotation_schedules_node(
3340 xmlNodePtr schedules_node
,
3341 uint64_t *rotation_timer_interval
,
3342 uint64_t *rotation_size
)
3347 for (child
= xmlFirstElementChild(schedules_node
);
3349 child
= xmlNextElementSibling(child
)) {
3350 if (!strcmp((const char *) child
->name
,
3351 config_element_rotation_schedule_periodic
)) {
3353 xmlNodePtr time_us_node
;
3355 /* periodic rotation schedule */
3356 time_us_node
= xmlFirstElementChild(child
);
3357 if (!time_us_node
||
3358 strcmp((const char *) time_us_node
->name
,
3359 config_element_rotation_schedule_periodic_time_us
)) {
3360 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3365 content
= xmlNodeGetContent(time_us_node
);
3367 ret
= -LTTNG_ERR_NOMEM
;
3370 ret
= parse_uint(content
, rotation_timer_interval
);
3373 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3376 } else if (!strcmp((const char *) child
->name
,
3377 config_element_rotation_schedule_size_threshold
)) {
3379 xmlNodePtr bytes_node
;
3381 /* size_threshold rotation schedule */
3382 bytes_node
= xmlFirstElementChild(child
);
3384 strcmp((const char *) bytes_node
->name
,
3385 config_element_rotation_schedule_size_threshold_bytes
)) {
3386 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3391 content
= xmlNodeGetContent(bytes_node
);
3393 ret
= -LTTNG_ERR_NOMEM
;
3396 ret
= parse_uint(content
, rotation_size
);
3399 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3410 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3412 const struct config_load_session_override_attr
*overrides
)
3414 int ret
, started
= -1, snapshot_mode
= -1;
3415 uint64_t live_timer_interval
= UINT64_MAX
,
3416 rotation_timer_interval
= 0,
3418 xmlChar
*name
= NULL
;
3419 xmlChar
*shm_path
= NULL
;
3420 xmlNodePtr domains_node
= NULL
;
3421 xmlNodePtr output_node
= NULL
;
3423 xmlNodePtr attributes_child
;
3424 struct lttng_domain
*kernel_domain
= NULL
;
3425 struct lttng_domain
*ust_domain
= NULL
;
3426 struct lttng_domain
*jul_domain
= NULL
;
3427 struct lttng_domain
*log4j_domain
= NULL
;
3428 struct lttng_domain
*python_domain
= NULL
;
3430 for (node
= xmlFirstElementChild(session_node
); node
;
3431 node
= xmlNextElementSibling(node
)) {
3432 if (!name
&& !strcmp((const char *) node
->name
,
3433 config_element_name
)) {
3435 xmlChar
*node_content
= xmlNodeGetContent(node
);
3436 if (!node_content
) {
3437 ret
= -LTTNG_ERR_NOMEM
;
3441 name
= node_content
;
3442 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3443 config_element_domains
)) {
3445 domains_node
= node
;
3446 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3447 config_element_started
)) {
3449 xmlChar
*node_content
= xmlNodeGetContent(node
);
3450 if (!node_content
) {
3451 ret
= -LTTNG_ERR_NOMEM
;
3455 ret
= parse_bool(node_content
, &started
);
3458 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3461 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3462 config_element_output
)) {
3465 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3466 config_element_shared_memory_path
)) {
3467 /* shared memory path */
3468 xmlChar
*node_content
= xmlNodeGetContent(node
);
3469 if (!node_content
) {
3470 ret
= -LTTNG_ERR_NOMEM
;
3474 shm_path
= node_content
;
3477 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3478 * rotation_timer_interval.
3480 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3481 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3482 if (!strcmp((const char *) attributes_child
->name
,
3483 config_element_snapshot_mode
)) {
3485 xmlChar
*snapshot_mode_content
=
3486 xmlNodeGetContent(attributes_child
);
3487 if (!snapshot_mode_content
) {
3488 ret
= -LTTNG_ERR_NOMEM
;
3492 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3493 free(snapshot_mode_content
);
3495 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3498 } else if (!strcmp((const char *) attributes_child
->name
,
3499 config_element_live_timer_interval
)) {
3500 /* live_timer_interval */
3501 xmlChar
*timer_interval_content
=
3502 xmlNodeGetContent(attributes_child
);
3503 if (!timer_interval_content
) {
3504 ret
= -LTTNG_ERR_NOMEM
;
3508 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3509 free(timer_interval_content
);
3511 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3514 } else if (!strcmp((const char *) attributes_child
->name
,
3515 config_element_rotation_schedules
)) {
3516 ret
= process_session_rotation_schedules_node(
3518 &rotation_timer_interval
,
3521 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3531 /* Mandatory attribute, as defined in the session XSD */
3532 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3536 if (session_name
&& strcmp((char *) name
, session_name
)) {
3537 /* This is not the session we are looking for */
3538 ret
= -LTTNG_ERR_NO_SESSION
;
3542 /* Init domains to create the session handles */
3543 for (node
= xmlFirstElementChild(domains_node
); node
;
3544 node
= xmlNextElementSibling(node
)) {
3545 struct lttng_domain
*domain
;
3547 domain
= zmalloc(sizeof(*domain
));
3549 ret
= -LTTNG_ERR_NOMEM
;
3553 ret
= init_domain(node
, domain
);
3555 goto domain_init_error
;
3558 switch (domain
->type
) {
3559 case LTTNG_DOMAIN_KERNEL
:
3560 if (kernel_domain
) {
3561 /* Same domain seen twice, invalid! */
3562 goto domain_init_error
;
3564 kernel_domain
= domain
;
3566 case LTTNG_DOMAIN_UST
:
3568 /* Same domain seen twice, invalid! */
3569 goto domain_init_error
;
3571 ust_domain
= domain
;
3573 case LTTNG_DOMAIN_JUL
:
3575 /* Same domain seen twice, invalid! */
3576 goto domain_init_error
;
3578 jul_domain
= domain
;
3580 case LTTNG_DOMAIN_LOG4J
:
3582 /* Same domain seen twice, invalid! */
3583 goto domain_init_error
;
3585 log4j_domain
= domain
;
3587 case LTTNG_DOMAIN_PYTHON
:
3588 if (python_domain
) {
3589 /* Same domain seen twice, invalid! */
3590 goto domain_init_error
;
3592 python_domain
= domain
;
3595 WARN("Invalid domain type");
3596 goto domain_init_error
;
3601 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3605 /* Apply overrides */
3607 if (overrides
->session_name
) {
3608 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3609 if (!name_override
) {
3610 ret
= -LTTNG_ERR_NOMEM
;
3614 /* Overrides the session name to the provided name */
3616 name
= name_override
;
3621 /* Destroy session if it exists */
3622 ret
= lttng_destroy_session((const char *) name
);
3623 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3624 ERR("Failed to destroy existing session.");
3629 /* Create session type depending on output type */
3630 if (snapshot_mode
&& snapshot_mode
!= -1) {
3631 ret
= create_snapshot_session((const char *) name
, output_node
,
3633 } else if (live_timer_interval
&&
3634 live_timer_interval
!= UINT64_MAX
) {
3635 ret
= create_session((const char *) name
,
3636 output_node
, live_timer_interval
, overrides
);
3638 /* regular session */
3639 ret
= create_session((const char *) name
,
3640 output_node
, UINT64_MAX
, overrides
);
3647 ret
= lttng_set_session_shm_path((const char *) name
,
3648 (const char *) shm_path
);
3654 for (node
= xmlFirstElementChild(domains_node
); node
;
3655 node
= xmlNextElementSibling(node
)) {
3656 ret
= process_domain_node(node
, (const char *) name
);
3662 if (rotation_timer_interval
) {
3663 ret
= add_periodic_rotation((const char *) name
,
3664 rotation_timer_interval
);
3669 if (rotation_size
) {
3670 ret
= add_size_rotation((const char *) name
,
3678 ret
= lttng_start_tracing((const char *) name
);
3686 ERR("Failed to load session %s: %s", (const char *) name
,
3687 lttng_strerror(ret
));
3688 lttng_destroy_session((const char *) name
);
3692 free(kernel_domain
);
3696 free(python_domain
);
3703 * Return 1 if the given path is readable by the current UID or 0 if not.
3704 * Return -1 if the path is EPERM.
3706 static int validate_file_read_creds(const char *path
)
3712 /* Can we read the file. */
3713 ret
= access(path
, R_OK
);
3717 if (errno
== EACCES
) {
3728 int load_session_from_file(const char *path
, const char *session_name
,
3729 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3730 const struct config_load_session_override_attr
*overrides
)
3732 int ret
, session_found
= !session_name
;
3733 xmlDocPtr doc
= NULL
;
3734 xmlNodePtr sessions_node
;
3735 xmlNodePtr session_node
;
3738 assert(validation_ctx
);
3740 ret
= validate_file_read_creds(path
);
3743 ret
= -LTTNG_ERR_EPERM
;
3745 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3750 doc
= xmlParseFile(path
);
3752 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3756 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3758 ERR("Session configuration file validation failed");
3759 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3763 sessions_node
= xmlDocGetRootElement(doc
);
3764 if (!sessions_node
) {
3765 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3769 for (session_node
= xmlFirstElementChild(sessions_node
);
3770 session_node
; session_node
=
3771 xmlNextElementSibling(session_node
)) {
3772 ret
= process_session_node(session_node
,
3773 session_name
, overwrite
, overrides
);
3774 if (!session_name
&& ret
) {
3775 /* Loading error occurred. */
3777 } else if (session_name
) {
3779 /* Target session found and loaded */
3782 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3784 * Ignore this error, we are looking for a
3789 /* Loading error occurred. */
3797 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3803 int load_session_from_path(const char *path
, const char *session_name
,
3804 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3805 const struct config_load_session_override_attr
*overrides
)
3807 int ret
, session_found
= !session_name
;
3808 DIR *directory
= NULL
;
3809 struct lttng_dynamic_buffer file_path
;
3813 assert(validation_ctx
);
3814 path_len
= strlen(path
);
3815 lttng_dynamic_buffer_init(&file_path
);
3816 if (path_len
>= LTTNG_PATH_MAX
) {
3817 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3818 path
, path_len
, LTTNG_PATH_MAX
);
3819 ret
= -LTTNG_ERR_INVALID
;
3823 directory
= opendir(path
);
3827 /* Try the file loading. */
3830 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3833 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3838 size_t file_path_root_len
;
3840 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3843 ret
= -LTTNG_ERR_NOMEM
;
3847 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3849 ret
= -LTTNG_ERR_NOMEM
;
3853 if (file_path
.data
[file_path
.size
- 1] != '/') {
3854 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3856 ret
= -LTTNG_ERR_NOMEM
;
3860 file_path_root_len
= file_path
.size
;
3862 /* Search for *.lttng files */
3864 size_t file_name_len
;
3865 struct dirent
*result
;
3868 * When the end of the directory stream is reached, NULL
3869 * is returned and errno is kept unchanged. When an
3870 * error occurs, NULL is returned and errno is set
3871 * accordingly. To distinguish between the two, set
3872 * errno to zero before calling readdir().
3874 * On success, readdir() returns a pointer to a dirent
3875 * structure. This structure may be statically
3876 * allocated, do not attempt to free(3) it.
3879 result
= readdir(directory
);
3881 /* Reached end of dir stream or error out. */
3884 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3885 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3891 file_name_len
= strlen(result
->d_name
);
3893 if (file_name_len
<=
3894 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3898 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3899 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3901 /* +1 to account for NULL terminator. */
3902 file_path
.size
+ file_name_len
+ 1,
3907 /* Does the file end with .lttng? */
3908 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3909 result
->d_name
+ file_name_len
- sizeof(
3910 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3914 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3917 ret
= -LTTNG_ERR_NOMEM
;
3921 ret
= load_session_from_file(file_path
.data
, session_name
,
3922 validation_ctx
, overwrite
, overrides
);
3924 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3928 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3932 * Reset the buffer's size to the location of the
3933 * path's trailing '/'.
3935 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3936 file_path_root_len
);
3938 ret
= -LTTNG_ERR_UNK
;
3943 ret
= load_session_from_file(path
, session_name
,
3944 validation_ctx
, overwrite
, overrides
);
3954 if (closedir(directory
)) {
3958 if (!ret
&& !session_found
) {
3959 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3961 lttng_dynamic_buffer_reset(&file_path
);
3966 * Validate that the given path's credentials and the current process have the
3967 * same UID. If so, return 1 else return 0 if it does NOT match.
3969 static int validate_path_creds(const char *path
)
3971 int ret
, uid
= getuid();
3980 ret
= stat(path
, &buf
);
3982 if (errno
!= ENOENT
) {
3988 if (buf
.st_uid
!= uid
) {
3999 int config_load_session(const char *path
, const char *session_name
,
4000 int overwrite
, unsigned int autoload
,
4001 const struct config_load_session_override_attr
*overrides
)
4004 bool session_loaded
= false;
4005 const char *path_ptr
= NULL
;
4006 struct session_config_validation_ctx validation_ctx
= { 0 };
4008 ret
= init_session_config_validation_ctx(&validation_ctx
);
4014 const char *home_path
;
4015 const char *sys_path
;
4018 home_path
= utils_get_home_dir();
4020 char path_buf
[PATH_MAX
];
4023 * Try user session configuration path. Ignore error here so we can
4024 * continue loading the system wide sessions.
4027 ret
= snprintf(path_buf
, sizeof(path_buf
),
4028 DEFAULT_SESSION_HOME_CONFIGPATH
4029 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
4032 PERROR("snprintf session autoload home config path");
4033 ret
= -LTTNG_ERR_INVALID
;
4038 * Credentials are only validated for the autoload in order to
4039 * avoid any user session daemon to try to load kernel sessions
4040 * automatically and failing all the times.
4042 ret
= validate_path_creds(path_buf
);
4044 path_ptr
= path_buf
;
4047 ret
= snprintf(path_buf
, sizeof(path_buf
),
4048 DEFAULT_SESSION_HOME_CONFIGPATH
,
4051 PERROR("snprintf session home config path");
4052 ret
= -LTTNG_ERR_INVALID
;
4055 path_ptr
= path_buf
;
4058 ret
= load_session_from_path(path_ptr
, session_name
,
4059 &validation_ctx
, overwrite
, overrides
);
4060 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4064 * Continue even if the session was found since we have to try
4065 * the system wide sessions.
4067 session_loaded
= true;
4071 /* Reset path pointer for the system wide dir. */
4074 /* Try system wide configuration directory. */
4076 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4077 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4078 ret
= validate_path_creds(sys_path
);
4080 path_ptr
= sys_path
;
4083 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4084 path_ptr
= sys_path
;
4088 ret
= load_session_from_path(path_ptr
, session_name
,
4089 &validation_ctx
, overwrite
, overrides
);
4091 session_loaded
= true;
4097 ret
= access(path
, F_OK
);
4102 ret
= -LTTNG_ERR_INVALID
;
4103 WARN("Session configuration path does not exist.");
4106 ret
= -LTTNG_ERR_EPERM
;
4109 ret
= -LTTNG_ERR_UNK
;
4115 ret
= load_session_from_path(path
, session_name
,
4116 &validation_ctx
, overwrite
, overrides
);
4119 fini_session_config_validation_ctx(&validation_ctx
);
4120 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4122 * Don't report an error if no sessions are found when called
4123 * without a session_name or a search path.
4128 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4129 /* A matching session was found in one of the search paths. */
4136 void __attribute__((destructor
)) session_config_exit(void)