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"
17 #include <sys/types.h>
21 #include <common/defaults.h>
22 #include <common/error.h>
23 #include <common/macros.h>
24 #include <common/utils.h>
25 #include <common/dynamic-buffer.h>
26 #include <common/compat/getenv.h>
27 #include <lttng/lttng-error.h>
28 #include <libxml/parser.h>
29 #include <libxml/valid.h>
30 #include <libxml/xmlschemas.h>
31 #include <libxml/tree.h>
32 #include <lttng/lttng.h>
33 #include <lttng/snapshot.h>
34 #include <lttng/rotation.h>
35 #include <lttng/userspace-probe.h>
37 #include "session-config.h"
38 #include "config-internal.h"
40 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
42 struct handler_filter_args
{
44 config_entry_handler_cb handler
;
48 struct session_config_validation_ctx
{
49 xmlSchemaParserCtxtPtr parser_ctx
;
51 xmlSchemaValidCtxtPtr schema_validation_ctx
;
54 const char * const config_element_all
= "all";
55 const char * const config_str_yes
= "yes";
56 const char * const config_str_true
= "true";
57 const char * const config_str_on
= "on";
58 const char * const config_str_no
= "no";
59 const char * const config_str_false
= "false";
60 const char * const config_str_off
= "off";
61 const char * const config_xml_encoding
= "UTF-8";
62 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
63 const char * const config_xml_indent_string
= "\t";
64 const char * const config_xml_true
= "true";
65 const char * const config_xml_false
= "false";
67 const char * const config_element_channel
= "channel";
68 const char * const config_element_channels
= "channels";
69 const char * const config_element_domain
= "domain";
70 const char * const config_element_domains
= "domains";
71 const char * const config_element_event
= "event";
72 const char * const config_element_events
= "events";
73 const char * const config_element_context
= "context";
74 const char * const config_element_contexts
= "contexts";
75 const char * const config_element_attributes
= "attributes";
76 const char * const config_element_exclusion
= "exclusion";
77 const char * const config_element_exclusions
= "exclusions";
78 const char * const config_element_function_attributes
= "function_attributes";
79 const char * const config_element_probe_attributes
= "probe_attributes";
80 const char * const config_element_symbol_name
= "symbol_name";
81 const char * const config_element_address
= "address";
82 const char * const config_element_offset
= "offset";
84 const char * const config_element_userspace_probe_lookup
= "lookup_method";
85 const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
86 const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
87 const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
88 const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
89 const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
90 const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
91 const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
92 const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
93 const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
95 const char * const config_element_name
= "name";
96 const char * const config_element_enabled
= "enabled";
97 const char * const config_element_overwrite_mode
= "overwrite_mode";
98 const char * const config_element_subbuf_size
= "subbuffer_size";
99 const char * const config_element_num_subbuf
= "subbuffer_count";
100 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
101 const char * const config_element_read_timer_interval
= "read_timer_interval";
102 const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
103 const char * const config_element_blocking_timeout
= "blocking_timeout";
104 const char * const config_element_output
= "output";
105 const char * const config_element_output_type
= "output_type";
106 const char * const config_element_tracefile_size
= "tracefile_size";
107 const char * const config_element_tracefile_count
= "tracefile_count";
108 const char * const config_element_live_timer_interval
= "live_timer_interval";
109 const char * const config_element_discarded_events
= "discarded_events";
110 const char * const config_element_lost_packets
= "lost_packets";
111 const char * const config_element_type
= "type";
112 const char * const config_element_buffer_type
= "buffer_type";
113 const char * const config_element_session
= "session";
114 const char * const config_element_sessions
= "sessions";
115 const char * const config_element_context_perf
= "perf";
116 const char * const config_element_context_app
= "app";
117 const char * const config_element_context_app_provider_name
= "provider_name";
118 const char * const config_element_context_app_ctx_name
= "ctx_name";
119 const char * const config_element_config
= "config";
120 const char * const config_element_started
= "started";
121 const char * const config_element_snapshot_mode
= "snapshot_mode";
122 const char * const config_element_loglevel
= "loglevel";
123 const char * const config_element_loglevel_type
= "loglevel_type";
124 const char * const config_element_filter
= "filter";
125 const char * const config_element_filter_expression
= "filter_expression";
126 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
127 const char * const config_element_consumer_output
= "consumer_output";
128 const char * const config_element_destination
= "destination";
129 const char * const config_element_path
= "path";
130 const char * const config_element_net_output
= "net_output";
131 const char * const config_element_control_uri
= "control_uri";
132 const char * const config_element_data_uri
= "data_uri";
133 const char * const config_element_max_size
= "max_size";
134 const char * const config_element_pid
= "pid";
135 const char * const config_element_pids
= "pids";
136 const char * const config_element_shared_memory_path
= "shared_memory_path";
138 const char * const config_element_process_attr_id
= "id";
139 const char * const config_element_process_attr_tracker_pid
= "pid_process_attr_tracker";
140 const char * const config_element_process_attr_tracker_vpid
= "vpid_process_attr_tracker";
141 const char * const config_element_process_attr_tracker_uid
= "uid_process_attr_tracker";
142 const char * const config_element_process_attr_tracker_vuid
= "vuid_process_attr_tracker";
143 const char * const config_element_process_attr_tracker_gid
= "gid_process_attr_tracker";
144 const char * const config_element_process_attr_tracker_vgid
= "vgid_process_attr_tracker";
145 const char * const config_element_process_attr_trackers
= "process_attr_trackers";
146 const char * const config_element_process_attr_values
= "process_attr_values";
147 const char * const config_element_process_attr_value_type
= "process_attr_value_type";
148 const char * const config_element_process_attr_pid_value
= "pid";
149 const char * const config_element_process_attr_vpid_value
= "vpid";
150 const char * const config_element_process_attr_uid_value
= "uid";
151 const char * const config_element_process_attr_vuid_value
= "vuid";
152 const char * const config_element_process_attr_gid_value
= "gid";
153 const char * const config_element_process_attr_vgid_value
= "vgid";
154 const char * const config_element_process_attr_tracker_type
= "process_attr_tracker_type";
156 /* Used for support of legacy tracker serialization (< 2.12). */
157 const char * const config_element_trackers_legacy
= "trackers";
158 const char * const config_element_pid_tracker_legacy
= "pid_tracker";
159 const char * const config_element_tracker_targets_legacy
= "targets";
160 const char * const config_element_tracker_pid_target_legacy
= "pid_target";
161 const char * const config_element_tracker_pid_legacy
= "pid";
163 const char * const config_element_rotation_schedules
= "rotation_schedules";
164 const char * const config_element_rotation_schedule_periodic
= "periodic";
165 const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
166 const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
167 const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
169 const char * const config_domain_type_kernel
= "KERNEL";
170 const char * const config_domain_type_ust
= "UST";
171 const char * const config_domain_type_jul
= "JUL";
172 const char * const config_domain_type_log4j
= "LOG4J";
173 const char * const config_domain_type_python
= "PYTHON";
175 const char * const config_buffer_type_per_pid
= "PER_PID";
176 const char * const config_buffer_type_per_uid
= "PER_UID";
177 const char * const config_buffer_type_global
= "GLOBAL";
179 const char * const config_overwrite_mode_discard
= "DISCARD";
180 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
182 const char * const config_output_type_splice
= "SPLICE";
183 const char * const config_output_type_mmap
= "MMAP";
185 const char * const config_loglevel_type_all
= "ALL";
186 const char * const config_loglevel_type_range
= "RANGE";
187 const char * const config_loglevel_type_single
= "SINGLE";
189 const char * const config_event_type_all
= "ALL";
190 const char * const config_event_type_tracepoint
= "TRACEPOINT";
191 const char * const config_event_type_probe
= "PROBE";
192 const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
193 const char * const config_event_type_function
= "FUNCTION";
194 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
195 const char * const config_event_type_noop
= "NOOP";
196 const char * const config_event_type_syscall
= "SYSCALL";
197 const char * const config_event_type_kprobe
= "KPROBE";
198 const char * const config_event_type_kretprobe
= "KRETPROBE";
200 const char * const config_event_context_pid
= "PID";
201 const char * const config_event_context_procname
= "PROCNAME";
202 const char * const config_event_context_prio
= "PRIO";
203 const char * const config_event_context_nice
= "NICE";
204 const char * const config_event_context_vpid
= "VPID";
205 const char * const config_event_context_tid
= "TID";
206 const char * const config_event_context_vtid
= "VTID";
207 const char * const config_event_context_ppid
= "PPID";
208 const char * const config_event_context_vppid
= "VPPID";
209 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
210 const char * const config_event_context_hostname
= "HOSTNAME";
211 const char * const config_event_context_ip
= "IP";
212 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
213 const char * const config_event_context_app
= "APP";
214 const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
215 const char * const config_event_context_preemptible
= "PREEMPTIBLE";
216 const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
217 const char * const config_event_context_migratable
= "MIGRATABLE";
218 const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
219 const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
220 const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
221 const char * const config_event_context_ipc_ns
= "IPC_NS";
222 const char * const config_event_context_mnt_ns
= "MNT_NS";
223 const char * const config_event_context_net_ns
= "NET_NS";
224 const char * const config_event_context_pid_ns
= "PID_NS";
225 const char * const config_event_context_time_ns
= "TIME_NS";
226 const char * const config_event_context_user_ns
= "USER_NS";
227 const char * const config_event_context_uts_ns
= "UTS_NS";
228 const char * const config_event_context_uid
= "UID";
229 const char * const config_event_context_euid
= "EUID";
230 const char * const config_event_context_suid
= "SUID";
231 const char * const config_event_context_gid
= "GID";
232 const char * const config_event_context_egid
= "EGID";
233 const char * const config_event_context_sgid
= "SGID";
234 const char * const config_event_context_vuid
= "VUID";
235 const char * const config_event_context_veuid
= "VEUID";
236 const char * const config_event_context_vsuid
= "VSUID";
237 const char * const config_event_context_vgid
= "VGID";
238 const char * const config_event_context_vegid
= "VEGID";
239 const char * const config_event_context_vsgid
= "VSGID";
241 /* Deprecated symbols */
242 const char * const config_element_perf
;
244 enum process_event_node_phase
{
249 struct consumer_output
{
256 static int config_entry_handler_filter(struct handler_filter_args
*args
,
257 const char *section
, const char *name
, const char *value
)
260 struct config_entry entry
= { section
, name
, value
};
264 if (!section
|| !name
|| !value
) {
270 if (strcmp(args
->section
, section
)) {
275 ret
= args
->handler(&entry
, args
->user_data
);
280 int config_get_section_entries(const char *override_path
, const char *section
,
281 config_entry_handler_cb handler
, void *user_data
)
285 FILE *config_file
= NULL
;
286 struct handler_filter_args filter
= { section
, handler
, user_data
};
288 /* First, try system-wide conf. file. */
289 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
291 config_file
= fopen(path
, "r");
293 DBG("Loading daemon conf file at %s", path
);
295 * Return value is not very important here since error or not, we
296 * continue and try the next possible conf. file.
298 (void) ini_parse_file(config_file
,
299 (ini_entry_handler
) config_entry_handler_filter
,
304 /* Second is the user local configuration. */
305 path
= utils_get_home_dir();
307 char fullpath
[PATH_MAX
];
309 ret
= snprintf(fullpath
, sizeof(fullpath
),
310 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
312 PERROR("snprintf user conf. path");
316 config_file
= fopen(fullpath
, "r");
318 DBG("Loading daemon user conf file at %s", path
);
320 * Return value is not very important here since error or not, we
321 * continue and try the next possible conf. file.
323 (void) ini_parse_file(config_file
,
324 (ini_entry_handler
) config_entry_handler_filter
,
330 /* Final path is the one that the user might have provided. */
332 config_file
= fopen(override_path
, "r");
334 DBG("Loading daemon command line conf file at %s", override_path
);
335 (void) ini_parse_file(config_file
,
336 (ini_entry_handler
) config_entry_handler_filter
,
340 ERR("Failed to open daemon configuration file at %s",
347 /* Everything went well. */
354 int config_parse_value(const char *value
)
357 char *endptr
, *lower_str
;
367 v
= strtoul(value
, &endptr
, 10);
368 if (endptr
!= value
) {
373 lower_str
= zmalloc(len
+ 1);
380 for (i
= 0; i
< len
; i
++) {
381 lower_str
[i
] = tolower(value
[i
]);
384 if (!strcmp(lower_str
, config_str_yes
) ||
385 !strcmp(lower_str
, config_str_true
) ||
386 !strcmp(lower_str
, config_str_on
)) {
388 } else if (!strcmp(lower_str
, config_str_no
) ||
389 !strcmp(lower_str
, config_str_false
) ||
390 !strcmp(lower_str
, config_str_off
)) {
402 * Returns a xmlChar string which must be released using xmlFree().
404 static xmlChar
*encode_string(const char *in_str
)
406 xmlChar
*out_str
= NULL
;
407 xmlCharEncodingHandlerPtr handler
;
408 int out_len
, ret
, in_len
;
410 LTTNG_ASSERT(in_str
);
412 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
414 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
418 in_len
= strlen(in_str
);
420 * Add 1 byte for the NULL terminted character. The factor 4 here is
421 * used because UTF-8 characters can take up to 4 bytes.
423 out_len
= (in_len
* 4) + 1;
424 out_str
= xmlMalloc(out_len
);
429 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
436 /* out_len is now the size of out_str */
437 out_str
[out_len
] = '\0';
442 struct config_writer
*config_writer_create(int fd_output
, int indent
)
445 struct config_writer
*writer
;
446 xmlOutputBufferPtr buffer
;
448 writer
= zmalloc(sizeof(struct config_writer
));
450 PERROR("zmalloc config_writer_create");
454 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
459 writer
->writer
= xmlNewTextWriter(buffer
);
460 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
461 config_xml_encoding
, NULL
);
466 ret
= xmlTextWriterSetIndentString(writer
->writer
,
467 BAD_CAST config_xml_indent_string
);
472 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
480 config_writer_destroy(writer
);
484 int config_writer_destroy(struct config_writer
*writer
)
493 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
494 WARN("Could not close XML document");
498 if (writer
->writer
) {
499 xmlFreeTextWriter(writer
->writer
);
507 int config_writer_open_element(struct config_writer
*writer
,
508 const char *element_name
)
511 xmlChar
*encoded_element_name
;
513 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
518 encoded_element_name
= encode_string(element_name
);
519 if (!encoded_element_name
) {
524 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
525 xmlFree(encoded_element_name
);
527 return ret
>= 0 ? 0 : ret
;
530 int config_writer_write_attribute(struct config_writer
*writer
,
531 const char *name
, const char *value
)
534 xmlChar
*encoded_name
= NULL
;
535 xmlChar
*encoded_value
= NULL
;
537 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
542 encoded_name
= encode_string(name
);
548 encoded_value
= encode_string(value
);
549 if (!encoded_value
) {
554 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
557 xmlFree(encoded_name
);
558 xmlFree(encoded_value
);
559 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
;
576 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
577 const char *element_name
, uint64_t value
)
580 xmlChar
*encoded_element_name
;
582 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
587 encoded_element_name
= encode_string(element_name
);
588 if (!encoded_element_name
) {
593 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
594 encoded_element_name
, "%" PRIu64
, value
);
595 xmlFree(encoded_element_name
);
597 return ret
>= 0 ? 0 : ret
;
600 int config_writer_write_element_signed_int(struct config_writer
*writer
,
601 const char *element_name
, int64_t value
)
604 xmlChar
*encoded_element_name
;
606 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
611 encoded_element_name
= encode_string(element_name
);
612 if (!encoded_element_name
) {
617 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
618 encoded_element_name
, "%" PRIi64
, value
);
619 xmlFree(encoded_element_name
);
621 return ret
>= 0 ? 0 : ret
;
624 int config_writer_write_element_bool(struct config_writer
*writer
,
625 const char *element_name
, int value
)
627 return config_writer_write_element_string(writer
, element_name
,
628 value
? config_xml_true
: config_xml_false
);
631 int config_writer_write_element_double(struct config_writer
*writer
,
632 const char *element_name
,
636 xmlChar
*encoded_element_name
;
638 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
643 encoded_element_name
= encode_string(element_name
);
644 if (!encoded_element_name
) {
649 ret
= xmlTextWriterWriteFormatElement(
650 writer
->writer
, encoded_element_name
, "%f", value
);
651 xmlFree(encoded_element_name
);
653 return ret
>= 0 ? 0 : ret
;
656 int config_writer_write_element_string(struct config_writer
*writer
,
657 const char *element_name
, const char *value
)
660 xmlChar
*encoded_element_name
= NULL
;
661 xmlChar
*encoded_value
= NULL
;
663 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
669 encoded_element_name
= encode_string(element_name
);
670 if (!encoded_element_name
) {
675 encoded_value
= encode_string(value
);
676 if (!encoded_value
) {
681 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
684 xmlFree(encoded_element_name
);
685 xmlFree(encoded_value
);
686 return ret
>= 0 ? 0 : ret
;
690 void xml_error_handler(void *ctx
, const char *format
, ...)
696 va_start(args
, format
);
697 ret
= vasprintf(&errMsg
, format
, args
);
700 ERR("String allocation failed in xml error handler");
704 fprintf(stderr
, "XML Error: %s", errMsg
);
709 void fini_session_config_validation_ctx(
710 struct session_config_validation_ctx
*ctx
)
712 if (ctx
->parser_ctx
) {
713 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
717 xmlSchemaFree(ctx
->schema
);
720 if (ctx
->schema_validation_ctx
) {
721 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
724 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
728 char *get_session_config_xsd_path(void)
731 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
732 size_t base_path_len
;
736 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
739 base_path_len
= strlen(base_path
);
740 max_path_len
= base_path_len
+
741 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
742 xsd_path
= zmalloc(max_path_len
);
747 strcpy(xsd_path
, base_path
);
748 if (xsd_path
[base_path_len
- 1] != '/') {
749 xsd_path
[base_path_len
++] = '/';
752 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
758 int init_session_config_validation_ctx(
759 struct session_config_validation_ctx
*ctx
)
762 char *xsd_path
= get_session_config_xsd_path();
765 ret
= -LTTNG_ERR_NOMEM
;
769 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
770 if (!ctx
->parser_ctx
) {
771 ERR("XSD parser context creation failed");
772 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
775 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
776 xml_error_handler
, NULL
);
778 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
780 ERR("XSD parsing failed");
781 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
785 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
786 if (!ctx
->schema_validation_ctx
) {
787 ERR("XSD validation context creation failed");
788 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
792 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
793 xml_error_handler
, NULL
);
798 fini_session_config_validation_ctx(ctx
);
806 int parse_uint(xmlChar
*str
, uint64_t *val
)
816 *val
= strtoull((const char *) str
, &endptr
, 10);
817 if (!endptr
|| *endptr
) {
828 int parse_int(xmlChar
*str
, int64_t *val
)
838 *val
= strtoll((const char *) str
, &endptr
, 10);
839 if (!endptr
|| *endptr
) {
850 int parse_bool(xmlChar
*str
, int *val
)
859 if (!strcmp((const char *) str
, config_xml_true
) ||
860 !strcmp((const char *) str
, "1")) {
862 } else if (!strcmp((const char *) str
, config_xml_false
) ||
863 !strcmp((const char *) str
, "0")) {
866 WARN("Invalid boolean value encountered (%s).",
875 int get_domain_type(xmlChar
*domain
)
883 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
884 ret
= LTTNG_DOMAIN_KERNEL
;
885 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
886 ret
= LTTNG_DOMAIN_UST
;
887 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
888 ret
= LTTNG_DOMAIN_JUL
;
889 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
890 ret
= LTTNG_DOMAIN_LOG4J
;
891 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
892 ret
= LTTNG_DOMAIN_PYTHON
;
903 int get_buffer_type(xmlChar
*buffer_type
)
911 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
912 ret
= LTTNG_BUFFER_GLOBAL
;
913 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
914 ret
= LTTNG_BUFFER_PER_UID
;
915 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
916 ret
= LTTNG_BUFFER_PER_PID
;
927 int get_overwrite_mode(xmlChar
*overwrite_mode
)
931 if (!overwrite_mode
) {
935 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
937 } else if (!strcmp((char *) overwrite_mode
,
938 config_overwrite_mode_discard
)) {
950 int get_output_type(xmlChar
*output_type
)
958 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
959 ret
= LTTNG_EVENT_MMAP
;
960 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
961 ret
= LTTNG_EVENT_SPLICE
;
972 int get_event_type(xmlChar
*event_type
)
980 if (!strcmp((char *) event_type
, config_event_type_all
)) {
981 ret
= LTTNG_EVENT_ALL
;
982 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
983 ret
= LTTNG_EVENT_TRACEPOINT
;
984 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
985 ret
= LTTNG_EVENT_PROBE
;
986 } else if (!strcmp((char *) event_type
,
987 config_event_type_userspace_probe
)) {
988 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
989 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
990 ret
= LTTNG_EVENT_FUNCTION
;
991 } else if (!strcmp((char *) event_type
,
992 config_event_type_function_entry
)) {
993 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
994 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
995 ret
= LTTNG_EVENT_NOOP
;
996 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
997 ret
= LTTNG_EVENT_SYSCALL
;
1008 int get_loglevel_type(xmlChar
*loglevel_type
)
1012 if (!loglevel_type
) {
1016 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1017 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1018 } else if (!strcmp((char *) loglevel_type
,
1019 config_loglevel_type_range
)) {
1020 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1021 } else if (!strcmp((char *) loglevel_type
,
1022 config_loglevel_type_single
)) {
1023 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1034 * Return the context type or -1 on error.
1037 int get_context_type(xmlChar
*context_type
)
1041 if (!context_type
) {
1045 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1046 ret
= LTTNG_EVENT_CONTEXT_PID
;
1047 } else if (!strcmp((char *) context_type
,
1048 config_event_context_procname
)) {
1049 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1050 } else if (!strcmp((char *) context_type
,
1051 config_event_context_prio
)) {
1052 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1053 } else if (!strcmp((char *) context_type
,
1054 config_event_context_nice
)) {
1055 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1056 } else if (!strcmp((char *) context_type
,
1057 config_event_context_vpid
)) {
1058 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1059 } else if (!strcmp((char *) context_type
,
1060 config_event_context_tid
)) {
1061 ret
= LTTNG_EVENT_CONTEXT_TID
;
1062 } else if (!strcmp((char *) context_type
,
1063 config_event_context_vtid
)) {
1064 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1065 } else if (!strcmp((char *) context_type
,
1066 config_event_context_ppid
)) {
1067 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1068 } else if (!strcmp((char *) context_type
,
1069 config_event_context_vppid
)) {
1070 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1071 } else if (!strcmp((char *) context_type
,
1072 config_event_context_pthread_id
)) {
1073 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1074 } else if (!strcmp((char *) context_type
,
1075 config_event_context_hostname
)) {
1076 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1077 } else if (!strcmp((char *) context_type
,
1078 config_event_context_ip
)) {
1079 ret
= LTTNG_EVENT_CONTEXT_IP
;
1080 } else if (!strcmp((char *) context_type
,
1081 config_event_context_interruptible
)) {
1082 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1083 } else if (!strcmp((char *) context_type
,
1084 config_event_context_preemptible
)) {
1085 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1086 } else if (!strcmp((char *) context_type
,
1087 config_event_context_need_reschedule
)) {
1088 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1089 } else if (!strcmp((char *) context_type
,
1090 config_event_context_migratable
)) {
1091 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1092 } else if (!strcmp((char *) context_type
,
1093 config_event_context_callstack_user
)) {
1094 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1095 } else if (!strcmp((char *) context_type
,
1096 config_event_context_callstack_kernel
)) {
1097 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1098 } else if (!strcmp((char *) context_type
,
1099 config_event_context_cgroup_ns
)) {
1100 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1101 } else if (!strcmp((char *) context_type
,
1102 config_event_context_ipc_ns
)) {
1103 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1104 } else if (!strcmp((char *) context_type
,
1105 config_event_context_mnt_ns
)) {
1106 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1107 } else if (!strcmp((char *) context_type
,
1108 config_event_context_net_ns
)) {
1109 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1110 } else if (!strcmp((char *) context_type
,
1111 config_event_context_pid_ns
)) {
1112 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1113 } else if (!strcmp((char *) context_type
,
1114 config_event_context_time_ns
)) {
1115 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1116 } else if (!strcmp((char *) context_type
,
1117 config_event_context_user_ns
)) {
1118 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1119 } else if (!strcmp((char *) context_type
,
1120 config_event_context_uts_ns
)) {
1121 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1122 } else if (!strcmp((char *) context_type
,
1123 config_event_context_uid
)) {
1124 ret
= LTTNG_EVENT_CONTEXT_UID
;
1125 } else if (!strcmp((char *) context_type
,
1126 config_event_context_euid
)) {
1127 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1128 } else if (!strcmp((char *) context_type
,
1129 config_event_context_suid
)) {
1130 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1131 } else if (!strcmp((char *) context_type
,
1132 config_event_context_gid
)) {
1133 ret
= LTTNG_EVENT_CONTEXT_GID
;
1134 } else if (!strcmp((char *) context_type
,
1135 config_event_context_egid
)) {
1136 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1137 } else if (!strcmp((char *) context_type
,
1138 config_event_context_sgid
)) {
1139 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1140 } else if (!strcmp((char *) context_type
,
1141 config_event_context_vuid
)) {
1142 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1143 } else if (!strcmp((char *) context_type
,
1144 config_event_context_veuid
)) {
1145 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1146 } else if (!strcmp((char *) context_type
,
1147 config_event_context_vsuid
)) {
1148 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1149 } else if (!strcmp((char *) context_type
,
1150 config_event_context_vgid
)) {
1151 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1152 } else if (!strcmp((char *) context_type
,
1153 config_event_context_vegid
)) {
1154 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1155 } else if (!strcmp((char *) context_type
,
1156 config_event_context_vsgid
)) {
1157 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1168 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1173 for (node
= xmlFirstElementChild(domain_node
); node
;
1174 node
= xmlNextElementSibling(node
)) {
1175 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1177 xmlChar
*node_content
= xmlNodeGetContent(node
);
1178 if (!node_content
) {
1179 ret
= -LTTNG_ERR_NOMEM
;
1183 ret
= get_domain_type(node_content
);
1186 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1191 } else if (!strcmp((const char *) node
->name
,
1192 config_element_buffer_type
)) {
1194 xmlChar
*node_content
= xmlNodeGetContent(node
);
1195 if (!node_content
) {
1196 ret
= -LTTNG_ERR_NOMEM
;
1200 ret
= get_buffer_type(node_content
);
1203 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1207 domain
->buf_type
= ret
;
1216 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1221 for (node
= xmlFirstElementChild(net_output_node
); node
;
1222 node
= xmlNextElementSibling(node
)) {
1223 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1225 *control_uri
= (char *) xmlNodeGetContent(node
);
1226 if (!*control_uri
) {
1231 *data_uri
= (char *) xmlNodeGetContent(node
);
1238 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1242 int process_consumer_output(xmlNodePtr consumer_output_node
,
1243 struct consumer_output
*output
)
1248 LTTNG_ASSERT(output
);
1250 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1251 node
= xmlNextElementSibling(node
)) {
1252 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1253 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1257 ret
= -LTTNG_ERR_NOMEM
;
1261 ret
= parse_bool(enabled_str
, &output
->enabled
);
1267 xmlNodePtr output_type_node
;
1270 output_type_node
= xmlFirstElementChild(node
);
1271 if (!output_type_node
) {
1272 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1276 if (!strcmp((const char *) output_type_node
->name
,
1277 config_element_path
)) {
1279 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1280 if (!output
->path
) {
1281 ret
= -LTTNG_ERR_NOMEM
;
1286 ret
= get_net_output_uris(output_type_node
,
1287 &output
->control_uri
, &output
->data_uri
);
1299 free(output
->control_uri
);
1300 free(output
->data_uri
);
1301 memset(output
, 0, sizeof(struct consumer_output
));
1307 int create_session_net_output(const char *name
, const char *control_uri
,
1308 const char *data_uri
)
1311 struct lttng_handle
*handle
;
1312 const char *uri
= NULL
;
1316 handle
= lttng_create_handle(name
, NULL
);
1318 ret
= -LTTNG_ERR_NOMEM
;
1322 if (!control_uri
|| !data_uri
) {
1323 uri
= control_uri
? control_uri
: data_uri
;
1328 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1329 lttng_destroy_handle(handle
);
1335 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1336 const struct config_load_session_override_attr
*overrides
)
1339 xmlNodePtr node
= NULL
;
1340 xmlNodePtr snapshot_output_list_node
;
1341 xmlNodePtr snapshot_output_node
;
1343 LTTNG_ASSERT(session_name
);
1345 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1354 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1356 /* Parse and create snapshot outputs */
1358 for (snapshot_output_node
=
1359 xmlFirstElementChild(snapshot_output_list_node
);
1360 snapshot_output_node
; snapshot_output_node
=
1361 xmlNextElementSibling(snapshot_output_node
)) {
1363 uint64_t max_size
= UINT64_MAX
;
1364 struct consumer_output output
= { 0 };
1365 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1366 const char *control_uri
= NULL
;
1367 const char *data_uri
= NULL
;
1368 const char *path
= NULL
;
1370 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1371 node
= xmlNextElementSibling(node
)) {
1372 if (!strcmp((const char *) node
->name
,
1373 config_element_name
)) {
1375 name
= (char *) xmlNodeGetContent(node
);
1377 ret
= -LTTNG_ERR_NOMEM
;
1378 goto error_snapshot_output
;
1380 } else if (!strcmp((const char *) node
->name
,
1381 config_element_max_size
)) {
1382 xmlChar
*content
= xmlNodeGetContent(node
);
1386 ret
= -LTTNG_ERR_NOMEM
;
1387 goto error_snapshot_output
;
1389 ret
= parse_uint(content
, &max_size
);
1392 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1393 goto error_snapshot_output
;
1396 /* consumer_output */
1397 ret
= process_consumer_output(node
, &output
);
1399 goto error_snapshot_output
;
1404 control_uri
= output
.control_uri
;
1405 data_uri
= output
.data_uri
;
1409 if (overrides
->path_url
) {
1410 path
= overrides
->path_url
;
1411 /* Control/data_uri are null */
1415 if (overrides
->ctrl_url
) {
1416 control_uri
= overrides
->ctrl_url
;
1420 if (overrides
->data_url
) {
1421 data_uri
= overrides
->data_url
;
1428 snapshot_output
= lttng_snapshot_output_create();
1429 if (!snapshot_output
) {
1430 ret
= -LTTNG_ERR_NOMEM
;
1431 goto error_snapshot_output
;
1434 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1436 goto error_snapshot_output
;
1439 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1441 goto error_snapshot_output
;
1445 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1448 goto error_snapshot_output
;
1452 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1455 goto error_snapshot_output
;
1460 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1463 goto error_snapshot_output
;
1468 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1469 error_snapshot_output
:
1472 free(output
.control_uri
);
1473 free(output
.data_uri
);
1474 lttng_snapshot_output_destroy(snapshot_output
);
1484 int create_session(const char *name
,
1485 xmlNodePtr output_node
,
1486 uint64_t live_timer_interval
,
1487 const struct config_load_session_override_attr
*overrides
)
1490 struct consumer_output output
= { 0 };
1491 xmlNodePtr consumer_output_node
;
1492 const char *control_uri
= NULL
;
1493 const char *data_uri
= NULL
;
1494 const char *path
= NULL
;
1499 consumer_output_node
= xmlFirstElementChild(output_node
);
1500 if (!consumer_output_node
) {
1501 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1505 if (strcmp((const char *) consumer_output_node
->name
,
1506 config_element_consumer_output
)) {
1507 WARN("Invalid output type, expected %s node",
1508 config_element_consumer_output
);
1509 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1513 ret
= process_consumer_output(consumer_output_node
, &output
);
1519 control_uri
= output
.control_uri
;
1520 data_uri
= output
.data_uri
;
1523 /* Check for override and apply them */
1525 if (overrides
->path_url
) {
1526 path
= overrides
->path_url
;
1527 /* control/data_uri are null */;
1531 if (overrides
->ctrl_url
) {
1532 control_uri
= overrides
->ctrl_url
;
1536 if (overrides
->data_url
) {
1537 data_uri
= overrides
->data_url
;
1545 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1546 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1550 if (control_uri
|| data_uri
) {
1551 /* network destination */
1552 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1554 * URLs are provided for sure since the test above make sure that
1555 * with a live timer the data and control URIs are provided. So,
1556 * NULL is passed here and will be set right after.
1558 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1560 ret
= lttng_create_session(name
, NULL
);
1566 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1572 /* either local output or no output */
1573 ret
= lttng_create_session(name
, path
);
1580 free(output
.control_uri
);
1581 free(output
.data_uri
);
1586 struct lttng_userspace_probe_location
*
1587 process_userspace_probe_function_attribute_node(
1588 xmlNodePtr attribute_node
)
1590 xmlNodePtr function_attribute_node
;
1591 char *function_name
= NULL
, *binary_path
= NULL
;
1592 struct lttng_userspace_probe_location
*location
= NULL
;
1593 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1596 * Process userspace probe location function attributes. The order of
1597 * the fields are not guaranteed so we need to iterate over all fields
1598 * and check at the end if everything we need for this location type is
1601 for (function_attribute_node
=
1602 xmlFirstElementChild(attribute_node
);
1603 function_attribute_node
;
1604 function_attribute_node
= xmlNextElementSibling(
1605 function_attribute_node
)) {
1606 /* Handle function name, binary path and lookup method. */
1607 if (!strcmp((const char *) function_attribute_node
->name
,
1608 config_element_userspace_probe_function_location_function_name
)) {
1609 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1610 if (!function_name
) {
1613 } else if (!strcmp((const char *) function_attribute_node
->name
,
1614 config_element_userspace_probe_location_binary_path
)) {
1615 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1619 } else if (!strcmp((const char *) function_attribute_node
->name
,
1620 config_element_userspace_probe_lookup
)) {
1621 char *lookup_method_name
;
1623 lookup_method_name
= (char *) xmlNodeGetContent(
1624 function_attribute_node
);
1625 if (!lookup_method_name
) {
1630 * function_default lookup method defaults to
1631 * function_elf lookup method at the moment.
1633 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1634 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1635 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1636 if (!lookup_method
) {
1637 PERROR("Error creating function default/ELF lookup method");
1640 WARN("Unknown function lookup method");
1643 free(lookup_method_name
);
1644 if (!lookup_method
) {
1651 /* Check if all the necessary fields were found. */
1652 if (binary_path
&& function_name
&& lookup_method
) {
1653 /* Ownership of lookup_method is transferred. */
1655 lttng_userspace_probe_location_function_create(
1656 binary_path
, function_name
,
1658 lookup_method
= NULL
;
1663 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1665 free(function_name
);
1670 struct lttng_userspace_probe_location
*
1671 process_userspace_probe_tracepoint_attribute_node(
1672 xmlNodePtr attribute_node
)
1674 xmlNodePtr tracepoint_attribute_node
;
1675 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1676 struct lttng_userspace_probe_location
*location
= NULL
;
1677 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1680 * Process userspace probe location tracepoint attributes. The order of
1681 * the fields are not guaranteed so we need to iterate over all fields
1682 * and check at the end if everything we need for this location type is
1685 for (tracepoint_attribute_node
=
1686 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1687 tracepoint_attribute_node
= xmlNextElementSibling(
1688 tracepoint_attribute_node
)) {
1689 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1690 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1691 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1695 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1696 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1697 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1698 if (!provider_name
) {
1701 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1702 config_element_userspace_probe_location_binary_path
)) {
1703 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1707 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1708 config_element_userspace_probe_lookup
)) {
1709 char *lookup_method_name
;
1711 lookup_method_name
= (char *) xmlNodeGetContent(
1712 tracepoint_attribute_node
);
1713 if (!lookup_method_name
) {
1717 if (!strcmp(lookup_method_name
,
1718 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1720 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1721 if (!lookup_method
) {
1722 PERROR("Error creating tracepoint SDT lookup method");
1725 WARN("Unknown tracepoint lookup method");
1728 free(lookup_method_name
);
1729 if (!lookup_method
) {
1733 WARN("Unknown tracepoint attribute");
1737 /* Check if all the necessary fields were found. */
1738 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1739 /* Ownership of lookup_method is transferred. */
1741 lttng_userspace_probe_location_tracepoint_create(
1742 binary_path
, provider_name
,
1743 probe_name
, lookup_method
);
1744 lookup_method
= NULL
;
1749 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1751 free(provider_name
);
1757 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1758 struct lttng_event_probe_attr
*attr
)
1762 LTTNG_ASSERT(probe_attribute_node
);
1765 if (!strcmp((const char *) probe_attribute_node
->name
,
1766 config_element_address
)) {
1771 content
= xmlNodeGetContent(probe_attribute_node
);
1773 ret
= -LTTNG_ERR_NOMEM
;
1777 ret
= parse_uint(content
, &addr
);
1780 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1785 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1786 config_element_offset
)) {
1788 uint64_t offset
= 0;
1791 content
= xmlNodeGetContent(probe_attribute_node
);
1793 ret
= -LTTNG_ERR_NOMEM
;
1797 ret
= parse_uint(content
, &offset
);
1800 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1804 attr
->offset
= offset
;
1805 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1806 config_element_symbol_name
)) {
1810 content
= xmlNodeGetContent(probe_attribute_node
);
1812 ret
= -LTTNG_ERR_NOMEM
;
1816 ret
= lttng_strncpy(attr
->symbol_name
,
1817 (const char *) content
,
1818 LTTNG_SYMBOL_NAME_LEN
);
1820 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1821 (const char *) content
,
1822 strlen((const char *) content
),
1823 LTTNG_SYMBOL_NAME_LEN
);
1824 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1836 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1837 const char *channel_name
, const enum process_event_node_phase phase
)
1841 struct lttng_event
*event
;
1842 char **exclusions
= NULL
;
1843 unsigned long exclusion_count
= 0;
1844 char *filter_expression
= NULL
;
1846 LTTNG_ASSERT(event_node
);
1847 LTTNG_ASSERT(handle
);
1848 LTTNG_ASSERT(channel_name
);
1850 event
= lttng_event_create();
1852 ret
= -LTTNG_ERR_NOMEM
;
1856 /* Initialize default log level which varies by domain */
1857 switch (handle
->domain
.type
)
1859 case LTTNG_DOMAIN_JUL
:
1860 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1862 case LTTNG_DOMAIN_LOG4J
:
1863 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1865 case LTTNG_DOMAIN_PYTHON
:
1866 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1868 case LTTNG_DOMAIN_UST
:
1869 case LTTNG_DOMAIN_KERNEL
:
1870 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1876 for (node
= xmlFirstElementChild(event_node
); node
;
1877 node
= xmlNextElementSibling(node
)) {
1878 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1882 content
= xmlNodeGetContent(node
);
1884 ret
= -LTTNG_ERR_NOMEM
;
1888 ret
= lttng_strncpy(event
->name
,
1889 (const char *) content
,
1890 LTTNG_SYMBOL_NAME_LEN
);
1892 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1893 (const char *) content
,
1894 strlen((const char *) content
),
1895 LTTNG_SYMBOL_NAME_LEN
);
1896 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1901 } else if (!strcmp((const char *) node
->name
,
1902 config_element_enabled
)) {
1903 xmlChar
*content
= xmlNodeGetContent(node
);
1907 ret
= -LTTNG_ERR_NOMEM
;
1911 ret
= parse_bool(content
, &event
->enabled
);
1914 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1917 } else if (!strcmp((const char *) node
->name
,
1918 config_element_type
)) {
1919 xmlChar
*content
= xmlNodeGetContent(node
);
1923 ret
= -LTTNG_ERR_NOMEM
;
1927 ret
= get_event_type(content
);
1930 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1935 } else if (!strcmp((const char *) node
->name
,
1936 config_element_loglevel_type
)) {
1937 xmlChar
*content
= xmlNodeGetContent(node
);
1941 ret
= -LTTNG_ERR_NOMEM
;
1945 ret
= get_loglevel_type(content
);
1948 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1952 event
->loglevel_type
= ret
;
1953 } else if (!strcmp((const char *) node
->name
,
1954 config_element_loglevel
)) {
1956 int64_t loglevel
= 0;
1959 content
= xmlNodeGetContent(node
);
1961 ret
= -LTTNG_ERR_NOMEM
;
1965 ret
= parse_int(content
, &loglevel
);
1968 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1972 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1973 WARN("loglevel out of range.");
1974 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1978 event
->loglevel
= loglevel
;
1979 } else if (!strcmp((const char *) node
->name
,
1980 config_element_filter
)) {
1982 xmlNodeGetContent(node
);
1986 ret
= -LTTNG_ERR_NOMEM
;
1990 free(filter_expression
);
1991 filter_expression
= strdup((char *) content
);
1993 if (!filter_expression
) {
1994 ret
= -LTTNG_ERR_NOMEM
;
1997 } else if (!strcmp((const char *) node
->name
,
1998 config_element_exclusions
)) {
1999 xmlNodePtr exclusion_node
;
2000 int exclusion_index
= 0;
2005 * Exclusions has already been initialized,
2008 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2012 exclusion_count
= xmlChildElementCount(node
);
2013 if (!exclusion_count
) {
2017 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2019 exclusion_count
= 0;
2020 ret
= -LTTNG_ERR_NOMEM
;
2024 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2025 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2027 xmlNodeGetContent(exclusion_node
);
2030 ret
= -LTTNG_ERR_NOMEM
;
2034 exclusions
[exclusion_index
] = strdup((const char *) content
);
2036 if (!exclusions
[exclusion_index
]) {
2037 ret
= -LTTNG_ERR_NOMEM
;
2043 event
->exclusion
= 1;
2044 } else if (!strcmp((const char *) node
->name
,
2045 config_element_attributes
)) {
2046 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2049 if (!attribute_node
) {
2050 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2054 if (!strcmp((const char *) attribute_node
->name
,
2055 config_element_probe_attributes
)) {
2056 xmlNodePtr probe_attribute_node
;
2058 /* probe_attributes */
2059 for (probe_attribute_node
=
2060 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2061 probe_attribute_node
= xmlNextElementSibling(
2062 probe_attribute_node
)) {
2064 ret
= process_probe_attribute_node(probe_attribute_node
,
2065 &event
->attr
.probe
);
2070 } else if (!strcmp((const char *) attribute_node
->name
,
2071 config_element_function_attributes
)) {
2074 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2076 /* function_attributes */
2077 content
= xmlNodeGetContent(symbol_node
);
2079 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2083 sym_len
= strlen((char *) content
);
2084 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2085 WARN("Function name too long.");
2086 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2091 ret
= lttng_strncpy(
2092 event
->attr
.ftrace
.symbol_name
,
2093 (char *) content
, sym_len
);
2095 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2100 } else if (!strcmp((const char *) attribute_node
->name
,
2101 config_element_userspace_probe_tracepoint_attributes
)) {
2102 struct lttng_userspace_probe_location
*location
;
2104 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2106 WARN("Error processing userspace probe tracepoint attribute");
2107 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2110 ret
= lttng_event_set_userspace_probe_location(
2113 WARN("Error setting userspace probe location field");
2114 lttng_userspace_probe_location_destroy(
2116 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2119 } else if (!strcmp((const char *) attribute_node
->name
,
2120 config_element_userspace_probe_function_attributes
)) {
2121 struct lttng_userspace_probe_location
*location
;
2124 process_userspace_probe_function_attribute_node(
2127 WARN("Error processing userspace probe function attribute");
2128 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2132 ret
= lttng_event_set_userspace_probe_location(
2135 WARN("Error setting userspace probe location field");
2136 lttng_userspace_probe_location_destroy(
2138 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2142 /* Unknown event attribute. */
2143 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2149 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2150 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2151 filter_expression
, exclusion_count
, exclusions
);
2153 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2154 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2160 for (i
= 0; i
< exclusion_count
; i
++) {
2161 free(exclusions
[i
]);
2164 lttng_event_destroy(event
);
2166 free(filter_expression
);
2171 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2172 const char *channel_name
)
2175 struct lttng_event event
;
2178 LTTNG_ASSERT(events_node
);
2179 LTTNG_ASSERT(handle
);
2180 LTTNG_ASSERT(channel_name
);
2182 for (node
= xmlFirstElementChild(events_node
); node
;
2183 node
= xmlNextElementSibling(node
)) {
2184 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2191 * Disable all events to enable only the necessary events.
2192 * Limitations regarding lttng_disable_events and tuple descriptor
2193 * force this approach.
2195 memset(&event
, 0, sizeof(event
));
2196 event
.loglevel
= -1;
2197 event
.type
= LTTNG_EVENT_ALL
;
2198 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2203 for (node
= xmlFirstElementChild(events_node
); node
;
2204 node
= xmlNextElementSibling(node
)) {
2205 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2216 int process_channel_attr_node(xmlNodePtr attr_node
,
2217 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2218 xmlNodePtr
*events_node
)
2222 LTTNG_ASSERT(attr_node
);
2223 LTTNG_ASSERT(channel
);
2224 LTTNG_ASSERT(contexts_node
);
2225 LTTNG_ASSERT(events_node
);
2227 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2231 content
= xmlNodeGetContent(attr_node
);
2233 ret
= -LTTNG_ERR_NOMEM
;
2237 ret
= lttng_strncpy(channel
->name
,
2238 (const char *) content
,
2239 LTTNG_SYMBOL_NAME_LEN
);
2241 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2242 (const char *) content
,
2243 strlen((const char *) content
),
2244 LTTNG_SYMBOL_NAME_LEN
);
2245 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2250 } else if (!strcmp((const char *) attr_node
->name
,
2251 config_element_enabled
)) {
2256 content
= xmlNodeGetContent(attr_node
);
2258 ret
= -LTTNG_ERR_NOMEM
;
2262 ret
= parse_bool(content
, &enabled
);
2265 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2269 channel
->enabled
= enabled
;
2270 } else if (!strcmp((const char *) attr_node
->name
,
2271 config_element_overwrite_mode
)) {
2274 /* overwrite_mode */
2275 content
= xmlNodeGetContent(attr_node
);
2277 ret
= -LTTNG_ERR_NOMEM
;
2281 ret
= get_overwrite_mode(content
);
2284 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2288 channel
->attr
.overwrite
= ret
;
2289 } else if (!strcmp((const char *) attr_node
->name
,
2290 config_element_subbuf_size
)) {
2293 /* subbuffer_size */
2294 content
= xmlNodeGetContent(attr_node
);
2296 ret
= -LTTNG_ERR_NOMEM
;
2300 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2303 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2306 } else if (!strcmp((const char *) attr_node
->name
,
2307 config_element_num_subbuf
)) {
2310 /* subbuffer_count */
2311 content
= xmlNodeGetContent(attr_node
);
2313 ret
= -LTTNG_ERR_NOMEM
;
2317 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2320 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2323 } else if (!strcmp((const char *) attr_node
->name
,
2324 config_element_switch_timer_interval
)) {
2326 uint64_t switch_timer_interval
= 0;
2328 /* switch_timer_interval */
2329 content
= xmlNodeGetContent(attr_node
);
2331 ret
= -LTTNG_ERR_NOMEM
;
2335 ret
= parse_uint(content
, &switch_timer_interval
);
2338 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2342 if (switch_timer_interval
> UINT_MAX
) {
2343 WARN("switch_timer_interval out of range.");
2344 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2348 channel
->attr
.switch_timer_interval
=
2349 switch_timer_interval
;
2350 } else if (!strcmp((const char *) attr_node
->name
,
2351 config_element_read_timer_interval
)) {
2353 uint64_t read_timer_interval
= 0;
2355 /* read_timer_interval */
2356 content
= xmlNodeGetContent(attr_node
);
2358 ret
= -LTTNG_ERR_NOMEM
;
2362 ret
= parse_uint(content
, &read_timer_interval
);
2365 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2369 if (read_timer_interval
> UINT_MAX
) {
2370 WARN("read_timer_interval out of range.");
2371 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2375 channel
->attr
.read_timer_interval
=
2376 read_timer_interval
;
2377 } else if (!strcmp((const char *) attr_node
->name
,
2378 config_element_output_type
)) {
2382 content
= xmlNodeGetContent(attr_node
);
2384 ret
= -LTTNG_ERR_NOMEM
;
2388 ret
= get_output_type(content
);
2391 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2395 channel
->attr
.output
= ret
;
2396 } else if (!strcmp((const char *) attr_node
->name
,
2397 config_element_tracefile_size
)) {
2400 /* tracefile_size */
2401 content
= xmlNodeGetContent(attr_node
);
2403 ret
= -LTTNG_ERR_NOMEM
;
2407 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2410 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2413 } else if (!strcmp((const char *) attr_node
->name
,
2414 config_element_tracefile_count
)) {
2417 /* tracefile_count */
2418 content
= xmlNodeGetContent(attr_node
);
2420 ret
= -LTTNG_ERR_NOMEM
;
2424 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2427 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2430 } else if (!strcmp((const char *) attr_node
->name
,
2431 config_element_live_timer_interval
)) {
2433 uint64_t live_timer_interval
= 0;
2435 /* live_timer_interval */
2436 content
= xmlNodeGetContent(attr_node
);
2438 ret
= -LTTNG_ERR_NOMEM
;
2442 ret
= parse_uint(content
, &live_timer_interval
);
2445 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2449 if (live_timer_interval
> UINT_MAX
) {
2450 WARN("live_timer_interval out of range.");
2451 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2455 channel
->attr
.live_timer_interval
=
2456 live_timer_interval
;
2457 } else if (!strcmp((const char *) attr_node
->name
,
2458 config_element_monitor_timer_interval
)) {
2460 uint64_t monitor_timer_interval
= 0;
2462 /* monitor_timer_interval */
2463 content
= xmlNodeGetContent(attr_node
);
2465 ret
= -LTTNG_ERR_NOMEM
;
2469 ret
= parse_uint(content
, &monitor_timer_interval
);
2472 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2476 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2477 monitor_timer_interval
);
2479 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2482 } else if (!strcmp((const char *) attr_node
->name
,
2483 config_element_blocking_timeout
)) {
2485 int64_t blocking_timeout
= 0;
2487 /* blocking_timeout */
2488 content
= xmlNodeGetContent(attr_node
);
2490 ret
= -LTTNG_ERR_NOMEM
;
2494 ret
= parse_int(content
, &blocking_timeout
);
2497 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2501 ret
= lttng_channel_set_blocking_timeout(channel
,
2504 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2507 } else if (!strcmp((const char *) attr_node
->name
,
2508 config_element_events
)) {
2510 *events_node
= attr_node
;
2513 *contexts_node
= attr_node
;
2521 int process_context_node(xmlNodePtr context_node
,
2522 struct lttng_handle
*handle
, const char *channel_name
)
2525 struct lttng_event_context context
;
2526 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2528 LTTNG_ASSERT(handle
);
2529 LTTNG_ASSERT(channel_name
);
2531 if (!context_child_node
) {
2532 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2536 memset(&context
, 0, sizeof(context
));
2538 if (!strcmp((const char *) context_child_node
->name
,
2539 config_element_type
)) {
2541 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2544 ret
= -LTTNG_ERR_NOMEM
;
2548 ret
= get_context_type(content
);
2551 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2556 } else if (!strcmp((const char *) context_child_node
->name
,
2557 config_element_context_perf
)) {
2559 xmlNodePtr perf_attr_node
;
2561 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2562 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2563 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2564 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2565 perf_attr_node
; perf_attr_node
=
2566 xmlNextElementSibling(perf_attr_node
)) {
2567 if (!strcmp((const char *) perf_attr_node
->name
,
2568 config_element_type
)) {
2573 content
= xmlNodeGetContent(perf_attr_node
);
2575 ret
= -LTTNG_ERR_NOMEM
;
2579 ret
= parse_uint(content
, &type
);
2582 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2586 if (type
> UINT32_MAX
) {
2587 WARN("perf context type out of range.");
2588 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2592 context
.u
.perf_counter
.type
= type
;
2593 } else if (!strcmp((const char *) perf_attr_node
->name
,
2594 config_element_config
)) {
2596 uint64_t config
= 0;
2599 content
= xmlNodeGetContent(perf_attr_node
);
2601 ret
= -LTTNG_ERR_NOMEM
;
2605 ret
= parse_uint(content
, &config
);
2608 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2612 context
.u
.perf_counter
.config
= config
;
2613 } else if (!strcmp((const char *) perf_attr_node
->name
,
2614 config_element_name
)) {
2618 content
= xmlNodeGetContent(perf_attr_node
);
2620 ret
= -LTTNG_ERR_NOMEM
;
2624 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2625 (const char *) content
,
2626 LTTNG_SYMBOL_NAME_LEN
);
2628 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2629 (const char *) content
,
2630 strlen((const char *) content
),
2631 LTTNG_SYMBOL_NAME_LEN
);
2632 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2639 } else if (!strcmp((const char *) context_child_node
->name
,
2640 config_element_context_app
)) {
2641 /* application context */
2642 xmlNodePtr app_ctx_node
;
2644 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2645 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2646 app_ctx_node
; app_ctx_node
=
2647 xmlNextElementSibling(app_ctx_node
)) {
2649 char **target
= strcmp(
2650 (const char *) app_ctx_node
->name
,
2651 config_element_context_app_provider_name
) == 0 ?
2652 &context
.u
.app_ctx
.provider_name
:
2653 &context
.u
.app_ctx
.ctx_name
;
2655 content
= xmlNodeGetContent(app_ctx_node
);
2657 ret
= -LTTNG_ERR_NOMEM
;
2661 *target
= (char *) content
;
2664 /* Unrecognized context type */
2665 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2669 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2670 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2671 free(context
.u
.app_ctx
.provider_name
);
2672 free(context
.u
.app_ctx
.ctx_name
);
2679 int process_contexts_node(xmlNodePtr contexts_node
,
2680 struct lttng_handle
*handle
, const char *channel_name
)
2683 xmlNodePtr context_node
;
2685 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2686 context_node
= xmlNextElementSibling(context_node
)) {
2687 ret
= process_context_node(context_node
, handle
, channel_name
);
2696 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2697 const char **element_id_tracker
,
2698 const char **element_value_type
,
2699 const char **element_value
,
2700 const char **element_value_alias
,
2701 const char **element_name
)
2705 switch (process_attr
) {
2706 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2707 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2708 *element_value_type
= config_element_process_attr_pid_value
;
2709 *element_value
= config_element_process_attr_id
;
2710 *element_value_alias
= config_element_process_attr_id
;
2711 *element_name
= NULL
;
2713 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2714 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2715 *element_value_type
= config_element_process_attr_vpid_value
;
2716 *element_value
= config_element_process_attr_id
;
2717 *element_value_alias
= NULL
;
2718 *element_name
= NULL
;
2720 case LTTNG_PROCESS_ATTR_USER_ID
:
2721 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2722 *element_value_type
= config_element_process_attr_uid_value
;
2723 *element_value
= config_element_process_attr_id
;
2724 *element_value_alias
= NULL
;
2725 *element_name
= config_element_name
;
2727 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2728 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2729 *element_value_type
= config_element_process_attr_vuid_value
;
2730 *element_value
= config_element_process_attr_id
;
2731 *element_value_alias
= NULL
;
2732 *element_name
= config_element_name
;
2734 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2735 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2736 *element_value_type
= config_element_process_attr_gid_value
;
2737 *element_value
= config_element_process_attr_id
;
2738 *element_value_alias
= NULL
;
2739 *element_name
= config_element_name
;
2741 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2742 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2743 *element_value_type
= config_element_process_attr_vgid_value
;
2744 *element_value
= config_element_process_attr_id
;
2745 *element_value_alias
= NULL
;
2746 *element_name
= config_element_name
;
2749 ret
= LTTNG_ERR_INVALID
;
2754 static int process_legacy_pid_tracker_node(
2755 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2757 int ret
= 0, child_count
;
2758 xmlNodePtr targets_node
= NULL
;
2760 const char *element_id_tracker
;
2761 const char *element_target_id
;
2762 const char *element_id
;
2763 const char *element_id_alias
;
2764 const char *element_name
;
2765 enum lttng_error_code tracker_handle_ret_code
;
2766 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2767 enum lttng_process_attr_tracker_handle_status status
;
2768 const enum lttng_process_attr process_attr
=
2769 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2770 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2771 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2773 LTTNG_ASSERT(handle
);
2775 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2776 handle
->session_name
, handle
->domain
.type
,
2779 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2780 ret
= LTTNG_ERR_INVALID
;
2784 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2785 &element_target_id
, &element_id
, &element_id_alias
,
2791 /* Get the targets node */
2792 for (node
= xmlFirstElementChild(trackers_node
); node
;
2793 node
= xmlNextElementSibling(node
)) {
2794 if (!strcmp((const char *) node
->name
,
2795 config_element_tracker_targets_legacy
)) {
2796 targets_node
= node
;
2801 if (!targets_node
) {
2802 ret
= LTTNG_ERR_INVALID
;
2806 /* Go through all id target node */
2807 child_count
= xmlChildElementCount(targets_node
);
2808 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2810 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2811 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2812 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2813 ret
= LTTNG_ERR_UNK
;
2817 /* Add all tracked values. */
2818 for (node
= xmlFirstElementChild(targets_node
); node
;
2819 node
= xmlNextElementSibling(node
)) {
2820 xmlNodePtr pid_target_node
= node
;
2822 /* get pid_target node and track it */
2823 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2824 node
= xmlNextElementSibling(node
)) {
2825 if (!strcmp((const char *) node
->name
,
2826 config_element_tracker_pid_legacy
)) {
2828 xmlChar
*content
= xmlNodeGetContent(node
);
2831 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2835 ret
= parse_int(content
, &id
);
2838 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2842 switch (process_attr
) {
2843 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2844 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2848 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2849 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2854 ret
= LTTNG_ERR_INVALID
;
2859 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2861 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2862 ret
= LTTNG_ERR_INVALID
;
2864 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2865 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2867 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2868 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2870 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2871 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2873 ret
= LTTNG_ERR_UNK
;
2877 node
= pid_target_node
;
2881 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2885 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2886 struct lttng_handle
*handle
,
2887 enum lttng_process_attr process_attr
)
2889 int ret
= 0, child_count
;
2890 xmlNodePtr values_node
= NULL
;
2892 const char *element_id_tracker
;
2893 const char *element_target_id
;
2894 const char *element_id
;
2895 const char *element_id_alias
;
2896 const char *element_name
;
2897 enum lttng_error_code tracker_handle_ret_code
;
2898 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2899 enum lttng_process_attr_tracker_handle_status status
;
2901 LTTNG_ASSERT(handle
);
2902 LTTNG_ASSERT(id_tracker_node
);
2904 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2905 handle
->session_name
, handle
->domain
.type
, process_attr
,
2907 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2908 ret
= LTTNG_ERR_INVALID
;
2912 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2913 &element_target_id
, &element_id
, &element_id_alias
,
2919 /* get the values node */
2920 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2921 node
= xmlNextElementSibling(node
)) {
2922 if (!strcmp((const char *) node
->name
,
2923 config_element_process_attr_values
)) {
2930 ret
= LTTNG_ERR_INVALID
;
2934 /* Go through all id target node */
2935 child_count
= xmlChildElementCount(values_node
);
2936 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2938 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2939 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2940 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2941 ret
= LTTNG_ERR_UNK
;
2945 /* Add all tracked values. */
2946 for (node
= xmlFirstElementChild(values_node
); node
;
2947 node
= xmlNextElementSibling(node
)) {
2948 xmlNodePtr id_target_node
= node
;
2950 /* get id node and track it */
2951 for (node
= xmlFirstElementChild(id_target_node
); node
;
2952 node
= xmlNextElementSibling(node
)) {
2953 if (!strcmp((const char *) node
->name
, element_id
) ||
2954 (element_id_alias
&&
2955 !strcmp((const char *) node
->name
,
2956 element_id_alias
))) {
2958 xmlChar
*content
= xmlNodeGetContent(node
);
2961 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2965 ret
= parse_int(content
, &id
);
2968 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2972 switch (process_attr
) {
2973 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2974 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2978 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2979 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2983 case LTTNG_PROCESS_ATTR_USER_ID
:
2984 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2988 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2989 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2993 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2994 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2998 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2999 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
3004 ret
= LTTNG_ERR_INVALID
;
3007 } else if (element_name
&&
3008 !strcmp((const char *) node
->name
,
3010 xmlChar
*content
= xmlNodeGetContent(node
);
3013 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3017 switch (process_attr
) {
3018 case LTTNG_PROCESS_ATTR_USER_ID
:
3019 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3021 (const char *) content
);
3023 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3024 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3026 (const char *) content
);
3028 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3029 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3031 (const char *) content
);
3033 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3034 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3036 (const char *) content
);
3040 ret
= LTTNG_ERR_INVALID
;
3046 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3048 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3049 ret
= LTTNG_ERR_INVALID
;
3051 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3052 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3054 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3055 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3057 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3058 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3060 ret
= LTTNG_ERR_UNK
;
3064 node
= id_target_node
;
3068 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3073 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3076 struct lttng_domain domain
= { 0 };
3077 struct lttng_handle
*handle
= NULL
;
3078 struct lttng_channel
*channel
= NULL
;
3079 xmlNodePtr channels_node
= NULL
;
3080 xmlNodePtr trackers_node
= NULL
;
3081 xmlNodePtr pid_tracker_node
= NULL
;
3082 xmlNodePtr vpid_tracker_node
= NULL
;
3083 xmlNodePtr uid_tracker_node
= NULL
;
3084 xmlNodePtr vuid_tracker_node
= NULL
;
3085 xmlNodePtr gid_tracker_node
= NULL
;
3086 xmlNodePtr vgid_tracker_node
= NULL
;
3089 LTTNG_ASSERT(session_name
);
3091 ret
= init_domain(domain_node
, &domain
);
3096 handle
= lttng_create_handle(session_name
, &domain
);
3098 ret
= -LTTNG_ERR_NOMEM
;
3102 /* get the channels node */
3103 for (node
= xmlFirstElementChild(domain_node
); node
;
3104 node
= xmlNextElementSibling(node
)) {
3105 if (!strcmp((const char *) node
->name
,
3106 config_element_channels
)) {
3107 channels_node
= node
;
3112 if (!channels_node
) {
3116 /* create all channels */
3117 for (node
= xmlFirstElementChild(channels_node
); node
;
3118 node
= xmlNextElementSibling(node
)) {
3119 const enum lttng_domain_type original_domain
= domain
.type
;
3120 xmlNodePtr contexts_node
= NULL
;
3121 xmlNodePtr events_node
= NULL
;
3122 xmlNodePtr channel_attr_node
;
3125 * Channels of the "agent" types cannot be created directly.
3126 * They are meant to be created implicitly through the
3127 * activation of events in their domain. However, a user
3128 * can override the default channel configuration attributes
3129 * by creating the underlying UST channel _before_ enabling
3130 * an agent domain event.
3132 * Hence, the channel's type is substituted before the creation
3133 * and restored by the time the events are created.
3135 switch (domain
.type
) {
3136 case LTTNG_DOMAIN_JUL
:
3137 case LTTNG_DOMAIN_LOG4J
:
3138 case LTTNG_DOMAIN_PYTHON
:
3139 domain
.type
= LTTNG_DOMAIN_UST
;
3144 channel
= lttng_channel_create(&domain
);
3150 for (channel_attr_node
= xmlFirstElementChild(node
);
3151 channel_attr_node
; channel_attr_node
=
3152 xmlNextElementSibling(channel_attr_node
)) {
3153 ret
= process_channel_attr_node(channel_attr_node
,
3154 channel
, &contexts_node
, &events_node
);
3160 ret
= lttng_enable_channel(handle
, channel
);
3165 /* Restore the original channel domain. */
3166 domain
.type
= original_domain
;
3168 ret
= process_events_node(events_node
, handle
, channel
->name
);
3173 ret
= process_contexts_node(contexts_node
, handle
,
3179 lttng_channel_destroy(channel
);
3183 /* get the trackers node */
3184 for (node
= xmlFirstElementChild(domain_node
); node
;
3185 node
= xmlNextElementSibling(node
)) {
3186 if (!strcmp((const char *) node
->name
,
3187 config_element_process_attr_trackers
) ||
3188 !strcmp((const char *) node
->name
,
3189 config_element_trackers_legacy
)) {
3190 if (trackers_node
) {
3191 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3192 config_element_process_attr_trackers
,
3193 config_element_trackers_legacy
);
3197 trackers_node
= node
;
3202 if (!trackers_node
) {
3206 for (node
= xmlFirstElementChild(trackers_node
); node
;
3207 node
= xmlNextElementSibling(node
)) {
3208 if (!strcmp((const char *) node
->name
,
3209 config_element_process_attr_tracker_pid
)) {
3210 pid_tracker_node
= node
;
3211 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3212 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3217 if (!strcmp((const char *) node
->name
,
3218 config_element_process_attr_tracker_vpid
)) {
3219 vpid_tracker_node
= node
;
3220 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3221 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3226 if (!strcmp((const char *) node
->name
,
3227 config_element_process_attr_tracker_uid
)) {
3228 uid_tracker_node
= node
;
3229 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3230 LTTNG_PROCESS_ATTR_USER_ID
);
3235 if (!strcmp((const char *) node
->name
,
3236 config_element_process_attr_tracker_vuid
)) {
3237 vuid_tracker_node
= node
;
3238 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3239 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3244 if (!strcmp((const char *) node
->name
,
3245 config_element_process_attr_tracker_gid
)) {
3246 gid_tracker_node
= node
;
3247 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3248 LTTNG_PROCESS_ATTR_GROUP_ID
);
3253 if (!strcmp((const char *) node
->name
,
3254 config_element_process_attr_tracker_vgid
)) {
3255 vgid_tracker_node
= node
;
3256 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3257 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3262 if (!strcmp((const char *) node
->name
,
3263 config_element_pid_tracker_legacy
)) {
3264 ret
= process_legacy_pid_tracker_node(node
, handle
);
3272 lttng_channel_destroy(channel
);
3273 lttng_destroy_handle(handle
);
3278 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3281 enum lttng_rotation_status status
;
3282 struct lttng_rotation_schedule
*periodic
=
3283 lttng_rotation_schedule_periodic_create();
3286 ret
= -LTTNG_ERR_NOMEM
;
3290 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3292 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3293 ret
= -LTTNG_ERR_INVALID
;
3297 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3299 case LTTNG_ROTATION_STATUS_OK
:
3302 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3303 case LTTNG_ROTATION_STATUS_INVALID
:
3304 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3307 ret
= -LTTNG_ERR_UNK
;
3311 lttng_rotation_schedule_destroy(periodic
);
3316 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3319 enum lttng_rotation_status status
;
3320 struct lttng_rotation_schedule
*size
=
3321 lttng_rotation_schedule_size_threshold_create();
3324 ret
= -LTTNG_ERR_NOMEM
;
3328 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3330 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3331 ret
= -LTTNG_ERR_INVALID
;
3335 status
= lttng_session_add_rotation_schedule(name
, size
);
3337 case LTTNG_ROTATION_STATUS_OK
:
3340 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3341 case LTTNG_ROTATION_STATUS_INVALID
:
3342 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3345 ret
= -LTTNG_ERR_UNK
;
3349 lttng_rotation_schedule_destroy(size
);
3354 int process_session_rotation_schedules_node(
3355 xmlNodePtr schedules_node
,
3356 uint64_t *rotation_timer_interval
,
3357 uint64_t *rotation_size
)
3362 for (child
= xmlFirstElementChild(schedules_node
);
3364 child
= xmlNextElementSibling(child
)) {
3365 if (!strcmp((const char *) child
->name
,
3366 config_element_rotation_schedule_periodic
)) {
3368 xmlNodePtr time_us_node
;
3370 /* periodic rotation schedule */
3371 time_us_node
= xmlFirstElementChild(child
);
3372 if (!time_us_node
||
3373 strcmp((const char *) time_us_node
->name
,
3374 config_element_rotation_schedule_periodic_time_us
)) {
3375 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3380 content
= xmlNodeGetContent(time_us_node
);
3382 ret
= -LTTNG_ERR_NOMEM
;
3385 ret
= parse_uint(content
, rotation_timer_interval
);
3388 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3391 } else if (!strcmp((const char *) child
->name
,
3392 config_element_rotation_schedule_size_threshold
)) {
3394 xmlNodePtr bytes_node
;
3396 /* size_threshold rotation schedule */
3397 bytes_node
= xmlFirstElementChild(child
);
3399 strcmp((const char *) bytes_node
->name
,
3400 config_element_rotation_schedule_size_threshold_bytes
)) {
3401 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3406 content
= xmlNodeGetContent(bytes_node
);
3408 ret
= -LTTNG_ERR_NOMEM
;
3411 ret
= parse_uint(content
, rotation_size
);
3414 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3425 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3427 const struct config_load_session_override_attr
*overrides
)
3429 int ret
, started
= -1, snapshot_mode
= -1;
3430 uint64_t live_timer_interval
= UINT64_MAX
,
3431 rotation_timer_interval
= 0,
3433 xmlChar
*name
= NULL
;
3434 xmlChar
*shm_path
= NULL
;
3435 xmlNodePtr domains_node
= NULL
;
3436 xmlNodePtr output_node
= NULL
;
3438 xmlNodePtr attributes_child
;
3439 struct lttng_domain
*kernel_domain
= NULL
;
3440 struct lttng_domain
*ust_domain
= NULL
;
3441 struct lttng_domain
*jul_domain
= NULL
;
3442 struct lttng_domain
*log4j_domain
= NULL
;
3443 struct lttng_domain
*python_domain
= NULL
;
3445 for (node
= xmlFirstElementChild(session_node
); node
;
3446 node
= xmlNextElementSibling(node
)) {
3447 if (!name
&& !strcmp((const char *) node
->name
,
3448 config_element_name
)) {
3450 xmlChar
*node_content
= xmlNodeGetContent(node
);
3451 if (!node_content
) {
3452 ret
= -LTTNG_ERR_NOMEM
;
3456 name
= node_content
;
3457 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3458 config_element_domains
)) {
3460 domains_node
= node
;
3461 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3462 config_element_started
)) {
3464 xmlChar
*node_content
= xmlNodeGetContent(node
);
3465 if (!node_content
) {
3466 ret
= -LTTNG_ERR_NOMEM
;
3470 ret
= parse_bool(node_content
, &started
);
3473 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3476 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3477 config_element_output
)) {
3480 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3481 config_element_shared_memory_path
)) {
3482 /* shared memory path */
3483 xmlChar
*node_content
= xmlNodeGetContent(node
);
3484 if (!node_content
) {
3485 ret
= -LTTNG_ERR_NOMEM
;
3489 shm_path
= node_content
;
3492 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3493 * rotation_timer_interval.
3495 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3496 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3497 if (!strcmp((const char *) attributes_child
->name
,
3498 config_element_snapshot_mode
)) {
3500 xmlChar
*snapshot_mode_content
=
3501 xmlNodeGetContent(attributes_child
);
3502 if (!snapshot_mode_content
) {
3503 ret
= -LTTNG_ERR_NOMEM
;
3507 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3508 free(snapshot_mode_content
);
3510 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3513 } else if (!strcmp((const char *) attributes_child
->name
,
3514 config_element_live_timer_interval
)) {
3515 /* live_timer_interval */
3516 xmlChar
*timer_interval_content
=
3517 xmlNodeGetContent(attributes_child
);
3518 if (!timer_interval_content
) {
3519 ret
= -LTTNG_ERR_NOMEM
;
3523 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3524 free(timer_interval_content
);
3526 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3529 } else if (!strcmp((const char *) attributes_child
->name
,
3530 config_element_rotation_schedules
)) {
3531 ret
= process_session_rotation_schedules_node(
3533 &rotation_timer_interval
,
3536 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3546 /* Mandatory attribute, as defined in the session XSD */
3547 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3551 if (session_name
&& strcmp((char *) name
, session_name
)) {
3552 /* This is not the session we are looking for */
3553 ret
= -LTTNG_ERR_NO_SESSION
;
3557 /* Init domains to create the session handles */
3558 for (node
= xmlFirstElementChild(domains_node
); node
;
3559 node
= xmlNextElementSibling(node
)) {
3560 struct lttng_domain
*domain
;
3562 domain
= zmalloc(sizeof(*domain
));
3564 ret
= -LTTNG_ERR_NOMEM
;
3568 ret
= init_domain(node
, domain
);
3570 goto domain_init_error
;
3573 switch (domain
->type
) {
3574 case LTTNG_DOMAIN_KERNEL
:
3575 if (kernel_domain
) {
3576 /* Same domain seen twice, invalid! */
3577 goto domain_init_error
;
3579 kernel_domain
= domain
;
3581 case LTTNG_DOMAIN_UST
:
3583 /* Same domain seen twice, invalid! */
3584 goto domain_init_error
;
3586 ust_domain
= domain
;
3588 case LTTNG_DOMAIN_JUL
:
3590 /* Same domain seen twice, invalid! */
3591 goto domain_init_error
;
3593 jul_domain
= domain
;
3595 case LTTNG_DOMAIN_LOG4J
:
3597 /* Same domain seen twice, invalid! */
3598 goto domain_init_error
;
3600 log4j_domain
= domain
;
3602 case LTTNG_DOMAIN_PYTHON
:
3603 if (python_domain
) {
3604 /* Same domain seen twice, invalid! */
3605 goto domain_init_error
;
3607 python_domain
= domain
;
3610 WARN("Invalid domain type");
3611 goto domain_init_error
;
3616 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3620 /* Apply overrides */
3622 if (overrides
->session_name
) {
3623 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3624 if (!name_override
) {
3625 ret
= -LTTNG_ERR_NOMEM
;
3629 /* Overrides the session name to the provided name */
3631 name
= name_override
;
3636 /* Destroy session if it exists */
3637 ret
= lttng_destroy_session((const char *) name
);
3638 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3639 ERR("Failed to destroy existing session.");
3644 /* Create session type depending on output type */
3645 if (snapshot_mode
&& snapshot_mode
!= -1) {
3646 ret
= create_snapshot_session((const char *) name
, output_node
,
3648 } else if (live_timer_interval
&&
3649 live_timer_interval
!= UINT64_MAX
) {
3650 ret
= create_session((const char *) name
,
3651 output_node
, live_timer_interval
, overrides
);
3653 /* regular session */
3654 ret
= create_session((const char *) name
,
3655 output_node
, UINT64_MAX
, overrides
);
3662 ret
= lttng_set_session_shm_path((const char *) name
,
3663 (const char *) shm_path
);
3669 for (node
= xmlFirstElementChild(domains_node
); node
;
3670 node
= xmlNextElementSibling(node
)) {
3671 ret
= process_domain_node(node
, (const char *) name
);
3677 if (rotation_timer_interval
) {
3678 ret
= add_periodic_rotation((const char *) name
,
3679 rotation_timer_interval
);
3684 if (rotation_size
) {
3685 ret
= add_size_rotation((const char *) name
,
3693 ret
= lttng_start_tracing((const char *) name
);
3701 ERR("Failed to load session %s: %s", (const char *) name
,
3702 lttng_strerror(ret
));
3703 lttng_destroy_session((const char *) name
);
3707 free(kernel_domain
);
3711 free(python_domain
);
3718 * Return 1 if the given path is readable by the current UID or 0 if not.
3719 * Return -1 if the path is EPERM.
3721 static int validate_file_read_creds(const char *path
)
3727 /* Can we read the file. */
3728 ret
= access(path
, R_OK
);
3732 if (errno
== EACCES
) {
3743 int load_session_from_file(const char *path
, const char *session_name
,
3744 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3745 const struct config_load_session_override_attr
*overrides
)
3747 int ret
, session_found
= !session_name
;
3748 xmlDocPtr doc
= NULL
;
3749 xmlNodePtr sessions_node
;
3750 xmlNodePtr session_node
;
3753 LTTNG_ASSERT(validation_ctx
);
3755 ret
= validate_file_read_creds(path
);
3758 ret
= -LTTNG_ERR_EPERM
;
3760 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3765 doc
= xmlParseFile(path
);
3767 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3771 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3773 ERR("Session configuration file validation failed");
3774 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3778 sessions_node
= xmlDocGetRootElement(doc
);
3779 if (!sessions_node
) {
3780 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3784 for (session_node
= xmlFirstElementChild(sessions_node
);
3785 session_node
; session_node
=
3786 xmlNextElementSibling(session_node
)) {
3787 ret
= process_session_node(session_node
,
3788 session_name
, overwrite
, overrides
);
3789 if (!session_name
&& ret
) {
3790 /* Loading error occurred. */
3792 } else if (session_name
) {
3794 /* Target session found and loaded */
3797 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3799 * Ignore this error, we are looking for a
3804 /* Loading error occurred. */
3812 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3818 int load_session_from_path(const char *path
, const char *session_name
,
3819 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3820 const struct config_load_session_override_attr
*overrides
)
3822 int ret
, session_found
= !session_name
;
3823 DIR *directory
= NULL
;
3824 struct lttng_dynamic_buffer file_path
;
3828 LTTNG_ASSERT(validation_ctx
);
3829 path_len
= strlen(path
);
3830 lttng_dynamic_buffer_init(&file_path
);
3831 if (path_len
>= LTTNG_PATH_MAX
) {
3832 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3833 path
, path_len
, LTTNG_PATH_MAX
);
3834 ret
= -LTTNG_ERR_INVALID
;
3838 directory
= opendir(path
);
3842 /* Try the file loading. */
3845 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3848 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3853 size_t file_path_root_len
;
3855 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3858 ret
= -LTTNG_ERR_NOMEM
;
3862 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3864 ret
= -LTTNG_ERR_NOMEM
;
3868 if (file_path
.data
[file_path
.size
- 1] != '/') {
3869 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3871 ret
= -LTTNG_ERR_NOMEM
;
3875 file_path_root_len
= file_path
.size
;
3877 /* Search for *.lttng files */
3879 size_t file_name_len
;
3880 struct dirent
*result
;
3883 * When the end of the directory stream is reached, NULL
3884 * is returned and errno is kept unchanged. When an
3885 * error occurs, NULL is returned and errno is set
3886 * accordingly. To distinguish between the two, set
3887 * errno to zero before calling readdir().
3889 * On success, readdir() returns a pointer to a dirent
3890 * structure. This structure may be statically
3891 * allocated, do not attempt to free(3) it.
3894 result
= readdir(directory
);
3896 /* Reached end of dir stream or error out. */
3899 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3900 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3906 file_name_len
= strlen(result
->d_name
);
3908 if (file_name_len
<=
3909 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3913 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3914 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3916 /* +1 to account for NULL terminator. */
3917 file_path
.size
+ file_name_len
+ 1,
3922 /* Does the file end with .lttng? */
3923 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3924 result
->d_name
+ file_name_len
- sizeof(
3925 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3929 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3932 ret
= -LTTNG_ERR_NOMEM
;
3936 ret
= load_session_from_file(file_path
.data
, session_name
,
3937 validation_ctx
, overwrite
, overrides
);
3939 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3943 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3947 * Reset the buffer's size to the location of the
3948 * path's trailing '/'.
3950 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3951 file_path_root_len
);
3953 ret
= -LTTNG_ERR_UNK
;
3958 ret
= load_session_from_file(path
, session_name
,
3959 validation_ctx
, overwrite
, overrides
);
3969 if (closedir(directory
)) {
3973 if (!ret
&& !session_found
) {
3974 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3976 lttng_dynamic_buffer_reset(&file_path
);
3981 * Validate that the given path's credentials and the current process have the
3982 * same UID. If so, return 1 else return 0 if it does NOT match.
3984 static int validate_path_creds(const char *path
)
3986 int ret
, uid
= getuid();
3995 ret
= stat(path
, &buf
);
3997 if (errno
!= ENOENT
) {
4003 if (buf
.st_uid
!= uid
) {
4013 int config_load_session(const char *path
, const char *session_name
,
4014 int overwrite
, unsigned int autoload
,
4015 const struct config_load_session_override_attr
*overrides
)
4018 bool session_loaded
= false;
4019 const char *path_ptr
= NULL
;
4020 struct session_config_validation_ctx validation_ctx
= { 0 };
4022 ret
= init_session_config_validation_ctx(&validation_ctx
);
4028 const char *home_path
;
4029 const char *sys_path
;
4032 home_path
= utils_get_home_dir();
4034 char path_buf
[PATH_MAX
];
4037 * Try user session configuration path. Ignore error here so we can
4038 * continue loading the system wide sessions.
4041 ret
= snprintf(path_buf
, sizeof(path_buf
),
4042 DEFAULT_SESSION_HOME_CONFIGPATH
4043 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
4046 PERROR("snprintf session autoload home config path");
4047 ret
= -LTTNG_ERR_INVALID
;
4052 * Credentials are only validated for the autoload in order to
4053 * avoid any user session daemon to try to load kernel sessions
4054 * automatically and failing all the times.
4056 ret
= validate_path_creds(path_buf
);
4058 path_ptr
= path_buf
;
4061 ret
= snprintf(path_buf
, sizeof(path_buf
),
4062 DEFAULT_SESSION_HOME_CONFIGPATH
,
4065 PERROR("snprintf session home config path");
4066 ret
= -LTTNG_ERR_INVALID
;
4069 path_ptr
= path_buf
;
4072 ret
= load_session_from_path(path_ptr
, session_name
,
4073 &validation_ctx
, overwrite
, overrides
);
4074 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4078 * Continue even if the session was found since we have to try
4079 * the system wide sessions.
4081 session_loaded
= true;
4085 /* Reset path pointer for the system wide dir. */
4088 /* Try system wide configuration directory. */
4090 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4091 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4092 ret
= validate_path_creds(sys_path
);
4094 path_ptr
= sys_path
;
4097 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4098 path_ptr
= sys_path
;
4102 ret
= load_session_from_path(path_ptr
, session_name
,
4103 &validation_ctx
, overwrite
, overrides
);
4105 session_loaded
= true;
4111 ret
= access(path
, F_OK
);
4116 ret
= -LTTNG_ERR_INVALID
;
4117 WARN("Session configuration path does not exist.");
4120 ret
= -LTTNG_ERR_EPERM
;
4123 ret
= -LTTNG_ERR_UNK
;
4129 ret
= load_session_from_path(path
, session_name
,
4130 &validation_ctx
, overwrite
, overrides
);
4133 fini_session_config_validation_ctx(&validation_ctx
);
4134 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4136 * Don't report an error if no sessions are found when called
4137 * without a session_name or a search path.
4142 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4143 /* A matching session was found in one of the search paths. */
4150 void __attribute__((destructor
)) session_config_exit(void)