2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
31 #include <common/defaults.h>
32 #include <common/error.h>
33 #include <common/macros.h>
34 #include <common/utils.h>
35 #include <common/dynamic-buffer.h>
36 #include <common/compat/getenv.h>
37 #include <lttng/lttng-error.h>
38 #include <libxml/parser.h>
39 #include <libxml/valid.h>
40 #include <libxml/xmlschemas.h>
41 #include <libxml/tree.h>
42 #include <lttng/lttng.h>
43 #include <lttng/snapshot.h>
44 #include <lttng/rotation.h>
45 #include <lttng/userspace-probe.h>
47 #include "session-config.h"
48 #include "config-internal.h"
50 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
52 struct handler_filter_args
{
54 config_entry_handler_cb handler
;
58 struct session_config_validation_ctx
{
59 xmlSchemaParserCtxtPtr parser_ctx
;
61 xmlSchemaValidCtxtPtr schema_validation_ctx
;
64 const char * const config_str_yes
= "yes";
65 const char * const config_str_true
= "true";
66 const char * const config_str_on
= "on";
67 const char * const config_str_no
= "no";
68 const char * const config_str_false
= "false";
69 const char * const config_str_off
= "off";
70 const char * const config_xml_encoding
= "UTF-8";
71 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
72 const char * const config_xml_indent_string
= "\t";
73 const char * const config_xml_true
= "true";
74 const char * const config_xml_false
= "false";
76 const char * const config_element_channel
= "channel";
77 const char * const config_element_channels
= "channels";
78 const char * const config_element_domain
= "domain";
79 const char * const config_element_domains
= "domains";
80 const char * const config_element_event
= "event";
81 const char * const config_element_events
= "events";
82 const char * const config_element_context
= "context";
83 const char * const config_element_contexts
= "contexts";
84 const char * const config_element_attributes
= "attributes";
85 const char * const config_element_exclusion
= "exclusion";
86 const char * const config_element_exclusions
= "exclusions";
87 const char * const config_element_function_attributes
= "function_attributes";
88 const char * const config_element_probe_attributes
= "probe_attributes";
89 const char * const config_element_symbol_name
= "symbol_name";
90 const char * const config_element_address
= "address";
91 const char * const config_element_offset
= "offset";
93 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
95 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
96 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
97 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
98 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
99 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
100 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
101 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
102 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
104 const char * const config_element_name
= "name";
105 const char * const config_element_enabled
= "enabled";
106 const char * const config_element_overwrite_mode
= "overwrite_mode";
107 const char * const config_element_subbuf_size
= "subbuffer_size";
108 const char * const config_element_num_subbuf
= "subbuffer_count";
109 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
110 const char * const config_element_read_timer_interval
= "read_timer_interval";
111 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
112 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
113 const char * const config_element_output
= "output";
114 const char * const config_element_output_type
= "output_type";
115 const char * const config_element_tracefile_size
= "tracefile_size";
116 const char * const config_element_tracefile_count
= "tracefile_count";
117 const char * const config_element_live_timer_interval
= "live_timer_interval";
118 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
119 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
120 const char * const config_element_type
= "type";
121 const char * const config_element_buffer_type
= "buffer_type";
122 const char * const config_element_session
= "session";
123 const char * const config_element_sessions
= "sessions";
124 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
125 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
126 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
127 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
128 const char * const config_element_config
= "config";
129 const char * const config_element_started
= "started";
130 const char * const config_element_snapshot_mode
= "snapshot_mode";
131 const char * const config_element_loglevel
= "loglevel";
132 const char * const config_element_loglevel_type
= "loglevel_type";
133 const char * const config_element_filter
= "filter";
134 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
135 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
136 const char * const config_element_consumer_output
= "consumer_output";
137 const char * const config_element_destination
= "destination";
138 const char * const config_element_path
= "path";
139 const char * const config_element_net_output
= "net_output";
140 const char * const config_element_control_uri
= "control_uri";
141 const char * const config_element_data_uri
= "data_uri";
142 const char * const config_element_max_size
= "max_size";
143 const char * const config_element_pid
= "pid";
144 const char * const config_element_pids
= "pids";
145 const char * const config_element_shared_memory_path
= "shared_memory_path";
146 const char * const config_element_pid_tracker
= "pid_tracker";
147 const char * const config_element_trackers
= "trackers";
148 const char * const config_element_targets
= "targets";
149 const char * const config_element_target_pid
= "pid_target";
151 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
152 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
153 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
154 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
155 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
157 const char * const config_domain_type_kernel
= "KERNEL";
158 const char * const config_domain_type_ust
= "UST";
159 const char * const config_domain_type_jul
= "JUL";
160 const char * const config_domain_type_log4j
= "LOG4J";
161 const char * const config_domain_type_python
= "PYTHON";
163 const char * const config_buffer_type_per_pid
= "PER_PID";
164 const char * const config_buffer_type_per_uid
= "PER_UID";
165 const char * const config_buffer_type_global
= "GLOBAL";
167 const char * const config_overwrite_mode_discard
= "DISCARD";
168 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
170 const char * const config_output_type_splice
= "SPLICE";
171 const char * const config_output_type_mmap
= "MMAP";
173 const char * const config_loglevel_type_all
= "ALL";
174 const char * const config_loglevel_type_range
= "RANGE";
175 const char * const config_loglevel_type_single
= "SINGLE";
177 const char * const config_event_type_all
= "ALL";
178 const char * const config_event_type_tracepoint
= "TRACEPOINT";
179 const char * const config_event_type_probe
= "PROBE";
180 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
181 const char * const config_event_type_function
= "FUNCTION";
182 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
183 const char * const config_event_type_noop
= "NOOP";
184 const char * const config_event_type_syscall
= "SYSCALL";
185 const char * const config_event_type_kprobe
= "KPROBE";
186 const char * const config_event_type_kretprobe
= "KRETPROBE";
188 const char * const config_event_context_pid
= "PID";
189 const char * const config_event_context_procname
= "PROCNAME";
190 const char * const config_event_context_prio
= "PRIO";
191 const char * const config_event_context_nice
= "NICE";
192 const char * const config_event_context_vpid
= "VPID";
193 const char * const config_event_context_tid
= "TID";
194 const char * const config_event_context_vtid
= "VTID";
195 const char * const config_event_context_ppid
= "PPID";
196 const char * const config_event_context_vppid
= "VPPID";
197 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
198 const char * const config_event_context_hostname
= "HOSTNAME";
199 const char * const config_event_context_ip
= "IP";
200 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
201 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
202 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
203 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
204 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
205 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
206 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
207 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
208 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
209 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
210 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
211 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
212 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
213 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
214 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
216 /* Deprecated symbols */
217 const char * const config_element_perf
;
219 enum process_event_node_phase
{
224 struct consumer_output
{
231 static int config_entry_handler_filter(struct handler_filter_args
*args
,
232 const char *section
, const char *name
, const char *value
)
235 struct config_entry entry
= { section
, name
, value
};
239 if (!section
|| !name
|| !value
) {
245 if (strcmp(args
->section
, section
)) {
250 ret
= args
->handler(&entry
, args
->user_data
);
256 int config_get_section_entries(const char *override_path
, const char *section
,
257 config_entry_handler_cb handler
, void *user_data
)
261 FILE *config_file
= NULL
;
262 struct handler_filter_args filter
= { section
, handler
, user_data
};
264 /* First, try system-wide conf. file. */
265 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
267 config_file
= fopen(path
, "r");
269 DBG("Loading daemon conf file at %s", path
);
271 * Return value is not very important here since error or not, we
272 * continue and try the next possible conf. file.
274 (void) ini_parse_file(config_file
,
275 (ini_entry_handler
) config_entry_handler_filter
,
280 /* Second is the user local configuration. */
281 path
= utils_get_home_dir();
283 char fullpath
[PATH_MAX
];
285 ret
= snprintf(fullpath
, sizeof(fullpath
),
286 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
288 PERROR("snprintf user conf. path");
292 config_file
= fopen(fullpath
, "r");
294 DBG("Loading daemon user conf file at %s", path
);
296 * Return value is not very important here since error or not, we
297 * continue and try the next possible conf. file.
299 (void) ini_parse_file(config_file
,
300 (ini_entry_handler
) config_entry_handler_filter
,
306 /* Final path is the one that the user might have provided. */
308 config_file
= fopen(override_path
, "r");
310 DBG("Loading daemon command line conf file at %s", override_path
);
311 (void) ini_parse_file(config_file
,
312 (ini_entry_handler
) config_entry_handler_filter
,
316 ERR("Failed to open daemon configuration file at %s",
323 /* Everything went well. */
331 int config_parse_value(const char *value
)
334 char *endptr
, *lower_str
;
344 v
= strtoul(value
, &endptr
, 10);
345 if (endptr
!= value
) {
350 lower_str
= zmalloc(len
+ 1);
357 for (i
= 0; i
< len
; i
++) {
358 lower_str
[i
] = tolower(value
[i
]);
361 if (!strcmp(lower_str
, config_str_yes
) ||
362 !strcmp(lower_str
, config_str_true
) ||
363 !strcmp(lower_str
, config_str_on
)) {
365 } else if (!strcmp(lower_str
, config_str_no
) ||
366 !strcmp(lower_str
, config_str_false
) ||
367 !strcmp(lower_str
, config_str_off
)) {
379 * Returns a xmlChar string which must be released using xmlFree().
381 static xmlChar
*encode_string(const char *in_str
)
383 xmlChar
*out_str
= NULL
;
384 xmlCharEncodingHandlerPtr handler
;
385 int out_len
, ret
, in_len
;
389 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
391 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
395 in_len
= strlen(in_str
);
397 * Add 1 byte for the NULL terminted character. The factor 4 here is
398 * used because UTF-8 characters can take up to 4 bytes.
400 out_len
= (in_len
* 4) + 1;
401 out_str
= xmlMalloc(out_len
);
406 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
413 /* out_len is now the size of out_str */
414 out_str
[out_len
] = '\0';
420 struct config_writer
*config_writer_create(int fd_output
, int indent
)
423 struct config_writer
*writer
;
424 xmlOutputBufferPtr buffer
;
426 writer
= zmalloc(sizeof(struct config_writer
));
428 PERROR("zmalloc config_writer_create");
432 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
437 writer
->writer
= xmlNewTextWriter(buffer
);
438 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
439 config_xml_encoding
, NULL
);
444 ret
= xmlTextWriterSetIndentString(writer
->writer
,
445 BAD_CAST config_xml_indent_string
);
450 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
458 config_writer_destroy(writer
);
463 int config_writer_destroy(struct config_writer
*writer
)
472 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
473 WARN("Could not close XML document");
477 if (writer
->writer
) {
478 xmlFreeTextWriter(writer
->writer
);
487 int config_writer_open_element(struct config_writer
*writer
,
488 const char *element_name
)
491 xmlChar
*encoded_element_name
;
493 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
498 encoded_element_name
= encode_string(element_name
);
499 if (!encoded_element_name
) {
504 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
505 xmlFree(encoded_element_name
);
507 return ret
>= 0 ? 0 : ret
;
511 int config_writer_write_attribute(struct config_writer
*writer
,
512 const char *name
, const char *value
)
515 xmlChar
*encoded_name
= NULL
;
516 xmlChar
*encoded_value
= NULL
;
518 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
523 encoded_name
= encode_string(name
);
529 encoded_value
= encode_string(value
);
530 if (!encoded_value
) {
535 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
538 xmlFree(encoded_name
);
539 xmlFree(encoded_value
);
540 return ret
>= 0 ? 0 : ret
;
544 int config_writer_close_element(struct config_writer
*writer
)
548 if (!writer
|| !writer
->writer
) {
553 ret
= xmlTextWriterEndElement(writer
->writer
);
555 return ret
>= 0 ? 0 : ret
;
559 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
560 const char *element_name
, uint64_t value
)
563 xmlChar
*encoded_element_name
;
565 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
570 encoded_element_name
= encode_string(element_name
);
571 if (!encoded_element_name
) {
576 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
577 encoded_element_name
, "%" PRIu64
, value
);
578 xmlFree(encoded_element_name
);
580 return ret
>= 0 ? 0 : ret
;
584 int config_writer_write_element_signed_int(struct config_writer
*writer
,
585 const char *element_name
, int64_t value
)
588 xmlChar
*encoded_element_name
;
590 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
595 encoded_element_name
= encode_string(element_name
);
596 if (!encoded_element_name
) {
601 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
602 encoded_element_name
, "%" PRIi64
, value
);
603 xmlFree(encoded_element_name
);
605 return ret
>= 0 ? 0 : ret
;
609 int config_writer_write_element_bool(struct config_writer
*writer
,
610 const char *element_name
, int value
)
612 return config_writer_write_element_string(writer
, element_name
,
613 value
? config_xml_true
: config_xml_false
);
617 int config_writer_write_element_string(struct config_writer
*writer
,
618 const char *element_name
, const char *value
)
621 xmlChar
*encoded_element_name
= NULL
;
622 xmlChar
*encoded_value
= NULL
;
624 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
630 encoded_element_name
= encode_string(element_name
);
631 if (!encoded_element_name
) {
636 encoded_value
= encode_string(value
);
637 if (!encoded_value
) {
642 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
645 xmlFree(encoded_element_name
);
646 xmlFree(encoded_value
);
647 return ret
>= 0 ? 0 : ret
;
651 void xml_error_handler(void *ctx
, const char *format
, ...)
657 va_start(args
, format
);
658 ret
= vasprintf(&errMsg
, format
, args
);
661 ERR("String allocation failed in xml error handler");
665 fprintf(stderr
, "XML Error: %s", errMsg
);
670 void fini_session_config_validation_ctx(
671 struct session_config_validation_ctx
*ctx
)
673 if (ctx
->parser_ctx
) {
674 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
678 xmlSchemaFree(ctx
->schema
);
681 if (ctx
->schema_validation_ctx
) {
682 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
685 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
689 char *get_session_config_xsd_path()
692 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
693 size_t base_path_len
;
697 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
700 base_path_len
= strlen(base_path
);
701 max_path_len
= base_path_len
+
702 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
703 xsd_path
= zmalloc(max_path_len
);
708 strcpy(xsd_path
, base_path
);
709 if (xsd_path
[base_path_len
- 1] != '/') {
710 xsd_path
[base_path_len
++] = '/';
713 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
719 int init_session_config_validation_ctx(
720 struct session_config_validation_ctx
*ctx
)
723 char *xsd_path
= get_session_config_xsd_path();
726 ret
= -LTTNG_ERR_NOMEM
;
730 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
731 if (!ctx
->parser_ctx
) {
732 ERR("XSD parser context creation failed");
733 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
736 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
737 xml_error_handler
, NULL
);
739 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
741 ERR("XSD parsing failed");
742 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
746 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
747 if (!ctx
->schema_validation_ctx
) {
748 ERR("XSD validation context creation failed");
749 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
753 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
754 xml_error_handler
, NULL
);
759 fini_session_config_validation_ctx(ctx
);
767 int parse_uint(xmlChar
*str
, uint64_t *val
)
777 *val
= strtoull((const char *) str
, &endptr
, 10);
778 if (!endptr
|| *endptr
) {
789 int parse_int(xmlChar
*str
, int64_t *val
)
799 *val
= strtoll((const char *) str
, &endptr
, 10);
800 if (!endptr
|| *endptr
) {
811 int parse_bool(xmlChar
*str
, int *val
)
820 if (!strcmp((const char *) str
, config_xml_true
)) {
822 } else if (!strcmp((const char *) str
, config_xml_false
)) {
825 WARN("Invalid boolean value encoutered (%s).",
834 int get_domain_type(xmlChar
*domain
)
842 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
843 ret
= LTTNG_DOMAIN_KERNEL
;
844 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
845 ret
= LTTNG_DOMAIN_UST
;
846 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
847 ret
= LTTNG_DOMAIN_JUL
;
848 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
849 ret
= LTTNG_DOMAIN_LOG4J
;
850 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
851 ret
= LTTNG_DOMAIN_PYTHON
;
862 int get_buffer_type(xmlChar
*buffer_type
)
870 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
871 ret
= LTTNG_BUFFER_GLOBAL
;
872 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
873 ret
= LTTNG_BUFFER_PER_UID
;
874 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
875 ret
= LTTNG_BUFFER_PER_PID
;
886 int get_overwrite_mode(xmlChar
*overwrite_mode
)
890 if (!overwrite_mode
) {
894 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
896 } else if (!strcmp((char *) overwrite_mode
,
897 config_overwrite_mode_discard
)) {
909 int get_output_type(xmlChar
*output_type
)
917 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
918 ret
= LTTNG_EVENT_MMAP
;
919 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
920 ret
= LTTNG_EVENT_SPLICE
;
931 int get_event_type(xmlChar
*event_type
)
939 if (!strcmp((char *) event_type
, config_event_type_all
)) {
940 ret
= LTTNG_EVENT_ALL
;
941 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
942 ret
= LTTNG_EVENT_TRACEPOINT
;
943 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
944 ret
= LTTNG_EVENT_PROBE
;
945 } else if (!strcmp((char *) event_type
,
946 config_event_type_userspace_probe
)) {
947 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
948 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
949 ret
= LTTNG_EVENT_FUNCTION
;
950 } else if (!strcmp((char *) event_type
,
951 config_event_type_function_entry
)) {
952 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
953 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
954 ret
= LTTNG_EVENT_NOOP
;
955 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
956 ret
= LTTNG_EVENT_SYSCALL
;
967 int get_loglevel_type(xmlChar
*loglevel_type
)
971 if (!loglevel_type
) {
975 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
976 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
977 } else if (!strcmp((char *) loglevel_type
,
978 config_loglevel_type_range
)) {
979 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
980 } else if (!strcmp((char *) loglevel_type
,
981 config_loglevel_type_single
)) {
982 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
993 * Return the context type or -1 on error.
996 int get_context_type(xmlChar
*context_type
)
1000 if (!context_type
) {
1004 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1005 ret
= LTTNG_EVENT_CONTEXT_PID
;
1006 } else if (!strcmp((char *) context_type
,
1007 config_event_context_procname
)) {
1008 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1009 } else if (!strcmp((char *) context_type
,
1010 config_event_context_prio
)) {
1011 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1012 } else if (!strcmp((char *) context_type
,
1013 config_event_context_nice
)) {
1014 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1015 } else if (!strcmp((char *) context_type
,
1016 config_event_context_vpid
)) {
1017 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1018 } else if (!strcmp((char *) context_type
,
1019 config_event_context_tid
)) {
1020 ret
= LTTNG_EVENT_CONTEXT_TID
;
1021 } else if (!strcmp((char *) context_type
,
1022 config_event_context_vtid
)) {
1023 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1024 } else if (!strcmp((char *) context_type
,
1025 config_event_context_ppid
)) {
1026 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1027 } else if (!strcmp((char *) context_type
,
1028 config_event_context_vppid
)) {
1029 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1030 } else if (!strcmp((char *) context_type
,
1031 config_event_context_pthread_id
)) {
1032 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1033 } else if (!strcmp((char *) context_type
,
1034 config_event_context_hostname
)) {
1035 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1036 } else if (!strcmp((char *) context_type
,
1037 config_event_context_ip
)) {
1038 ret
= LTTNG_EVENT_CONTEXT_IP
;
1039 } else if (!strcmp((char *) context_type
,
1040 config_event_context_interruptible
)) {
1041 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1042 } else if (!strcmp((char *) context_type
,
1043 config_event_context_preemptible
)) {
1044 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1045 } else if (!strcmp((char *) context_type
,
1046 config_event_context_need_reschedule
)) {
1047 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1048 } else if (!strcmp((char *) context_type
,
1049 config_event_context_migratable
)) {
1050 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1051 } else if (!strcmp((char *) context_type
,
1052 config_event_context_callstack_user
)) {
1053 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1054 } else if (!strcmp((char *) context_type
,
1055 config_event_context_callstack_kernel
)) {
1056 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1057 } else if (!strcmp((char *) context_type
,
1058 config_event_context_cgroup_ns
)) {
1059 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1060 } else if (!strcmp((char *) context_type
,
1061 config_event_context_ipc_ns
)) {
1062 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1063 } else if (!strcmp((char *) context_type
,
1064 config_event_context_mnt_ns
)) {
1065 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1066 } else if (!strcmp((char *) context_type
,
1067 config_event_context_net_ns
)) {
1068 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1069 } else if (!strcmp((char *) context_type
,
1070 config_event_context_pid_ns
)) {
1071 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1072 } else if (!strcmp((char *) context_type
,
1073 config_event_context_user_ns
)) {
1074 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1075 } else if (!strcmp((char *) context_type
,
1076 config_event_context_uts_ns
)) {
1077 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1088 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1093 for (node
= xmlFirstElementChild(domain_node
); node
;
1094 node
= xmlNextElementSibling(node
)) {
1095 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1097 xmlChar
*node_content
= xmlNodeGetContent(node
);
1098 if (!node_content
) {
1099 ret
= -LTTNG_ERR_NOMEM
;
1103 ret
= get_domain_type(node_content
);
1106 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1111 } else if (!strcmp((const char *) node
->name
,
1112 config_element_buffer_type
)) {
1114 xmlChar
*node_content
= xmlNodeGetContent(node
);
1115 if (!node_content
) {
1116 ret
= -LTTNG_ERR_NOMEM
;
1120 ret
= get_buffer_type(node_content
);
1123 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1127 domain
->buf_type
= ret
;
1136 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1141 for (node
= xmlFirstElementChild(net_output_node
); node
;
1142 node
= xmlNextElementSibling(node
)) {
1143 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1145 *control_uri
= (char *) xmlNodeGetContent(node
);
1146 if (!*control_uri
) {
1151 *data_uri
= (char *) xmlNodeGetContent(node
);
1158 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1162 int process_consumer_output(xmlNodePtr consumer_output_node
,
1163 struct consumer_output
*output
)
1170 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1171 node
= xmlNextElementSibling(node
)) {
1172 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1173 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1177 ret
= -LTTNG_ERR_NOMEM
;
1181 ret
= parse_bool(enabled_str
, &output
->enabled
);
1187 xmlNodePtr output_type_node
;
1190 output_type_node
= xmlFirstElementChild(node
);
1191 if (!output_type_node
) {
1192 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1196 if (!strcmp((const char *) output_type_node
->name
,
1197 config_element_path
)) {
1199 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1200 if (!output
->path
) {
1201 ret
= -LTTNG_ERR_NOMEM
;
1206 ret
= get_net_output_uris(output_type_node
,
1207 &output
->control_uri
, &output
->data_uri
);
1219 free(output
->control_uri
);
1220 free(output
->data_uri
);
1221 memset(output
, 0, sizeof(struct consumer_output
));
1227 int create_session_net_output(const char *name
, const char *control_uri
,
1228 const char *data_uri
)
1231 struct lttng_handle
*handle
;
1232 const char *uri
= NULL
;
1236 handle
= lttng_create_handle(name
, NULL
);
1238 ret
= -LTTNG_ERR_NOMEM
;
1242 if (!control_uri
|| !data_uri
) {
1243 uri
= control_uri
? control_uri
: data_uri
;
1248 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1249 lttng_destroy_handle(handle
);
1255 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1256 const struct config_load_session_override_attr
*overrides
)
1259 xmlNodePtr node
= NULL
;
1260 xmlNodePtr snapshot_output_list_node
;
1261 xmlNodePtr snapshot_output_node
;
1263 assert(session_name
);
1265 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1274 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1276 /* Parse and create snapshot outputs */
1278 for (snapshot_output_node
=
1279 xmlFirstElementChild(snapshot_output_list_node
);
1280 snapshot_output_node
; snapshot_output_node
=
1281 xmlNextElementSibling(snapshot_output_node
)) {
1283 uint64_t max_size
= UINT64_MAX
;
1284 struct consumer_output output
= { 0 };
1285 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1286 const char *control_uri
= NULL
;
1287 const char *data_uri
= NULL
;
1288 const char *path
= NULL
;
1290 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1291 node
= xmlNextElementSibling(node
)) {
1292 if (!strcmp((const char *) node
->name
,
1293 config_element_name
)) {
1295 name
= (char *) xmlNodeGetContent(node
);
1297 ret
= -LTTNG_ERR_NOMEM
;
1298 goto error_snapshot_output
;
1300 } else if (!strcmp((const char *) node
->name
,
1301 config_element_max_size
)) {
1302 xmlChar
*content
= xmlNodeGetContent(node
);
1306 ret
= -LTTNG_ERR_NOMEM
;
1307 goto error_snapshot_output
;
1309 ret
= parse_uint(content
, &max_size
);
1312 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1313 goto error_snapshot_output
;
1316 /* consumer_output */
1317 ret
= process_consumer_output(node
, &output
);
1319 goto error_snapshot_output
;
1324 control_uri
= output
.control_uri
;
1325 data_uri
= output
.data_uri
;
1329 if (overrides
->path_url
) {
1330 path
= overrides
->path_url
;
1331 /* Control/data_uri are null */
1335 if (overrides
->ctrl_url
) {
1336 control_uri
= overrides
->ctrl_url
;
1340 if (overrides
->data_url
) {
1341 data_uri
= overrides
->data_url
;
1348 snapshot_output
= lttng_snapshot_output_create();
1349 if (!snapshot_output
) {
1350 ret
= -LTTNG_ERR_NOMEM
;
1351 goto error_snapshot_output
;
1354 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1356 goto error_snapshot_output
;
1359 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1361 goto error_snapshot_output
;
1365 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1368 goto error_snapshot_output
;
1372 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1375 goto error_snapshot_output
;
1380 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1383 goto error_snapshot_output
;
1388 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1389 error_snapshot_output
:
1392 free(output
.control_uri
);
1393 free(output
.data_uri
);
1394 lttng_snapshot_output_destroy(snapshot_output
);
1404 int create_session(const char *name
,
1405 xmlNodePtr output_node
,
1406 uint64_t live_timer_interval
,
1407 const struct config_load_session_override_attr
*overrides
)
1410 struct consumer_output output
= { 0 };
1411 xmlNodePtr consumer_output_node
;
1412 const char *control_uri
= NULL
;
1413 const char *data_uri
= NULL
;
1414 const char *path
= NULL
;
1419 consumer_output_node
= xmlFirstElementChild(output_node
);
1420 if (!consumer_output_node
) {
1421 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1425 if (strcmp((const char *) consumer_output_node
->name
,
1426 config_element_consumer_output
)) {
1427 WARN("Invalid output type, expected %s node",
1428 config_element_consumer_output
);
1429 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1433 ret
= process_consumer_output(consumer_output_node
, &output
);
1439 control_uri
= output
.control_uri
;
1440 data_uri
= output
.data_uri
;
1443 /* Check for override and apply them */
1445 if (overrides
->path_url
) {
1446 path
= overrides
->path_url
;
1447 /* control/data_uri are null */;
1451 if (overrides
->ctrl_url
) {
1452 control_uri
= overrides
->ctrl_url
;
1456 if (overrides
->data_url
) {
1457 data_uri
= overrides
->data_url
;
1465 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1466 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1470 if (control_uri
|| data_uri
) {
1471 /* network destination */
1472 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1474 * URLs are provided for sure since the test above make sure that
1475 * with a live timer the data and control URIs are provided. So,
1476 * NULL is passed here and will be set right after.
1478 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1480 ret
= lttng_create_session(name
, NULL
);
1486 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1492 /* either local output or no output */
1493 ret
= lttng_create_session(name
, path
);
1500 free(output
.control_uri
);
1501 free(output
.data_uri
);
1506 struct lttng_userspace_probe_location
*
1507 process_userspace_probe_function_attribute_node(
1508 xmlNodePtr attribute_node
)
1510 xmlNodePtr function_attribute_node
;
1511 char *function_name
= NULL
, *binary_path
= NULL
;
1512 struct lttng_userspace_probe_location
*location
= NULL
;
1513 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1516 * Process userspace probe location function attributes. The order of
1517 * the fields are not guaranteed so we need to iterate over all fields
1518 * and check at the end if everything we need for this location type is
1521 for (function_attribute_node
=
1522 xmlFirstElementChild(attribute_node
);
1523 function_attribute_node
;
1524 function_attribute_node
= xmlNextElementSibling(
1525 function_attribute_node
)) {
1526 /* Handle function name, binary path and lookup method. */
1527 if (!strcmp((const char *) function_attribute_node
->name
,
1528 config_element_userspace_probe_function_location_function_name
)) {
1529 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1530 if (!function_name
) {
1533 } else if (!strcmp((const char *) function_attribute_node
->name
,
1534 config_element_userspace_probe_location_binary_path
)) {
1535 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1539 } else if (!strcmp((const char *) function_attribute_node
->name
,
1540 config_element_userspace_probe_lookup
)) {
1541 char *lookup_method_name
;
1543 lookup_method_name
= (char *) xmlNodeGetContent(
1544 function_attribute_node
);
1545 if (!lookup_method_name
) {
1550 * function_default lookup method defaults to
1551 * function_elf lookup method at the moment.
1553 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1554 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1555 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1556 if (!lookup_method
) {
1557 PERROR("Error creating function default/ELF lookup method");
1560 WARN("Unknown function lookup method");
1563 free(lookup_method_name
);
1564 if (!lookup_method
) {
1571 /* Check if all the necessary fields were found. */
1572 if (binary_path
&& function_name
&& lookup_method
) {
1573 /* Ownership of lookup_method is transferred. */
1575 lttng_userspace_probe_location_function_create(
1576 binary_path
, function_name
,
1578 lookup_method
= NULL
;
1583 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1585 free(function_name
);
1590 struct lttng_userspace_probe_location
*
1591 process_userspace_probe_tracepoint_attribute_node(
1592 xmlNodePtr attribute_node
)
1594 xmlNodePtr tracepoint_attribute_node
;
1595 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1596 struct lttng_userspace_probe_location
*location
= NULL
;
1597 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1600 * Process userspace probe location tracepoint attributes. The order of
1601 * the fields are not guaranteed so we need to iterate over all fields
1602 * and check at the end if everything we need for this location type is
1605 for (tracepoint_attribute_node
=
1606 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1607 tracepoint_attribute_node
= xmlNextElementSibling(
1608 tracepoint_attribute_node
)) {
1609 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1610 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1611 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1615 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1616 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1617 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1618 if (!provider_name
) {
1621 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1622 config_element_userspace_probe_location_binary_path
)) {
1623 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1627 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1628 config_element_userspace_probe_lookup
)) {
1629 char *lookup_method_name
;
1631 lookup_method_name
= (char *) xmlNodeGetContent(
1632 tracepoint_attribute_node
);
1633 if (!lookup_method_name
) {
1637 if (!strcmp(lookup_method_name
,
1638 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1640 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1641 if (!lookup_method
) {
1642 PERROR("Error creating tracepoint SDT lookup method");
1645 WARN("Unknown tracepoint lookup method");
1648 free(lookup_method_name
);
1649 if (!lookup_method
) {
1653 WARN("Unknown tracepoint attribute");
1657 /* Check if all the necessary fields were found. */
1658 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1659 /* Ownership of lookup_method is transferred. */
1661 lttng_userspace_probe_location_tracepoint_create(
1662 binary_path
, provider_name
,
1663 probe_name
, lookup_method
);
1664 lookup_method
= NULL
;
1669 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1671 free(provider_name
);
1677 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1678 struct lttng_event_probe_attr
*attr
)
1682 assert(probe_attribute_node
);
1685 if (!strcmp((const char *) probe_attribute_node
->name
,
1686 config_element_address
)) {
1691 content
= xmlNodeGetContent(probe_attribute_node
);
1693 ret
= -LTTNG_ERR_NOMEM
;
1697 ret
= parse_uint(content
, &addr
);
1700 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1705 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1706 config_element_offset
)) {
1708 uint64_t offset
= 0;
1711 content
= xmlNodeGetContent(probe_attribute_node
);
1713 ret
= -LTTNG_ERR_NOMEM
;
1717 ret
= parse_uint(content
, &offset
);
1720 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1724 attr
->offset
= offset
;
1725 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1726 config_element_symbol_name
)) {
1730 content
= xmlNodeGetContent(probe_attribute_node
);
1732 ret
= -LTTNG_ERR_NOMEM
;
1736 ret
= lttng_strncpy(attr
->symbol_name
,
1737 (const char *) content
,
1738 LTTNG_SYMBOL_NAME_LEN
);
1740 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1741 (const char *) content
,
1742 strlen((const char *) content
),
1743 LTTNG_SYMBOL_NAME_LEN
);
1744 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1756 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1757 const char *channel_name
, const enum process_event_node_phase phase
)
1761 struct lttng_event
*event
;
1762 char **exclusions
= NULL
;
1763 unsigned long exclusion_count
= 0;
1764 char *filter_expression
= NULL
;
1768 assert(channel_name
);
1770 event
= lttng_event_create();
1772 ret
= -LTTNG_ERR_NOMEM
;
1776 /* Initialize default log level which varies by domain */
1777 switch (handle
->domain
.type
)
1779 case LTTNG_DOMAIN_JUL
:
1780 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1782 case LTTNG_DOMAIN_LOG4J
:
1783 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1785 case LTTNG_DOMAIN_PYTHON
:
1786 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1788 case LTTNG_DOMAIN_UST
:
1789 case LTTNG_DOMAIN_KERNEL
:
1790 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1796 for (node
= xmlFirstElementChild(event_node
); node
;
1797 node
= xmlNextElementSibling(node
)) {
1798 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1802 content
= xmlNodeGetContent(node
);
1804 ret
= -LTTNG_ERR_NOMEM
;
1808 ret
= lttng_strncpy(event
->name
,
1809 (const char *) content
,
1810 LTTNG_SYMBOL_NAME_LEN
);
1812 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1813 (const char *) content
,
1814 strlen((const char *) content
),
1815 LTTNG_SYMBOL_NAME_LEN
);
1816 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1821 } else if (!strcmp((const char *) node
->name
,
1822 config_element_enabled
)) {
1823 xmlChar
*content
= xmlNodeGetContent(node
);
1827 ret
= -LTTNG_ERR_NOMEM
;
1831 ret
= parse_bool(content
, &event
->enabled
);
1834 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1837 } else if (!strcmp((const char *) node
->name
,
1838 config_element_type
)) {
1839 xmlChar
*content
= xmlNodeGetContent(node
);
1843 ret
= -LTTNG_ERR_NOMEM
;
1847 ret
= get_event_type(content
);
1850 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1855 } else if (!strcmp((const char *) node
->name
,
1856 config_element_loglevel_type
)) {
1857 xmlChar
*content
= xmlNodeGetContent(node
);
1861 ret
= -LTTNG_ERR_NOMEM
;
1865 ret
= get_loglevel_type(content
);
1868 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1872 event
->loglevel_type
= ret
;
1873 } else if (!strcmp((const char *) node
->name
,
1874 config_element_loglevel
)) {
1876 int64_t loglevel
= 0;
1879 content
= xmlNodeGetContent(node
);
1881 ret
= -LTTNG_ERR_NOMEM
;
1885 ret
= parse_int(content
, &loglevel
);
1888 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1892 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1893 WARN("loglevel out of range.");
1894 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1898 event
->loglevel
= loglevel
;
1899 } else if (!strcmp((const char *) node
->name
,
1900 config_element_filter
)) {
1902 xmlNodeGetContent(node
);
1906 ret
= -LTTNG_ERR_NOMEM
;
1910 free(filter_expression
);
1911 filter_expression
= strdup((char *) content
);
1913 if (!filter_expression
) {
1914 ret
= -LTTNG_ERR_NOMEM
;
1917 } else if (!strcmp((const char *) node
->name
,
1918 config_element_exclusions
)) {
1919 xmlNodePtr exclusion_node
;
1920 int exclusion_index
= 0;
1925 * Exclusions has already been initialized,
1928 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1932 exclusion_count
= xmlChildElementCount(node
);
1933 if (!exclusion_count
) {
1937 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1939 exclusion_count
= 0;
1940 ret
= -LTTNG_ERR_NOMEM
;
1944 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1945 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1947 xmlNodeGetContent(exclusion_node
);
1950 ret
= -LTTNG_ERR_NOMEM
;
1954 exclusions
[exclusion_index
] = strdup((const char *) content
);
1956 if (!exclusions
[exclusion_index
]) {
1957 ret
= -LTTNG_ERR_NOMEM
;
1963 event
->exclusion
= 1;
1964 } else if (!strcmp((const char *) node
->name
,
1965 config_element_attributes
)) {
1966 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1969 if (!attribute_node
) {
1970 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1974 if (!strcmp((const char *) attribute_node
->name
,
1975 config_element_probe_attributes
)) {
1976 xmlNodePtr probe_attribute_node
;
1978 /* probe_attributes */
1979 for (probe_attribute_node
=
1980 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1981 probe_attribute_node
= xmlNextElementSibling(
1982 probe_attribute_node
)) {
1984 ret
= process_probe_attribute_node(probe_attribute_node
,
1985 &event
->attr
.probe
);
1990 } else if (!strcmp((const char *) attribute_node
->name
,
1991 config_element_function_attributes
)) {
1994 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1996 /* function_attributes */
1997 content
= xmlNodeGetContent(symbol_node
);
1999 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2003 sym_len
= strlen((char *) content
);
2004 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2005 WARN("Function name too long.");
2006 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2011 ret
= lttng_strncpy(
2012 event
->attr
.ftrace
.symbol_name
,
2013 (char *) content
, sym_len
);
2015 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2020 } else if (!strcmp((const char *) attribute_node
->name
,
2021 config_element_userspace_probe_tracepoint_attributes
)) {
2022 struct lttng_userspace_probe_location
*location
;
2024 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2026 WARN("Error processing userspace probe tracepoint attribute");
2027 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2030 ret
= lttng_event_set_userspace_probe_location(
2033 WARN("Error setting userspace probe location field");
2034 lttng_userspace_probe_location_destroy(
2036 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2039 } else if (!strcmp((const char *) attribute_node
->name
,
2040 config_element_userspace_probe_function_attributes
)) {
2041 struct lttng_userspace_probe_location
*location
;
2044 process_userspace_probe_function_attribute_node(
2047 WARN("Error processing userspace probe function attribute");
2048 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2052 ret
= lttng_event_set_userspace_probe_location(
2055 WARN("Error setting userspace probe location field");
2056 lttng_userspace_probe_location_destroy(
2058 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2062 /* Unknown event attribute. */
2063 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2069 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2070 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2071 filter_expression
, exclusion_count
, exclusions
);
2073 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2074 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2080 for (i
= 0; i
< exclusion_count
; i
++) {
2081 free(exclusions
[i
]);
2084 lttng_event_destroy(event
);
2086 free(filter_expression
);
2091 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2092 const char *channel_name
)
2095 struct lttng_event event
;
2098 assert(events_node
);
2100 assert(channel_name
);
2102 for (node
= xmlFirstElementChild(events_node
); node
;
2103 node
= xmlNextElementSibling(node
)) {
2104 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2111 * Disable all events to enable only the necessary events.
2112 * Limitations regarding lttng_disable_events and tuple descriptor
2113 * force this approach.
2115 memset(&event
, 0, sizeof(event
));
2116 event
.loglevel
= -1;
2117 event
.type
= LTTNG_EVENT_ALL
;
2118 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2123 for (node
= xmlFirstElementChild(events_node
); node
;
2124 node
= xmlNextElementSibling(node
)) {
2125 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2136 int process_channel_attr_node(xmlNodePtr attr_node
,
2137 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2138 xmlNodePtr
*events_node
)
2144 assert(contexts_node
);
2145 assert(events_node
);
2147 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2151 content
= xmlNodeGetContent(attr_node
);
2153 ret
= -LTTNG_ERR_NOMEM
;
2157 ret
= lttng_strncpy(channel
->name
,
2158 (const char *) content
,
2159 LTTNG_SYMBOL_NAME_LEN
);
2161 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2162 (const char *) content
,
2163 strlen((const char *) content
),
2164 LTTNG_SYMBOL_NAME_LEN
);
2165 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2170 } else if (!strcmp((const char *) attr_node
->name
,
2171 config_element_enabled
)) {
2176 content
= xmlNodeGetContent(attr_node
);
2178 ret
= -LTTNG_ERR_NOMEM
;
2182 ret
= parse_bool(content
, &enabled
);
2185 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2189 channel
->enabled
= enabled
;
2190 } else if (!strcmp((const char *) attr_node
->name
,
2191 config_element_overwrite_mode
)) {
2194 /* overwrite_mode */
2195 content
= xmlNodeGetContent(attr_node
);
2197 ret
= -LTTNG_ERR_NOMEM
;
2201 ret
= get_overwrite_mode(content
);
2204 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2208 channel
->attr
.overwrite
= ret
;
2209 } else if (!strcmp((const char *) attr_node
->name
,
2210 config_element_subbuf_size
)) {
2213 /* subbuffer_size */
2214 content
= xmlNodeGetContent(attr_node
);
2216 ret
= -LTTNG_ERR_NOMEM
;
2220 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2223 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2226 } else if (!strcmp((const char *) attr_node
->name
,
2227 config_element_num_subbuf
)) {
2230 /* subbuffer_count */
2231 content
= xmlNodeGetContent(attr_node
);
2233 ret
= -LTTNG_ERR_NOMEM
;
2237 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2240 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2243 } else if (!strcmp((const char *) attr_node
->name
,
2244 config_element_switch_timer_interval
)) {
2246 uint64_t switch_timer_interval
= 0;
2248 /* switch_timer_interval */
2249 content
= xmlNodeGetContent(attr_node
);
2251 ret
= -LTTNG_ERR_NOMEM
;
2255 ret
= parse_uint(content
, &switch_timer_interval
);
2258 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2262 if (switch_timer_interval
> UINT_MAX
) {
2263 WARN("switch_timer_interval out of range.");
2264 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2268 channel
->attr
.switch_timer_interval
=
2269 switch_timer_interval
;
2270 } else if (!strcmp((const char *) attr_node
->name
,
2271 config_element_read_timer_interval
)) {
2273 uint64_t read_timer_interval
= 0;
2275 /* read_timer_interval */
2276 content
= xmlNodeGetContent(attr_node
);
2278 ret
= -LTTNG_ERR_NOMEM
;
2282 ret
= parse_uint(content
, &read_timer_interval
);
2285 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2289 if (read_timer_interval
> UINT_MAX
) {
2290 WARN("read_timer_interval out of range.");
2291 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2295 channel
->attr
.read_timer_interval
=
2296 read_timer_interval
;
2297 } else if (!strcmp((const char *) attr_node
->name
,
2298 config_element_output_type
)) {
2302 content
= xmlNodeGetContent(attr_node
);
2304 ret
= -LTTNG_ERR_NOMEM
;
2308 ret
= get_output_type(content
);
2311 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2315 channel
->attr
.output
= ret
;
2316 } else if (!strcmp((const char *) attr_node
->name
,
2317 config_element_tracefile_size
)) {
2320 /* tracefile_size */
2321 content
= xmlNodeGetContent(attr_node
);
2323 ret
= -LTTNG_ERR_NOMEM
;
2327 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2330 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2333 } else if (!strcmp((const char *) attr_node
->name
,
2334 config_element_tracefile_count
)) {
2337 /* tracefile_count */
2338 content
= xmlNodeGetContent(attr_node
);
2340 ret
= -LTTNG_ERR_NOMEM
;
2344 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2347 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2350 } else if (!strcmp((const char *) attr_node
->name
,
2351 config_element_live_timer_interval
)) {
2353 uint64_t live_timer_interval
= 0;
2355 /* live_timer_interval */
2356 content
= xmlNodeGetContent(attr_node
);
2358 ret
= -LTTNG_ERR_NOMEM
;
2362 ret
= parse_uint(content
, &live_timer_interval
);
2365 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2369 if (live_timer_interval
> UINT_MAX
) {
2370 WARN("live_timer_interval out of range.");
2371 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2375 channel
->attr
.live_timer_interval
=
2376 live_timer_interval
;
2377 } else if (!strcmp((const char *) attr_node
->name
,
2378 config_element_monitor_timer_interval
)) {
2380 uint64_t monitor_timer_interval
= 0;
2382 /* monitor_timer_interval */
2383 content
= xmlNodeGetContent(attr_node
);
2385 ret
= -LTTNG_ERR_NOMEM
;
2389 ret
= parse_uint(content
, &monitor_timer_interval
);
2392 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2396 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2397 monitor_timer_interval
);
2399 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2402 } else if (!strcmp((const char *) attr_node
->name
,
2403 config_element_blocking_timeout
)) {
2405 int64_t blocking_timeout
= 0;
2407 /* blocking_timeout */
2408 content
= xmlNodeGetContent(attr_node
);
2410 ret
= -LTTNG_ERR_NOMEM
;
2414 ret
= parse_int(content
, &blocking_timeout
);
2417 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2421 ret
= lttng_channel_set_blocking_timeout(channel
,
2424 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2427 } else if (!strcmp((const char *) attr_node
->name
,
2428 config_element_events
)) {
2430 *events_node
= attr_node
;
2433 *contexts_node
= attr_node
;
2441 int process_context_node(xmlNodePtr context_node
,
2442 struct lttng_handle
*handle
, const char *channel_name
)
2445 struct lttng_event_context context
;
2446 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2449 assert(channel_name
);
2451 if (!context_child_node
) {
2452 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2456 memset(&context
, 0, sizeof(context
));
2458 if (!strcmp((const char *) context_child_node
->name
,
2459 config_element_type
)) {
2461 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2464 ret
= -LTTNG_ERR_NOMEM
;
2468 ret
= get_context_type(content
);
2471 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2476 } else if (!strcmp((const char *) context_child_node
->name
,
2477 config_element_context_perf
)) {
2479 xmlNodePtr perf_attr_node
;
2481 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2482 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2483 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2484 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2485 perf_attr_node
; perf_attr_node
=
2486 xmlNextElementSibling(perf_attr_node
)) {
2487 if (!strcmp((const char *) perf_attr_node
->name
,
2488 config_element_type
)) {
2493 content
= xmlNodeGetContent(perf_attr_node
);
2495 ret
= -LTTNG_ERR_NOMEM
;
2499 ret
= parse_uint(content
, &type
);
2502 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2506 if (type
> UINT32_MAX
) {
2507 WARN("perf context type out of range.");
2508 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2512 context
.u
.perf_counter
.type
= type
;
2513 } else if (!strcmp((const char *) perf_attr_node
->name
,
2514 config_element_config
)) {
2516 uint64_t config
= 0;
2519 content
= xmlNodeGetContent(perf_attr_node
);
2521 ret
= -LTTNG_ERR_NOMEM
;
2525 ret
= parse_uint(content
, &config
);
2528 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2532 context
.u
.perf_counter
.config
= config
;
2533 } else if (!strcmp((const char *) perf_attr_node
->name
,
2534 config_element_name
)) {
2538 content
= xmlNodeGetContent(perf_attr_node
);
2540 ret
= -LTTNG_ERR_NOMEM
;
2544 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2545 (const char *) content
,
2546 LTTNG_SYMBOL_NAME_LEN
);
2548 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2549 (const char *) content
,
2550 strlen((const char *) content
),
2551 LTTNG_SYMBOL_NAME_LEN
);
2552 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2559 } else if (!strcmp((const char *) context_child_node
->name
,
2560 config_element_context_app
)) {
2561 /* application context */
2562 xmlNodePtr app_ctx_node
;
2564 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2565 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2566 app_ctx_node
; app_ctx_node
=
2567 xmlNextElementSibling(app_ctx_node
)) {
2569 char **target
= strcmp(
2570 (const char *) app_ctx_node
->name
,
2571 config_element_context_app_provider_name
) == 0 ?
2572 &context
.u
.app_ctx
.provider_name
:
2573 &context
.u
.app_ctx
.ctx_name
;
2575 content
= xmlNodeGetContent(app_ctx_node
);
2577 ret
= -LTTNG_ERR_NOMEM
;
2581 *target
= (char *) content
;
2584 /* Unrecognized context type */
2585 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2589 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2590 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2591 free(context
.u
.app_ctx
.provider_name
);
2592 free(context
.u
.app_ctx
.ctx_name
);
2599 int process_contexts_node(xmlNodePtr contexts_node
,
2600 struct lttng_handle
*handle
, const char *channel_name
)
2603 xmlNodePtr context_node
;
2605 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2606 context_node
= xmlNextElementSibling(context_node
)) {
2607 ret
= process_context_node(context_node
, handle
, channel_name
);
2617 int process_pid_tracker_node(xmlNodePtr pid_tracker_node
,
2618 struct lttng_handle
*handle
)
2621 xmlNodePtr targets_node
= NULL
;
2625 assert(pid_tracker_node
);
2626 /* get the targets node */
2627 for (node
= xmlFirstElementChild(pid_tracker_node
); node
;
2628 node
= xmlNextElementSibling(node
)) {
2629 if (!strcmp((const char *) node
->name
,
2630 config_element_targets
)) {
2631 targets_node
= node
;
2636 if (!targets_node
) {
2637 ret
= LTTNG_ERR_INVALID
;
2641 /* Go through all pid_target node */
2642 child
= xmlChildElementCount(targets_node
);
2644 /* The session is explicitly set to target nothing. */
2645 ret
= lttng_untrack_pid(handle
, -1);
2650 for (node
= xmlFirstElementChild(targets_node
); node
;
2651 node
= xmlNextElementSibling(node
)) {
2652 xmlNodePtr pid_target_node
= node
;
2654 /* get pid node and track it */
2655 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2656 node
= xmlNextElementSibling(node
)) {
2657 if (!strcmp((const char *) node
->name
,
2658 config_element_pid
)) {
2660 xmlChar
*content
= NULL
;
2662 content
= xmlNodeGetContent(node
);
2664 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2668 ret
= parse_int(content
, &pid
);
2671 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2675 ret
= lttng_track_pid(handle
, (int) pid
);
2681 node
= pid_target_node
;
2689 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2692 struct lttng_domain domain
= { 0 };
2693 struct lttng_handle
*handle
= NULL
;
2694 struct lttng_channel
*channel
= NULL
;
2695 xmlNodePtr channels_node
= NULL
;
2696 xmlNodePtr trackers_node
= NULL
;
2697 xmlNodePtr pid_tracker_node
= NULL
;
2700 assert(session_name
);
2702 ret
= init_domain(domain_node
, &domain
);
2707 handle
= lttng_create_handle(session_name
, &domain
);
2709 ret
= -LTTNG_ERR_NOMEM
;
2713 /* get the channels node */
2714 for (node
= xmlFirstElementChild(domain_node
); node
;
2715 node
= xmlNextElementSibling(node
)) {
2716 if (!strcmp((const char *) node
->name
,
2717 config_element_channels
)) {
2718 channels_node
= node
;
2723 if (!channels_node
) {
2727 /* create all channels */
2728 for (node
= xmlFirstElementChild(channels_node
); node
;
2729 node
= xmlNextElementSibling(node
)) {
2730 const enum lttng_domain_type original_domain
= domain
.type
;
2731 xmlNodePtr contexts_node
= NULL
;
2732 xmlNodePtr events_node
= NULL
;
2733 xmlNodePtr channel_attr_node
;
2736 * Channels of the "agent" types cannot be created directly.
2737 * They are meant to be created implicitly through the
2738 * activation of events in their domain. However, a user
2739 * can override the default channel configuration attributes
2740 * by creating the underlying UST channel _before_ enabling
2741 * an agent domain event.
2743 * Hence, the channel's type is substituted before the creation
2744 * and restored by the time the events are created.
2746 switch (domain
.type
) {
2747 case LTTNG_DOMAIN_JUL
:
2748 case LTTNG_DOMAIN_LOG4J
:
2749 case LTTNG_DOMAIN_PYTHON
:
2750 domain
.type
= LTTNG_DOMAIN_UST
;
2755 channel
= lttng_channel_create(&domain
);
2761 for (channel_attr_node
= xmlFirstElementChild(node
);
2762 channel_attr_node
; channel_attr_node
=
2763 xmlNextElementSibling(channel_attr_node
)) {
2764 ret
= process_channel_attr_node(channel_attr_node
,
2765 channel
, &contexts_node
, &events_node
);
2771 ret
= lttng_enable_channel(handle
, channel
);
2776 /* Restore the original channel domain. */
2777 domain
.type
= original_domain
;
2779 ret
= process_events_node(events_node
, handle
, channel
->name
);
2784 ret
= process_contexts_node(contexts_node
, handle
,
2790 lttng_channel_destroy(channel
);
2794 /* get the trackers node */
2795 for (node
= xmlFirstElementChild(domain_node
); node
;
2796 node
= xmlNextElementSibling(node
)) {
2797 if (!strcmp((const char *) node
->name
,
2798 config_element_trackers
)) {
2799 trackers_node
= node
;
2804 if (!trackers_node
) {
2808 for (node
= xmlFirstElementChild(trackers_node
); node
;
2809 node
= xmlNextElementSibling(node
)) {
2810 if (!strcmp((const char *)node
->name
,config_element_pid_tracker
)) {
2811 pid_tracker_node
= node
;
2812 ret
= process_pid_tracker_node(pid_tracker_node
, handle
);
2819 if (!pid_tracker_node
) {
2820 lttng_track_pid(handle
, -1);
2824 lttng_channel_destroy(channel
);
2825 lttng_destroy_handle(handle
);
2830 int add_periodic_rotation(const char *name
, uint64_t time_us
)
2833 enum lttng_rotation_status status
;
2834 struct lttng_rotation_schedule
*periodic
=
2835 lttng_rotation_schedule_periodic_create();
2838 ret
= -LTTNG_ERR_NOMEM
;
2842 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
2844 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2845 ret
= -LTTNG_ERR_INVALID
;
2849 status
= lttng_session_add_rotation_schedule(name
, periodic
);
2851 case LTTNG_ROTATION_STATUS_OK
:
2854 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
2855 case LTTNG_ROTATION_STATUS_INVALID
:
2856 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2859 ret
= -LTTNG_ERR_UNK
;
2863 lttng_rotation_schedule_destroy(periodic
);
2868 int add_size_rotation(const char *name
, uint64_t size_bytes
)
2871 enum lttng_rotation_status status
;
2872 struct lttng_rotation_schedule
*size
=
2873 lttng_rotation_schedule_size_threshold_create();
2876 ret
= -LTTNG_ERR_NOMEM
;
2880 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
2882 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2883 ret
= -LTTNG_ERR_INVALID
;
2887 status
= lttng_session_add_rotation_schedule(name
, size
);
2889 case LTTNG_ROTATION_STATUS_OK
:
2892 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
2893 case LTTNG_ROTATION_STATUS_INVALID
:
2894 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2897 ret
= -LTTNG_ERR_UNK
;
2901 lttng_rotation_schedule_destroy(size
);
2906 int process_session_rotation_schedules_node(
2907 xmlNodePtr schedules_node
,
2908 uint64_t *rotation_timer_interval
,
2909 uint64_t *rotation_size
)
2914 for (child
= xmlFirstElementChild(schedules_node
);
2916 child
= xmlNextElementSibling(child
)) {
2917 if (!strcmp((const char *) child
->name
,
2918 config_element_rotation_schedule_periodic
)) {
2920 xmlNodePtr time_us_node
;
2922 /* periodic rotation schedule */
2923 time_us_node
= xmlFirstElementChild(child
);
2924 if (!time_us_node
||
2925 strcmp((const char *) time_us_node
->name
,
2926 config_element_rotation_schedule_periodic_time_us
)) {
2927 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2932 content
= xmlNodeGetContent(time_us_node
);
2934 ret
= -LTTNG_ERR_NOMEM
;
2937 ret
= parse_uint(content
, rotation_timer_interval
);
2940 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2943 } else if (!strcmp((const char *) child
->name
,
2944 config_element_rotation_schedule_size_threshold
)) {
2946 xmlNodePtr bytes_node
;
2948 /* size_threshold rotation schedule */
2949 bytes_node
= xmlFirstElementChild(child
);
2951 strcmp((const char *) bytes_node
->name
,
2952 config_element_rotation_schedule_size_threshold_bytes
)) {
2953 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2958 content
= xmlNodeGetContent(bytes_node
);
2960 ret
= -LTTNG_ERR_NOMEM
;
2963 ret
= parse_uint(content
, rotation_size
);
2966 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2977 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
2979 const struct config_load_session_override_attr
*overrides
)
2981 int ret
, started
= -1, snapshot_mode
= -1;
2982 uint64_t live_timer_interval
= UINT64_MAX
,
2983 rotation_timer_interval
= 0,
2985 xmlChar
*name
= NULL
;
2986 xmlChar
*shm_path
= NULL
;
2987 xmlNodePtr domains_node
= NULL
;
2988 xmlNodePtr output_node
= NULL
;
2990 xmlNodePtr attributes_child
;
2991 struct lttng_domain
*kernel_domain
= NULL
;
2992 struct lttng_domain
*ust_domain
= NULL
;
2993 struct lttng_domain
*jul_domain
= NULL
;
2994 struct lttng_domain
*log4j_domain
= NULL
;
2995 struct lttng_domain
*python_domain
= NULL
;
2997 for (node
= xmlFirstElementChild(session_node
); node
;
2998 node
= xmlNextElementSibling(node
)) {
2999 if (!name
&& !strcmp((const char *) node
->name
,
3000 config_element_name
)) {
3002 xmlChar
*node_content
= xmlNodeGetContent(node
);
3003 if (!node_content
) {
3004 ret
= -LTTNG_ERR_NOMEM
;
3008 name
= node_content
;
3009 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3010 config_element_domains
)) {
3012 domains_node
= node
;
3013 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3014 config_element_started
)) {
3016 xmlChar
*node_content
= xmlNodeGetContent(node
);
3017 if (!node_content
) {
3018 ret
= -LTTNG_ERR_NOMEM
;
3022 ret
= parse_bool(node_content
, &started
);
3025 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3028 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3029 config_element_output
)) {
3032 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3033 config_element_shared_memory_path
)) {
3034 /* shared memory path */
3035 xmlChar
*node_content
= xmlNodeGetContent(node
);
3036 if (!node_content
) {
3037 ret
= -LTTNG_ERR_NOMEM
;
3041 shm_path
= node_content
;
3044 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3045 * rotation_timer_interval.
3047 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3048 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3049 if (!strcmp((const char *) attributes_child
->name
,
3050 config_element_snapshot_mode
)) {
3052 xmlChar
*snapshot_mode_content
=
3053 xmlNodeGetContent(attributes_child
);
3054 if (!snapshot_mode_content
) {
3055 ret
= -LTTNG_ERR_NOMEM
;
3059 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3060 free(snapshot_mode_content
);
3062 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3065 } else if (!strcmp((const char *) attributes_child
->name
,
3066 config_element_live_timer_interval
)) {
3067 /* live_timer_interval */
3068 xmlChar
*timer_interval_content
=
3069 xmlNodeGetContent(attributes_child
);
3070 if (!timer_interval_content
) {
3071 ret
= -LTTNG_ERR_NOMEM
;
3075 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3076 free(timer_interval_content
);
3078 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3081 } else if (!strcmp((const char *) attributes_child
->name
,
3082 config_element_rotation_schedules
)) {
3083 ret
= process_session_rotation_schedules_node(
3085 &rotation_timer_interval
,
3088 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3098 /* Mandatory attribute, as defined in the session XSD */
3099 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3103 if (session_name
&& strcmp((char *) name
, session_name
)) {
3104 /* This is not the session we are looking for */
3105 ret
= -LTTNG_ERR_NO_SESSION
;
3109 /* Init domains to create the session handles */
3110 for (node
= xmlFirstElementChild(domains_node
); node
;
3111 node
= xmlNextElementSibling(node
)) {
3112 struct lttng_domain
*domain
;
3114 domain
= zmalloc(sizeof(*domain
));
3116 ret
= -LTTNG_ERR_NOMEM
;
3120 ret
= init_domain(node
, domain
);
3122 goto domain_init_error
;
3125 switch (domain
->type
) {
3126 case LTTNG_DOMAIN_KERNEL
:
3127 if (kernel_domain
) {
3128 /* Same domain seen twice, invalid! */
3129 goto domain_init_error
;
3131 kernel_domain
= domain
;
3133 case LTTNG_DOMAIN_UST
:
3135 /* Same domain seen twice, invalid! */
3136 goto domain_init_error
;
3138 ust_domain
= domain
;
3140 case LTTNG_DOMAIN_JUL
:
3142 /* Same domain seen twice, invalid! */
3143 goto domain_init_error
;
3145 jul_domain
= domain
;
3147 case LTTNG_DOMAIN_LOG4J
:
3149 /* Same domain seen twice, invalid! */
3150 goto domain_init_error
;
3152 log4j_domain
= domain
;
3154 case LTTNG_DOMAIN_PYTHON
:
3155 if (python_domain
) {
3156 /* Same domain seen twice, invalid! */
3157 goto domain_init_error
;
3159 python_domain
= domain
;
3162 WARN("Invalid domain type");
3163 goto domain_init_error
;
3168 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3172 /* Apply overrides */
3174 if (overrides
->session_name
) {
3175 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3176 if (!name_override
) {
3177 ret
= -LTTNG_ERR_NOMEM
;
3181 /* Overrides the session name to the provided name */
3183 name
= name_override
;
3188 /* Destroy session if it exists */
3189 ret
= lttng_destroy_session((const char *) name
);
3190 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3191 ERR("Failed to destroy existing session.");
3196 /* Create session type depending on output type */
3197 if (snapshot_mode
&& snapshot_mode
!= -1) {
3198 ret
= create_snapshot_session((const char *) name
, output_node
,
3200 } else if (live_timer_interval
&&
3201 live_timer_interval
!= UINT64_MAX
) {
3202 ret
= create_session((const char *) name
,
3203 output_node
, live_timer_interval
, overrides
);
3205 /* regular session */
3206 ret
= create_session((const char *) name
,
3207 output_node
, UINT64_MAX
, overrides
);
3214 ret
= lttng_set_session_shm_path((const char *) name
,
3215 (const char *) shm_path
);
3221 for (node
= xmlFirstElementChild(domains_node
); node
;
3222 node
= xmlNextElementSibling(node
)) {
3223 ret
= process_domain_node(node
, (const char *) name
);
3229 if (rotation_timer_interval
) {
3230 ret
= add_periodic_rotation((const char *) name
,
3231 rotation_timer_interval
);
3236 if (rotation_size
) {
3237 ret
= add_size_rotation((const char *) name
,
3245 ret
= lttng_start_tracing((const char *) name
);
3253 ERR("Failed to load session %s: %s", (const char *) name
,
3254 lttng_strerror(ret
));
3255 lttng_destroy_session((const char *) name
);
3259 free(kernel_domain
);
3263 free(python_domain
);
3270 * Return 1 if the given path is readable by the current UID or 0 if not.
3271 * Return -1 if the path is EPERM.
3273 static int validate_file_read_creds(const char *path
)
3279 /* Can we read the file. */
3280 ret
= access(path
, R_OK
);
3284 if (errno
== EACCES
) {
3295 int load_session_from_file(const char *path
, const char *session_name
,
3296 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3297 const struct config_load_session_override_attr
*overrides
)
3299 int ret
, session_found
= !session_name
;
3300 xmlDocPtr doc
= NULL
;
3301 xmlNodePtr sessions_node
;
3302 xmlNodePtr session_node
;
3305 assert(validation_ctx
);
3307 ret
= validate_file_read_creds(path
);
3310 ret
= -LTTNG_ERR_EPERM
;
3312 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3317 doc
= xmlParseFile(path
);
3319 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3323 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3325 ERR("Session configuration file validation failed");
3326 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3330 sessions_node
= xmlDocGetRootElement(doc
);
3331 if (!sessions_node
) {
3335 for (session_node
= xmlFirstElementChild(sessions_node
);
3336 session_node
; session_node
=
3337 xmlNextElementSibling(session_node
)) {
3338 ret
= process_session_node(session_node
,
3339 session_name
, overwrite
, overrides
);
3340 if (session_name
&& ret
== 0) {
3341 /* Target session found and loaded */
3349 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3355 int load_session_from_path(const char *path
, const char *session_name
,
3356 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3357 const struct config_load_session_override_attr
*overrides
)
3359 int ret
, session_found
= !session_name
;
3360 DIR *directory
= NULL
;
3361 struct lttng_dynamic_buffer file_path
;
3365 assert(validation_ctx
);
3366 path_len
= strlen(path
);
3367 lttng_dynamic_buffer_init(&file_path
);
3368 if (path_len
>= LTTNG_PATH_MAX
) {
3369 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3370 path
, path_len
, LTTNG_PATH_MAX
);
3371 ret
= -LTTNG_ERR_INVALID
;
3375 directory
= opendir(path
);
3379 /* Try the file loading. */
3382 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3385 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3390 size_t file_path_root_len
;
3392 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3395 ret
= -LTTNG_ERR_NOMEM
;
3399 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3401 ret
= -LTTNG_ERR_NOMEM
;
3405 if (file_path
.data
[file_path
.size
- 1] != '/') {
3406 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3408 ret
= -LTTNG_ERR_NOMEM
;
3412 file_path_root_len
= file_path
.size
;
3414 /* Search for *.lttng files */
3416 size_t file_name_len
;
3417 struct dirent
*result
;
3420 * When the end of the directory stream is reached, NULL
3421 * is returned and errno is kept unchanged. When an
3422 * error occurs, NULL is returned and errno is set
3423 * accordingly. To distinguish between the two, set
3424 * errno to zero before calling readdir().
3426 * On success, readdir() returns a pointer to a dirent
3427 * structure. This structure may be statically
3428 * allocated, do not attempt to free(3) it.
3431 result
= readdir(directory
);
3433 /* Reached end of dir stream or error out. */
3436 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3437 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3443 file_name_len
= strlen(result
->d_name
);
3445 if (file_name_len
<=
3446 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3450 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3451 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3453 /* +1 to account for NULL terminator. */
3454 file_path
.size
+ file_name_len
+ 1,
3459 /* Does the file end with .lttng? */
3460 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3461 result
->d_name
+ file_name_len
- sizeof(
3462 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3466 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3469 ret
= -LTTNG_ERR_NOMEM
;
3473 ret
= load_session_from_file(file_path
.data
, session_name
,
3474 validation_ctx
, overwrite
, overrides
);
3475 if (session_name
&& !ret
) {
3480 * Reset the buffer's size to the location of the
3481 * path's trailing '/'.
3483 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3484 file_path_root_len
);
3486 ret
= -LTTNG_ERR_UNK
;
3492 ret
= load_session_from_file(path
, session_name
,
3493 validation_ctx
, overwrite
, overrides
);
3503 if (closedir(directory
)) {
3507 if (session_found
&& !ret
) {
3510 lttng_dynamic_buffer_reset(&file_path
);
3515 * Validate that the given path's credentials and the current process have the
3516 * same UID. If so, return 1 else return 0 if it does NOT match.
3518 static int validate_path_creds(const char *path
)
3520 int ret
, uid
= getuid();
3529 ret
= stat(path
, &buf
);
3531 if (errno
!= ENOENT
) {
3537 if (buf
.st_uid
!= uid
) {
3548 int config_load_session(const char *path
, const char *session_name
,
3549 int overwrite
, unsigned int autoload
,
3550 const struct config_load_session_override_attr
*overrides
)
3553 bool session_loaded
= false;
3554 const char *path_ptr
= NULL
;
3555 struct session_config_validation_ctx validation_ctx
= { 0 };
3557 ret
= init_session_config_validation_ctx(&validation_ctx
);
3563 const char *home_path
;
3564 const char *sys_path
;
3567 home_path
= utils_get_home_dir();
3569 char path
[PATH_MAX
];
3572 * Try user session configuration path. Ignore error here so we can
3573 * continue loading the system wide sessions.
3576 ret
= snprintf(path
, sizeof(path
),
3577 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3578 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3580 PERROR("snprintf session autoload home config path");
3585 * Credentials are only validated for the autoload in order to
3586 * avoid any user session daemon to try to load kernel sessions
3587 * automatically and failing all the times.
3589 ret
= validate_path_creds(path
);
3594 ret
= snprintf(path
, sizeof(path
),
3595 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3597 PERROR("snprintf session home config path");
3603 ret
= load_session_from_path(path_ptr
, session_name
,
3604 &validation_ctx
, overwrite
, overrides
);
3605 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3609 * Continue even if the session was found since we have to try
3610 * the system wide sessions.
3612 session_loaded
= true;
3616 /* Reset path pointer for the system wide dir. */
3619 /* Try system wide configuration directory. */
3621 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3622 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3623 ret
= validate_path_creds(sys_path
);
3625 path_ptr
= sys_path
;
3628 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3629 path_ptr
= sys_path
;
3633 ret
= load_session_from_path(path_ptr
, session_name
,
3634 &validation_ctx
, overwrite
, overrides
);
3636 session_loaded
= true;
3640 ret
= access(path
, F_OK
);
3645 ret
= -LTTNG_ERR_INVALID
;
3646 WARN("Session configuration path does not exist.");
3649 ret
= -LTTNG_ERR_EPERM
;
3652 ret
= -LTTNG_ERR_UNK
;
3658 ret
= load_session_from_path(path
, session_name
,
3659 &validation_ctx
, overwrite
, overrides
);
3662 fini_session_config_validation_ctx(&validation_ctx
);
3663 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3665 * Don't report an error if no sessions are found when called
3666 * without a session_name or a search path.
3671 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3672 /* A matching session was found in one of the search paths. */
3679 void __attribute__((destructor
)) session_config_exit(void)