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 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
158 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
159 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
160 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
161 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
163 const char * const config_domain_type_kernel
= "KERNEL";
164 const char * const config_domain_type_ust
= "UST";
165 const char * const config_domain_type_jul
= "JUL";
166 const char * const config_domain_type_log4j
= "LOG4J";
167 const char * const config_domain_type_python
= "PYTHON";
169 const char * const config_buffer_type_per_pid
= "PER_PID";
170 const char * const config_buffer_type_per_uid
= "PER_UID";
171 const char * const config_buffer_type_global
= "GLOBAL";
173 const char * const config_overwrite_mode_discard
= "DISCARD";
174 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
176 const char * const config_output_type_splice
= "SPLICE";
177 const char * const config_output_type_mmap
= "MMAP";
179 const char * const config_loglevel_type_all
= "ALL";
180 const char * const config_loglevel_type_range
= "RANGE";
181 const char * const config_loglevel_type_single
= "SINGLE";
183 const char * const config_event_type_all
= "ALL";
184 const char * const config_event_type_tracepoint
= "TRACEPOINT";
185 const char * const config_event_type_probe
= "PROBE";
186 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
187 const char * const config_event_type_function
= "FUNCTION";
188 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
189 const char * const config_event_type_noop
= "NOOP";
190 const char * const config_event_type_syscall
= "SYSCALL";
191 const char * const config_event_type_kprobe
= "KPROBE";
192 const char * const config_event_type_kretprobe
= "KRETPROBE";
194 const char * const config_event_context_pid
= "PID";
195 const char * const config_event_context_procname
= "PROCNAME";
196 const char * const config_event_context_prio
= "PRIO";
197 const char * const config_event_context_nice
= "NICE";
198 const char * const config_event_context_vpid
= "VPID";
199 const char * const config_event_context_tid
= "TID";
200 const char * const config_event_context_vtid
= "VTID";
201 const char * const config_event_context_ppid
= "PPID";
202 const char * const config_event_context_vppid
= "VPPID";
203 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
204 const char * const config_event_context_hostname
= "HOSTNAME";
205 const char * const config_event_context_ip
= "IP";
206 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
207 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
208 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
209 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
210 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
211 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
212 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
213 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
214 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
215 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
216 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
217 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
218 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
219 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
220 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
221 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
222 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
223 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
224 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
225 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
226 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
227 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
228 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
229 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
230 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
231 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
232 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
234 /* Deprecated symbols */
235 const char * const config_element_perf
;
237 enum process_event_node_phase
{
242 struct consumer_output
{
249 static int config_entry_handler_filter(struct handler_filter_args
*args
,
250 const char *section
, const char *name
, const char *value
)
253 struct config_entry entry
= { section
, name
, value
};
257 if (!section
|| !name
|| !value
) {
263 if (strcmp(args
->section
, section
)) {
268 ret
= args
->handler(&entry
, args
->user_data
);
274 int config_get_section_entries(const char *override_path
, const char *section
,
275 config_entry_handler_cb handler
, void *user_data
)
279 FILE *config_file
= NULL
;
280 struct handler_filter_args filter
= { section
, handler
, user_data
};
282 /* First, try system-wide conf. file. */
283 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
285 config_file
= fopen(path
, "r");
287 DBG("Loading daemon conf file at %s", path
);
289 * Return value is not very important here since error or not, we
290 * continue and try the next possible conf. file.
292 (void) ini_parse_file(config_file
,
293 (ini_entry_handler
) config_entry_handler_filter
,
298 /* Second is the user local configuration. */
299 path
= utils_get_home_dir();
301 char fullpath
[PATH_MAX
];
303 ret
= snprintf(fullpath
, sizeof(fullpath
),
304 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
306 PERROR("snprintf user conf. path");
310 config_file
= fopen(fullpath
, "r");
312 DBG("Loading daemon user conf file at %s", path
);
314 * Return value is not very important here since error or not, we
315 * continue and try the next possible conf. file.
317 (void) ini_parse_file(config_file
,
318 (ini_entry_handler
) config_entry_handler_filter
,
324 /* Final path is the one that the user might have provided. */
326 config_file
= fopen(override_path
, "r");
328 DBG("Loading daemon command line conf file at %s", override_path
);
329 (void) ini_parse_file(config_file
,
330 (ini_entry_handler
) config_entry_handler_filter
,
334 ERR("Failed to open daemon configuration file at %s",
341 /* Everything went well. */
349 int config_parse_value(const char *value
)
352 char *endptr
, *lower_str
;
362 v
= strtoul(value
, &endptr
, 10);
363 if (endptr
!= value
) {
368 lower_str
= zmalloc(len
+ 1);
375 for (i
= 0; i
< len
; i
++) {
376 lower_str
[i
] = tolower(value
[i
]);
379 if (!strcmp(lower_str
, config_str_yes
) ||
380 !strcmp(lower_str
, config_str_true
) ||
381 !strcmp(lower_str
, config_str_on
)) {
383 } else if (!strcmp(lower_str
, config_str_no
) ||
384 !strcmp(lower_str
, config_str_false
) ||
385 !strcmp(lower_str
, config_str_off
)) {
397 * Returns a xmlChar string which must be released using xmlFree().
399 static xmlChar
*encode_string(const char *in_str
)
401 xmlChar
*out_str
= NULL
;
402 xmlCharEncodingHandlerPtr handler
;
403 int out_len
, ret
, in_len
;
407 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
409 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
413 in_len
= strlen(in_str
);
415 * Add 1 byte for the NULL terminted character. The factor 4 here is
416 * used because UTF-8 characters can take up to 4 bytes.
418 out_len
= (in_len
* 4) + 1;
419 out_str
= xmlMalloc(out_len
);
424 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
431 /* out_len is now the size of out_str */
432 out_str
[out_len
] = '\0';
438 struct config_writer
*config_writer_create(int fd_output
, int indent
)
441 struct config_writer
*writer
;
442 xmlOutputBufferPtr buffer
;
444 writer
= zmalloc(sizeof(struct config_writer
));
446 PERROR("zmalloc config_writer_create");
450 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
455 writer
->writer
= xmlNewTextWriter(buffer
);
456 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
457 config_xml_encoding
, NULL
);
462 ret
= xmlTextWriterSetIndentString(writer
->writer
,
463 BAD_CAST config_xml_indent_string
);
468 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
476 config_writer_destroy(writer
);
481 int config_writer_destroy(struct config_writer
*writer
)
490 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
491 WARN("Could not close XML document");
495 if (writer
->writer
) {
496 xmlFreeTextWriter(writer
->writer
);
505 int config_writer_open_element(struct config_writer
*writer
,
506 const char *element_name
)
509 xmlChar
*encoded_element_name
;
511 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
516 encoded_element_name
= encode_string(element_name
);
517 if (!encoded_element_name
) {
522 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
523 xmlFree(encoded_element_name
);
525 return ret
>= 0 ? 0 : ret
;
529 int config_writer_write_attribute(struct config_writer
*writer
,
530 const char *name
, const char *value
)
533 xmlChar
*encoded_name
= NULL
;
534 xmlChar
*encoded_value
= NULL
;
536 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
541 encoded_name
= encode_string(name
);
547 encoded_value
= encode_string(value
);
548 if (!encoded_value
) {
553 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
556 xmlFree(encoded_name
);
557 xmlFree(encoded_value
);
558 return ret
>= 0 ? 0 : ret
;
562 int config_writer_close_element(struct config_writer
*writer
)
566 if (!writer
|| !writer
->writer
) {
571 ret
= xmlTextWriterEndElement(writer
->writer
);
573 return ret
>= 0 ? 0 : ret
;
577 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
578 const char *element_name
, uint64_t value
)
581 xmlChar
*encoded_element_name
;
583 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
588 encoded_element_name
= encode_string(element_name
);
589 if (!encoded_element_name
) {
594 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
595 encoded_element_name
, "%" PRIu64
, value
);
596 xmlFree(encoded_element_name
);
598 return ret
>= 0 ? 0 : ret
;
602 int config_writer_write_element_signed_int(struct config_writer
*writer
,
603 const char *element_name
, int64_t value
)
606 xmlChar
*encoded_element_name
;
608 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
613 encoded_element_name
= encode_string(element_name
);
614 if (!encoded_element_name
) {
619 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
620 encoded_element_name
, "%" PRIi64
, value
);
621 xmlFree(encoded_element_name
);
623 return ret
>= 0 ? 0 : ret
;
627 int config_writer_write_element_bool(struct config_writer
*writer
,
628 const char *element_name
, int value
)
630 return config_writer_write_element_string(writer
, element_name
,
631 value
? config_xml_true
: config_xml_false
);
635 int config_writer_write_element_string(struct config_writer
*writer
,
636 const char *element_name
, const char *value
)
639 xmlChar
*encoded_element_name
= NULL
;
640 xmlChar
*encoded_value
= NULL
;
642 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
648 encoded_element_name
= encode_string(element_name
);
649 if (!encoded_element_name
) {
654 encoded_value
= encode_string(value
);
655 if (!encoded_value
) {
660 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
663 xmlFree(encoded_element_name
);
664 xmlFree(encoded_value
);
665 return ret
>= 0 ? 0 : ret
;
669 void xml_error_handler(void *ctx
, const char *format
, ...)
675 va_start(args
, format
);
676 ret
= vasprintf(&errMsg
, format
, args
);
679 ERR("String allocation failed in xml error handler");
683 fprintf(stderr
, "XML Error: %s", errMsg
);
688 void fini_session_config_validation_ctx(
689 struct session_config_validation_ctx
*ctx
)
691 if (ctx
->parser_ctx
) {
692 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
696 xmlSchemaFree(ctx
->schema
);
699 if (ctx
->schema_validation_ctx
) {
700 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
703 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
707 char *get_session_config_xsd_path()
710 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
711 size_t base_path_len
;
715 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
718 base_path_len
= strlen(base_path
);
719 max_path_len
= base_path_len
+
720 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
721 xsd_path
= zmalloc(max_path_len
);
726 strcpy(xsd_path
, base_path
);
727 if (xsd_path
[base_path_len
- 1] != '/') {
728 xsd_path
[base_path_len
++] = '/';
731 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
737 int init_session_config_validation_ctx(
738 struct session_config_validation_ctx
*ctx
)
741 char *xsd_path
= get_session_config_xsd_path();
744 ret
= -LTTNG_ERR_NOMEM
;
748 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
749 if (!ctx
->parser_ctx
) {
750 ERR("XSD parser context creation failed");
751 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
754 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
755 xml_error_handler
, NULL
);
757 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
759 ERR("XSD parsing failed");
760 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
764 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
765 if (!ctx
->schema_validation_ctx
) {
766 ERR("XSD validation context creation failed");
767 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
771 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
772 xml_error_handler
, NULL
);
777 fini_session_config_validation_ctx(ctx
);
785 int parse_uint(xmlChar
*str
, uint64_t *val
)
795 *val
= strtoull((const char *) str
, &endptr
, 10);
796 if (!endptr
|| *endptr
) {
807 int parse_int(xmlChar
*str
, int64_t *val
)
817 *val
= strtoll((const char *) str
, &endptr
, 10);
818 if (!endptr
|| *endptr
) {
829 int parse_bool(xmlChar
*str
, int *val
)
838 if (!strcmp((const char *) str
, config_xml_true
)) {
840 } else if (!strcmp((const char *) str
, config_xml_false
)) {
843 WARN("Invalid boolean value encoutered (%s).",
852 int get_domain_type(xmlChar
*domain
)
860 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
861 ret
= LTTNG_DOMAIN_KERNEL
;
862 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
863 ret
= LTTNG_DOMAIN_UST
;
864 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
865 ret
= LTTNG_DOMAIN_JUL
;
866 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
867 ret
= LTTNG_DOMAIN_LOG4J
;
868 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
869 ret
= LTTNG_DOMAIN_PYTHON
;
880 int get_buffer_type(xmlChar
*buffer_type
)
888 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
889 ret
= LTTNG_BUFFER_GLOBAL
;
890 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
891 ret
= LTTNG_BUFFER_PER_UID
;
892 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
893 ret
= LTTNG_BUFFER_PER_PID
;
904 int get_overwrite_mode(xmlChar
*overwrite_mode
)
908 if (!overwrite_mode
) {
912 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
914 } else if (!strcmp((char *) overwrite_mode
,
915 config_overwrite_mode_discard
)) {
927 int get_output_type(xmlChar
*output_type
)
935 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
936 ret
= LTTNG_EVENT_MMAP
;
937 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
938 ret
= LTTNG_EVENT_SPLICE
;
949 int get_event_type(xmlChar
*event_type
)
957 if (!strcmp((char *) event_type
, config_event_type_all
)) {
958 ret
= LTTNG_EVENT_ALL
;
959 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
960 ret
= LTTNG_EVENT_TRACEPOINT
;
961 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
962 ret
= LTTNG_EVENT_PROBE
;
963 } else if (!strcmp((char *) event_type
,
964 config_event_type_userspace_probe
)) {
965 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
966 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
967 ret
= LTTNG_EVENT_FUNCTION
;
968 } else if (!strcmp((char *) event_type
,
969 config_event_type_function_entry
)) {
970 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
971 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
972 ret
= LTTNG_EVENT_NOOP
;
973 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
974 ret
= LTTNG_EVENT_SYSCALL
;
985 int get_loglevel_type(xmlChar
*loglevel_type
)
989 if (!loglevel_type
) {
993 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
994 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
995 } else if (!strcmp((char *) loglevel_type
,
996 config_loglevel_type_range
)) {
997 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
998 } else if (!strcmp((char *) loglevel_type
,
999 config_loglevel_type_single
)) {
1000 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1011 * Return the context type or -1 on error.
1014 int get_context_type(xmlChar
*context_type
)
1018 if (!context_type
) {
1022 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1023 ret
= LTTNG_EVENT_CONTEXT_PID
;
1024 } else if (!strcmp((char *) context_type
,
1025 config_event_context_procname
)) {
1026 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1027 } else if (!strcmp((char *) context_type
,
1028 config_event_context_prio
)) {
1029 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1030 } else if (!strcmp((char *) context_type
,
1031 config_event_context_nice
)) {
1032 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1033 } else if (!strcmp((char *) context_type
,
1034 config_event_context_vpid
)) {
1035 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1036 } else if (!strcmp((char *) context_type
,
1037 config_event_context_tid
)) {
1038 ret
= LTTNG_EVENT_CONTEXT_TID
;
1039 } else if (!strcmp((char *) context_type
,
1040 config_event_context_vtid
)) {
1041 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1042 } else if (!strcmp((char *) context_type
,
1043 config_event_context_ppid
)) {
1044 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1045 } else if (!strcmp((char *) context_type
,
1046 config_event_context_vppid
)) {
1047 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1048 } else if (!strcmp((char *) context_type
,
1049 config_event_context_pthread_id
)) {
1050 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1051 } else if (!strcmp((char *) context_type
,
1052 config_event_context_hostname
)) {
1053 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1054 } else if (!strcmp((char *) context_type
,
1055 config_event_context_ip
)) {
1056 ret
= LTTNG_EVENT_CONTEXT_IP
;
1057 } else if (!strcmp((char *) context_type
,
1058 config_event_context_interruptible
)) {
1059 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1060 } else if (!strcmp((char *) context_type
,
1061 config_event_context_preemptible
)) {
1062 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1063 } else if (!strcmp((char *) context_type
,
1064 config_event_context_need_reschedule
)) {
1065 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1066 } else if (!strcmp((char *) context_type
,
1067 config_event_context_migratable
)) {
1068 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1069 } else if (!strcmp((char *) context_type
,
1070 config_event_context_callstack_user
)) {
1071 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1072 } else if (!strcmp((char *) context_type
,
1073 config_event_context_callstack_kernel
)) {
1074 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1075 } else if (!strcmp((char *) context_type
,
1076 config_event_context_cgroup_ns
)) {
1077 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1078 } else if (!strcmp((char *) context_type
,
1079 config_event_context_ipc_ns
)) {
1080 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1081 } else if (!strcmp((char *) context_type
,
1082 config_event_context_mnt_ns
)) {
1083 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1084 } else if (!strcmp((char *) context_type
,
1085 config_event_context_net_ns
)) {
1086 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1087 } else if (!strcmp((char *) context_type
,
1088 config_event_context_pid_ns
)) {
1089 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1090 } else if (!strcmp((char *) context_type
,
1091 config_event_context_user_ns
)) {
1092 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1093 } else if (!strcmp((char *) context_type
,
1094 config_event_context_uts_ns
)) {
1095 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1096 } else if (!strcmp((char *) context_type
,
1097 config_event_context_uid
)) {
1098 ret
= LTTNG_EVENT_CONTEXT_UID
;
1099 } else if (!strcmp((char *) context_type
,
1100 config_event_context_euid
)) {
1101 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1102 } else if (!strcmp((char *) context_type
,
1103 config_event_context_suid
)) {
1104 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1105 } else if (!strcmp((char *) context_type
,
1106 config_event_context_gid
)) {
1107 ret
= LTTNG_EVENT_CONTEXT_GID
;
1108 } else if (!strcmp((char *) context_type
,
1109 config_event_context_egid
)) {
1110 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1111 } else if (!strcmp((char *) context_type
,
1112 config_event_context_sgid
)) {
1113 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1114 } else if (!strcmp((char *) context_type
,
1115 config_event_context_vuid
)) {
1116 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1117 } else if (!strcmp((char *) context_type
,
1118 config_event_context_veuid
)) {
1119 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1120 } else if (!strcmp((char *) context_type
,
1121 config_event_context_vsuid
)) {
1122 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1123 } else if (!strcmp((char *) context_type
,
1124 config_event_context_vgid
)) {
1125 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1126 } else if (!strcmp((char *) context_type
,
1127 config_event_context_vegid
)) {
1128 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1129 } else if (!strcmp((char *) context_type
,
1130 config_event_context_vsgid
)) {
1131 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1142 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1147 for (node
= xmlFirstElementChild(domain_node
); node
;
1148 node
= xmlNextElementSibling(node
)) {
1149 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1151 xmlChar
*node_content
= xmlNodeGetContent(node
);
1152 if (!node_content
) {
1153 ret
= -LTTNG_ERR_NOMEM
;
1157 ret
= get_domain_type(node_content
);
1160 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1165 } else if (!strcmp((const char *) node
->name
,
1166 config_element_buffer_type
)) {
1168 xmlChar
*node_content
= xmlNodeGetContent(node
);
1169 if (!node_content
) {
1170 ret
= -LTTNG_ERR_NOMEM
;
1174 ret
= get_buffer_type(node_content
);
1177 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1181 domain
->buf_type
= ret
;
1190 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1195 for (node
= xmlFirstElementChild(net_output_node
); node
;
1196 node
= xmlNextElementSibling(node
)) {
1197 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1199 *control_uri
= (char *) xmlNodeGetContent(node
);
1200 if (!*control_uri
) {
1205 *data_uri
= (char *) xmlNodeGetContent(node
);
1212 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1216 int process_consumer_output(xmlNodePtr consumer_output_node
,
1217 struct consumer_output
*output
)
1224 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1225 node
= xmlNextElementSibling(node
)) {
1226 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1227 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1231 ret
= -LTTNG_ERR_NOMEM
;
1235 ret
= parse_bool(enabled_str
, &output
->enabled
);
1241 xmlNodePtr output_type_node
;
1244 output_type_node
= xmlFirstElementChild(node
);
1245 if (!output_type_node
) {
1246 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1250 if (!strcmp((const char *) output_type_node
->name
,
1251 config_element_path
)) {
1253 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1254 if (!output
->path
) {
1255 ret
= -LTTNG_ERR_NOMEM
;
1260 ret
= get_net_output_uris(output_type_node
,
1261 &output
->control_uri
, &output
->data_uri
);
1273 free(output
->control_uri
);
1274 free(output
->data_uri
);
1275 memset(output
, 0, sizeof(struct consumer_output
));
1281 int create_session_net_output(const char *name
, const char *control_uri
,
1282 const char *data_uri
)
1285 struct lttng_handle
*handle
;
1286 const char *uri
= NULL
;
1290 handle
= lttng_create_handle(name
, NULL
);
1292 ret
= -LTTNG_ERR_NOMEM
;
1296 if (!control_uri
|| !data_uri
) {
1297 uri
= control_uri
? control_uri
: data_uri
;
1302 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1303 lttng_destroy_handle(handle
);
1309 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1310 const struct config_load_session_override_attr
*overrides
)
1313 xmlNodePtr node
= NULL
;
1314 xmlNodePtr snapshot_output_list_node
;
1315 xmlNodePtr snapshot_output_node
;
1317 assert(session_name
);
1319 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1328 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1330 /* Parse and create snapshot outputs */
1332 for (snapshot_output_node
=
1333 xmlFirstElementChild(snapshot_output_list_node
);
1334 snapshot_output_node
; snapshot_output_node
=
1335 xmlNextElementSibling(snapshot_output_node
)) {
1337 uint64_t max_size
= UINT64_MAX
;
1338 struct consumer_output output
= { 0 };
1339 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1340 const char *control_uri
= NULL
;
1341 const char *data_uri
= NULL
;
1342 const char *path
= NULL
;
1344 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1345 node
= xmlNextElementSibling(node
)) {
1346 if (!strcmp((const char *) node
->name
,
1347 config_element_name
)) {
1349 name
= (char *) xmlNodeGetContent(node
);
1351 ret
= -LTTNG_ERR_NOMEM
;
1352 goto error_snapshot_output
;
1354 } else if (!strcmp((const char *) node
->name
,
1355 config_element_max_size
)) {
1356 xmlChar
*content
= xmlNodeGetContent(node
);
1360 ret
= -LTTNG_ERR_NOMEM
;
1361 goto error_snapshot_output
;
1363 ret
= parse_uint(content
, &max_size
);
1366 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1367 goto error_snapshot_output
;
1370 /* consumer_output */
1371 ret
= process_consumer_output(node
, &output
);
1373 goto error_snapshot_output
;
1378 control_uri
= output
.control_uri
;
1379 data_uri
= output
.data_uri
;
1383 if (overrides
->path_url
) {
1384 path
= overrides
->path_url
;
1385 /* Control/data_uri are null */
1389 if (overrides
->ctrl_url
) {
1390 control_uri
= overrides
->ctrl_url
;
1394 if (overrides
->data_url
) {
1395 data_uri
= overrides
->data_url
;
1402 snapshot_output
= lttng_snapshot_output_create();
1403 if (!snapshot_output
) {
1404 ret
= -LTTNG_ERR_NOMEM
;
1405 goto error_snapshot_output
;
1408 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1410 goto error_snapshot_output
;
1413 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1415 goto error_snapshot_output
;
1419 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1422 goto error_snapshot_output
;
1426 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1429 goto error_snapshot_output
;
1434 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1437 goto error_snapshot_output
;
1442 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1443 error_snapshot_output
:
1446 free(output
.control_uri
);
1447 free(output
.data_uri
);
1448 lttng_snapshot_output_destroy(snapshot_output
);
1458 int create_session(const char *name
,
1459 xmlNodePtr output_node
,
1460 uint64_t live_timer_interval
,
1461 const struct config_load_session_override_attr
*overrides
)
1464 struct consumer_output output
= { 0 };
1465 xmlNodePtr consumer_output_node
;
1466 const char *control_uri
= NULL
;
1467 const char *data_uri
= NULL
;
1468 const char *path
= NULL
;
1473 consumer_output_node
= xmlFirstElementChild(output_node
);
1474 if (!consumer_output_node
) {
1475 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1479 if (strcmp((const char *) consumer_output_node
->name
,
1480 config_element_consumer_output
)) {
1481 WARN("Invalid output type, expected %s node",
1482 config_element_consumer_output
);
1483 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1487 ret
= process_consumer_output(consumer_output_node
, &output
);
1493 control_uri
= output
.control_uri
;
1494 data_uri
= output
.data_uri
;
1497 /* Check for override and apply them */
1499 if (overrides
->path_url
) {
1500 path
= overrides
->path_url
;
1501 /* control/data_uri are null */;
1505 if (overrides
->ctrl_url
) {
1506 control_uri
= overrides
->ctrl_url
;
1510 if (overrides
->data_url
) {
1511 data_uri
= overrides
->data_url
;
1519 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1520 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1524 if (control_uri
|| data_uri
) {
1525 /* network destination */
1526 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1528 * URLs are provided for sure since the test above make sure that
1529 * with a live timer the data and control URIs are provided. So,
1530 * NULL is passed here and will be set right after.
1532 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1534 ret
= lttng_create_session(name
, NULL
);
1540 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1546 /* either local output or no output */
1547 ret
= lttng_create_session(name
, path
);
1554 free(output
.control_uri
);
1555 free(output
.data_uri
);
1560 struct lttng_userspace_probe_location
*
1561 process_userspace_probe_function_attribute_node(
1562 xmlNodePtr attribute_node
)
1564 xmlNodePtr function_attribute_node
;
1565 char *function_name
= NULL
, *binary_path
= NULL
;
1566 struct lttng_userspace_probe_location
*location
= NULL
;
1567 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1570 * Process userspace probe location function attributes. The order of
1571 * the fields are not guaranteed so we need to iterate over all fields
1572 * and check at the end if everything we need for this location type is
1575 for (function_attribute_node
=
1576 xmlFirstElementChild(attribute_node
);
1577 function_attribute_node
;
1578 function_attribute_node
= xmlNextElementSibling(
1579 function_attribute_node
)) {
1580 /* Handle function name, binary path and lookup method. */
1581 if (!strcmp((const char *) function_attribute_node
->name
,
1582 config_element_userspace_probe_function_location_function_name
)) {
1583 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1584 if (!function_name
) {
1587 } else if (!strcmp((const char *) function_attribute_node
->name
,
1588 config_element_userspace_probe_location_binary_path
)) {
1589 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1593 } else if (!strcmp((const char *) function_attribute_node
->name
,
1594 config_element_userspace_probe_lookup
)) {
1595 char *lookup_method_name
;
1597 lookup_method_name
= (char *) xmlNodeGetContent(
1598 function_attribute_node
);
1599 if (!lookup_method_name
) {
1604 * function_default lookup method defaults to
1605 * function_elf lookup method at the moment.
1607 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1608 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1609 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1610 if (!lookup_method
) {
1611 PERROR("Error creating function default/ELF lookup method");
1614 WARN("Unknown function lookup method");
1617 free(lookup_method_name
);
1618 if (!lookup_method
) {
1625 /* Check if all the necessary fields were found. */
1626 if (binary_path
&& function_name
&& lookup_method
) {
1627 /* Ownership of lookup_method is transferred. */
1629 lttng_userspace_probe_location_function_create(
1630 binary_path
, function_name
,
1632 lookup_method
= NULL
;
1637 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1639 free(function_name
);
1644 struct lttng_userspace_probe_location
*
1645 process_userspace_probe_tracepoint_attribute_node(
1646 xmlNodePtr attribute_node
)
1648 xmlNodePtr tracepoint_attribute_node
;
1649 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1650 struct lttng_userspace_probe_location
*location
= NULL
;
1651 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1654 * Process userspace probe location tracepoint attributes. The order of
1655 * the fields are not guaranteed so we need to iterate over all fields
1656 * and check at the end if everything we need for this location type is
1659 for (tracepoint_attribute_node
=
1660 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1661 tracepoint_attribute_node
= xmlNextElementSibling(
1662 tracepoint_attribute_node
)) {
1663 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1664 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1665 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1669 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1670 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1671 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1672 if (!provider_name
) {
1675 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1676 config_element_userspace_probe_location_binary_path
)) {
1677 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1681 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1682 config_element_userspace_probe_lookup
)) {
1683 char *lookup_method_name
;
1685 lookup_method_name
= (char *) xmlNodeGetContent(
1686 tracepoint_attribute_node
);
1687 if (!lookup_method_name
) {
1691 if (!strcmp(lookup_method_name
,
1692 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1694 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1695 if (!lookup_method
) {
1696 PERROR("Error creating tracepoint SDT lookup method");
1699 WARN("Unknown tracepoint lookup method");
1702 free(lookup_method_name
);
1703 if (!lookup_method
) {
1707 WARN("Unknown tracepoint attribute");
1711 /* Check if all the necessary fields were found. */
1712 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1713 /* Ownership of lookup_method is transferred. */
1715 lttng_userspace_probe_location_tracepoint_create(
1716 binary_path
, provider_name
,
1717 probe_name
, lookup_method
);
1718 lookup_method
= NULL
;
1723 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1725 free(provider_name
);
1731 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1732 struct lttng_event_probe_attr
*attr
)
1736 assert(probe_attribute_node
);
1739 if (!strcmp((const char *) probe_attribute_node
->name
,
1740 config_element_address
)) {
1745 content
= xmlNodeGetContent(probe_attribute_node
);
1747 ret
= -LTTNG_ERR_NOMEM
;
1751 ret
= parse_uint(content
, &addr
);
1754 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1759 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1760 config_element_offset
)) {
1762 uint64_t offset
= 0;
1765 content
= xmlNodeGetContent(probe_attribute_node
);
1767 ret
= -LTTNG_ERR_NOMEM
;
1771 ret
= parse_uint(content
, &offset
);
1774 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1778 attr
->offset
= offset
;
1779 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1780 config_element_symbol_name
)) {
1784 content
= xmlNodeGetContent(probe_attribute_node
);
1786 ret
= -LTTNG_ERR_NOMEM
;
1790 ret
= lttng_strncpy(attr
->symbol_name
,
1791 (const char *) content
,
1792 LTTNG_SYMBOL_NAME_LEN
);
1794 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1795 (const char *) content
,
1796 strlen((const char *) content
),
1797 LTTNG_SYMBOL_NAME_LEN
);
1798 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1810 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1811 const char *channel_name
, const enum process_event_node_phase phase
)
1815 struct lttng_event
*event
;
1816 char **exclusions
= NULL
;
1817 unsigned long exclusion_count
= 0;
1818 char *filter_expression
= NULL
;
1822 assert(channel_name
);
1824 event
= lttng_event_create();
1826 ret
= -LTTNG_ERR_NOMEM
;
1830 /* Initialize default log level which varies by domain */
1831 switch (handle
->domain
.type
)
1833 case LTTNG_DOMAIN_JUL
:
1834 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1836 case LTTNG_DOMAIN_LOG4J
:
1837 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1839 case LTTNG_DOMAIN_PYTHON
:
1840 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1842 case LTTNG_DOMAIN_UST
:
1843 case LTTNG_DOMAIN_KERNEL
:
1844 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1850 for (node
= xmlFirstElementChild(event_node
); node
;
1851 node
= xmlNextElementSibling(node
)) {
1852 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1856 content
= xmlNodeGetContent(node
);
1858 ret
= -LTTNG_ERR_NOMEM
;
1862 ret
= lttng_strncpy(event
->name
,
1863 (const char *) content
,
1864 LTTNG_SYMBOL_NAME_LEN
);
1866 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1867 (const char *) content
,
1868 strlen((const char *) content
),
1869 LTTNG_SYMBOL_NAME_LEN
);
1870 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1875 } else if (!strcmp((const char *) node
->name
,
1876 config_element_enabled
)) {
1877 xmlChar
*content
= xmlNodeGetContent(node
);
1881 ret
= -LTTNG_ERR_NOMEM
;
1885 ret
= parse_bool(content
, &event
->enabled
);
1888 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1891 } else if (!strcmp((const char *) node
->name
,
1892 config_element_type
)) {
1893 xmlChar
*content
= xmlNodeGetContent(node
);
1897 ret
= -LTTNG_ERR_NOMEM
;
1901 ret
= get_event_type(content
);
1904 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1909 } else if (!strcmp((const char *) node
->name
,
1910 config_element_loglevel_type
)) {
1911 xmlChar
*content
= xmlNodeGetContent(node
);
1915 ret
= -LTTNG_ERR_NOMEM
;
1919 ret
= get_loglevel_type(content
);
1922 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1926 event
->loglevel_type
= ret
;
1927 } else if (!strcmp((const char *) node
->name
,
1928 config_element_loglevel
)) {
1930 int64_t loglevel
= 0;
1933 content
= xmlNodeGetContent(node
);
1935 ret
= -LTTNG_ERR_NOMEM
;
1939 ret
= parse_int(content
, &loglevel
);
1942 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1946 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1947 WARN("loglevel out of range.");
1948 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1952 event
->loglevel
= loglevel
;
1953 } else if (!strcmp((const char *) node
->name
,
1954 config_element_filter
)) {
1956 xmlNodeGetContent(node
);
1960 ret
= -LTTNG_ERR_NOMEM
;
1964 free(filter_expression
);
1965 filter_expression
= strdup((char *) content
);
1967 if (!filter_expression
) {
1968 ret
= -LTTNG_ERR_NOMEM
;
1971 } else if (!strcmp((const char *) node
->name
,
1972 config_element_exclusions
)) {
1973 xmlNodePtr exclusion_node
;
1974 int exclusion_index
= 0;
1979 * Exclusions has already been initialized,
1982 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1986 exclusion_count
= xmlChildElementCount(node
);
1987 if (!exclusion_count
) {
1991 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1993 exclusion_count
= 0;
1994 ret
= -LTTNG_ERR_NOMEM
;
1998 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1999 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2001 xmlNodeGetContent(exclusion_node
);
2004 ret
= -LTTNG_ERR_NOMEM
;
2008 exclusions
[exclusion_index
] = strdup((const char *) content
);
2010 if (!exclusions
[exclusion_index
]) {
2011 ret
= -LTTNG_ERR_NOMEM
;
2017 event
->exclusion
= 1;
2018 } else if (!strcmp((const char *) node
->name
,
2019 config_element_attributes
)) {
2020 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2023 if (!attribute_node
) {
2024 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2028 if (!strcmp((const char *) attribute_node
->name
,
2029 config_element_probe_attributes
)) {
2030 xmlNodePtr probe_attribute_node
;
2032 /* probe_attributes */
2033 for (probe_attribute_node
=
2034 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2035 probe_attribute_node
= xmlNextElementSibling(
2036 probe_attribute_node
)) {
2038 ret
= process_probe_attribute_node(probe_attribute_node
,
2039 &event
->attr
.probe
);
2044 } else if (!strcmp((const char *) attribute_node
->name
,
2045 config_element_function_attributes
)) {
2048 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2050 /* function_attributes */
2051 content
= xmlNodeGetContent(symbol_node
);
2053 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2057 sym_len
= strlen((char *) content
);
2058 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2059 WARN("Function name too long.");
2060 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2065 ret
= lttng_strncpy(
2066 event
->attr
.ftrace
.symbol_name
,
2067 (char *) content
, sym_len
);
2069 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2074 } else if (!strcmp((const char *) attribute_node
->name
,
2075 config_element_userspace_probe_tracepoint_attributes
)) {
2076 struct lttng_userspace_probe_location
*location
;
2078 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2080 WARN("Error processing userspace probe tracepoint attribute");
2081 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2084 ret
= lttng_event_set_userspace_probe_location(
2087 WARN("Error setting userspace probe location field");
2088 lttng_userspace_probe_location_destroy(
2090 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2093 } else if (!strcmp((const char *) attribute_node
->name
,
2094 config_element_userspace_probe_function_attributes
)) {
2095 struct lttng_userspace_probe_location
*location
;
2098 process_userspace_probe_function_attribute_node(
2101 WARN("Error processing userspace probe function attribute");
2102 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2106 ret
= lttng_event_set_userspace_probe_location(
2109 WARN("Error setting userspace probe location field");
2110 lttng_userspace_probe_location_destroy(
2112 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2116 /* Unknown event attribute. */
2117 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2123 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2124 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2125 filter_expression
, exclusion_count
, exclusions
);
2127 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2128 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2134 for (i
= 0; i
< exclusion_count
; i
++) {
2135 free(exclusions
[i
]);
2138 lttng_event_destroy(event
);
2140 free(filter_expression
);
2145 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2146 const char *channel_name
)
2149 struct lttng_event event
;
2152 assert(events_node
);
2154 assert(channel_name
);
2156 for (node
= xmlFirstElementChild(events_node
); node
;
2157 node
= xmlNextElementSibling(node
)) {
2158 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2165 * Disable all events to enable only the necessary events.
2166 * Limitations regarding lttng_disable_events and tuple descriptor
2167 * force this approach.
2169 memset(&event
, 0, sizeof(event
));
2170 event
.loglevel
= -1;
2171 event
.type
= LTTNG_EVENT_ALL
;
2172 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2177 for (node
= xmlFirstElementChild(events_node
); node
;
2178 node
= xmlNextElementSibling(node
)) {
2179 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2190 int process_channel_attr_node(xmlNodePtr attr_node
,
2191 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2192 xmlNodePtr
*events_node
)
2198 assert(contexts_node
);
2199 assert(events_node
);
2201 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2205 content
= xmlNodeGetContent(attr_node
);
2207 ret
= -LTTNG_ERR_NOMEM
;
2211 ret
= lttng_strncpy(channel
->name
,
2212 (const char *) content
,
2213 LTTNG_SYMBOL_NAME_LEN
);
2215 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2216 (const char *) content
,
2217 strlen((const char *) content
),
2218 LTTNG_SYMBOL_NAME_LEN
);
2219 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2224 } else if (!strcmp((const char *) attr_node
->name
,
2225 config_element_enabled
)) {
2230 content
= xmlNodeGetContent(attr_node
);
2232 ret
= -LTTNG_ERR_NOMEM
;
2236 ret
= parse_bool(content
, &enabled
);
2239 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2243 channel
->enabled
= enabled
;
2244 } else if (!strcmp((const char *) attr_node
->name
,
2245 config_element_overwrite_mode
)) {
2248 /* overwrite_mode */
2249 content
= xmlNodeGetContent(attr_node
);
2251 ret
= -LTTNG_ERR_NOMEM
;
2255 ret
= get_overwrite_mode(content
);
2258 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2262 channel
->attr
.overwrite
= ret
;
2263 } else if (!strcmp((const char *) attr_node
->name
,
2264 config_element_subbuf_size
)) {
2267 /* subbuffer_size */
2268 content
= xmlNodeGetContent(attr_node
);
2270 ret
= -LTTNG_ERR_NOMEM
;
2274 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2277 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2280 } else if (!strcmp((const char *) attr_node
->name
,
2281 config_element_num_subbuf
)) {
2284 /* subbuffer_count */
2285 content
= xmlNodeGetContent(attr_node
);
2287 ret
= -LTTNG_ERR_NOMEM
;
2291 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2294 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2297 } else if (!strcmp((const char *) attr_node
->name
,
2298 config_element_switch_timer_interval
)) {
2300 uint64_t switch_timer_interval
= 0;
2302 /* switch_timer_interval */
2303 content
= xmlNodeGetContent(attr_node
);
2305 ret
= -LTTNG_ERR_NOMEM
;
2309 ret
= parse_uint(content
, &switch_timer_interval
);
2312 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2316 if (switch_timer_interval
> UINT_MAX
) {
2317 WARN("switch_timer_interval out of range.");
2318 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2322 channel
->attr
.switch_timer_interval
=
2323 switch_timer_interval
;
2324 } else if (!strcmp((const char *) attr_node
->name
,
2325 config_element_read_timer_interval
)) {
2327 uint64_t read_timer_interval
= 0;
2329 /* read_timer_interval */
2330 content
= xmlNodeGetContent(attr_node
);
2332 ret
= -LTTNG_ERR_NOMEM
;
2336 ret
= parse_uint(content
, &read_timer_interval
);
2339 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2343 if (read_timer_interval
> UINT_MAX
) {
2344 WARN("read_timer_interval out of range.");
2345 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2349 channel
->attr
.read_timer_interval
=
2350 read_timer_interval
;
2351 } else if (!strcmp((const char *) attr_node
->name
,
2352 config_element_output_type
)) {
2356 content
= xmlNodeGetContent(attr_node
);
2358 ret
= -LTTNG_ERR_NOMEM
;
2362 ret
= get_output_type(content
);
2365 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2369 channel
->attr
.output
= ret
;
2370 } else if (!strcmp((const char *) attr_node
->name
,
2371 config_element_tracefile_size
)) {
2374 /* tracefile_size */
2375 content
= xmlNodeGetContent(attr_node
);
2377 ret
= -LTTNG_ERR_NOMEM
;
2381 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2384 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2387 } else if (!strcmp((const char *) attr_node
->name
,
2388 config_element_tracefile_count
)) {
2391 /* tracefile_count */
2392 content
= xmlNodeGetContent(attr_node
);
2394 ret
= -LTTNG_ERR_NOMEM
;
2398 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2401 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2404 } else if (!strcmp((const char *) attr_node
->name
,
2405 config_element_live_timer_interval
)) {
2407 uint64_t live_timer_interval
= 0;
2409 /* live_timer_interval */
2410 content
= xmlNodeGetContent(attr_node
);
2412 ret
= -LTTNG_ERR_NOMEM
;
2416 ret
= parse_uint(content
, &live_timer_interval
);
2419 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2423 if (live_timer_interval
> UINT_MAX
) {
2424 WARN("live_timer_interval out of range.");
2425 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2429 channel
->attr
.live_timer_interval
=
2430 live_timer_interval
;
2431 } else if (!strcmp((const char *) attr_node
->name
,
2432 config_element_monitor_timer_interval
)) {
2434 uint64_t monitor_timer_interval
= 0;
2436 /* monitor_timer_interval */
2437 content
= xmlNodeGetContent(attr_node
);
2439 ret
= -LTTNG_ERR_NOMEM
;
2443 ret
= parse_uint(content
, &monitor_timer_interval
);
2446 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2450 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2451 monitor_timer_interval
);
2453 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2456 } else if (!strcmp((const char *) attr_node
->name
,
2457 config_element_blocking_timeout
)) {
2459 int64_t blocking_timeout
= 0;
2461 /* blocking_timeout */
2462 content
= xmlNodeGetContent(attr_node
);
2464 ret
= -LTTNG_ERR_NOMEM
;
2468 ret
= parse_int(content
, &blocking_timeout
);
2471 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2475 ret
= lttng_channel_set_blocking_timeout(channel
,
2478 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2481 } else if (!strcmp((const char *) attr_node
->name
,
2482 config_element_events
)) {
2484 *events_node
= attr_node
;
2487 *contexts_node
= attr_node
;
2495 int process_context_node(xmlNodePtr context_node
,
2496 struct lttng_handle
*handle
, const char *channel_name
)
2499 struct lttng_event_context context
;
2500 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2503 assert(channel_name
);
2505 if (!context_child_node
) {
2506 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2510 memset(&context
, 0, sizeof(context
));
2512 if (!strcmp((const char *) context_child_node
->name
,
2513 config_element_type
)) {
2515 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2518 ret
= -LTTNG_ERR_NOMEM
;
2522 ret
= get_context_type(content
);
2525 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2530 } else if (!strcmp((const char *) context_child_node
->name
,
2531 config_element_context_perf
)) {
2533 xmlNodePtr perf_attr_node
;
2535 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2536 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2537 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2538 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2539 perf_attr_node
; perf_attr_node
=
2540 xmlNextElementSibling(perf_attr_node
)) {
2541 if (!strcmp((const char *) perf_attr_node
->name
,
2542 config_element_type
)) {
2547 content
= xmlNodeGetContent(perf_attr_node
);
2549 ret
= -LTTNG_ERR_NOMEM
;
2553 ret
= parse_uint(content
, &type
);
2556 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2560 if (type
> UINT32_MAX
) {
2561 WARN("perf context type out of range.");
2562 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2566 context
.u
.perf_counter
.type
= type
;
2567 } else if (!strcmp((const char *) perf_attr_node
->name
,
2568 config_element_config
)) {
2570 uint64_t config
= 0;
2573 content
= xmlNodeGetContent(perf_attr_node
);
2575 ret
= -LTTNG_ERR_NOMEM
;
2579 ret
= parse_uint(content
, &config
);
2582 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2586 context
.u
.perf_counter
.config
= config
;
2587 } else if (!strcmp((const char *) perf_attr_node
->name
,
2588 config_element_name
)) {
2592 content
= xmlNodeGetContent(perf_attr_node
);
2594 ret
= -LTTNG_ERR_NOMEM
;
2598 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2599 (const char *) content
,
2600 LTTNG_SYMBOL_NAME_LEN
);
2602 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2603 (const char *) content
,
2604 strlen((const char *) content
),
2605 LTTNG_SYMBOL_NAME_LEN
);
2606 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2613 } else if (!strcmp((const char *) context_child_node
->name
,
2614 config_element_context_app
)) {
2615 /* application context */
2616 xmlNodePtr app_ctx_node
;
2618 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2619 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2620 app_ctx_node
; app_ctx_node
=
2621 xmlNextElementSibling(app_ctx_node
)) {
2623 char **target
= strcmp(
2624 (const char *) app_ctx_node
->name
,
2625 config_element_context_app_provider_name
) == 0 ?
2626 &context
.u
.app_ctx
.provider_name
:
2627 &context
.u
.app_ctx
.ctx_name
;
2629 content
= xmlNodeGetContent(app_ctx_node
);
2631 ret
= -LTTNG_ERR_NOMEM
;
2635 *target
= (char *) content
;
2638 /* Unrecognized context type */
2639 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2643 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2644 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2645 free(context
.u
.app_ctx
.provider_name
);
2646 free(context
.u
.app_ctx
.ctx_name
);
2653 int process_contexts_node(xmlNodePtr contexts_node
,
2654 struct lttng_handle
*handle
, const char *channel_name
)
2657 xmlNodePtr context_node
;
2659 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2660 context_node
= xmlNextElementSibling(context_node
)) {
2661 ret
= process_context_node(context_node
, handle
, channel_name
);
2670 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2671 const char **element_id_tracker
,
2672 const char **element_value_type
,
2673 const char **element_value
,
2674 const char **element_value_alias
,
2675 const char **element_name
)
2679 switch (process_attr
) {
2680 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2681 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2682 *element_value_type
= config_element_process_attr_pid_value
;
2683 *element_value
= config_element_process_attr_id
;
2684 *element_value_alias
= config_element_process_attr_id
;
2685 *element_name
= NULL
;
2687 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2688 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2689 *element_value_type
= config_element_process_attr_vpid_value
;
2690 *element_value
= config_element_process_attr_id
;
2691 *element_value_alias
= NULL
;
2692 *element_name
= NULL
;
2694 case LTTNG_PROCESS_ATTR_USER_ID
:
2695 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2696 *element_value_type
= config_element_process_attr_uid_value
;
2697 *element_value
= config_element_process_attr_id
;
2698 *element_value_alias
= NULL
;
2699 *element_name
= config_element_name
;
2701 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2702 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2703 *element_value_type
= config_element_process_attr_vuid_value
;
2704 *element_value
= config_element_process_attr_id
;
2705 *element_value_alias
= NULL
;
2706 *element_name
= config_element_name
;
2708 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2709 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2710 *element_value_type
= config_element_process_attr_gid_value
;
2711 *element_value
= config_element_process_attr_id
;
2712 *element_value_alias
= NULL
;
2713 *element_name
= config_element_name
;
2715 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2716 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2717 *element_value_type
= config_element_process_attr_vgid_value
;
2718 *element_value
= config_element_process_attr_id
;
2719 *element_value_alias
= NULL
;
2720 *element_name
= config_element_name
;
2723 ret
= LTTNG_ERR_INVALID
;
2728 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2729 struct lttng_handle
*handle
,
2730 enum lttng_process_attr process_attr
)
2732 int ret
= 0, child_count
;
2733 xmlNodePtr targets_node
= NULL
;
2735 const char *element_id_tracker
;
2736 const char *element_target_id
;
2737 const char *element_id
;
2738 const char *element_id_alias
;
2739 const char *element_name
;
2740 enum lttng_error_code tracker_handle_ret_code
;
2741 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2742 enum lttng_process_attr_tracker_handle_status status
;
2745 assert(id_tracker_node
);
2747 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2748 handle
->session_name
, handle
->domain
.type
, process_attr
,
2750 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2751 ret
= LTTNG_ERR_INVALID
;
2755 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2756 &element_target_id
, &element_id
, &element_id_alias
,
2762 /* get the targets node */
2763 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2764 node
= xmlNextElementSibling(node
)) {
2765 if (!strcmp((const char *) node
->name
,
2766 config_element_process_attr_values
)) {
2767 targets_node
= node
;
2772 if (!targets_node
) {
2773 ret
= LTTNG_ERR_INVALID
;
2777 /* Go through all id target node */
2778 child_count
= xmlChildElementCount(targets_node
);
2779 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2781 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2782 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2783 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2784 ret
= LTTNG_ERR_UNK
;
2788 /* Add all tracked values. */
2789 for (node
= xmlFirstElementChild(targets_node
); node
;
2790 node
= xmlNextElementSibling(node
)) {
2791 xmlNodePtr id_target_node
= node
;
2793 /* get id node and track it */
2794 for (node
= xmlFirstElementChild(id_target_node
); node
;
2795 node
= xmlNextElementSibling(node
)) {
2796 if (!strcmp((const char *) node
->name
, element_id
) ||
2797 (element_id_alias
&&
2798 !strcmp((const char *) node
->name
,
2799 element_id_alias
))) {
2801 xmlChar
*content
= xmlNodeGetContent(node
);
2804 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2808 ret
= parse_int(content
, &id
);
2811 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2815 switch (process_attr
) {
2816 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2817 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2821 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2822 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2826 case LTTNG_PROCESS_ATTR_USER_ID
:
2827 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2831 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2832 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2836 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2837 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2841 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2842 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
2847 ret
= LTTNG_ERR_INVALID
;
2850 } else if (element_name
&&
2851 !strcmp((const char *) node
->name
,
2853 xmlChar
*content
= xmlNodeGetContent(node
);
2856 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2860 switch (process_attr
) {
2861 case LTTNG_PROCESS_ATTR_USER_ID
:
2862 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
2864 (const char *) content
);
2866 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2867 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
2869 (const char *) content
);
2871 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2872 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
2874 (const char *) content
);
2876 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2877 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
2879 (const char *) content
);
2883 ret
= LTTNG_ERR_INVALID
;
2889 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2891 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2892 ret
= LTTNG_ERR_INVALID
;
2894 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2895 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2897 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2898 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2900 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2901 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2903 ret
= LTTNG_ERR_UNK
;
2907 node
= id_target_node
;
2911 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2916 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2919 struct lttng_domain domain
= { 0 };
2920 struct lttng_handle
*handle
= NULL
;
2921 struct lttng_channel
*channel
= NULL
;
2922 xmlNodePtr channels_node
= NULL
;
2923 xmlNodePtr trackers_node
= NULL
;
2924 xmlNodePtr pid_tracker_node
= NULL
;
2925 xmlNodePtr vpid_tracker_node
= NULL
;
2926 xmlNodePtr uid_tracker_node
= NULL
;
2927 xmlNodePtr vuid_tracker_node
= NULL
;
2928 xmlNodePtr gid_tracker_node
= NULL
;
2929 xmlNodePtr vgid_tracker_node
= NULL
;
2932 assert(session_name
);
2934 ret
= init_domain(domain_node
, &domain
);
2939 handle
= lttng_create_handle(session_name
, &domain
);
2941 ret
= -LTTNG_ERR_NOMEM
;
2945 /* get the channels node */
2946 for (node
= xmlFirstElementChild(domain_node
); node
;
2947 node
= xmlNextElementSibling(node
)) {
2948 if (!strcmp((const char *) node
->name
,
2949 config_element_channels
)) {
2950 channels_node
= node
;
2955 if (!channels_node
) {
2959 /* create all channels */
2960 for (node
= xmlFirstElementChild(channels_node
); node
;
2961 node
= xmlNextElementSibling(node
)) {
2962 const enum lttng_domain_type original_domain
= domain
.type
;
2963 xmlNodePtr contexts_node
= NULL
;
2964 xmlNodePtr events_node
= NULL
;
2965 xmlNodePtr channel_attr_node
;
2968 * Channels of the "agent" types cannot be created directly.
2969 * They are meant to be created implicitly through the
2970 * activation of events in their domain. However, a user
2971 * can override the default channel configuration attributes
2972 * by creating the underlying UST channel _before_ enabling
2973 * an agent domain event.
2975 * Hence, the channel's type is substituted before the creation
2976 * and restored by the time the events are created.
2978 switch (domain
.type
) {
2979 case LTTNG_DOMAIN_JUL
:
2980 case LTTNG_DOMAIN_LOG4J
:
2981 case LTTNG_DOMAIN_PYTHON
:
2982 domain
.type
= LTTNG_DOMAIN_UST
;
2987 channel
= lttng_channel_create(&domain
);
2993 for (channel_attr_node
= xmlFirstElementChild(node
);
2994 channel_attr_node
; channel_attr_node
=
2995 xmlNextElementSibling(channel_attr_node
)) {
2996 ret
= process_channel_attr_node(channel_attr_node
,
2997 channel
, &contexts_node
, &events_node
);
3003 ret
= lttng_enable_channel(handle
, channel
);
3008 /* Restore the original channel domain. */
3009 domain
.type
= original_domain
;
3011 ret
= process_events_node(events_node
, handle
, channel
->name
);
3016 ret
= process_contexts_node(contexts_node
, handle
,
3022 lttng_channel_destroy(channel
);
3026 /* get the trackers node */
3027 for (node
= xmlFirstElementChild(domain_node
); node
;
3028 node
= xmlNextElementSibling(node
)) {
3029 if (!strcmp((const char *) node
->name
,
3030 config_element_process_attr_trackers
)) {
3031 trackers_node
= node
;
3036 if (!trackers_node
) {
3040 for (node
= xmlFirstElementChild(trackers_node
); node
;
3041 node
= xmlNextElementSibling(node
)) {
3042 if (!strcmp((const char *) node
->name
,
3043 config_element_process_attr_tracker_pid
)) {
3044 pid_tracker_node
= node
;
3045 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3046 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3051 if (!strcmp((const char *) node
->name
,
3052 config_element_process_attr_tracker_vpid
)) {
3053 vpid_tracker_node
= node
;
3054 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3055 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3060 if (!strcmp((const char *) node
->name
,
3061 config_element_process_attr_tracker_uid
)) {
3062 uid_tracker_node
= node
;
3063 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3064 LTTNG_PROCESS_ATTR_USER_ID
);
3069 if (!strcmp((const char *) node
->name
,
3070 config_element_process_attr_tracker_vuid
)) {
3071 vuid_tracker_node
= node
;
3072 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3073 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3078 if (!strcmp((const char *) node
->name
,
3079 config_element_process_attr_tracker_gid
)) {
3080 gid_tracker_node
= node
;
3081 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3082 LTTNG_PROCESS_ATTR_GROUP_ID
);
3087 if (!strcmp((const char *) node
->name
,
3088 config_element_process_attr_tracker_vgid
)) {
3089 vgid_tracker_node
= node
;
3090 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3091 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3099 lttng_channel_destroy(channel
);
3100 lttng_destroy_handle(handle
);
3105 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3108 enum lttng_rotation_status status
;
3109 struct lttng_rotation_schedule
*periodic
=
3110 lttng_rotation_schedule_periodic_create();
3113 ret
= -LTTNG_ERR_NOMEM
;
3117 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3119 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3120 ret
= -LTTNG_ERR_INVALID
;
3124 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3126 case LTTNG_ROTATION_STATUS_OK
:
3129 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3130 case LTTNG_ROTATION_STATUS_INVALID
:
3131 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3134 ret
= -LTTNG_ERR_UNK
;
3138 lttng_rotation_schedule_destroy(periodic
);
3143 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3146 enum lttng_rotation_status status
;
3147 struct lttng_rotation_schedule
*size
=
3148 lttng_rotation_schedule_size_threshold_create();
3151 ret
= -LTTNG_ERR_NOMEM
;
3155 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3157 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3158 ret
= -LTTNG_ERR_INVALID
;
3162 status
= lttng_session_add_rotation_schedule(name
, size
);
3164 case LTTNG_ROTATION_STATUS_OK
:
3167 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3168 case LTTNG_ROTATION_STATUS_INVALID
:
3169 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3172 ret
= -LTTNG_ERR_UNK
;
3176 lttng_rotation_schedule_destroy(size
);
3181 int process_session_rotation_schedules_node(
3182 xmlNodePtr schedules_node
,
3183 uint64_t *rotation_timer_interval
,
3184 uint64_t *rotation_size
)
3189 for (child
= xmlFirstElementChild(schedules_node
);
3191 child
= xmlNextElementSibling(child
)) {
3192 if (!strcmp((const char *) child
->name
,
3193 config_element_rotation_schedule_periodic
)) {
3195 xmlNodePtr time_us_node
;
3197 /* periodic rotation schedule */
3198 time_us_node
= xmlFirstElementChild(child
);
3199 if (!time_us_node
||
3200 strcmp((const char *) time_us_node
->name
,
3201 config_element_rotation_schedule_periodic_time_us
)) {
3202 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3207 content
= xmlNodeGetContent(time_us_node
);
3209 ret
= -LTTNG_ERR_NOMEM
;
3212 ret
= parse_uint(content
, rotation_timer_interval
);
3215 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3218 } else if (!strcmp((const char *) child
->name
,
3219 config_element_rotation_schedule_size_threshold
)) {
3221 xmlNodePtr bytes_node
;
3223 /* size_threshold rotation schedule */
3224 bytes_node
= xmlFirstElementChild(child
);
3226 strcmp((const char *) bytes_node
->name
,
3227 config_element_rotation_schedule_size_threshold_bytes
)) {
3228 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3233 content
= xmlNodeGetContent(bytes_node
);
3235 ret
= -LTTNG_ERR_NOMEM
;
3238 ret
= parse_uint(content
, rotation_size
);
3241 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3252 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3254 const struct config_load_session_override_attr
*overrides
)
3256 int ret
, started
= -1, snapshot_mode
= -1;
3257 uint64_t live_timer_interval
= UINT64_MAX
,
3258 rotation_timer_interval
= 0,
3260 xmlChar
*name
= NULL
;
3261 xmlChar
*shm_path
= NULL
;
3262 xmlNodePtr domains_node
= NULL
;
3263 xmlNodePtr output_node
= NULL
;
3265 xmlNodePtr attributes_child
;
3266 struct lttng_domain
*kernel_domain
= NULL
;
3267 struct lttng_domain
*ust_domain
= NULL
;
3268 struct lttng_domain
*jul_domain
= NULL
;
3269 struct lttng_domain
*log4j_domain
= NULL
;
3270 struct lttng_domain
*python_domain
= NULL
;
3272 for (node
= xmlFirstElementChild(session_node
); node
;
3273 node
= xmlNextElementSibling(node
)) {
3274 if (!name
&& !strcmp((const char *) node
->name
,
3275 config_element_name
)) {
3277 xmlChar
*node_content
= xmlNodeGetContent(node
);
3278 if (!node_content
) {
3279 ret
= -LTTNG_ERR_NOMEM
;
3283 name
= node_content
;
3284 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3285 config_element_domains
)) {
3287 domains_node
= node
;
3288 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3289 config_element_started
)) {
3291 xmlChar
*node_content
= xmlNodeGetContent(node
);
3292 if (!node_content
) {
3293 ret
= -LTTNG_ERR_NOMEM
;
3297 ret
= parse_bool(node_content
, &started
);
3300 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3303 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3304 config_element_output
)) {
3307 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3308 config_element_shared_memory_path
)) {
3309 /* shared memory path */
3310 xmlChar
*node_content
= xmlNodeGetContent(node
);
3311 if (!node_content
) {
3312 ret
= -LTTNG_ERR_NOMEM
;
3316 shm_path
= node_content
;
3319 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3320 * rotation_timer_interval.
3322 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3323 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3324 if (!strcmp((const char *) attributes_child
->name
,
3325 config_element_snapshot_mode
)) {
3327 xmlChar
*snapshot_mode_content
=
3328 xmlNodeGetContent(attributes_child
);
3329 if (!snapshot_mode_content
) {
3330 ret
= -LTTNG_ERR_NOMEM
;
3334 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3335 free(snapshot_mode_content
);
3337 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3340 } else if (!strcmp((const char *) attributes_child
->name
,
3341 config_element_live_timer_interval
)) {
3342 /* live_timer_interval */
3343 xmlChar
*timer_interval_content
=
3344 xmlNodeGetContent(attributes_child
);
3345 if (!timer_interval_content
) {
3346 ret
= -LTTNG_ERR_NOMEM
;
3350 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3351 free(timer_interval_content
);
3353 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3356 } else if (!strcmp((const char *) attributes_child
->name
,
3357 config_element_rotation_schedules
)) {
3358 ret
= process_session_rotation_schedules_node(
3360 &rotation_timer_interval
,
3363 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3373 /* Mandatory attribute, as defined in the session XSD */
3374 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3378 if (session_name
&& strcmp((char *) name
, session_name
)) {
3379 /* This is not the session we are looking for */
3380 ret
= -LTTNG_ERR_NO_SESSION
;
3384 /* Init domains to create the session handles */
3385 for (node
= xmlFirstElementChild(domains_node
); node
;
3386 node
= xmlNextElementSibling(node
)) {
3387 struct lttng_domain
*domain
;
3389 domain
= zmalloc(sizeof(*domain
));
3391 ret
= -LTTNG_ERR_NOMEM
;
3395 ret
= init_domain(node
, domain
);
3397 goto domain_init_error
;
3400 switch (domain
->type
) {
3401 case LTTNG_DOMAIN_KERNEL
:
3402 if (kernel_domain
) {
3403 /* Same domain seen twice, invalid! */
3404 goto domain_init_error
;
3406 kernel_domain
= domain
;
3408 case LTTNG_DOMAIN_UST
:
3410 /* Same domain seen twice, invalid! */
3411 goto domain_init_error
;
3413 ust_domain
= domain
;
3415 case LTTNG_DOMAIN_JUL
:
3417 /* Same domain seen twice, invalid! */
3418 goto domain_init_error
;
3420 jul_domain
= domain
;
3422 case LTTNG_DOMAIN_LOG4J
:
3424 /* Same domain seen twice, invalid! */
3425 goto domain_init_error
;
3427 log4j_domain
= domain
;
3429 case LTTNG_DOMAIN_PYTHON
:
3430 if (python_domain
) {
3431 /* Same domain seen twice, invalid! */
3432 goto domain_init_error
;
3434 python_domain
= domain
;
3437 WARN("Invalid domain type");
3438 goto domain_init_error
;
3443 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3447 /* Apply overrides */
3449 if (overrides
->session_name
) {
3450 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3451 if (!name_override
) {
3452 ret
= -LTTNG_ERR_NOMEM
;
3456 /* Overrides the session name to the provided name */
3458 name
= name_override
;
3463 /* Destroy session if it exists */
3464 ret
= lttng_destroy_session((const char *) name
);
3465 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3466 ERR("Failed to destroy existing session.");
3471 /* Create session type depending on output type */
3472 if (snapshot_mode
&& snapshot_mode
!= -1) {
3473 ret
= create_snapshot_session((const char *) name
, output_node
,
3475 } else if (live_timer_interval
&&
3476 live_timer_interval
!= UINT64_MAX
) {
3477 ret
= create_session((const char *) name
,
3478 output_node
, live_timer_interval
, overrides
);
3480 /* regular session */
3481 ret
= create_session((const char *) name
,
3482 output_node
, UINT64_MAX
, overrides
);
3489 ret
= lttng_set_session_shm_path((const char *) name
,
3490 (const char *) shm_path
);
3496 for (node
= xmlFirstElementChild(domains_node
); node
;
3497 node
= xmlNextElementSibling(node
)) {
3498 ret
= process_domain_node(node
, (const char *) name
);
3504 if (rotation_timer_interval
) {
3505 ret
= add_periodic_rotation((const char *) name
,
3506 rotation_timer_interval
);
3511 if (rotation_size
) {
3512 ret
= add_size_rotation((const char *) name
,
3520 ret
= lttng_start_tracing((const char *) name
);
3528 ERR("Failed to load session %s: %s", (const char *) name
,
3529 lttng_strerror(ret
));
3530 lttng_destroy_session((const char *) name
);
3534 free(kernel_domain
);
3538 free(python_domain
);
3545 * Return 1 if the given path is readable by the current UID or 0 if not.
3546 * Return -1 if the path is EPERM.
3548 static int validate_file_read_creds(const char *path
)
3554 /* Can we read the file. */
3555 ret
= access(path
, R_OK
);
3559 if (errno
== EACCES
) {
3570 int load_session_from_file(const char *path
, const char *session_name
,
3571 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3572 const struct config_load_session_override_attr
*overrides
)
3574 int ret
, session_found
= !session_name
;
3575 xmlDocPtr doc
= NULL
;
3576 xmlNodePtr sessions_node
;
3577 xmlNodePtr session_node
;
3580 assert(validation_ctx
);
3582 ret
= validate_file_read_creds(path
);
3585 ret
= -LTTNG_ERR_EPERM
;
3587 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3592 doc
= xmlParseFile(path
);
3594 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3598 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3600 ERR("Session configuration file validation failed");
3601 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3605 sessions_node
= xmlDocGetRootElement(doc
);
3606 if (!sessions_node
) {
3607 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3611 for (session_node
= xmlFirstElementChild(sessions_node
);
3612 session_node
; session_node
=
3613 xmlNextElementSibling(session_node
)) {
3614 ret
= process_session_node(session_node
,
3615 session_name
, overwrite
, overrides
);
3616 if (session_name
&& ret
== 0) {
3617 /* Target session found and loaded */
3625 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3627 if (ret
== -LTTNG_ERR_NO_SESSION
) {
3628 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3634 int load_session_from_path(const char *path
, const char *session_name
,
3635 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3636 const struct config_load_session_override_attr
*overrides
)
3638 int ret
, session_found
= !session_name
;
3639 DIR *directory
= NULL
;
3640 struct lttng_dynamic_buffer file_path
;
3644 assert(validation_ctx
);
3645 path_len
= strlen(path
);
3646 lttng_dynamic_buffer_init(&file_path
);
3647 if (path_len
>= LTTNG_PATH_MAX
) {
3648 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3649 path
, path_len
, LTTNG_PATH_MAX
);
3650 ret
= -LTTNG_ERR_INVALID
;
3654 directory
= opendir(path
);
3658 /* Try the file loading. */
3661 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3664 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3669 size_t file_path_root_len
;
3671 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3674 ret
= -LTTNG_ERR_NOMEM
;
3678 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3680 ret
= -LTTNG_ERR_NOMEM
;
3684 if (file_path
.data
[file_path
.size
- 1] != '/') {
3685 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3687 ret
= -LTTNG_ERR_NOMEM
;
3691 file_path_root_len
= file_path
.size
;
3693 /* Search for *.lttng files */
3695 size_t file_name_len
;
3696 struct dirent
*result
;
3699 * When the end of the directory stream is reached, NULL
3700 * is returned and errno is kept unchanged. When an
3701 * error occurs, NULL is returned and errno is set
3702 * accordingly. To distinguish between the two, set
3703 * errno to zero before calling readdir().
3705 * On success, readdir() returns a pointer to a dirent
3706 * structure. This structure may be statically
3707 * allocated, do not attempt to free(3) it.
3710 result
= readdir(directory
);
3712 /* Reached end of dir stream or error out. */
3715 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3716 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3722 file_name_len
= strlen(result
->d_name
);
3724 if (file_name_len
<=
3725 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3729 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3730 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3732 /* +1 to account for NULL terminator. */
3733 file_path
.size
+ file_name_len
+ 1,
3738 /* Does the file end with .lttng? */
3739 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3740 result
->d_name
+ file_name_len
- sizeof(
3741 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3745 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3748 ret
= -LTTNG_ERR_NOMEM
;
3752 ret
= load_session_from_file(file_path
.data
, session_name
,
3753 validation_ctx
, overwrite
, overrides
);
3755 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3759 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3763 * Reset the buffer's size to the location of the
3764 * path's trailing '/'.
3766 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3767 file_path_root_len
);
3769 ret
= -LTTNG_ERR_UNK
;
3774 ret
= load_session_from_file(path
, session_name
,
3775 validation_ctx
, overwrite
, overrides
);
3785 if (closedir(directory
)) {
3789 if (!ret
&& !session_found
) {
3790 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3792 lttng_dynamic_buffer_reset(&file_path
);
3797 * Validate that the given path's credentials and the current process have the
3798 * same UID. If so, return 1 else return 0 if it does NOT match.
3800 static int validate_path_creds(const char *path
)
3802 int ret
, uid
= getuid();
3811 ret
= stat(path
, &buf
);
3813 if (errno
!= ENOENT
) {
3819 if (buf
.st_uid
!= uid
) {
3830 int config_load_session(const char *path
, const char *session_name
,
3831 int overwrite
, unsigned int autoload
,
3832 const struct config_load_session_override_attr
*overrides
)
3835 bool session_loaded
= false;
3836 const char *path_ptr
= NULL
;
3837 struct session_config_validation_ctx validation_ctx
= { 0 };
3839 ret
= init_session_config_validation_ctx(&validation_ctx
);
3845 const char *home_path
;
3846 const char *sys_path
;
3849 home_path
= utils_get_home_dir();
3851 char path
[PATH_MAX
];
3854 * Try user session configuration path. Ignore error here so we can
3855 * continue loading the system wide sessions.
3858 ret
= snprintf(path
, sizeof(path
),
3859 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3860 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3862 PERROR("snprintf session autoload home config path");
3863 ret
= -LTTNG_ERR_INVALID
;
3868 * Credentials are only validated for the autoload in order to
3869 * avoid any user session daemon to try to load kernel sessions
3870 * automatically and failing all the times.
3872 ret
= validate_path_creds(path
);
3877 ret
= snprintf(path
, sizeof(path
),
3878 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3880 PERROR("snprintf session home config path");
3881 ret
= -LTTNG_ERR_INVALID
;
3887 ret
= load_session_from_path(path_ptr
, session_name
,
3888 &validation_ctx
, overwrite
, overrides
);
3889 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3893 * Continue even if the session was found since we have to try
3894 * the system wide sessions.
3896 session_loaded
= true;
3900 /* Reset path pointer for the system wide dir. */
3903 /* Try system wide configuration directory. */
3905 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3906 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3907 ret
= validate_path_creds(sys_path
);
3909 path_ptr
= sys_path
;
3912 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3913 path_ptr
= sys_path
;
3917 ret
= load_session_from_path(path_ptr
, session_name
,
3918 &validation_ctx
, overwrite
, overrides
);
3920 session_loaded
= true;
3926 ret
= access(path
, F_OK
);
3931 ret
= -LTTNG_ERR_INVALID
;
3932 WARN("Session configuration path does not exist.");
3935 ret
= -LTTNG_ERR_EPERM
;
3938 ret
= -LTTNG_ERR_UNK
;
3944 ret
= load_session_from_path(path
, session_name
,
3945 &validation_ctx
, overwrite
, overrides
);
3948 fini_session_config_validation_ctx(&validation_ctx
);
3949 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3951 * Don't report an error if no sessions are found when called
3952 * without a session_name or a search path.
3957 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3958 /* A matching session was found in one of the search paths. */
3965 void __attribute__((destructor
)) session_config_exit(void)