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 LTTNG_EXPORT
const char *config_str_yes
= "yes";
56 LTTNG_EXPORT
const char *config_str_true
= "true";
57 LTTNG_EXPORT
const char *config_str_on
= "on";
58 LTTNG_EXPORT
const char *config_str_no
= "no";
59 LTTNG_EXPORT
const char *config_str_false
= "false";
60 LTTNG_EXPORT
const char *config_str_off
= "off";
61 LTTNG_EXPORT
const char *config_xml_encoding
= "UTF-8";
62 LTTNG_EXPORT
size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
63 LTTNG_EXPORT
const char *config_xml_indent_string
= "\t";
64 LTTNG_EXPORT
const char *config_xml_true
= "true";
65 LTTNG_EXPORT
const char *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_legacy
= "pid";
162 const char * const config_element_rotation_schedules
= "rotation_schedules";
163 const char * const config_element_rotation_schedule_periodic
= "periodic";
164 const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
165 const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
166 const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
168 const char * const config_domain_type_kernel
= "KERNEL";
169 const char * const config_domain_type_ust
= "UST";
170 const char * const config_domain_type_jul
= "JUL";
171 const char * const config_domain_type_log4j
= "LOG4J";
172 const char * const config_domain_type_python
= "PYTHON";
174 const char * const config_buffer_type_per_pid
= "PER_PID";
175 const char * const config_buffer_type_per_uid
= "PER_UID";
176 const char * const config_buffer_type_global
= "GLOBAL";
178 const char * const config_overwrite_mode_discard
= "DISCARD";
179 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
181 const char * const config_output_type_splice
= "SPLICE";
182 const char * const config_output_type_mmap
= "MMAP";
184 const char * const config_loglevel_type_all
= "ALL";
185 const char * const config_loglevel_type_range
= "RANGE";
186 const char * const config_loglevel_type_single
= "SINGLE";
188 const char * const config_event_type_all
= "ALL";
189 const char * const config_event_type_tracepoint
= "TRACEPOINT";
190 const char * const config_event_type_probe
= "PROBE";
191 const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
192 const char * const config_event_type_function
= "FUNCTION";
193 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
194 const char * const config_event_type_noop
= "NOOP";
195 const char * const config_event_type_syscall
= "SYSCALL";
196 const char * const config_event_type_kprobe
= "KPROBE";
197 const char * const config_event_type_kretprobe
= "KRETPROBE";
199 const char * const config_event_context_pid
= "PID";
200 const char * const config_event_context_procname
= "PROCNAME";
201 const char * const config_event_context_prio
= "PRIO";
202 const char * const config_event_context_nice
= "NICE";
203 const char * const config_event_context_vpid
= "VPID";
204 const char * const config_event_context_tid
= "TID";
205 const char * const config_event_context_vtid
= "VTID";
206 const char * const config_event_context_ppid
= "PPID";
207 const char * const config_event_context_vppid
= "VPPID";
208 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
209 const char * const config_event_context_hostname
= "HOSTNAME";
210 const char * const config_event_context_ip
= "IP";
211 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
212 const char * const config_event_context_app
= "APP";
213 const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
214 const char * const config_event_context_preemptible
= "PREEMPTIBLE";
215 const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
216 const char * const config_event_context_migratable
= "MIGRATABLE";
217 const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
218 const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
219 const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
220 const char * const config_event_context_ipc_ns
= "IPC_NS";
221 const char * const config_event_context_mnt_ns
= "MNT_NS";
222 const char * const config_event_context_net_ns
= "NET_NS";
223 const char * const config_event_context_pid_ns
= "PID_NS";
224 const char * const config_event_context_time_ns
= "TIME_NS";
225 const char * const config_event_context_user_ns
= "USER_NS";
226 const char * const config_event_context_uts_ns
= "UTS_NS";
227 const char * const config_event_context_uid
= "UID";
228 const char * const config_event_context_euid
= "EUID";
229 const char * const config_event_context_suid
= "SUID";
230 const char * const config_event_context_gid
= "GID";
231 const char * const config_event_context_egid
= "EGID";
232 const char * const config_event_context_sgid
= "SGID";
233 const char * const config_event_context_vuid
= "VUID";
234 const char * const config_event_context_veuid
= "VEUID";
235 const char * const config_event_context_vsuid
= "VSUID";
236 const char * const config_event_context_vgid
= "VGID";
237 const char * const config_event_context_vegid
= "VEGID";
238 const char * const config_event_context_vsgid
= "VSGID";
240 /* Deprecated symbols */
241 LTTNG_EXPORT
const char *config_element_perf
;
243 enum process_event_node_phase
{
248 struct consumer_output
{
255 static int config_entry_handler_filter(struct handler_filter_args
*args
,
256 const char *section
, const char *name
, const char *value
)
259 struct config_entry entry
= { section
, name
, value
};
263 if (!section
|| !name
|| !value
) {
269 if (strcmp(args
->section
, section
)) {
274 ret
= args
->handler(&entry
, args
->user_data
);
279 int config_get_section_entries(const char *override_path
, const char *section
,
280 config_entry_handler_cb handler
, void *user_data
)
284 FILE *config_file
= NULL
;
285 struct handler_filter_args filter
= { section
, handler
, user_data
};
287 /* First, try system-wide conf. file. */
288 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
290 config_file
= fopen(path
, "r");
292 DBG("Loading daemon conf file at %s", path
);
294 * Return value is not very important here since error or not, we
295 * continue and try the next possible conf. file.
297 (void) ini_parse_file(config_file
,
298 (ini_entry_handler
) config_entry_handler_filter
,
303 /* Second is the user local configuration. */
304 path
= utils_get_home_dir();
306 char fullpath
[PATH_MAX
];
308 ret
= snprintf(fullpath
, sizeof(fullpath
),
309 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
311 PERROR("snprintf user conf. path");
315 config_file
= fopen(fullpath
, "r");
317 DBG("Loading daemon user conf file at %s", path
);
319 * Return value is not very important here since error or not, we
320 * continue and try the next possible conf. file.
322 (void) ini_parse_file(config_file
,
323 (ini_entry_handler
) config_entry_handler_filter
,
329 /* Final path is the one that the user might have provided. */
331 config_file
= fopen(override_path
, "r");
333 DBG("Loading daemon command line conf file at %s", override_path
);
334 (void) ini_parse_file(config_file
,
335 (ini_entry_handler
) config_entry_handler_filter
,
339 ERR("Failed to open daemon configuration file at %s",
346 /* Everything went well. */
353 int config_parse_value(const char *value
)
356 char *endptr
, *lower_str
;
366 v
= strtoul(value
, &endptr
, 10);
367 if (endptr
!= value
) {
372 lower_str
= (char *) zmalloc(len
+ 1);
379 for (i
= 0; i
< len
; i
++) {
380 lower_str
[i
] = tolower(value
[i
]);
383 if (!strcmp(lower_str
, config_str_yes
) ||
384 !strcmp(lower_str
, config_str_true
) ||
385 !strcmp(lower_str
, config_str_on
)) {
387 } else if (!strcmp(lower_str
, config_str_no
) ||
388 !strcmp(lower_str
, config_str_false
) ||
389 !strcmp(lower_str
, config_str_off
)) {
401 * Returns a xmlChar string which must be released using xmlFree().
403 static xmlChar
*encode_string(const char *in_str
)
405 xmlChar
*out_str
= NULL
;
406 xmlCharEncodingHandlerPtr handler
;
407 int out_len
, ret
, in_len
;
409 LTTNG_ASSERT(in_str
);
411 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
413 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
417 in_len
= strlen(in_str
);
419 * Add 1 byte for the NULL terminted character. The factor 4 here is
420 * used because UTF-8 characters can take up to 4 bytes.
422 out_len
= (in_len
* 4) + 1;
423 out_str
= (xmlChar
*) xmlMalloc(out_len
);
428 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
435 /* out_len is now the size of out_str */
436 out_str
[out_len
] = '\0';
441 struct config_writer
*config_writer_create(int fd_output
, int indent
)
444 struct config_writer
*writer
;
445 xmlOutputBufferPtr buffer
;
447 writer
= (config_writer
*) zmalloc(sizeof(struct config_writer
));
449 PERROR("zmalloc config_writer_create");
453 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
458 writer
->writer
= xmlNewTextWriter(buffer
);
459 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
460 config_xml_encoding
, NULL
);
465 ret
= xmlTextWriterSetIndentString(writer
->writer
,
466 BAD_CAST config_xml_indent_string
);
471 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
479 config_writer_destroy(writer
);
483 int config_writer_destroy(struct config_writer
*writer
)
492 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
493 WARN("Could not close XML document");
497 if (writer
->writer
) {
498 xmlFreeTextWriter(writer
->writer
);
506 int config_writer_open_element(struct config_writer
*writer
,
507 const char *element_name
)
510 xmlChar
*encoded_element_name
;
512 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
517 encoded_element_name
= encode_string(element_name
);
518 if (!encoded_element_name
) {
523 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
524 xmlFree(encoded_element_name
);
526 return ret
>= 0 ? 0 : ret
;
529 int config_writer_write_attribute(struct config_writer
*writer
,
530 const char *name
, const char *value
)
533 xmlChar
*encoded_name
= NULL
;
534 xmlChar
*encoded_value
= NULL
;
536 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
541 encoded_name
= encode_string(name
);
547 encoded_value
= encode_string(value
);
548 if (!encoded_value
) {
553 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
556 xmlFree(encoded_name
);
557 xmlFree(encoded_value
);
558 return ret
>= 0 ? 0 : ret
;
561 int config_writer_close_element(struct config_writer
*writer
)
565 if (!writer
|| !writer
->writer
) {
570 ret
= xmlTextWriterEndElement(writer
->writer
);
572 return ret
>= 0 ? 0 : ret
;
575 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
576 const char *element_name
, uint64_t value
)
579 xmlChar
*encoded_element_name
;
581 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
586 encoded_element_name
= encode_string(element_name
);
587 if (!encoded_element_name
) {
592 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
593 encoded_element_name
, "%" PRIu64
, value
);
594 xmlFree(encoded_element_name
);
596 return ret
>= 0 ? 0 : ret
;
599 int config_writer_write_element_signed_int(struct config_writer
*writer
,
600 const char *element_name
, int64_t value
)
603 xmlChar
*encoded_element_name
;
605 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
610 encoded_element_name
= encode_string(element_name
);
611 if (!encoded_element_name
) {
616 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
617 encoded_element_name
, "%" PRIi64
, value
);
618 xmlFree(encoded_element_name
);
620 return ret
>= 0 ? 0 : ret
;
623 int config_writer_write_element_bool(struct config_writer
*writer
,
624 const char *element_name
, int value
)
626 return config_writer_write_element_string(writer
, element_name
,
627 value
? config_xml_true
: config_xml_false
);
630 int config_writer_write_element_double(struct config_writer
*writer
,
631 const char *element_name
,
635 xmlChar
*encoded_element_name
;
637 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
642 encoded_element_name
= encode_string(element_name
);
643 if (!encoded_element_name
) {
648 ret
= xmlTextWriterWriteFormatElement(
649 writer
->writer
, encoded_element_name
, "%f", value
);
650 xmlFree(encoded_element_name
);
652 return ret
>= 0 ? 0 : ret
;
655 int config_writer_write_element_string(struct config_writer
*writer
,
656 const char *element_name
, const char *value
)
659 xmlChar
*encoded_element_name
= NULL
;
660 xmlChar
*encoded_value
= NULL
;
662 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
668 encoded_element_name
= encode_string(element_name
);
669 if (!encoded_element_name
) {
674 encoded_value
= encode_string(value
);
675 if (!encoded_value
) {
680 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
683 xmlFree(encoded_element_name
);
684 xmlFree(encoded_value
);
685 return ret
>= 0 ? 0 : ret
;
689 void xml_error_handler(void *ctx
, const char *format
, ...)
695 va_start(args
, format
);
696 ret
= vasprintf(&errMsg
, format
, args
);
699 ERR("String allocation failed in xml error handler");
703 fprintf(stderr
, "XML Error: %s", errMsg
);
708 void fini_session_config_validation_ctx(
709 struct session_config_validation_ctx
*ctx
)
711 if (ctx
->parser_ctx
) {
712 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
716 xmlSchemaFree(ctx
->schema
);
719 if (ctx
->schema_validation_ctx
) {
720 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
723 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
727 char *get_session_config_xsd_path(void)
730 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
731 size_t base_path_len
;
735 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
738 base_path_len
= strlen(base_path
);
739 max_path_len
= base_path_len
+
740 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
741 xsd_path
= (char *) zmalloc(max_path_len
);
746 strcpy(xsd_path
, base_path
);
747 if (xsd_path
[base_path_len
- 1] != '/') {
748 xsd_path
[base_path_len
++] = '/';
751 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
757 int init_session_config_validation_ctx(
758 struct session_config_validation_ctx
*ctx
)
761 char *xsd_path
= get_session_config_xsd_path();
764 ret
= -LTTNG_ERR_NOMEM
;
768 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
769 if (!ctx
->parser_ctx
) {
770 ERR("XSD parser context creation failed");
771 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
774 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
775 xml_error_handler
, NULL
);
777 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
779 ERR("XSD parsing failed");
780 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
784 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
785 if (!ctx
->schema_validation_ctx
) {
786 ERR("XSD validation context creation failed");
787 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
791 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
792 xml_error_handler
, NULL
);
797 fini_session_config_validation_ctx(ctx
);
805 int parse_uint(xmlChar
*str
, uint64_t *val
)
815 *val
= strtoull((const char *) str
, &endptr
, 10);
816 if (!endptr
|| *endptr
) {
827 int parse_int(xmlChar
*str
, int64_t *val
)
837 *val
= strtoll((const char *) str
, &endptr
, 10);
838 if (!endptr
|| *endptr
) {
849 int parse_bool(xmlChar
*str
, int *val
)
858 if (!strcmp((const char *) str
, config_xml_true
) ||
859 !strcmp((const char *) str
, "1")) {
861 } else if (!strcmp((const char *) str
, config_xml_false
) ||
862 !strcmp((const char *) str
, "0")) {
865 WARN("Invalid boolean value encountered (%s).",
874 int get_domain_type(xmlChar
*domain
)
882 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
883 ret
= LTTNG_DOMAIN_KERNEL
;
884 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
885 ret
= LTTNG_DOMAIN_UST
;
886 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
887 ret
= LTTNG_DOMAIN_JUL
;
888 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
889 ret
= LTTNG_DOMAIN_LOG4J
;
890 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
891 ret
= LTTNG_DOMAIN_PYTHON
;
902 int get_buffer_type(xmlChar
*buffer_type
)
910 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
911 ret
= LTTNG_BUFFER_GLOBAL
;
912 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
913 ret
= LTTNG_BUFFER_PER_UID
;
914 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
915 ret
= LTTNG_BUFFER_PER_PID
;
926 int get_overwrite_mode(xmlChar
*overwrite_mode
)
930 if (!overwrite_mode
) {
934 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
936 } else if (!strcmp((char *) overwrite_mode
,
937 config_overwrite_mode_discard
)) {
949 int get_output_type(xmlChar
*output_type
)
957 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
958 ret
= LTTNG_EVENT_MMAP
;
959 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
960 ret
= LTTNG_EVENT_SPLICE
;
971 int get_event_type(xmlChar
*event_type
)
979 if (!strcmp((char *) event_type
, config_event_type_all
)) {
980 ret
= LTTNG_EVENT_ALL
;
981 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
982 ret
= LTTNG_EVENT_TRACEPOINT
;
983 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
984 ret
= LTTNG_EVENT_PROBE
;
985 } else if (!strcmp((char *) event_type
,
986 config_event_type_userspace_probe
)) {
987 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
988 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
989 ret
= LTTNG_EVENT_FUNCTION
;
990 } else if (!strcmp((char *) event_type
,
991 config_event_type_function_entry
)) {
992 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
993 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
994 ret
= LTTNG_EVENT_NOOP
;
995 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
996 ret
= LTTNG_EVENT_SYSCALL
;
1007 int get_loglevel_type(xmlChar
*loglevel_type
)
1011 if (!loglevel_type
) {
1015 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1016 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1017 } else if (!strcmp((char *) loglevel_type
,
1018 config_loglevel_type_range
)) {
1019 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1020 } else if (!strcmp((char *) loglevel_type
,
1021 config_loglevel_type_single
)) {
1022 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1033 * Return the context type or -1 on error.
1036 int get_context_type(xmlChar
*context_type
)
1040 if (!context_type
) {
1044 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1045 ret
= LTTNG_EVENT_CONTEXT_PID
;
1046 } else if (!strcmp((char *) context_type
,
1047 config_event_context_procname
)) {
1048 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1049 } else if (!strcmp((char *) context_type
,
1050 config_event_context_prio
)) {
1051 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1052 } else if (!strcmp((char *) context_type
,
1053 config_event_context_nice
)) {
1054 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1055 } else if (!strcmp((char *) context_type
,
1056 config_event_context_vpid
)) {
1057 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1058 } else if (!strcmp((char *) context_type
,
1059 config_event_context_tid
)) {
1060 ret
= LTTNG_EVENT_CONTEXT_TID
;
1061 } else if (!strcmp((char *) context_type
,
1062 config_event_context_vtid
)) {
1063 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1064 } else if (!strcmp((char *) context_type
,
1065 config_event_context_ppid
)) {
1066 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1067 } else if (!strcmp((char *) context_type
,
1068 config_event_context_vppid
)) {
1069 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1070 } else if (!strcmp((char *) context_type
,
1071 config_event_context_pthread_id
)) {
1072 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1073 } else if (!strcmp((char *) context_type
,
1074 config_event_context_hostname
)) {
1075 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1076 } else if (!strcmp((char *) context_type
,
1077 config_event_context_ip
)) {
1078 ret
= LTTNG_EVENT_CONTEXT_IP
;
1079 } else if (!strcmp((char *) context_type
,
1080 config_event_context_interruptible
)) {
1081 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1082 } else if (!strcmp((char *) context_type
,
1083 config_event_context_preemptible
)) {
1084 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1085 } else if (!strcmp((char *) context_type
,
1086 config_event_context_need_reschedule
)) {
1087 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1088 } else if (!strcmp((char *) context_type
,
1089 config_event_context_migratable
)) {
1090 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1091 } else if (!strcmp((char *) context_type
,
1092 config_event_context_callstack_user
)) {
1093 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1094 } else if (!strcmp((char *) context_type
,
1095 config_event_context_callstack_kernel
)) {
1096 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1097 } else if (!strcmp((char *) context_type
,
1098 config_event_context_cgroup_ns
)) {
1099 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1100 } else if (!strcmp((char *) context_type
,
1101 config_event_context_ipc_ns
)) {
1102 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1103 } else if (!strcmp((char *) context_type
,
1104 config_event_context_mnt_ns
)) {
1105 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1106 } else if (!strcmp((char *) context_type
,
1107 config_event_context_net_ns
)) {
1108 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1109 } else if (!strcmp((char *) context_type
,
1110 config_event_context_pid_ns
)) {
1111 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1112 } else if (!strcmp((char *) context_type
,
1113 config_event_context_time_ns
)) {
1114 ret
= LTTNG_EVENT_CONTEXT_TIME_NS
;
1115 } else if (!strcmp((char *) context_type
,
1116 config_event_context_user_ns
)) {
1117 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1118 } else if (!strcmp((char *) context_type
,
1119 config_event_context_uts_ns
)) {
1120 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1121 } else if (!strcmp((char *) context_type
,
1122 config_event_context_uid
)) {
1123 ret
= LTTNG_EVENT_CONTEXT_UID
;
1124 } else if (!strcmp((char *) context_type
,
1125 config_event_context_euid
)) {
1126 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1127 } else if (!strcmp((char *) context_type
,
1128 config_event_context_suid
)) {
1129 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1130 } else if (!strcmp((char *) context_type
,
1131 config_event_context_gid
)) {
1132 ret
= LTTNG_EVENT_CONTEXT_GID
;
1133 } else if (!strcmp((char *) context_type
,
1134 config_event_context_egid
)) {
1135 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1136 } else if (!strcmp((char *) context_type
,
1137 config_event_context_sgid
)) {
1138 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1139 } else if (!strcmp((char *) context_type
,
1140 config_event_context_vuid
)) {
1141 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1142 } else if (!strcmp((char *) context_type
,
1143 config_event_context_veuid
)) {
1144 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1145 } else if (!strcmp((char *) context_type
,
1146 config_event_context_vsuid
)) {
1147 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1148 } else if (!strcmp((char *) context_type
,
1149 config_event_context_vgid
)) {
1150 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1151 } else if (!strcmp((char *) context_type
,
1152 config_event_context_vegid
)) {
1153 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1154 } else if (!strcmp((char *) context_type
,
1155 config_event_context_vsgid
)) {
1156 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1167 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1172 for (node
= xmlFirstElementChild(domain_node
); node
;
1173 node
= xmlNextElementSibling(node
)) {
1174 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1176 xmlChar
*node_content
= xmlNodeGetContent(node
);
1177 if (!node_content
) {
1178 ret
= -LTTNG_ERR_NOMEM
;
1182 ret
= get_domain_type(node_content
);
1185 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1189 domain
->type
= (lttng_domain_type
) ret
;
1190 } else if (!strcmp((const char *) node
->name
,
1191 config_element_buffer_type
)) {
1193 xmlChar
*node_content
= xmlNodeGetContent(node
);
1194 if (!node_content
) {
1195 ret
= -LTTNG_ERR_NOMEM
;
1199 ret
= get_buffer_type(node_content
);
1202 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1206 domain
->buf_type
= (lttng_buffer_type
) ret
;
1215 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1220 for (node
= xmlFirstElementChild(net_output_node
); node
;
1221 node
= xmlNextElementSibling(node
)) {
1222 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1224 *control_uri
= (char *) xmlNodeGetContent(node
);
1225 if (!*control_uri
) {
1230 *data_uri
= (char *) xmlNodeGetContent(node
);
1237 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1241 int process_consumer_output(xmlNodePtr consumer_output_node
,
1242 struct consumer_output
*output
)
1247 LTTNG_ASSERT(output
);
1249 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1250 node
= xmlNextElementSibling(node
)) {
1251 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1252 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1256 ret
= -LTTNG_ERR_NOMEM
;
1260 ret
= parse_bool(enabled_str
, &output
->enabled
);
1266 xmlNodePtr output_type_node
;
1269 output_type_node
= xmlFirstElementChild(node
);
1270 if (!output_type_node
) {
1271 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1275 if (!strcmp((const char *) output_type_node
->name
,
1276 config_element_path
)) {
1278 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1279 if (!output
->path
) {
1280 ret
= -LTTNG_ERR_NOMEM
;
1285 ret
= get_net_output_uris(output_type_node
,
1286 &output
->control_uri
, &output
->data_uri
);
1298 free(output
->control_uri
);
1299 free(output
->data_uri
);
1300 memset(output
, 0, sizeof(struct consumer_output
));
1306 int create_session_net_output(const char *name
, const char *control_uri
,
1307 const char *data_uri
)
1310 struct lttng_handle
*handle
;
1311 const char *uri
= NULL
;
1315 handle
= lttng_create_handle(name
, NULL
);
1317 ret
= -LTTNG_ERR_NOMEM
;
1321 if (!control_uri
|| !data_uri
) {
1322 uri
= control_uri
? control_uri
: data_uri
;
1327 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1328 lttng_destroy_handle(handle
);
1334 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1335 const struct config_load_session_override_attr
*overrides
)
1338 xmlNodePtr node
= NULL
;
1339 xmlNodePtr snapshot_output_list_node
;
1340 xmlNodePtr snapshot_output_node
;
1342 LTTNG_ASSERT(session_name
);
1344 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1353 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1355 /* Parse and create snapshot outputs */
1357 for (snapshot_output_node
=
1358 xmlFirstElementChild(snapshot_output_list_node
);
1359 snapshot_output_node
; snapshot_output_node
=
1360 xmlNextElementSibling(snapshot_output_node
)) {
1362 uint64_t max_size
= UINT64_MAX
;
1363 struct consumer_output output
= { 0 };
1364 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1365 const char *control_uri
= NULL
;
1366 const char *data_uri
= NULL
;
1367 const char *path
= NULL
;
1369 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1370 node
= xmlNextElementSibling(node
)) {
1371 if (!strcmp((const char *) node
->name
,
1372 config_element_name
)) {
1374 name
= (char *) xmlNodeGetContent(node
);
1376 ret
= -LTTNG_ERR_NOMEM
;
1377 goto error_snapshot_output
;
1379 } else if (!strcmp((const char *) node
->name
,
1380 config_element_max_size
)) {
1381 xmlChar
*content
= xmlNodeGetContent(node
);
1385 ret
= -LTTNG_ERR_NOMEM
;
1386 goto error_snapshot_output
;
1388 ret
= parse_uint(content
, &max_size
);
1391 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1392 goto error_snapshot_output
;
1395 /* consumer_output */
1396 ret
= process_consumer_output(node
, &output
);
1398 goto error_snapshot_output
;
1403 control_uri
= output
.control_uri
;
1404 data_uri
= output
.data_uri
;
1408 if (overrides
->path_url
) {
1409 path
= overrides
->path_url
;
1410 /* Control/data_uri are null */
1414 if (overrides
->ctrl_url
) {
1415 control_uri
= overrides
->ctrl_url
;
1419 if (overrides
->data_url
) {
1420 data_uri
= overrides
->data_url
;
1427 snapshot_output
= lttng_snapshot_output_create();
1428 if (!snapshot_output
) {
1429 ret
= -LTTNG_ERR_NOMEM
;
1430 goto error_snapshot_output
;
1433 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1435 goto error_snapshot_output
;
1438 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1440 goto error_snapshot_output
;
1444 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1447 goto error_snapshot_output
;
1451 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1454 goto error_snapshot_output
;
1459 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1462 goto error_snapshot_output
;
1467 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1468 error_snapshot_output
:
1471 free(output
.control_uri
);
1472 free(output
.data_uri
);
1473 lttng_snapshot_output_destroy(snapshot_output
);
1483 int create_session(const char *name
,
1484 xmlNodePtr output_node
,
1485 uint64_t live_timer_interval
,
1486 const struct config_load_session_override_attr
*overrides
)
1489 struct consumer_output output
= { 0 };
1490 xmlNodePtr consumer_output_node
;
1491 const char *control_uri
= NULL
;
1492 const char *data_uri
= NULL
;
1493 const char *path
= NULL
;
1498 consumer_output_node
= xmlFirstElementChild(output_node
);
1499 if (!consumer_output_node
) {
1500 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1504 if (strcmp((const char *) consumer_output_node
->name
,
1505 config_element_consumer_output
)) {
1506 WARN("Invalid output type, expected %s node",
1507 config_element_consumer_output
);
1508 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1512 ret
= process_consumer_output(consumer_output_node
, &output
);
1518 control_uri
= output
.control_uri
;
1519 data_uri
= output
.data_uri
;
1522 /* Check for override and apply them */
1524 if (overrides
->path_url
) {
1525 path
= overrides
->path_url
;
1526 /* control/data_uri are null */;
1530 if (overrides
->ctrl_url
) {
1531 control_uri
= overrides
->ctrl_url
;
1535 if (overrides
->data_url
) {
1536 data_uri
= overrides
->data_url
;
1544 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1545 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1549 if (control_uri
|| data_uri
) {
1550 /* network destination */
1551 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1553 * URLs are provided for sure since the test above make sure that
1554 * with a live timer the data and control URIs are provided. So,
1555 * NULL is passed here and will be set right after.
1557 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1559 ret
= lttng_create_session(name
, NULL
);
1565 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1571 /* either local output or no output */
1572 ret
= lttng_create_session(name
, path
);
1579 free(output
.control_uri
);
1580 free(output
.data_uri
);
1585 struct lttng_userspace_probe_location
*
1586 process_userspace_probe_function_attribute_node(
1587 xmlNodePtr attribute_node
)
1589 xmlNodePtr function_attribute_node
;
1590 char *function_name
= NULL
, *binary_path
= NULL
;
1591 struct lttng_userspace_probe_location
*location
= NULL
;
1592 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1595 * Process userspace probe location function attributes. The order of
1596 * the fields are not guaranteed so we need to iterate over all fields
1597 * and check at the end if everything we need for this location type is
1600 for (function_attribute_node
=
1601 xmlFirstElementChild(attribute_node
);
1602 function_attribute_node
;
1603 function_attribute_node
= xmlNextElementSibling(
1604 function_attribute_node
)) {
1605 /* Handle function name, binary path and lookup method. */
1606 if (!strcmp((const char *) function_attribute_node
->name
,
1607 config_element_userspace_probe_function_location_function_name
)) {
1608 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1609 if (!function_name
) {
1612 } else if (!strcmp((const char *) function_attribute_node
->name
,
1613 config_element_userspace_probe_location_binary_path
)) {
1614 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1618 } else if (!strcmp((const char *) function_attribute_node
->name
,
1619 config_element_userspace_probe_lookup
)) {
1620 char *lookup_method_name
;
1622 lookup_method_name
= (char *) xmlNodeGetContent(
1623 function_attribute_node
);
1624 if (!lookup_method_name
) {
1629 * function_default lookup method defaults to
1630 * function_elf lookup method at the moment.
1632 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1633 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1634 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1635 if (!lookup_method
) {
1636 PERROR("Error creating function default/ELF lookup method");
1639 WARN("Unknown function lookup method");
1642 free(lookup_method_name
);
1643 if (!lookup_method
) {
1650 /* Check if all the necessary fields were found. */
1651 if (binary_path
&& function_name
&& lookup_method
) {
1652 /* Ownership of lookup_method is transferred. */
1654 lttng_userspace_probe_location_function_create(
1655 binary_path
, function_name
,
1657 lookup_method
= NULL
;
1662 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1664 free(function_name
);
1669 struct lttng_userspace_probe_location
*
1670 process_userspace_probe_tracepoint_attribute_node(
1671 xmlNodePtr attribute_node
)
1673 xmlNodePtr tracepoint_attribute_node
;
1674 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1675 struct lttng_userspace_probe_location
*location
= NULL
;
1676 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1679 * Process userspace probe location tracepoint attributes. The order of
1680 * the fields are not guaranteed so we need to iterate over all fields
1681 * and check at the end if everything we need for this location type is
1684 for (tracepoint_attribute_node
=
1685 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1686 tracepoint_attribute_node
= xmlNextElementSibling(
1687 tracepoint_attribute_node
)) {
1688 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1689 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1690 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1694 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1695 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1696 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1697 if (!provider_name
) {
1700 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1701 config_element_userspace_probe_location_binary_path
)) {
1702 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1706 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1707 config_element_userspace_probe_lookup
)) {
1708 char *lookup_method_name
;
1710 lookup_method_name
= (char *) xmlNodeGetContent(
1711 tracepoint_attribute_node
);
1712 if (!lookup_method_name
) {
1716 if (!strcmp(lookup_method_name
,
1717 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1719 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1720 if (!lookup_method
) {
1721 PERROR("Error creating tracepoint SDT lookup method");
1724 WARN("Unknown tracepoint lookup method");
1727 free(lookup_method_name
);
1728 if (!lookup_method
) {
1732 WARN("Unknown tracepoint attribute");
1736 /* Check if all the necessary fields were found. */
1737 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1738 /* Ownership of lookup_method is transferred. */
1740 lttng_userspace_probe_location_tracepoint_create(
1741 binary_path
, provider_name
,
1742 probe_name
, lookup_method
);
1743 lookup_method
= NULL
;
1748 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1750 free(provider_name
);
1756 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1757 struct lttng_event_probe_attr
*attr
)
1761 LTTNG_ASSERT(probe_attribute_node
);
1764 if (!strcmp((const char *) probe_attribute_node
->name
,
1765 config_element_address
)) {
1770 content
= xmlNodeGetContent(probe_attribute_node
);
1772 ret
= -LTTNG_ERR_NOMEM
;
1776 ret
= parse_uint(content
, &addr
);
1779 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1784 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1785 config_element_offset
)) {
1787 uint64_t offset
= 0;
1790 content
= xmlNodeGetContent(probe_attribute_node
);
1792 ret
= -LTTNG_ERR_NOMEM
;
1796 ret
= parse_uint(content
, &offset
);
1799 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1803 attr
->offset
= offset
;
1804 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1805 config_element_symbol_name
)) {
1809 content
= xmlNodeGetContent(probe_attribute_node
);
1811 ret
= -LTTNG_ERR_NOMEM
;
1815 ret
= lttng_strncpy(attr
->symbol_name
,
1816 (const char *) content
,
1817 LTTNG_SYMBOL_NAME_LEN
);
1819 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1820 (const char *) content
,
1821 strlen((const char *) content
),
1822 LTTNG_SYMBOL_NAME_LEN
);
1823 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1835 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1836 const char *channel_name
, const enum process_event_node_phase phase
)
1840 struct lttng_event
*event
;
1841 char **exclusions
= NULL
;
1842 unsigned long exclusion_count
= 0;
1843 char *filter_expression
= NULL
;
1845 LTTNG_ASSERT(event_node
);
1846 LTTNG_ASSERT(handle
);
1847 LTTNG_ASSERT(channel_name
);
1849 event
= lttng_event_create();
1851 ret
= -LTTNG_ERR_NOMEM
;
1855 /* Initialize default log level which varies by domain */
1856 switch (handle
->domain
.type
)
1858 case LTTNG_DOMAIN_JUL
:
1859 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1861 case LTTNG_DOMAIN_LOG4J
:
1862 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1864 case LTTNG_DOMAIN_PYTHON
:
1865 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1867 case LTTNG_DOMAIN_UST
:
1868 case LTTNG_DOMAIN_KERNEL
:
1869 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1875 for (node
= xmlFirstElementChild(event_node
); node
;
1876 node
= xmlNextElementSibling(node
)) {
1877 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1881 content
= xmlNodeGetContent(node
);
1883 ret
= -LTTNG_ERR_NOMEM
;
1887 ret
= lttng_strncpy(event
->name
,
1888 (const char *) content
,
1889 LTTNG_SYMBOL_NAME_LEN
);
1891 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1892 (const char *) content
,
1893 strlen((const char *) content
),
1894 LTTNG_SYMBOL_NAME_LEN
);
1895 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1900 } else if (!strcmp((const char *) node
->name
,
1901 config_element_enabled
)) {
1902 xmlChar
*content
= xmlNodeGetContent(node
);
1906 ret
= -LTTNG_ERR_NOMEM
;
1910 ret
= parse_bool(content
, &event
->enabled
);
1913 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1916 } else if (!strcmp((const char *) node
->name
,
1917 config_element_type
)) {
1918 xmlChar
*content
= xmlNodeGetContent(node
);
1922 ret
= -LTTNG_ERR_NOMEM
;
1926 ret
= get_event_type(content
);
1929 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1933 event
->type
= (lttng_event_type
) ret
;
1934 } else if (!strcmp((const char *) node
->name
,
1935 config_element_loglevel_type
)) {
1936 xmlChar
*content
= xmlNodeGetContent(node
);
1940 ret
= -LTTNG_ERR_NOMEM
;
1944 ret
= get_loglevel_type(content
);
1947 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1951 event
->loglevel_type
= (lttng_loglevel_type
) ret
;
1952 } else if (!strcmp((const char *) node
->name
,
1953 config_element_loglevel
)) {
1955 int64_t loglevel
= 0;
1958 content
= xmlNodeGetContent(node
);
1960 ret
= -LTTNG_ERR_NOMEM
;
1964 ret
= parse_int(content
, &loglevel
);
1967 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1971 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1972 WARN("loglevel out of range.");
1973 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1977 event
->loglevel
= loglevel
;
1978 } else if (!strcmp((const char *) node
->name
,
1979 config_element_filter
)) {
1981 xmlNodeGetContent(node
);
1985 ret
= -LTTNG_ERR_NOMEM
;
1989 free(filter_expression
);
1990 filter_expression
= strdup((char *) content
);
1992 if (!filter_expression
) {
1993 ret
= -LTTNG_ERR_NOMEM
;
1996 } else if (!strcmp((const char *) node
->name
,
1997 config_element_exclusions
)) {
1998 xmlNodePtr exclusion_node
;
1999 int exclusion_index
= 0;
2004 * Exclusions has already been initialized,
2007 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2011 exclusion_count
= xmlChildElementCount(node
);
2012 if (!exclusion_count
) {
2016 exclusions
= (char **) zmalloc(exclusion_count
* sizeof(char *));
2018 exclusion_count
= 0;
2019 ret
= -LTTNG_ERR_NOMEM
;
2023 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2024 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2026 xmlNodeGetContent(exclusion_node
);
2029 ret
= -LTTNG_ERR_NOMEM
;
2033 exclusions
[exclusion_index
] = strdup((const char *) content
);
2035 if (!exclusions
[exclusion_index
]) {
2036 ret
= -LTTNG_ERR_NOMEM
;
2042 event
->exclusion
= 1;
2043 } else if (!strcmp((const char *) node
->name
,
2044 config_element_attributes
)) {
2045 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2048 if (!attribute_node
) {
2049 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2053 if (!strcmp((const char *) attribute_node
->name
,
2054 config_element_probe_attributes
)) {
2055 xmlNodePtr probe_attribute_node
;
2057 /* probe_attributes */
2058 for (probe_attribute_node
=
2059 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2060 probe_attribute_node
= xmlNextElementSibling(
2061 probe_attribute_node
)) {
2063 ret
= process_probe_attribute_node(probe_attribute_node
,
2064 &event
->attr
.probe
);
2069 } else if (!strcmp((const char *) attribute_node
->name
,
2070 config_element_function_attributes
)) {
2073 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2075 /* function_attributes */
2076 content
= xmlNodeGetContent(symbol_node
);
2078 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2082 sym_len
= strlen((char *) content
);
2083 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2084 WARN("Function name too long.");
2085 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2090 ret
= lttng_strncpy(
2091 event
->attr
.ftrace
.symbol_name
,
2092 (char *) content
, sym_len
);
2094 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2099 } else if (!strcmp((const char *) attribute_node
->name
,
2100 config_element_userspace_probe_tracepoint_attributes
)) {
2101 struct lttng_userspace_probe_location
*location
;
2103 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2105 WARN("Error processing userspace probe tracepoint attribute");
2106 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2109 ret
= lttng_event_set_userspace_probe_location(
2112 WARN("Error setting userspace probe location field");
2113 lttng_userspace_probe_location_destroy(
2115 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2118 } else if (!strcmp((const char *) attribute_node
->name
,
2119 config_element_userspace_probe_function_attributes
)) {
2120 struct lttng_userspace_probe_location
*location
;
2123 process_userspace_probe_function_attribute_node(
2126 WARN("Error processing userspace probe function attribute");
2127 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2131 ret
= lttng_event_set_userspace_probe_location(
2134 WARN("Error setting userspace probe location field");
2135 lttng_userspace_probe_location_destroy(
2137 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2141 /* Unknown event attribute. */
2142 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2148 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2149 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2150 filter_expression
, exclusion_count
, exclusions
);
2152 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2153 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2159 for (i
= 0; i
< exclusion_count
; i
++) {
2160 free(exclusions
[i
]);
2163 lttng_event_destroy(event
);
2165 free(filter_expression
);
2170 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2171 const char *channel_name
)
2174 struct lttng_event event
;
2177 LTTNG_ASSERT(events_node
);
2178 LTTNG_ASSERT(handle
);
2179 LTTNG_ASSERT(channel_name
);
2181 for (node
= xmlFirstElementChild(events_node
); node
;
2182 node
= xmlNextElementSibling(node
)) {
2183 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2190 * Disable all events to enable only the necessary events.
2191 * Limitations regarding lttng_disable_events and tuple descriptor
2192 * force this approach.
2194 memset(&event
, 0, sizeof(event
));
2195 event
.loglevel
= -1;
2196 event
.type
= LTTNG_EVENT_ALL
;
2197 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2202 for (node
= xmlFirstElementChild(events_node
); node
;
2203 node
= xmlNextElementSibling(node
)) {
2204 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2215 int process_channel_attr_node(xmlNodePtr attr_node
,
2216 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2217 xmlNodePtr
*events_node
)
2221 LTTNG_ASSERT(attr_node
);
2222 LTTNG_ASSERT(channel
);
2223 LTTNG_ASSERT(contexts_node
);
2224 LTTNG_ASSERT(events_node
);
2226 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2230 content
= xmlNodeGetContent(attr_node
);
2232 ret
= -LTTNG_ERR_NOMEM
;
2236 ret
= lttng_strncpy(channel
->name
,
2237 (const char *) content
,
2238 LTTNG_SYMBOL_NAME_LEN
);
2240 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2241 (const char *) content
,
2242 strlen((const char *) content
),
2243 LTTNG_SYMBOL_NAME_LEN
);
2244 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2249 } else if (!strcmp((const char *) attr_node
->name
,
2250 config_element_enabled
)) {
2255 content
= xmlNodeGetContent(attr_node
);
2257 ret
= -LTTNG_ERR_NOMEM
;
2261 ret
= parse_bool(content
, &enabled
);
2264 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2268 channel
->enabled
= enabled
;
2269 } else if (!strcmp((const char *) attr_node
->name
,
2270 config_element_overwrite_mode
)) {
2273 /* overwrite_mode */
2274 content
= xmlNodeGetContent(attr_node
);
2276 ret
= -LTTNG_ERR_NOMEM
;
2280 ret
= get_overwrite_mode(content
);
2283 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2287 channel
->attr
.overwrite
= ret
;
2288 } else if (!strcmp((const char *) attr_node
->name
,
2289 config_element_subbuf_size
)) {
2292 /* subbuffer_size */
2293 content
= xmlNodeGetContent(attr_node
);
2295 ret
= -LTTNG_ERR_NOMEM
;
2299 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2302 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2305 } else if (!strcmp((const char *) attr_node
->name
,
2306 config_element_num_subbuf
)) {
2309 /* subbuffer_count */
2310 content
= xmlNodeGetContent(attr_node
);
2312 ret
= -LTTNG_ERR_NOMEM
;
2316 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2319 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2322 } else if (!strcmp((const char *) attr_node
->name
,
2323 config_element_switch_timer_interval
)) {
2325 uint64_t switch_timer_interval
= 0;
2327 /* switch_timer_interval */
2328 content
= xmlNodeGetContent(attr_node
);
2330 ret
= -LTTNG_ERR_NOMEM
;
2334 ret
= parse_uint(content
, &switch_timer_interval
);
2337 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2341 if (switch_timer_interval
> UINT_MAX
) {
2342 WARN("switch_timer_interval out of range.");
2343 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2347 channel
->attr
.switch_timer_interval
=
2348 switch_timer_interval
;
2349 } else if (!strcmp((const char *) attr_node
->name
,
2350 config_element_read_timer_interval
)) {
2352 uint64_t read_timer_interval
= 0;
2354 /* read_timer_interval */
2355 content
= xmlNodeGetContent(attr_node
);
2357 ret
= -LTTNG_ERR_NOMEM
;
2361 ret
= parse_uint(content
, &read_timer_interval
);
2364 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2368 if (read_timer_interval
> UINT_MAX
) {
2369 WARN("read_timer_interval out of range.");
2370 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2374 channel
->attr
.read_timer_interval
=
2375 read_timer_interval
;
2376 } else if (!strcmp((const char *) attr_node
->name
,
2377 config_element_output_type
)) {
2381 content
= xmlNodeGetContent(attr_node
);
2383 ret
= -LTTNG_ERR_NOMEM
;
2387 ret
= get_output_type(content
);
2390 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2394 channel
->attr
.output
= (lttng_event_output
) ret
;
2395 } else if (!strcmp((const char *) attr_node
->name
,
2396 config_element_tracefile_size
)) {
2399 /* tracefile_size */
2400 content
= xmlNodeGetContent(attr_node
);
2402 ret
= -LTTNG_ERR_NOMEM
;
2406 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2409 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2412 } else if (!strcmp((const char *) attr_node
->name
,
2413 config_element_tracefile_count
)) {
2416 /* tracefile_count */
2417 content
= xmlNodeGetContent(attr_node
);
2419 ret
= -LTTNG_ERR_NOMEM
;
2423 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2426 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2429 } else if (!strcmp((const char *) attr_node
->name
,
2430 config_element_live_timer_interval
)) {
2432 uint64_t live_timer_interval
= 0;
2434 /* live_timer_interval */
2435 content
= xmlNodeGetContent(attr_node
);
2437 ret
= -LTTNG_ERR_NOMEM
;
2441 ret
= parse_uint(content
, &live_timer_interval
);
2444 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2448 if (live_timer_interval
> UINT_MAX
) {
2449 WARN("live_timer_interval out of range.");
2450 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2454 channel
->attr
.live_timer_interval
=
2455 live_timer_interval
;
2456 } else if (!strcmp((const char *) attr_node
->name
,
2457 config_element_monitor_timer_interval
)) {
2459 uint64_t monitor_timer_interval
= 0;
2461 /* monitor_timer_interval */
2462 content
= xmlNodeGetContent(attr_node
);
2464 ret
= -LTTNG_ERR_NOMEM
;
2468 ret
= parse_uint(content
, &monitor_timer_interval
);
2471 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2475 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2476 monitor_timer_interval
);
2478 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2481 } else if (!strcmp((const char *) attr_node
->name
,
2482 config_element_blocking_timeout
)) {
2484 int64_t blocking_timeout
= 0;
2486 /* blocking_timeout */
2487 content
= xmlNodeGetContent(attr_node
);
2489 ret
= -LTTNG_ERR_NOMEM
;
2493 ret
= parse_int(content
, &blocking_timeout
);
2496 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2500 ret
= lttng_channel_set_blocking_timeout(channel
,
2503 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2506 } else if (!strcmp((const char *) attr_node
->name
,
2507 config_element_events
)) {
2509 *events_node
= attr_node
;
2512 *contexts_node
= attr_node
;
2520 int process_context_node(xmlNodePtr context_node
,
2521 struct lttng_handle
*handle
, const char *channel_name
)
2524 struct lttng_event_context context
;
2525 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2527 LTTNG_ASSERT(handle
);
2528 LTTNG_ASSERT(channel_name
);
2530 if (!context_child_node
) {
2531 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2535 memset(&context
, 0, sizeof(context
));
2537 if (!strcmp((const char *) context_child_node
->name
,
2538 config_element_type
)) {
2540 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2543 ret
= -LTTNG_ERR_NOMEM
;
2547 ret
= get_context_type(content
);
2550 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2554 context
.ctx
= (lttng_event_context_type
) ret
;
2555 } else if (!strcmp((const char *) context_child_node
->name
,
2556 config_element_context_perf
)) {
2558 xmlNodePtr perf_attr_node
;
2560 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2561 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2562 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2563 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2564 perf_attr_node
; perf_attr_node
=
2565 xmlNextElementSibling(perf_attr_node
)) {
2566 if (!strcmp((const char *) perf_attr_node
->name
,
2567 config_element_type
)) {
2572 content
= xmlNodeGetContent(perf_attr_node
);
2574 ret
= -LTTNG_ERR_NOMEM
;
2578 ret
= parse_uint(content
, &type
);
2581 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2585 if (type
> UINT32_MAX
) {
2586 WARN("perf context type out of range.");
2587 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2591 context
.u
.perf_counter
.type
= type
;
2592 } else if (!strcmp((const char *) perf_attr_node
->name
,
2593 config_element_config
)) {
2595 uint64_t config
= 0;
2598 content
= xmlNodeGetContent(perf_attr_node
);
2600 ret
= -LTTNG_ERR_NOMEM
;
2604 ret
= parse_uint(content
, &config
);
2607 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2611 context
.u
.perf_counter
.config
= config
;
2612 } else if (!strcmp((const char *) perf_attr_node
->name
,
2613 config_element_name
)) {
2617 content
= xmlNodeGetContent(perf_attr_node
);
2619 ret
= -LTTNG_ERR_NOMEM
;
2623 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2624 (const char *) content
,
2625 LTTNG_SYMBOL_NAME_LEN
);
2627 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2628 (const char *) content
,
2629 strlen((const char *) content
),
2630 LTTNG_SYMBOL_NAME_LEN
);
2631 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2638 } else if (!strcmp((const char *) context_child_node
->name
,
2639 config_element_context_app
)) {
2640 /* application context */
2641 xmlNodePtr app_ctx_node
;
2643 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2644 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2645 app_ctx_node
; app_ctx_node
=
2646 xmlNextElementSibling(app_ctx_node
)) {
2648 char **target
= strcmp(
2649 (const char *) app_ctx_node
->name
,
2650 config_element_context_app_provider_name
) == 0 ?
2651 &context
.u
.app_ctx
.provider_name
:
2652 &context
.u
.app_ctx
.ctx_name
;
2654 content
= xmlNodeGetContent(app_ctx_node
);
2656 ret
= -LTTNG_ERR_NOMEM
;
2660 *target
= (char *) content
;
2663 /* Unrecognized context type */
2664 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2668 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2669 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2670 free(context
.u
.app_ctx
.provider_name
);
2671 free(context
.u
.app_ctx
.ctx_name
);
2678 int process_contexts_node(xmlNodePtr contexts_node
,
2679 struct lttng_handle
*handle
, const char *channel_name
)
2682 xmlNodePtr context_node
;
2684 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2685 context_node
= xmlNextElementSibling(context_node
)) {
2686 ret
= process_context_node(context_node
, handle
, channel_name
);
2695 static int get_tracker_elements(enum lttng_process_attr process_attr
,
2696 const char **element_id_tracker
,
2697 const char **element_value_type
,
2698 const char **element_value
,
2699 const char **element_value_alias
,
2700 const char **element_name
)
2704 switch (process_attr
) {
2705 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2706 *element_id_tracker
= config_element_process_attr_tracker_pid
;
2707 *element_value_type
= config_element_process_attr_pid_value
;
2708 *element_value
= config_element_process_attr_id
;
2709 *element_value_alias
= config_element_process_attr_id
;
2710 *element_name
= NULL
;
2712 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2713 *element_id_tracker
= config_element_process_attr_tracker_vpid
;
2714 *element_value_type
= config_element_process_attr_vpid_value
;
2715 *element_value
= config_element_process_attr_id
;
2716 *element_value_alias
= NULL
;
2717 *element_name
= NULL
;
2719 case LTTNG_PROCESS_ATTR_USER_ID
:
2720 *element_id_tracker
= config_element_process_attr_tracker_uid
;
2721 *element_value_type
= config_element_process_attr_uid_value
;
2722 *element_value
= config_element_process_attr_id
;
2723 *element_value_alias
= NULL
;
2724 *element_name
= config_element_name
;
2726 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2727 *element_id_tracker
= config_element_process_attr_tracker_vuid
;
2728 *element_value_type
= config_element_process_attr_vuid_value
;
2729 *element_value
= config_element_process_attr_id
;
2730 *element_value_alias
= NULL
;
2731 *element_name
= config_element_name
;
2733 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2734 *element_id_tracker
= config_element_process_attr_tracker_gid
;
2735 *element_value_type
= config_element_process_attr_gid_value
;
2736 *element_value
= config_element_process_attr_id
;
2737 *element_value_alias
= NULL
;
2738 *element_name
= config_element_name
;
2740 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2741 *element_id_tracker
= config_element_process_attr_tracker_vgid
;
2742 *element_value_type
= config_element_process_attr_vgid_value
;
2743 *element_value
= config_element_process_attr_id
;
2744 *element_value_alias
= NULL
;
2745 *element_name
= config_element_name
;
2748 ret
= LTTNG_ERR_INVALID
;
2753 static int process_legacy_pid_tracker_node(
2754 xmlNodePtr trackers_node
, struct lttng_handle
*handle
)
2756 int ret
= 0, child_count
;
2757 xmlNodePtr targets_node
= NULL
;
2759 const char *element_id_tracker
;
2760 const char *element_target_id
;
2761 const char *element_id
;
2762 const char *element_id_alias
;
2763 const char *element_name
;
2764 enum lttng_error_code tracker_handle_ret_code
;
2765 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2766 enum lttng_process_attr_tracker_handle_status status
;
2767 const enum lttng_process_attr process_attr
=
2768 handle
->domain
.type
== LTTNG_DOMAIN_UST
?
2769 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2770 LTTNG_PROCESS_ATTR_PROCESS_ID
;
2772 LTTNG_ASSERT(handle
);
2774 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2775 handle
->session_name
, handle
->domain
.type
,
2778 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2779 ret
= LTTNG_ERR_INVALID
;
2783 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2784 &element_target_id
, &element_id
, &element_id_alias
,
2790 /* Get the targets node */
2791 for (node
= xmlFirstElementChild(trackers_node
); node
;
2792 node
= xmlNextElementSibling(node
)) {
2793 if (!strcmp((const char *) node
->name
,
2794 config_element_tracker_targets_legacy
)) {
2795 targets_node
= node
;
2800 if (!targets_node
) {
2801 ret
= LTTNG_ERR_INVALID
;
2805 /* Go through all id target node */
2806 child_count
= xmlChildElementCount(targets_node
);
2807 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2809 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2810 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2811 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2812 ret
= LTTNG_ERR_UNK
;
2816 /* Add all tracked values. */
2817 for (node
= xmlFirstElementChild(targets_node
); node
;
2818 node
= xmlNextElementSibling(node
)) {
2819 xmlNodePtr pid_target_node
= node
;
2821 /* get pid_target node and track it */
2822 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2823 node
= xmlNextElementSibling(node
)) {
2824 if (!strcmp((const char *) node
->name
,
2825 config_element_tracker_pid_legacy
)) {
2827 xmlChar
*content
= xmlNodeGetContent(node
);
2830 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2834 ret
= parse_int(content
, &id
);
2837 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2841 switch (process_attr
) {
2842 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2843 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2847 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2848 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2853 ret
= LTTNG_ERR_INVALID
;
2858 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
2860 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
2861 ret
= LTTNG_ERR_INVALID
;
2863 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
2864 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
2866 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
2867 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
2869 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
2870 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
2872 ret
= LTTNG_ERR_UNK
;
2876 node
= pid_target_node
;
2880 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
2884 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2885 struct lttng_handle
*handle
,
2886 enum lttng_process_attr process_attr
)
2888 int ret
= 0, child_count
;
2889 xmlNodePtr values_node
= NULL
;
2891 const char *element_id_tracker
;
2892 const char *element_target_id
;
2893 const char *element_id
;
2894 const char *element_id_alias
;
2895 const char *element_name
;
2896 enum lttng_error_code tracker_handle_ret_code
;
2897 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
2898 enum lttng_process_attr_tracker_handle_status status
;
2900 LTTNG_ASSERT(handle
);
2901 LTTNG_ASSERT(id_tracker_node
);
2903 tracker_handle_ret_code
= lttng_session_get_tracker_handle(
2904 handle
->session_name
, handle
->domain
.type
, process_attr
,
2906 if (tracker_handle_ret_code
!= LTTNG_OK
) {
2907 ret
= LTTNG_ERR_INVALID
;
2911 ret
= get_tracker_elements(process_attr
, &element_id_tracker
,
2912 &element_target_id
, &element_id
, &element_id_alias
,
2918 /* get the values node */
2919 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2920 node
= xmlNextElementSibling(node
)) {
2921 if (!strcmp((const char *) node
->name
,
2922 config_element_process_attr_values
)) {
2929 ret
= LTTNG_ERR_INVALID
;
2933 /* Go through all id target node */
2934 child_count
= xmlChildElementCount(values_node
);
2935 status
= lttng_process_attr_tracker_handle_set_tracking_policy(
2937 child_count
== 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
2938 LTTNG_TRACKING_POLICY_INCLUDE_SET
);
2939 if (status
!= LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
) {
2940 ret
= LTTNG_ERR_UNK
;
2944 /* Add all tracked values. */
2945 for (node
= xmlFirstElementChild(values_node
); node
;
2946 node
= xmlNextElementSibling(node
)) {
2947 xmlNodePtr id_target_node
= node
;
2949 /* get id node and track it */
2950 for (node
= xmlFirstElementChild(id_target_node
); node
;
2951 node
= xmlNextElementSibling(node
)) {
2952 if (!strcmp((const char *) node
->name
, element_id
) ||
2953 (element_id_alias
&&
2954 !strcmp((const char *) node
->name
,
2955 element_id_alias
))) {
2957 xmlChar
*content
= xmlNodeGetContent(node
);
2960 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2964 ret
= parse_int(content
, &id
);
2967 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2971 switch (process_attr
) {
2972 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
2973 status
= lttng_process_attr_process_id_tracker_handle_add_pid(
2977 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
2978 status
= lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
2982 case LTTNG_PROCESS_ATTR_USER_ID
:
2983 status
= lttng_process_attr_user_id_tracker_handle_add_uid(
2987 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
2988 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_uid(
2992 case LTTNG_PROCESS_ATTR_GROUP_ID
:
2993 status
= lttng_process_attr_group_id_tracker_handle_add_gid(
2997 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
2998 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_gid(
3003 ret
= LTTNG_ERR_INVALID
;
3006 } else if (element_name
&&
3007 !strcmp((const char *) node
->name
,
3009 xmlChar
*content
= xmlNodeGetContent(node
);
3012 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
3016 switch (process_attr
) {
3017 case LTTNG_PROCESS_ATTR_USER_ID
:
3018 status
= lttng_process_attr_user_id_tracker_handle_add_user_name(
3020 (const char *) content
);
3022 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
3023 status
= lttng_process_attr_virtual_user_id_tracker_handle_add_user_name(
3025 (const char *) content
);
3027 case LTTNG_PROCESS_ATTR_GROUP_ID
:
3028 status
= lttng_process_attr_group_id_tracker_handle_add_group_name(
3030 (const char *) content
);
3032 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
3033 status
= lttng_process_attr_virtual_group_id_tracker_handle_add_group_name(
3035 (const char *) content
);
3039 ret
= LTTNG_ERR_INVALID
;
3045 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
3047 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID
:
3048 ret
= LTTNG_ERR_INVALID
;
3050 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS
:
3051 ret
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
3053 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING
:
3054 ret
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
3056 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR
:
3057 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
3059 ret
= LTTNG_ERR_UNK
;
3063 node
= id_target_node
;
3067 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
3072 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
3075 struct lttng_domain domain
{};
3076 struct lttng_handle
*handle
= NULL
;
3077 struct lttng_channel
*channel
= NULL
;
3078 xmlNodePtr channels_node
= NULL
;
3079 xmlNodePtr trackers_node
= NULL
;
3080 xmlNodePtr pid_tracker_node
= NULL
;
3081 xmlNodePtr vpid_tracker_node
= NULL
;
3082 xmlNodePtr uid_tracker_node
= NULL
;
3083 xmlNodePtr vuid_tracker_node
= NULL
;
3084 xmlNodePtr gid_tracker_node
= NULL
;
3085 xmlNodePtr vgid_tracker_node
= NULL
;
3088 LTTNG_ASSERT(session_name
);
3090 ret
= init_domain(domain_node
, &domain
);
3095 handle
= lttng_create_handle(session_name
, &domain
);
3097 ret
= -LTTNG_ERR_NOMEM
;
3101 /* get the channels node */
3102 for (node
= xmlFirstElementChild(domain_node
); node
;
3103 node
= xmlNextElementSibling(node
)) {
3104 if (!strcmp((const char *) node
->name
,
3105 config_element_channels
)) {
3106 channels_node
= node
;
3111 if (!channels_node
) {
3115 /* create all channels */
3116 for (node
= xmlFirstElementChild(channels_node
); node
;
3117 node
= xmlNextElementSibling(node
)) {
3118 const enum lttng_domain_type original_domain
= domain
.type
;
3119 xmlNodePtr contexts_node
= NULL
;
3120 xmlNodePtr events_node
= NULL
;
3121 xmlNodePtr channel_attr_node
;
3124 * Channels of the "agent" types cannot be created directly.
3125 * They are meant to be created implicitly through the
3126 * activation of events in their domain. However, a user
3127 * can override the default channel configuration attributes
3128 * by creating the underlying UST channel _before_ enabling
3129 * an agent domain event.
3131 * Hence, the channel's type is substituted before the creation
3132 * and restored by the time the events are created.
3134 switch (domain
.type
) {
3135 case LTTNG_DOMAIN_JUL
:
3136 case LTTNG_DOMAIN_LOG4J
:
3137 case LTTNG_DOMAIN_PYTHON
:
3138 domain
.type
= LTTNG_DOMAIN_UST
;
3143 channel
= lttng_channel_create(&domain
);
3149 for (channel_attr_node
= xmlFirstElementChild(node
);
3150 channel_attr_node
; channel_attr_node
=
3151 xmlNextElementSibling(channel_attr_node
)) {
3152 ret
= process_channel_attr_node(channel_attr_node
,
3153 channel
, &contexts_node
, &events_node
);
3159 ret
= lttng_enable_channel(handle
, channel
);
3164 /* Restore the original channel domain. */
3165 domain
.type
= original_domain
;
3167 ret
= process_events_node(events_node
, handle
, channel
->name
);
3172 ret
= process_contexts_node(contexts_node
, handle
,
3178 lttng_channel_destroy(channel
);
3182 /* get the trackers node */
3183 for (node
= xmlFirstElementChild(domain_node
); node
;
3184 node
= xmlNextElementSibling(node
)) {
3185 if (!strcmp((const char *) node
->name
,
3186 config_element_process_attr_trackers
) ||
3187 !strcmp((const char *) node
->name
,
3188 config_element_trackers_legacy
)) {
3189 if (trackers_node
) {
3190 ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
3191 config_element_process_attr_trackers
,
3192 config_element_trackers_legacy
);
3196 trackers_node
= node
;
3201 if (!trackers_node
) {
3205 for (node
= xmlFirstElementChild(trackers_node
); node
;
3206 node
= xmlNextElementSibling(node
)) {
3207 if (!strcmp((const char *) node
->name
,
3208 config_element_process_attr_tracker_pid
)) {
3209 pid_tracker_node
= node
;
3210 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3211 LTTNG_PROCESS_ATTR_PROCESS_ID
);
3216 if (!strcmp((const char *) node
->name
,
3217 config_element_process_attr_tracker_vpid
)) {
3218 vpid_tracker_node
= node
;
3219 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3220 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
3225 if (!strcmp((const char *) node
->name
,
3226 config_element_process_attr_tracker_uid
)) {
3227 uid_tracker_node
= node
;
3228 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3229 LTTNG_PROCESS_ATTR_USER_ID
);
3234 if (!strcmp((const char *) node
->name
,
3235 config_element_process_attr_tracker_vuid
)) {
3236 vuid_tracker_node
= node
;
3237 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3238 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
3243 if (!strcmp((const char *) node
->name
,
3244 config_element_process_attr_tracker_gid
)) {
3245 gid_tracker_node
= node
;
3246 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3247 LTTNG_PROCESS_ATTR_GROUP_ID
);
3252 if (!strcmp((const char *) node
->name
,
3253 config_element_process_attr_tracker_vgid
)) {
3254 vgid_tracker_node
= node
;
3255 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3256 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
3261 if (!strcmp((const char *) node
->name
,
3262 config_element_pid_tracker_legacy
)) {
3263 ret
= process_legacy_pid_tracker_node(node
, handle
);
3271 lttng_channel_destroy(channel
);
3272 lttng_destroy_handle(handle
);
3277 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3280 enum lttng_rotation_status status
;
3281 struct lttng_rotation_schedule
*periodic
=
3282 lttng_rotation_schedule_periodic_create();
3285 ret
= -LTTNG_ERR_NOMEM
;
3289 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3291 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3292 ret
= -LTTNG_ERR_INVALID
;
3296 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3298 case LTTNG_ROTATION_STATUS_OK
:
3301 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3302 case LTTNG_ROTATION_STATUS_INVALID
:
3303 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3306 ret
= -LTTNG_ERR_UNK
;
3310 lttng_rotation_schedule_destroy(periodic
);
3315 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3318 enum lttng_rotation_status status
;
3319 struct lttng_rotation_schedule
*size
=
3320 lttng_rotation_schedule_size_threshold_create();
3323 ret
= -LTTNG_ERR_NOMEM
;
3327 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3329 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3330 ret
= -LTTNG_ERR_INVALID
;
3334 status
= lttng_session_add_rotation_schedule(name
, size
);
3336 case LTTNG_ROTATION_STATUS_OK
:
3339 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3340 case LTTNG_ROTATION_STATUS_INVALID
:
3341 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3344 ret
= -LTTNG_ERR_UNK
;
3348 lttng_rotation_schedule_destroy(size
);
3353 int process_session_rotation_schedules_node(
3354 xmlNodePtr schedules_node
,
3355 uint64_t *rotation_timer_interval
,
3356 uint64_t *rotation_size
)
3361 for (child
= xmlFirstElementChild(schedules_node
);
3363 child
= xmlNextElementSibling(child
)) {
3364 if (!strcmp((const char *) child
->name
,
3365 config_element_rotation_schedule_periodic
)) {
3367 xmlNodePtr time_us_node
;
3369 /* periodic rotation schedule */
3370 time_us_node
= xmlFirstElementChild(child
);
3371 if (!time_us_node
||
3372 strcmp((const char *) time_us_node
->name
,
3373 config_element_rotation_schedule_periodic_time_us
)) {
3374 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3379 content
= xmlNodeGetContent(time_us_node
);
3381 ret
= -LTTNG_ERR_NOMEM
;
3384 ret
= parse_uint(content
, rotation_timer_interval
);
3387 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3390 } else if (!strcmp((const char *) child
->name
,
3391 config_element_rotation_schedule_size_threshold
)) {
3393 xmlNodePtr bytes_node
;
3395 /* size_threshold rotation schedule */
3396 bytes_node
= xmlFirstElementChild(child
);
3398 strcmp((const char *) bytes_node
->name
,
3399 config_element_rotation_schedule_size_threshold_bytes
)) {
3400 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3405 content
= xmlNodeGetContent(bytes_node
);
3407 ret
= -LTTNG_ERR_NOMEM
;
3410 ret
= parse_uint(content
, rotation_size
);
3413 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3424 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3426 const struct config_load_session_override_attr
*overrides
)
3428 int ret
, started
= -1, snapshot_mode
= -1;
3429 uint64_t live_timer_interval
= UINT64_MAX
,
3430 rotation_timer_interval
= 0,
3432 xmlChar
*name
= NULL
;
3433 xmlChar
*shm_path
= NULL
;
3434 xmlNodePtr domains_node
= NULL
;
3435 xmlNodePtr output_node
= NULL
;
3437 xmlNodePtr attributes_child
;
3438 struct lttng_domain
*kernel_domain
= NULL
;
3439 struct lttng_domain
*ust_domain
= NULL
;
3440 struct lttng_domain
*jul_domain
= NULL
;
3441 struct lttng_domain
*log4j_domain
= NULL
;
3442 struct lttng_domain
*python_domain
= NULL
;
3444 for (node
= xmlFirstElementChild(session_node
); node
;
3445 node
= xmlNextElementSibling(node
)) {
3446 if (!name
&& !strcmp((const char *) node
->name
,
3447 config_element_name
)) {
3449 xmlChar
*node_content
= xmlNodeGetContent(node
);
3450 if (!node_content
) {
3451 ret
= -LTTNG_ERR_NOMEM
;
3455 name
= node_content
;
3456 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3457 config_element_domains
)) {
3459 domains_node
= node
;
3460 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3461 config_element_started
)) {
3463 xmlChar
*node_content
= xmlNodeGetContent(node
);
3464 if (!node_content
) {
3465 ret
= -LTTNG_ERR_NOMEM
;
3469 ret
= parse_bool(node_content
, &started
);
3472 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3475 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3476 config_element_output
)) {
3479 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3480 config_element_shared_memory_path
)) {
3481 /* shared memory path */
3482 xmlChar
*node_content
= xmlNodeGetContent(node
);
3483 if (!node_content
) {
3484 ret
= -LTTNG_ERR_NOMEM
;
3488 shm_path
= node_content
;
3491 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3492 * rotation_timer_interval.
3494 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3495 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3496 if (!strcmp((const char *) attributes_child
->name
,
3497 config_element_snapshot_mode
)) {
3499 xmlChar
*snapshot_mode_content
=
3500 xmlNodeGetContent(attributes_child
);
3501 if (!snapshot_mode_content
) {
3502 ret
= -LTTNG_ERR_NOMEM
;
3506 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3507 free(snapshot_mode_content
);
3509 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3512 } else if (!strcmp((const char *) attributes_child
->name
,
3513 config_element_live_timer_interval
)) {
3514 /* live_timer_interval */
3515 xmlChar
*timer_interval_content
=
3516 xmlNodeGetContent(attributes_child
);
3517 if (!timer_interval_content
) {
3518 ret
= -LTTNG_ERR_NOMEM
;
3522 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3523 free(timer_interval_content
);
3525 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3528 } else if (!strcmp((const char *) attributes_child
->name
,
3529 config_element_rotation_schedules
)) {
3530 ret
= process_session_rotation_schedules_node(
3532 &rotation_timer_interval
,
3535 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3545 /* Mandatory attribute, as defined in the session XSD */
3546 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3550 if (session_name
&& strcmp((char *) name
, session_name
)) {
3551 /* This is not the session we are looking for */
3552 ret
= -LTTNG_ERR_NO_SESSION
;
3556 /* Init domains to create the session handles */
3557 for (node
= xmlFirstElementChild(domains_node
); node
;
3558 node
= xmlNextElementSibling(node
)) {
3559 struct lttng_domain
*domain
;
3561 domain
= (lttng_domain
*) zmalloc(sizeof(*domain
));
3563 ret
= -LTTNG_ERR_NOMEM
;
3567 ret
= init_domain(node
, domain
);
3569 goto domain_init_error
;
3572 switch (domain
->type
) {
3573 case LTTNG_DOMAIN_KERNEL
:
3574 if (kernel_domain
) {
3575 /* Same domain seen twice, invalid! */
3576 goto domain_init_error
;
3578 kernel_domain
= domain
;
3580 case LTTNG_DOMAIN_UST
:
3582 /* Same domain seen twice, invalid! */
3583 goto domain_init_error
;
3585 ust_domain
= domain
;
3587 case LTTNG_DOMAIN_JUL
:
3589 /* Same domain seen twice, invalid! */
3590 goto domain_init_error
;
3592 jul_domain
= domain
;
3594 case LTTNG_DOMAIN_LOG4J
:
3596 /* Same domain seen twice, invalid! */
3597 goto domain_init_error
;
3599 log4j_domain
= domain
;
3601 case LTTNG_DOMAIN_PYTHON
:
3602 if (python_domain
) {
3603 /* Same domain seen twice, invalid! */
3604 goto domain_init_error
;
3606 python_domain
= domain
;
3609 WARN("Invalid domain type");
3610 goto domain_init_error
;
3615 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3619 /* Apply overrides */
3621 if (overrides
->session_name
) {
3622 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3623 if (!name_override
) {
3624 ret
= -LTTNG_ERR_NOMEM
;
3628 /* Overrides the session name to the provided name */
3630 name
= name_override
;
3635 /* Destroy session if it exists */
3636 ret
= lttng_destroy_session((const char *) name
);
3637 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3638 ERR("Failed to destroy existing session.");
3643 /* Create session type depending on output type */
3644 if (snapshot_mode
&& snapshot_mode
!= -1) {
3645 ret
= create_snapshot_session((const char *) name
, output_node
,
3647 } else if (live_timer_interval
&&
3648 live_timer_interval
!= UINT64_MAX
) {
3649 ret
= create_session((const char *) name
,
3650 output_node
, live_timer_interval
, overrides
);
3652 /* regular session */
3653 ret
= create_session((const char *) name
,
3654 output_node
, UINT64_MAX
, overrides
);
3661 ret
= lttng_set_session_shm_path((const char *) name
,
3662 (const char *) shm_path
);
3668 for (node
= xmlFirstElementChild(domains_node
); node
;
3669 node
= xmlNextElementSibling(node
)) {
3670 ret
= process_domain_node(node
, (const char *) name
);
3676 if (rotation_timer_interval
) {
3677 ret
= add_periodic_rotation((const char *) name
,
3678 rotation_timer_interval
);
3683 if (rotation_size
) {
3684 ret
= add_size_rotation((const char *) name
,
3692 ret
= lttng_start_tracing((const char *) name
);
3700 ERR("Failed to load session %s: %s", (const char *) name
,
3701 lttng_strerror(ret
));
3702 lttng_destroy_session((const char *) name
);
3706 free(kernel_domain
);
3710 free(python_domain
);
3717 * Return 1 if the given path is readable by the current UID or 0 if not.
3718 * Return -1 if the path is EPERM.
3720 static int validate_file_read_creds(const char *path
)
3726 /* Can we read the file. */
3727 ret
= access(path
, R_OK
);
3731 if (errno
== EACCES
) {
3742 int load_session_from_file(const char *path
, const char *session_name
,
3743 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3744 const struct config_load_session_override_attr
*overrides
)
3746 int ret
, session_found
= !session_name
;
3747 xmlDocPtr doc
= NULL
;
3748 xmlNodePtr sessions_node
;
3749 xmlNodePtr session_node
;
3752 LTTNG_ASSERT(validation_ctx
);
3754 ret
= validate_file_read_creds(path
);
3757 ret
= -LTTNG_ERR_EPERM
;
3759 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3764 doc
= xmlParseFile(path
);
3766 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3770 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3772 ERR("Session configuration file validation failed");
3773 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3777 sessions_node
= xmlDocGetRootElement(doc
);
3778 if (!sessions_node
) {
3779 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3783 for (session_node
= xmlFirstElementChild(sessions_node
);
3784 session_node
; session_node
=
3785 xmlNextElementSibling(session_node
)) {
3786 ret
= process_session_node(session_node
,
3787 session_name
, overwrite
, overrides
);
3788 if (!session_name
&& ret
) {
3789 /* Loading error occurred. */
3791 } else if (session_name
) {
3793 /* Target session found and loaded */
3796 } else if (ret
== -LTTNG_ERR_NO_SESSION
) {
3798 * Ignore this error, we are looking for a
3803 /* Loading error occurred. */
3811 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3817 int load_session_from_path(const char *path
, const char *session_name
,
3818 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3819 const struct config_load_session_override_attr
*overrides
)
3821 int ret
, session_found
= !session_name
;
3822 DIR *directory
= NULL
;
3823 struct lttng_dynamic_buffer file_path
;
3827 LTTNG_ASSERT(validation_ctx
);
3828 path_len
= strlen(path
);
3829 lttng_dynamic_buffer_init(&file_path
);
3830 if (path_len
>= LTTNG_PATH_MAX
) {
3831 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3832 path
, path_len
, LTTNG_PATH_MAX
);
3833 ret
= -LTTNG_ERR_INVALID
;
3837 directory
= opendir(path
);
3841 /* Try the file loading. */
3844 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3847 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3852 size_t file_path_root_len
;
3854 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3857 ret
= -LTTNG_ERR_NOMEM
;
3861 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3863 ret
= -LTTNG_ERR_NOMEM
;
3867 if (file_path
.data
[file_path
.size
- 1] != '/') {
3868 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3870 ret
= -LTTNG_ERR_NOMEM
;
3874 file_path_root_len
= file_path
.size
;
3876 /* Search for *.lttng files */
3878 size_t file_name_len
;
3879 struct dirent
*result
;
3882 * When the end of the directory stream is reached, NULL
3883 * is returned and errno is kept unchanged. When an
3884 * error occurs, NULL is returned and errno is set
3885 * accordingly. To distinguish between the two, set
3886 * errno to zero before calling readdir().
3888 * On success, readdir() returns a pointer to a dirent
3889 * structure. This structure may be statically
3890 * allocated, do not attempt to free(3) it.
3893 result
= readdir(directory
);
3895 /* Reached end of dir stream or error out. */
3898 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3899 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3905 file_name_len
= strlen(result
->d_name
);
3907 if (file_name_len
<=
3908 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3912 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3913 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3915 /* +1 to account for NULL terminator. */
3916 file_path
.size
+ file_name_len
+ 1,
3921 /* Does the file end with .lttng? */
3922 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3923 result
->d_name
+ file_name_len
- sizeof(
3924 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3928 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3931 ret
= -LTTNG_ERR_NOMEM
;
3935 ret
= load_session_from_file(file_path
.data
, session_name
,
3936 validation_ctx
, overwrite
, overrides
);
3938 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3942 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3946 * Reset the buffer's size to the location of the
3947 * path's trailing '/'.
3949 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3950 file_path_root_len
);
3952 ret
= -LTTNG_ERR_UNK
;
3957 ret
= load_session_from_file(path
, session_name
,
3958 validation_ctx
, overwrite
, overrides
);
3968 if (closedir(directory
)) {
3972 if (!ret
&& !session_found
) {
3973 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3975 lttng_dynamic_buffer_reset(&file_path
);
3980 * Validate that the given path's credentials and the current process have the
3981 * same UID. If so, return 1 else return 0 if it does NOT match.
3983 static int validate_path_creds(const char *path
)
3985 int ret
, uid
= getuid();
3994 ret
= stat(path
, &buf
);
3996 if (errno
!= ENOENT
) {
4002 if (buf
.st_uid
!= uid
) {
4012 int config_load_session(const char *path
, const char *session_name
,
4013 int overwrite
, unsigned int autoload
,
4014 const struct config_load_session_override_attr
*overrides
)
4017 bool session_loaded
= false;
4018 const char *path_ptr
= NULL
;
4019 struct session_config_validation_ctx validation_ctx
= { 0 };
4021 ret
= init_session_config_validation_ctx(&validation_ctx
);
4027 const char *home_path
;
4028 const char *sys_path
;
4031 home_path
= utils_get_home_dir();
4033 char path_buf
[PATH_MAX
];
4036 * Try user session configuration path. Ignore error here so we can
4037 * continue loading the system wide sessions.
4040 ret
= snprintf(path_buf
, sizeof(path_buf
),
4041 DEFAULT_SESSION_HOME_CONFIGPATH
4042 "/" DEFAULT_SESSION_CONFIG_AUTOLOAD
,
4045 PERROR("snprintf session autoload home config path");
4046 ret
= -LTTNG_ERR_INVALID
;
4051 * Credentials are only validated for the autoload in order to
4052 * avoid any user session daemon to try to load kernel sessions
4053 * automatically and failing all the times.
4055 ret
= validate_path_creds(path_buf
);
4057 path_ptr
= path_buf
;
4060 ret
= snprintf(path_buf
, sizeof(path_buf
),
4061 DEFAULT_SESSION_HOME_CONFIGPATH
,
4064 PERROR("snprintf session home config path");
4065 ret
= -LTTNG_ERR_INVALID
;
4068 path_ptr
= path_buf
;
4071 ret
= load_session_from_path(path_ptr
, session_name
,
4072 &validation_ctx
, overwrite
, overrides
);
4073 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4077 * Continue even if the session was found since we have to try
4078 * the system wide sessions.
4080 session_loaded
= true;
4084 /* Reset path pointer for the system wide dir. */
4087 /* Try system wide configuration directory. */
4089 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
4090 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
4091 ret
= validate_path_creds(sys_path
);
4093 path_ptr
= sys_path
;
4096 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
4097 path_ptr
= sys_path
;
4101 ret
= load_session_from_path(path_ptr
, session_name
,
4102 &validation_ctx
, overwrite
, overrides
);
4104 session_loaded
= true;
4110 ret
= access(path
, F_OK
);
4115 ret
= -LTTNG_ERR_INVALID
;
4116 WARN("Session configuration path does not exist.");
4119 ret
= -LTTNG_ERR_EPERM
;
4122 ret
= -LTTNG_ERR_UNK
;
4128 ret
= load_session_from_path(path
, session_name
,
4129 &validation_ctx
, overwrite
, overrides
);
4132 fini_session_config_validation_ctx(&validation_ctx
);
4133 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
4135 * Don't report an error if no sessions are found when called
4136 * without a session_name or a search path.
4141 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
4142 /* A matching session was found in one of the search paths. */
4149 void __attribute__((destructor
)) session_config_exit(void)