2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
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 LTTNG_HIDDEN
const char * const config_element_all
= "all";
55 const char * const config_str_yes
= "yes";
56 const char * const config_str_true
= "true";
57 const char * const config_str_on
= "on";
58 const char * const config_str_no
= "no";
59 const char * const config_str_false
= "false";
60 const char * const config_str_off
= "off";
61 const char * const config_xml_encoding
= "UTF-8";
62 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
63 const char * const config_xml_indent_string
= "\t";
64 const char * const config_xml_true
= "true";
65 const char * const config_xml_false
= "false";
67 const char * const config_element_channel
= "channel";
68 const char * const config_element_channels
= "channels";
69 const char * const config_element_domain
= "domain";
70 const char * const config_element_domains
= "domains";
71 const char * const config_element_event
= "event";
72 const char * const config_element_events
= "events";
73 const char * const config_element_context
= "context";
74 const char * const config_element_contexts
= "contexts";
75 const char * const config_element_attributes
= "attributes";
76 const char * const config_element_exclusion
= "exclusion";
77 const char * const config_element_exclusions
= "exclusions";
78 const char * const config_element_function_attributes
= "function_attributes";
79 const char * const config_element_probe_attributes
= "probe_attributes";
80 const char * const config_element_symbol_name
= "symbol_name";
81 const char * const config_element_address
= "address";
82 const char * const config_element_offset
= "offset";
84 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
85 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
86 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
87 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
88 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
89 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
90 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
91 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
92 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
93 LTTNG_HIDDEN
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 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
103 LTTNG_HIDDEN
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 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
110 LTTNG_HIDDEN
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 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
116 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
117 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
118 LTTNG_HIDDEN
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 LTTNG_HIDDEN
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 LTTNG_HIDDEN
const char * const config_element_id
= "id";
136 const char * const config_element_pids
= "pids";
137 const char * const config_element_shared_memory_path
= "shared_memory_path";
138 const char * const config_element_pid_tracker
= "pid_tracker";
139 LTTNG_HIDDEN
const char * const config_element_vpid_tracker
= "vpid_tracker";
140 LTTNG_HIDDEN
const char * const config_element_uid_tracker
= "uid_tracker";
141 LTTNG_HIDDEN
const char * const config_element_vuid_tracker
= "vuid_tracker";
142 LTTNG_HIDDEN
const char * const config_element_gid_tracker
= "gid_tracker";
143 LTTNG_HIDDEN
const char * const config_element_vgid_tracker
= "vgid_tracker";
144 const char * const config_element_trackers
= "trackers";
145 const char * const config_element_targets
= "targets";
146 LTTNG_HIDDEN
const char * const config_element_target_type
= "target_type";
147 const char * const config_element_target_pid
= "pid_target";
148 LTTNG_HIDDEN
const char * const config_element_target_vpid
= "vpid_target";
149 LTTNG_HIDDEN
const char * const config_element_target_uid
= "uid_target";
150 LTTNG_HIDDEN
const char * const config_element_target_vuid
= "vuid_target";
151 LTTNG_HIDDEN
const char * const config_element_target_gid
= "gid_target";
152 LTTNG_HIDDEN
const char * const config_element_target_vgid
= "vgid_target";
153 LTTNG_HIDDEN
const char * const config_element_tracker_type
= "tracker_type";
155 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
156 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
157 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
158 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
159 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
161 const char * const config_domain_type_kernel
= "KERNEL";
162 const char * const config_domain_type_ust
= "UST";
163 const char * const config_domain_type_jul
= "JUL";
164 const char * const config_domain_type_log4j
= "LOG4J";
165 const char * const config_domain_type_python
= "PYTHON";
167 const char * const config_buffer_type_per_pid
= "PER_PID";
168 const char * const config_buffer_type_per_uid
= "PER_UID";
169 const char * const config_buffer_type_global
= "GLOBAL";
171 const char * const config_overwrite_mode_discard
= "DISCARD";
172 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
174 const char * const config_output_type_splice
= "SPLICE";
175 const char * const config_output_type_mmap
= "MMAP";
177 const char * const config_loglevel_type_all
= "ALL";
178 const char * const config_loglevel_type_range
= "RANGE";
179 const char * const config_loglevel_type_single
= "SINGLE";
181 const char * const config_event_type_all
= "ALL";
182 const char * const config_event_type_tracepoint
= "TRACEPOINT";
183 const char * const config_event_type_probe
= "PROBE";
184 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
185 const char * const config_event_type_function
= "FUNCTION";
186 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
187 const char * const config_event_type_noop
= "NOOP";
188 const char * const config_event_type_syscall
= "SYSCALL";
189 const char * const config_event_type_kprobe
= "KPROBE";
190 const char * const config_event_type_kretprobe
= "KRETPROBE";
192 const char * const config_event_context_pid
= "PID";
193 const char * const config_event_context_procname
= "PROCNAME";
194 const char * const config_event_context_prio
= "PRIO";
195 const char * const config_event_context_nice
= "NICE";
196 const char * const config_event_context_vpid
= "VPID";
197 const char * const config_event_context_tid
= "TID";
198 const char * const config_event_context_vtid
= "VTID";
199 const char * const config_event_context_ppid
= "PPID";
200 const char * const config_event_context_vppid
= "VPPID";
201 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
202 const char * const config_event_context_hostname
= "HOSTNAME";
203 const char * const config_event_context_ip
= "IP";
204 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
205 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
206 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
207 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
208 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
209 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
210 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
211 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
212 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
213 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
214 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
215 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
216 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
217 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
218 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
219 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
220 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
221 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
222 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
223 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
224 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
225 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
226 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
227 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
228 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
229 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
230 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
232 /* Deprecated symbols */
233 const char * const config_element_perf
;
235 enum process_event_node_phase
{
240 struct consumer_output
{
247 static int config_entry_handler_filter(struct handler_filter_args
*args
,
248 const char *section
, const char *name
, const char *value
)
251 struct config_entry entry
= { section
, name
, value
};
255 if (!section
|| !name
|| !value
) {
261 if (strcmp(args
->section
, section
)) {
266 ret
= args
->handler(&entry
, args
->user_data
);
272 int config_get_section_entries(const char *override_path
, const char *section
,
273 config_entry_handler_cb handler
, void *user_data
)
277 FILE *config_file
= NULL
;
278 struct handler_filter_args filter
= { section
, handler
, user_data
};
280 /* First, try system-wide conf. file. */
281 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
283 config_file
= fopen(path
, "r");
285 DBG("Loading daemon conf file at %s", path
);
287 * Return value is not very important here since error or not, we
288 * continue and try the next possible conf. file.
290 (void) ini_parse_file(config_file
,
291 (ini_entry_handler
) config_entry_handler_filter
,
296 /* Second is the user local configuration. */
297 path
= utils_get_home_dir();
299 char fullpath
[PATH_MAX
];
301 ret
= snprintf(fullpath
, sizeof(fullpath
),
302 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
304 PERROR("snprintf user conf. path");
308 config_file
= fopen(fullpath
, "r");
310 DBG("Loading daemon user conf file at %s", path
);
312 * Return value is not very important here since error or not, we
313 * continue and try the next possible conf. file.
315 (void) ini_parse_file(config_file
,
316 (ini_entry_handler
) config_entry_handler_filter
,
322 /* Final path is the one that the user might have provided. */
324 config_file
= fopen(override_path
, "r");
326 DBG("Loading daemon command line conf file at %s", override_path
);
327 (void) ini_parse_file(config_file
,
328 (ini_entry_handler
) config_entry_handler_filter
,
332 ERR("Failed to open daemon configuration file at %s",
339 /* Everything went well. */
347 int config_parse_value(const char *value
)
350 char *endptr
, *lower_str
;
360 v
= strtoul(value
, &endptr
, 10);
361 if (endptr
!= value
) {
366 lower_str
= zmalloc(len
+ 1);
373 for (i
= 0; i
< len
; i
++) {
374 lower_str
[i
] = tolower(value
[i
]);
377 if (!strcmp(lower_str
, config_str_yes
) ||
378 !strcmp(lower_str
, config_str_true
) ||
379 !strcmp(lower_str
, config_str_on
)) {
381 } else if (!strcmp(lower_str
, config_str_no
) ||
382 !strcmp(lower_str
, config_str_false
) ||
383 !strcmp(lower_str
, config_str_off
)) {
395 * Returns a xmlChar string which must be released using xmlFree().
397 static xmlChar
*encode_string(const char *in_str
)
399 xmlChar
*out_str
= NULL
;
400 xmlCharEncodingHandlerPtr handler
;
401 int out_len
, ret
, in_len
;
405 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
407 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
411 in_len
= strlen(in_str
);
413 * Add 1 byte for the NULL terminted character. The factor 4 here is
414 * used because UTF-8 characters can take up to 4 bytes.
416 out_len
= (in_len
* 4) + 1;
417 out_str
= xmlMalloc(out_len
);
422 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
429 /* out_len is now the size of out_str */
430 out_str
[out_len
] = '\0';
436 struct config_writer
*config_writer_create(int fd_output
, int indent
)
439 struct config_writer
*writer
;
440 xmlOutputBufferPtr buffer
;
442 writer
= zmalloc(sizeof(struct config_writer
));
444 PERROR("zmalloc config_writer_create");
448 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
453 writer
->writer
= xmlNewTextWriter(buffer
);
454 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
455 config_xml_encoding
, NULL
);
460 ret
= xmlTextWriterSetIndentString(writer
->writer
,
461 BAD_CAST config_xml_indent_string
);
466 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
474 config_writer_destroy(writer
);
479 int config_writer_destroy(struct config_writer
*writer
)
488 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
489 WARN("Could not close XML document");
493 if (writer
->writer
) {
494 xmlFreeTextWriter(writer
->writer
);
503 int config_writer_open_element(struct config_writer
*writer
,
504 const char *element_name
)
507 xmlChar
*encoded_element_name
;
509 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
514 encoded_element_name
= encode_string(element_name
);
515 if (!encoded_element_name
) {
520 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
521 xmlFree(encoded_element_name
);
523 return ret
>= 0 ? 0 : ret
;
527 int config_writer_write_attribute(struct config_writer
*writer
,
528 const char *name
, const char *value
)
531 xmlChar
*encoded_name
= NULL
;
532 xmlChar
*encoded_value
= NULL
;
534 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
539 encoded_name
= encode_string(name
);
545 encoded_value
= encode_string(value
);
546 if (!encoded_value
) {
551 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
554 xmlFree(encoded_name
);
555 xmlFree(encoded_value
);
556 return ret
>= 0 ? 0 : ret
;
560 int config_writer_close_element(struct config_writer
*writer
)
564 if (!writer
|| !writer
->writer
) {
569 ret
= xmlTextWriterEndElement(writer
->writer
);
571 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
;
600 int config_writer_write_element_signed_int(struct config_writer
*writer
,
601 const char *element_name
, int64_t value
)
604 xmlChar
*encoded_element_name
;
606 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
611 encoded_element_name
= encode_string(element_name
);
612 if (!encoded_element_name
) {
617 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
618 encoded_element_name
, "%" PRIi64
, value
);
619 xmlFree(encoded_element_name
);
621 return ret
>= 0 ? 0 : ret
;
625 int config_writer_write_element_bool(struct config_writer
*writer
,
626 const char *element_name
, int value
)
628 return config_writer_write_element_string(writer
, element_name
,
629 value
? config_xml_true
: config_xml_false
);
633 int config_writer_write_element_string(struct config_writer
*writer
,
634 const char *element_name
, const char *value
)
637 xmlChar
*encoded_element_name
= NULL
;
638 xmlChar
*encoded_value
= NULL
;
640 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
646 encoded_element_name
= encode_string(element_name
);
647 if (!encoded_element_name
) {
652 encoded_value
= encode_string(value
);
653 if (!encoded_value
) {
658 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
661 xmlFree(encoded_element_name
);
662 xmlFree(encoded_value
);
663 return ret
>= 0 ? 0 : ret
;
667 void xml_error_handler(void *ctx
, const char *format
, ...)
673 va_start(args
, format
);
674 ret
= vasprintf(&errMsg
, format
, args
);
677 ERR("String allocation failed in xml error handler");
681 fprintf(stderr
, "XML Error: %s", errMsg
);
686 void fini_session_config_validation_ctx(
687 struct session_config_validation_ctx
*ctx
)
689 if (ctx
->parser_ctx
) {
690 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
694 xmlSchemaFree(ctx
->schema
);
697 if (ctx
->schema_validation_ctx
) {
698 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
701 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
705 char *get_session_config_xsd_path()
708 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
709 size_t base_path_len
;
713 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
716 base_path_len
= strlen(base_path
);
717 max_path_len
= base_path_len
+
718 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
719 xsd_path
= zmalloc(max_path_len
);
724 strcpy(xsd_path
, base_path
);
725 if (xsd_path
[base_path_len
- 1] != '/') {
726 xsd_path
[base_path_len
++] = '/';
729 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
735 int init_session_config_validation_ctx(
736 struct session_config_validation_ctx
*ctx
)
739 char *xsd_path
= get_session_config_xsd_path();
742 ret
= -LTTNG_ERR_NOMEM
;
746 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
747 if (!ctx
->parser_ctx
) {
748 ERR("XSD parser context creation failed");
749 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
752 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
753 xml_error_handler
, NULL
);
755 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
757 ERR("XSD parsing failed");
758 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
762 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
763 if (!ctx
->schema_validation_ctx
) {
764 ERR("XSD validation context creation failed");
765 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
769 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
770 xml_error_handler
, NULL
);
775 fini_session_config_validation_ctx(ctx
);
783 int parse_uint(xmlChar
*str
, uint64_t *val
)
793 *val
= strtoull((const char *) str
, &endptr
, 10);
794 if (!endptr
|| *endptr
) {
805 int parse_int(xmlChar
*str
, int64_t *val
)
815 *val
= strtoll((const char *) str
, &endptr
, 10);
816 if (!endptr
|| *endptr
) {
827 int parse_bool(xmlChar
*str
, int *val
)
836 if (!strcmp((const char *) str
, config_xml_true
)) {
838 } else if (!strcmp((const char *) str
, config_xml_false
)) {
841 WARN("Invalid boolean value encoutered (%s).",
850 int get_domain_type(xmlChar
*domain
)
858 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
859 ret
= LTTNG_DOMAIN_KERNEL
;
860 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
861 ret
= LTTNG_DOMAIN_UST
;
862 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
863 ret
= LTTNG_DOMAIN_JUL
;
864 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
865 ret
= LTTNG_DOMAIN_LOG4J
;
866 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
867 ret
= LTTNG_DOMAIN_PYTHON
;
878 int get_buffer_type(xmlChar
*buffer_type
)
886 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
887 ret
= LTTNG_BUFFER_GLOBAL
;
888 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
889 ret
= LTTNG_BUFFER_PER_UID
;
890 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
891 ret
= LTTNG_BUFFER_PER_PID
;
902 int get_overwrite_mode(xmlChar
*overwrite_mode
)
906 if (!overwrite_mode
) {
910 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
912 } else if (!strcmp((char *) overwrite_mode
,
913 config_overwrite_mode_discard
)) {
925 int get_output_type(xmlChar
*output_type
)
933 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
934 ret
= LTTNG_EVENT_MMAP
;
935 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
936 ret
= LTTNG_EVENT_SPLICE
;
947 int get_event_type(xmlChar
*event_type
)
955 if (!strcmp((char *) event_type
, config_event_type_all
)) {
956 ret
= LTTNG_EVENT_ALL
;
957 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
958 ret
= LTTNG_EVENT_TRACEPOINT
;
959 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
960 ret
= LTTNG_EVENT_PROBE
;
961 } else if (!strcmp((char *) event_type
,
962 config_event_type_userspace_probe
)) {
963 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
964 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
965 ret
= LTTNG_EVENT_FUNCTION
;
966 } else if (!strcmp((char *) event_type
,
967 config_event_type_function_entry
)) {
968 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
969 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
970 ret
= LTTNG_EVENT_NOOP
;
971 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
972 ret
= LTTNG_EVENT_SYSCALL
;
983 int get_loglevel_type(xmlChar
*loglevel_type
)
987 if (!loglevel_type
) {
991 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
992 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
993 } else if (!strcmp((char *) loglevel_type
,
994 config_loglevel_type_range
)) {
995 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
996 } else if (!strcmp((char *) loglevel_type
,
997 config_loglevel_type_single
)) {
998 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1009 * Return the context type or -1 on error.
1012 int get_context_type(xmlChar
*context_type
)
1016 if (!context_type
) {
1020 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1021 ret
= LTTNG_EVENT_CONTEXT_PID
;
1022 } else if (!strcmp((char *) context_type
,
1023 config_event_context_procname
)) {
1024 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1025 } else if (!strcmp((char *) context_type
,
1026 config_event_context_prio
)) {
1027 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1028 } else if (!strcmp((char *) context_type
,
1029 config_event_context_nice
)) {
1030 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1031 } else if (!strcmp((char *) context_type
,
1032 config_event_context_vpid
)) {
1033 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1034 } else if (!strcmp((char *) context_type
,
1035 config_event_context_tid
)) {
1036 ret
= LTTNG_EVENT_CONTEXT_TID
;
1037 } else if (!strcmp((char *) context_type
,
1038 config_event_context_vtid
)) {
1039 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1040 } else if (!strcmp((char *) context_type
,
1041 config_event_context_ppid
)) {
1042 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1043 } else if (!strcmp((char *) context_type
,
1044 config_event_context_vppid
)) {
1045 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1046 } else if (!strcmp((char *) context_type
,
1047 config_event_context_pthread_id
)) {
1048 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1049 } else if (!strcmp((char *) context_type
,
1050 config_event_context_hostname
)) {
1051 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1052 } else if (!strcmp((char *) context_type
,
1053 config_event_context_ip
)) {
1054 ret
= LTTNG_EVENT_CONTEXT_IP
;
1055 } else if (!strcmp((char *) context_type
,
1056 config_event_context_interruptible
)) {
1057 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1058 } else if (!strcmp((char *) context_type
,
1059 config_event_context_preemptible
)) {
1060 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1061 } else if (!strcmp((char *) context_type
,
1062 config_event_context_need_reschedule
)) {
1063 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1064 } else if (!strcmp((char *) context_type
,
1065 config_event_context_migratable
)) {
1066 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1067 } else if (!strcmp((char *) context_type
,
1068 config_event_context_callstack_user
)) {
1069 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1070 } else if (!strcmp((char *) context_type
,
1071 config_event_context_callstack_kernel
)) {
1072 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1073 } else if (!strcmp((char *) context_type
,
1074 config_event_context_cgroup_ns
)) {
1075 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1076 } else if (!strcmp((char *) context_type
,
1077 config_event_context_ipc_ns
)) {
1078 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1079 } else if (!strcmp((char *) context_type
,
1080 config_event_context_mnt_ns
)) {
1081 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1082 } else if (!strcmp((char *) context_type
,
1083 config_event_context_net_ns
)) {
1084 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1085 } else if (!strcmp((char *) context_type
,
1086 config_event_context_pid_ns
)) {
1087 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1088 } else if (!strcmp((char *) context_type
,
1089 config_event_context_user_ns
)) {
1090 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1091 } else if (!strcmp((char *) context_type
,
1092 config_event_context_uts_ns
)) {
1093 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1094 } else if (!strcmp((char *) context_type
,
1095 config_event_context_uid
)) {
1096 ret
= LTTNG_EVENT_CONTEXT_UID
;
1097 } else if (!strcmp((char *) context_type
,
1098 config_event_context_euid
)) {
1099 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1100 } else if (!strcmp((char *) context_type
,
1101 config_event_context_suid
)) {
1102 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1103 } else if (!strcmp((char *) context_type
,
1104 config_event_context_gid
)) {
1105 ret
= LTTNG_EVENT_CONTEXT_GID
;
1106 } else if (!strcmp((char *) context_type
,
1107 config_event_context_egid
)) {
1108 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1109 } else if (!strcmp((char *) context_type
,
1110 config_event_context_sgid
)) {
1111 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1112 } else if (!strcmp((char *) context_type
,
1113 config_event_context_vuid
)) {
1114 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1115 } else if (!strcmp((char *) context_type
,
1116 config_event_context_veuid
)) {
1117 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1118 } else if (!strcmp((char *) context_type
,
1119 config_event_context_vsuid
)) {
1120 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1121 } else if (!strcmp((char *) context_type
,
1122 config_event_context_vgid
)) {
1123 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1124 } else if (!strcmp((char *) context_type
,
1125 config_event_context_vegid
)) {
1126 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1127 } else if (!strcmp((char *) context_type
,
1128 config_event_context_vsgid
)) {
1129 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1140 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1145 for (node
= xmlFirstElementChild(domain_node
); node
;
1146 node
= xmlNextElementSibling(node
)) {
1147 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1149 xmlChar
*node_content
= xmlNodeGetContent(node
);
1150 if (!node_content
) {
1151 ret
= -LTTNG_ERR_NOMEM
;
1155 ret
= get_domain_type(node_content
);
1158 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1163 } else if (!strcmp((const char *) node
->name
,
1164 config_element_buffer_type
)) {
1166 xmlChar
*node_content
= xmlNodeGetContent(node
);
1167 if (!node_content
) {
1168 ret
= -LTTNG_ERR_NOMEM
;
1172 ret
= get_buffer_type(node_content
);
1175 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1179 domain
->buf_type
= ret
;
1188 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1193 for (node
= xmlFirstElementChild(net_output_node
); node
;
1194 node
= xmlNextElementSibling(node
)) {
1195 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1197 *control_uri
= (char *) xmlNodeGetContent(node
);
1198 if (!*control_uri
) {
1203 *data_uri
= (char *) xmlNodeGetContent(node
);
1210 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1214 int process_consumer_output(xmlNodePtr consumer_output_node
,
1215 struct consumer_output
*output
)
1222 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1223 node
= xmlNextElementSibling(node
)) {
1224 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1225 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1229 ret
= -LTTNG_ERR_NOMEM
;
1233 ret
= parse_bool(enabled_str
, &output
->enabled
);
1239 xmlNodePtr output_type_node
;
1242 output_type_node
= xmlFirstElementChild(node
);
1243 if (!output_type_node
) {
1244 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1248 if (!strcmp((const char *) output_type_node
->name
,
1249 config_element_path
)) {
1251 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1252 if (!output
->path
) {
1253 ret
= -LTTNG_ERR_NOMEM
;
1258 ret
= get_net_output_uris(output_type_node
,
1259 &output
->control_uri
, &output
->data_uri
);
1271 free(output
->control_uri
);
1272 free(output
->data_uri
);
1273 memset(output
, 0, sizeof(struct consumer_output
));
1279 int create_session_net_output(const char *name
, const char *control_uri
,
1280 const char *data_uri
)
1283 struct lttng_handle
*handle
;
1284 const char *uri
= NULL
;
1288 handle
= lttng_create_handle(name
, NULL
);
1290 ret
= -LTTNG_ERR_NOMEM
;
1294 if (!control_uri
|| !data_uri
) {
1295 uri
= control_uri
? control_uri
: data_uri
;
1300 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1301 lttng_destroy_handle(handle
);
1307 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1308 const struct config_load_session_override_attr
*overrides
)
1311 xmlNodePtr node
= NULL
;
1312 xmlNodePtr snapshot_output_list_node
;
1313 xmlNodePtr snapshot_output_node
;
1315 assert(session_name
);
1317 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1326 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1328 /* Parse and create snapshot outputs */
1330 for (snapshot_output_node
=
1331 xmlFirstElementChild(snapshot_output_list_node
);
1332 snapshot_output_node
; snapshot_output_node
=
1333 xmlNextElementSibling(snapshot_output_node
)) {
1335 uint64_t max_size
= UINT64_MAX
;
1336 struct consumer_output output
= { 0 };
1337 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1338 const char *control_uri
= NULL
;
1339 const char *data_uri
= NULL
;
1340 const char *path
= NULL
;
1342 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1343 node
= xmlNextElementSibling(node
)) {
1344 if (!strcmp((const char *) node
->name
,
1345 config_element_name
)) {
1347 name
= (char *) xmlNodeGetContent(node
);
1349 ret
= -LTTNG_ERR_NOMEM
;
1350 goto error_snapshot_output
;
1352 } else if (!strcmp((const char *) node
->name
,
1353 config_element_max_size
)) {
1354 xmlChar
*content
= xmlNodeGetContent(node
);
1358 ret
= -LTTNG_ERR_NOMEM
;
1359 goto error_snapshot_output
;
1361 ret
= parse_uint(content
, &max_size
);
1364 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1365 goto error_snapshot_output
;
1368 /* consumer_output */
1369 ret
= process_consumer_output(node
, &output
);
1371 goto error_snapshot_output
;
1376 control_uri
= output
.control_uri
;
1377 data_uri
= output
.data_uri
;
1381 if (overrides
->path_url
) {
1382 path
= overrides
->path_url
;
1383 /* Control/data_uri are null */
1387 if (overrides
->ctrl_url
) {
1388 control_uri
= overrides
->ctrl_url
;
1392 if (overrides
->data_url
) {
1393 data_uri
= overrides
->data_url
;
1400 snapshot_output
= lttng_snapshot_output_create();
1401 if (!snapshot_output
) {
1402 ret
= -LTTNG_ERR_NOMEM
;
1403 goto error_snapshot_output
;
1406 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1408 goto error_snapshot_output
;
1411 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1413 goto error_snapshot_output
;
1417 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1420 goto error_snapshot_output
;
1424 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1427 goto error_snapshot_output
;
1432 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1435 goto error_snapshot_output
;
1440 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1441 error_snapshot_output
:
1444 free(output
.control_uri
);
1445 free(output
.data_uri
);
1446 lttng_snapshot_output_destroy(snapshot_output
);
1456 int create_session(const char *name
,
1457 xmlNodePtr output_node
,
1458 uint64_t live_timer_interval
,
1459 const struct config_load_session_override_attr
*overrides
)
1462 struct consumer_output output
= { 0 };
1463 xmlNodePtr consumer_output_node
;
1464 const char *control_uri
= NULL
;
1465 const char *data_uri
= NULL
;
1466 const char *path
= NULL
;
1471 consumer_output_node
= xmlFirstElementChild(output_node
);
1472 if (!consumer_output_node
) {
1473 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1477 if (strcmp((const char *) consumer_output_node
->name
,
1478 config_element_consumer_output
)) {
1479 WARN("Invalid output type, expected %s node",
1480 config_element_consumer_output
);
1481 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1485 ret
= process_consumer_output(consumer_output_node
, &output
);
1491 control_uri
= output
.control_uri
;
1492 data_uri
= output
.data_uri
;
1495 /* Check for override and apply them */
1497 if (overrides
->path_url
) {
1498 path
= overrides
->path_url
;
1499 /* control/data_uri are null */;
1503 if (overrides
->ctrl_url
) {
1504 control_uri
= overrides
->ctrl_url
;
1508 if (overrides
->data_url
) {
1509 data_uri
= overrides
->data_url
;
1517 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1518 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1522 if (control_uri
|| data_uri
) {
1523 /* network destination */
1524 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1526 * URLs are provided for sure since the test above make sure that
1527 * with a live timer the data and control URIs are provided. So,
1528 * NULL is passed here and will be set right after.
1530 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1532 ret
= lttng_create_session(name
, NULL
);
1538 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1544 /* either local output or no output */
1545 ret
= lttng_create_session(name
, path
);
1552 free(output
.control_uri
);
1553 free(output
.data_uri
);
1558 struct lttng_userspace_probe_location
*
1559 process_userspace_probe_function_attribute_node(
1560 xmlNodePtr attribute_node
)
1562 xmlNodePtr function_attribute_node
;
1563 char *function_name
= NULL
, *binary_path
= NULL
;
1564 struct lttng_userspace_probe_location
*location
= NULL
;
1565 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1568 * Process userspace probe location function attributes. The order of
1569 * the fields are not guaranteed so we need to iterate over all fields
1570 * and check at the end if everything we need for this location type is
1573 for (function_attribute_node
=
1574 xmlFirstElementChild(attribute_node
);
1575 function_attribute_node
;
1576 function_attribute_node
= xmlNextElementSibling(
1577 function_attribute_node
)) {
1578 /* Handle function name, binary path and lookup method. */
1579 if (!strcmp((const char *) function_attribute_node
->name
,
1580 config_element_userspace_probe_function_location_function_name
)) {
1581 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1582 if (!function_name
) {
1585 } else if (!strcmp((const char *) function_attribute_node
->name
,
1586 config_element_userspace_probe_location_binary_path
)) {
1587 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1591 } else if (!strcmp((const char *) function_attribute_node
->name
,
1592 config_element_userspace_probe_lookup
)) {
1593 char *lookup_method_name
;
1595 lookup_method_name
= (char *) xmlNodeGetContent(
1596 function_attribute_node
);
1597 if (!lookup_method_name
) {
1602 * function_default lookup method defaults to
1603 * function_elf lookup method at the moment.
1605 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1606 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1607 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1608 if (!lookup_method
) {
1609 PERROR("Error creating function default/ELF lookup method");
1612 WARN("Unknown function lookup method");
1615 free(lookup_method_name
);
1616 if (!lookup_method
) {
1623 /* Check if all the necessary fields were found. */
1624 if (binary_path
&& function_name
&& lookup_method
) {
1625 /* Ownership of lookup_method is transferred. */
1627 lttng_userspace_probe_location_function_create(
1628 binary_path
, function_name
,
1630 lookup_method
= NULL
;
1635 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1637 free(function_name
);
1642 struct lttng_userspace_probe_location
*
1643 process_userspace_probe_tracepoint_attribute_node(
1644 xmlNodePtr attribute_node
)
1646 xmlNodePtr tracepoint_attribute_node
;
1647 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1648 struct lttng_userspace_probe_location
*location
= NULL
;
1649 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1652 * Process userspace probe location tracepoint attributes. The order of
1653 * the fields are not guaranteed so we need to iterate over all fields
1654 * and check at the end if everything we need for this location type is
1657 for (tracepoint_attribute_node
=
1658 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1659 tracepoint_attribute_node
= xmlNextElementSibling(
1660 tracepoint_attribute_node
)) {
1661 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1662 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1663 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1667 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1668 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1669 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1670 if (!provider_name
) {
1673 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1674 config_element_userspace_probe_location_binary_path
)) {
1675 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1679 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1680 config_element_userspace_probe_lookup
)) {
1681 char *lookup_method_name
;
1683 lookup_method_name
= (char *) xmlNodeGetContent(
1684 tracepoint_attribute_node
);
1685 if (!lookup_method_name
) {
1689 if (!strcmp(lookup_method_name
,
1690 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1692 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1693 if (!lookup_method
) {
1694 PERROR("Error creating tracepoint SDT lookup method");
1697 WARN("Unknown tracepoint lookup method");
1700 free(lookup_method_name
);
1701 if (!lookup_method
) {
1705 WARN("Unknown tracepoint attribute");
1709 /* Check if all the necessary fields were found. */
1710 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1711 /* Ownership of lookup_method is transferred. */
1713 lttng_userspace_probe_location_tracepoint_create(
1714 binary_path
, provider_name
,
1715 probe_name
, lookup_method
);
1716 lookup_method
= NULL
;
1721 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1723 free(provider_name
);
1729 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1730 struct lttng_event_probe_attr
*attr
)
1734 assert(probe_attribute_node
);
1737 if (!strcmp((const char *) probe_attribute_node
->name
,
1738 config_element_address
)) {
1743 content
= xmlNodeGetContent(probe_attribute_node
);
1745 ret
= -LTTNG_ERR_NOMEM
;
1749 ret
= parse_uint(content
, &addr
);
1752 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1757 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1758 config_element_offset
)) {
1760 uint64_t offset
= 0;
1763 content
= xmlNodeGetContent(probe_attribute_node
);
1765 ret
= -LTTNG_ERR_NOMEM
;
1769 ret
= parse_uint(content
, &offset
);
1772 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1776 attr
->offset
= offset
;
1777 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1778 config_element_symbol_name
)) {
1782 content
= xmlNodeGetContent(probe_attribute_node
);
1784 ret
= -LTTNG_ERR_NOMEM
;
1788 ret
= lttng_strncpy(attr
->symbol_name
,
1789 (const char *) content
,
1790 LTTNG_SYMBOL_NAME_LEN
);
1792 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1793 (const char *) content
,
1794 strlen((const char *) content
),
1795 LTTNG_SYMBOL_NAME_LEN
);
1796 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1808 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1809 const char *channel_name
, const enum process_event_node_phase phase
)
1813 struct lttng_event
*event
;
1814 char **exclusions
= NULL
;
1815 unsigned long exclusion_count
= 0;
1816 char *filter_expression
= NULL
;
1820 assert(channel_name
);
1822 event
= lttng_event_create();
1824 ret
= -LTTNG_ERR_NOMEM
;
1828 /* Initialize default log level which varies by domain */
1829 switch (handle
->domain
.type
)
1831 case LTTNG_DOMAIN_JUL
:
1832 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1834 case LTTNG_DOMAIN_LOG4J
:
1835 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1837 case LTTNG_DOMAIN_PYTHON
:
1838 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1840 case LTTNG_DOMAIN_UST
:
1841 case LTTNG_DOMAIN_KERNEL
:
1842 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1848 for (node
= xmlFirstElementChild(event_node
); node
;
1849 node
= xmlNextElementSibling(node
)) {
1850 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1854 content
= xmlNodeGetContent(node
);
1856 ret
= -LTTNG_ERR_NOMEM
;
1860 ret
= lttng_strncpy(event
->name
,
1861 (const char *) content
,
1862 LTTNG_SYMBOL_NAME_LEN
);
1864 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1865 (const char *) content
,
1866 strlen((const char *) content
),
1867 LTTNG_SYMBOL_NAME_LEN
);
1868 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1873 } else if (!strcmp((const char *) node
->name
,
1874 config_element_enabled
)) {
1875 xmlChar
*content
= xmlNodeGetContent(node
);
1879 ret
= -LTTNG_ERR_NOMEM
;
1883 ret
= parse_bool(content
, &event
->enabled
);
1886 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1889 } else if (!strcmp((const char *) node
->name
,
1890 config_element_type
)) {
1891 xmlChar
*content
= xmlNodeGetContent(node
);
1895 ret
= -LTTNG_ERR_NOMEM
;
1899 ret
= get_event_type(content
);
1902 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1907 } else if (!strcmp((const char *) node
->name
,
1908 config_element_loglevel_type
)) {
1909 xmlChar
*content
= xmlNodeGetContent(node
);
1913 ret
= -LTTNG_ERR_NOMEM
;
1917 ret
= get_loglevel_type(content
);
1920 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1924 event
->loglevel_type
= ret
;
1925 } else if (!strcmp((const char *) node
->name
,
1926 config_element_loglevel
)) {
1928 int64_t loglevel
= 0;
1931 content
= xmlNodeGetContent(node
);
1933 ret
= -LTTNG_ERR_NOMEM
;
1937 ret
= parse_int(content
, &loglevel
);
1940 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1944 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1945 WARN("loglevel out of range.");
1946 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1950 event
->loglevel
= loglevel
;
1951 } else if (!strcmp((const char *) node
->name
,
1952 config_element_filter
)) {
1954 xmlNodeGetContent(node
);
1958 ret
= -LTTNG_ERR_NOMEM
;
1962 free(filter_expression
);
1963 filter_expression
= strdup((char *) content
);
1965 if (!filter_expression
) {
1966 ret
= -LTTNG_ERR_NOMEM
;
1969 } else if (!strcmp((const char *) node
->name
,
1970 config_element_exclusions
)) {
1971 xmlNodePtr exclusion_node
;
1972 int exclusion_index
= 0;
1977 * Exclusions has already been initialized,
1980 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1984 exclusion_count
= xmlChildElementCount(node
);
1985 if (!exclusion_count
) {
1989 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1991 exclusion_count
= 0;
1992 ret
= -LTTNG_ERR_NOMEM
;
1996 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1997 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1999 xmlNodeGetContent(exclusion_node
);
2002 ret
= -LTTNG_ERR_NOMEM
;
2006 exclusions
[exclusion_index
] = strdup((const char *) content
);
2008 if (!exclusions
[exclusion_index
]) {
2009 ret
= -LTTNG_ERR_NOMEM
;
2015 event
->exclusion
= 1;
2016 } else if (!strcmp((const char *) node
->name
,
2017 config_element_attributes
)) {
2018 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2021 if (!attribute_node
) {
2022 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2026 if (!strcmp((const char *) attribute_node
->name
,
2027 config_element_probe_attributes
)) {
2028 xmlNodePtr probe_attribute_node
;
2030 /* probe_attributes */
2031 for (probe_attribute_node
=
2032 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2033 probe_attribute_node
= xmlNextElementSibling(
2034 probe_attribute_node
)) {
2036 ret
= process_probe_attribute_node(probe_attribute_node
,
2037 &event
->attr
.probe
);
2042 } else if (!strcmp((const char *) attribute_node
->name
,
2043 config_element_function_attributes
)) {
2046 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2048 /* function_attributes */
2049 content
= xmlNodeGetContent(symbol_node
);
2051 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2055 sym_len
= strlen((char *) content
);
2056 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2057 WARN("Function name too long.");
2058 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2063 ret
= lttng_strncpy(
2064 event
->attr
.ftrace
.symbol_name
,
2065 (char *) content
, sym_len
);
2067 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2072 } else if (!strcmp((const char *) attribute_node
->name
,
2073 config_element_userspace_probe_tracepoint_attributes
)) {
2074 struct lttng_userspace_probe_location
*location
;
2076 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2078 WARN("Error processing userspace probe tracepoint attribute");
2079 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2082 ret
= lttng_event_set_userspace_probe_location(
2085 WARN("Error setting userspace probe location field");
2086 lttng_userspace_probe_location_destroy(
2088 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2091 } else if (!strcmp((const char *) attribute_node
->name
,
2092 config_element_userspace_probe_function_attributes
)) {
2093 struct lttng_userspace_probe_location
*location
;
2096 process_userspace_probe_function_attribute_node(
2099 WARN("Error processing userspace probe function attribute");
2100 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2104 ret
= lttng_event_set_userspace_probe_location(
2107 WARN("Error setting userspace probe location field");
2108 lttng_userspace_probe_location_destroy(
2110 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2114 /* Unknown event attribute. */
2115 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2121 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2122 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2123 filter_expression
, exclusion_count
, exclusions
);
2125 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2126 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2132 for (i
= 0; i
< exclusion_count
; i
++) {
2133 free(exclusions
[i
]);
2136 lttng_event_destroy(event
);
2138 free(filter_expression
);
2143 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2144 const char *channel_name
)
2147 struct lttng_event event
;
2150 assert(events_node
);
2152 assert(channel_name
);
2154 for (node
= xmlFirstElementChild(events_node
); node
;
2155 node
= xmlNextElementSibling(node
)) {
2156 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2163 * Disable all events to enable only the necessary events.
2164 * Limitations regarding lttng_disable_events and tuple descriptor
2165 * force this approach.
2167 memset(&event
, 0, sizeof(event
));
2168 event
.loglevel
= -1;
2169 event
.type
= LTTNG_EVENT_ALL
;
2170 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2175 for (node
= xmlFirstElementChild(events_node
); node
;
2176 node
= xmlNextElementSibling(node
)) {
2177 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2188 int process_channel_attr_node(xmlNodePtr attr_node
,
2189 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2190 xmlNodePtr
*events_node
)
2196 assert(contexts_node
);
2197 assert(events_node
);
2199 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2203 content
= xmlNodeGetContent(attr_node
);
2205 ret
= -LTTNG_ERR_NOMEM
;
2209 ret
= lttng_strncpy(channel
->name
,
2210 (const char *) content
,
2211 LTTNG_SYMBOL_NAME_LEN
);
2213 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2214 (const char *) content
,
2215 strlen((const char *) content
),
2216 LTTNG_SYMBOL_NAME_LEN
);
2217 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2222 } else if (!strcmp((const char *) attr_node
->name
,
2223 config_element_enabled
)) {
2228 content
= xmlNodeGetContent(attr_node
);
2230 ret
= -LTTNG_ERR_NOMEM
;
2234 ret
= parse_bool(content
, &enabled
);
2237 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2241 channel
->enabled
= enabled
;
2242 } else if (!strcmp((const char *) attr_node
->name
,
2243 config_element_overwrite_mode
)) {
2246 /* overwrite_mode */
2247 content
= xmlNodeGetContent(attr_node
);
2249 ret
= -LTTNG_ERR_NOMEM
;
2253 ret
= get_overwrite_mode(content
);
2256 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2260 channel
->attr
.overwrite
= ret
;
2261 } else if (!strcmp((const char *) attr_node
->name
,
2262 config_element_subbuf_size
)) {
2265 /* subbuffer_size */
2266 content
= xmlNodeGetContent(attr_node
);
2268 ret
= -LTTNG_ERR_NOMEM
;
2272 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2275 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2278 } else if (!strcmp((const char *) attr_node
->name
,
2279 config_element_num_subbuf
)) {
2282 /* subbuffer_count */
2283 content
= xmlNodeGetContent(attr_node
);
2285 ret
= -LTTNG_ERR_NOMEM
;
2289 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2292 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2295 } else if (!strcmp((const char *) attr_node
->name
,
2296 config_element_switch_timer_interval
)) {
2298 uint64_t switch_timer_interval
= 0;
2300 /* switch_timer_interval */
2301 content
= xmlNodeGetContent(attr_node
);
2303 ret
= -LTTNG_ERR_NOMEM
;
2307 ret
= parse_uint(content
, &switch_timer_interval
);
2310 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2314 if (switch_timer_interval
> UINT_MAX
) {
2315 WARN("switch_timer_interval out of range.");
2316 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2320 channel
->attr
.switch_timer_interval
=
2321 switch_timer_interval
;
2322 } else if (!strcmp((const char *) attr_node
->name
,
2323 config_element_read_timer_interval
)) {
2325 uint64_t read_timer_interval
= 0;
2327 /* read_timer_interval */
2328 content
= xmlNodeGetContent(attr_node
);
2330 ret
= -LTTNG_ERR_NOMEM
;
2334 ret
= parse_uint(content
, &read_timer_interval
);
2337 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2341 if (read_timer_interval
> UINT_MAX
) {
2342 WARN("read_timer_interval out of range.");
2343 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2347 channel
->attr
.read_timer_interval
=
2348 read_timer_interval
;
2349 } else if (!strcmp((const char *) attr_node
->name
,
2350 config_element_output_type
)) {
2354 content
= xmlNodeGetContent(attr_node
);
2356 ret
= -LTTNG_ERR_NOMEM
;
2360 ret
= get_output_type(content
);
2363 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2367 channel
->attr
.output
= ret
;
2368 } else if (!strcmp((const char *) attr_node
->name
,
2369 config_element_tracefile_size
)) {
2372 /* tracefile_size */
2373 content
= xmlNodeGetContent(attr_node
);
2375 ret
= -LTTNG_ERR_NOMEM
;
2379 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2382 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2385 } else if (!strcmp((const char *) attr_node
->name
,
2386 config_element_tracefile_count
)) {
2389 /* tracefile_count */
2390 content
= xmlNodeGetContent(attr_node
);
2392 ret
= -LTTNG_ERR_NOMEM
;
2396 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2399 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2402 } else if (!strcmp((const char *) attr_node
->name
,
2403 config_element_live_timer_interval
)) {
2405 uint64_t live_timer_interval
= 0;
2407 /* live_timer_interval */
2408 content
= xmlNodeGetContent(attr_node
);
2410 ret
= -LTTNG_ERR_NOMEM
;
2414 ret
= parse_uint(content
, &live_timer_interval
);
2417 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2421 if (live_timer_interval
> UINT_MAX
) {
2422 WARN("live_timer_interval out of range.");
2423 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2427 channel
->attr
.live_timer_interval
=
2428 live_timer_interval
;
2429 } else if (!strcmp((const char *) attr_node
->name
,
2430 config_element_monitor_timer_interval
)) {
2432 uint64_t monitor_timer_interval
= 0;
2434 /* monitor_timer_interval */
2435 content
= xmlNodeGetContent(attr_node
);
2437 ret
= -LTTNG_ERR_NOMEM
;
2441 ret
= parse_uint(content
, &monitor_timer_interval
);
2444 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2448 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2449 monitor_timer_interval
);
2451 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2454 } else if (!strcmp((const char *) attr_node
->name
,
2455 config_element_blocking_timeout
)) {
2457 int64_t blocking_timeout
= 0;
2459 /* blocking_timeout */
2460 content
= xmlNodeGetContent(attr_node
);
2462 ret
= -LTTNG_ERR_NOMEM
;
2466 ret
= parse_int(content
, &blocking_timeout
);
2469 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2473 ret
= lttng_channel_set_blocking_timeout(channel
,
2476 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2479 } else if (!strcmp((const char *) attr_node
->name
,
2480 config_element_events
)) {
2482 *events_node
= attr_node
;
2485 *contexts_node
= attr_node
;
2493 int process_context_node(xmlNodePtr context_node
,
2494 struct lttng_handle
*handle
, const char *channel_name
)
2497 struct lttng_event_context context
;
2498 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2501 assert(channel_name
);
2503 if (!context_child_node
) {
2504 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2508 memset(&context
, 0, sizeof(context
));
2510 if (!strcmp((const char *) context_child_node
->name
,
2511 config_element_type
)) {
2513 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2516 ret
= -LTTNG_ERR_NOMEM
;
2520 ret
= get_context_type(content
);
2523 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2528 } else if (!strcmp((const char *) context_child_node
->name
,
2529 config_element_context_perf
)) {
2531 xmlNodePtr perf_attr_node
;
2533 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2534 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2535 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2536 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2537 perf_attr_node
; perf_attr_node
=
2538 xmlNextElementSibling(perf_attr_node
)) {
2539 if (!strcmp((const char *) perf_attr_node
->name
,
2540 config_element_type
)) {
2545 content
= xmlNodeGetContent(perf_attr_node
);
2547 ret
= -LTTNG_ERR_NOMEM
;
2551 ret
= parse_uint(content
, &type
);
2554 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2558 if (type
> UINT32_MAX
) {
2559 WARN("perf context type out of range.");
2560 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2564 context
.u
.perf_counter
.type
= type
;
2565 } else if (!strcmp((const char *) perf_attr_node
->name
,
2566 config_element_config
)) {
2568 uint64_t config
= 0;
2571 content
= xmlNodeGetContent(perf_attr_node
);
2573 ret
= -LTTNG_ERR_NOMEM
;
2577 ret
= parse_uint(content
, &config
);
2580 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2584 context
.u
.perf_counter
.config
= config
;
2585 } else if (!strcmp((const char *) perf_attr_node
->name
,
2586 config_element_name
)) {
2590 content
= xmlNodeGetContent(perf_attr_node
);
2592 ret
= -LTTNG_ERR_NOMEM
;
2596 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2597 (const char *) content
,
2598 LTTNG_SYMBOL_NAME_LEN
);
2600 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2601 (const char *) content
,
2602 strlen((const char *) content
),
2603 LTTNG_SYMBOL_NAME_LEN
);
2604 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2611 } else if (!strcmp((const char *) context_child_node
->name
,
2612 config_element_context_app
)) {
2613 /* application context */
2614 xmlNodePtr app_ctx_node
;
2616 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2617 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2618 app_ctx_node
; app_ctx_node
=
2619 xmlNextElementSibling(app_ctx_node
)) {
2621 char **target
= strcmp(
2622 (const char *) app_ctx_node
->name
,
2623 config_element_context_app_provider_name
) == 0 ?
2624 &context
.u
.app_ctx
.provider_name
:
2625 &context
.u
.app_ctx
.ctx_name
;
2627 content
= xmlNodeGetContent(app_ctx_node
);
2629 ret
= -LTTNG_ERR_NOMEM
;
2633 *target
= (char *) content
;
2636 /* Unrecognized context type */
2637 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2641 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2642 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2643 free(context
.u
.app_ctx
.provider_name
);
2644 free(context
.u
.app_ctx
.ctx_name
);
2651 int process_contexts_node(xmlNodePtr contexts_node
,
2652 struct lttng_handle
*handle
, const char *channel_name
)
2655 xmlNodePtr context_node
;
2657 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2658 context_node
= xmlNextElementSibling(context_node
)) {
2659 ret
= process_context_node(context_node
, handle
, channel_name
);
2668 static int get_tracker_elements(enum lttng_tracker_type tracker_type
,
2669 const char **element_id_tracker
,
2670 const char **element_target_id
,
2671 const char **element_id
,
2672 const char **element_id_alias
,
2673 const char **element_name
)
2677 switch (tracker_type
) {
2678 case LTTNG_TRACKER_PID
:
2679 *element_id_tracker
= config_element_pid_tracker
;
2680 *element_target_id
= config_element_target_pid
;
2681 *element_id
= config_element_id
;
2682 *element_id_alias
= config_element_pid
;
2683 *element_name
= NULL
;
2685 case LTTNG_TRACKER_VPID
:
2686 *element_id_tracker
= config_element_vpid_tracker
;
2687 *element_target_id
= config_element_target_vpid
;
2688 *element_id
= config_element_id
;
2689 *element_id_alias
= NULL
;
2690 *element_name
= NULL
;
2692 case LTTNG_TRACKER_UID
:
2693 *element_id_tracker
= config_element_uid_tracker
;
2694 *element_target_id
= config_element_target_uid
;
2695 *element_id
= config_element_id
;
2696 *element_id_alias
= NULL
;
2697 *element_name
= config_element_name
;
2699 case LTTNG_TRACKER_VUID
:
2700 *element_id_tracker
= config_element_vuid_tracker
;
2701 *element_target_id
= config_element_target_vuid
;
2702 *element_id
= config_element_id
;
2703 *element_id_alias
= NULL
;
2704 *element_name
= config_element_name
;
2706 case LTTNG_TRACKER_GID
:
2707 *element_id_tracker
= config_element_gid_tracker
;
2708 *element_target_id
= config_element_target_gid
;
2709 *element_id
= config_element_id
;
2710 *element_id_alias
= NULL
;
2711 *element_name
= config_element_name
;
2713 case LTTNG_TRACKER_VGID
:
2714 *element_id_tracker
= config_element_vgid_tracker
;
2715 *element_target_id
= config_element_target_vgid
;
2716 *element_id
= config_element_id
;
2717 *element_id_alias
= NULL
;
2718 *element_name
= config_element_name
;
2721 ret
= LTTNG_ERR_INVALID
;
2726 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2727 struct lttng_handle
*handle
,
2728 enum lttng_tracker_type tracker_type
)
2731 xmlNodePtr targets_node
= NULL
;
2733 const char *element_id_tracker
;
2734 const char *element_target_id
;
2735 const char *element_id
;
2736 const char *element_id_alias
;
2737 const char *element_name
;
2738 enum lttng_tracker_id_status status
;
2741 assert(id_tracker_node
);
2743 ret
= get_tracker_elements(tracker_type
, &element_id_tracker
,
2744 &element_target_id
, &element_id
, &element_id_alias
,
2750 /* get the targets node */
2751 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2752 node
= xmlNextElementSibling(node
)) {
2753 if (!strcmp((const char *) node
->name
,
2754 config_element_targets
)) {
2755 targets_node
= node
;
2760 if (!targets_node
) {
2761 ret
= LTTNG_ERR_INVALID
;
2765 /* Go through all id target node */
2766 child
= xmlChildElementCount(targets_node
);
2768 struct lttng_tracker_id
*tracker_id
= NULL
;
2769 tracker_id
= lttng_tracker_id_create();
2770 if (tracker_id
== NULL
) {
2771 ret
= LTTNG_ERR_NOMEM
;
2774 status
= lttng_tracker_id_set_all(tracker_id
);
2775 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
2776 ret
= LTTNG_ERR_INVALID
;
2780 /* The session is explicitly set to target nothing. */
2781 ret
= lttng_untrack_id(handle
, tracker_type
, tracker_id
);
2782 lttng_tracker_id_destroy(tracker_id
);
2787 for (node
= xmlFirstElementChild(targets_node
); node
;
2788 node
= xmlNextElementSibling(node
)) {
2789 xmlNodePtr id_target_node
= node
;
2791 /* get id node and track it */
2792 for (node
= xmlFirstElementChild(id_target_node
); node
;
2793 node
= xmlNextElementSibling(node
)) {
2794 if (!strcmp((const char *) node
->name
, element_id
) ||
2795 (element_id_alias
&&
2796 !strcmp((const char *) node
->name
,
2797 element_id_alias
))) {
2799 xmlChar
*content
= NULL
;
2800 struct lttng_tracker_id
*tracker_id
= NULL
;
2802 content
= xmlNodeGetContent(node
);
2804 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2808 ret
= parse_int(content
, &id
);
2811 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2815 tracker_id
= lttng_tracker_id_create();
2816 if (tracker_id
== NULL
) {
2817 ret
= LTTNG_ERR_NOMEM
;
2821 status
= lttng_tracker_id_set_value(
2823 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
2824 lttng_tracker_id_destroy(tracker_id
);
2825 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2829 ret
= lttng_track_id(handle
, tracker_type
,
2831 lttng_tracker_id_destroy(tracker_id
);
2836 if (element_name
&& !strcmp((const char *) node
->name
,
2838 xmlChar
*content
= NULL
;
2839 struct lttng_tracker_id
*tracker_id
= NULL
;
2841 content
= xmlNodeGetContent(node
);
2843 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2847 tracker_id
= lttng_tracker_id_create();
2848 if (tracker_id
== NULL
) {
2849 ret
= LTTNG_ERR_NOMEM
;
2853 status
= lttng_tracker_id_set_string(tracker_id
,
2854 (const char *) content
);
2855 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
2856 lttng_tracker_id_destroy(tracker_id
);
2857 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2861 ret
= lttng_track_id(handle
, tracker_type
,
2863 lttng_tracker_id_destroy(tracker_id
);
2870 node
= id_target_node
;
2878 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2881 struct lttng_domain domain
= { 0 };
2882 struct lttng_handle
*handle
= NULL
;
2883 struct lttng_channel
*channel
= NULL
;
2884 xmlNodePtr channels_node
= NULL
;
2885 xmlNodePtr trackers_node
= NULL
;
2886 xmlNodePtr pid_tracker_node
= NULL
;
2887 xmlNodePtr vpid_tracker_node
= NULL
;
2888 xmlNodePtr uid_tracker_node
= NULL
;
2889 xmlNodePtr vuid_tracker_node
= NULL
;
2890 xmlNodePtr gid_tracker_node
= NULL
;
2891 xmlNodePtr vgid_tracker_node
= NULL
;
2894 assert(session_name
);
2896 ret
= init_domain(domain_node
, &domain
);
2901 handle
= lttng_create_handle(session_name
, &domain
);
2903 ret
= -LTTNG_ERR_NOMEM
;
2907 /* get the channels node */
2908 for (node
= xmlFirstElementChild(domain_node
); node
;
2909 node
= xmlNextElementSibling(node
)) {
2910 if (!strcmp((const char *) node
->name
,
2911 config_element_channels
)) {
2912 channels_node
= node
;
2917 if (!channels_node
) {
2921 /* create all channels */
2922 for (node
= xmlFirstElementChild(channels_node
); node
;
2923 node
= xmlNextElementSibling(node
)) {
2924 const enum lttng_domain_type original_domain
= domain
.type
;
2925 xmlNodePtr contexts_node
= NULL
;
2926 xmlNodePtr events_node
= NULL
;
2927 xmlNodePtr channel_attr_node
;
2930 * Channels of the "agent" types cannot be created directly.
2931 * They are meant to be created implicitly through the
2932 * activation of events in their domain. However, a user
2933 * can override the default channel configuration attributes
2934 * by creating the underlying UST channel _before_ enabling
2935 * an agent domain event.
2937 * Hence, the channel's type is substituted before the creation
2938 * and restored by the time the events are created.
2940 switch (domain
.type
) {
2941 case LTTNG_DOMAIN_JUL
:
2942 case LTTNG_DOMAIN_LOG4J
:
2943 case LTTNG_DOMAIN_PYTHON
:
2944 domain
.type
= LTTNG_DOMAIN_UST
;
2949 channel
= lttng_channel_create(&domain
);
2955 for (channel_attr_node
= xmlFirstElementChild(node
);
2956 channel_attr_node
; channel_attr_node
=
2957 xmlNextElementSibling(channel_attr_node
)) {
2958 ret
= process_channel_attr_node(channel_attr_node
,
2959 channel
, &contexts_node
, &events_node
);
2965 ret
= lttng_enable_channel(handle
, channel
);
2970 /* Restore the original channel domain. */
2971 domain
.type
= original_domain
;
2973 ret
= process_events_node(events_node
, handle
, channel
->name
);
2978 ret
= process_contexts_node(contexts_node
, handle
,
2984 lttng_channel_destroy(channel
);
2988 /* get the trackers node */
2989 for (node
= xmlFirstElementChild(domain_node
); node
;
2990 node
= xmlNextElementSibling(node
)) {
2991 if (!strcmp((const char *) node
->name
,
2992 config_element_trackers
)) {
2993 trackers_node
= node
;
2998 if (!trackers_node
) {
3002 for (node
= xmlFirstElementChild(trackers_node
); node
;
3003 node
= xmlNextElementSibling(node
)) {
3004 if (!strcmp((const char *) node
->name
,
3005 config_element_pid_tracker
)) {
3006 pid_tracker_node
= node
;
3007 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
3013 if (!strcmp((const char *) node
->name
,
3014 config_element_vpid_tracker
)) {
3015 vpid_tracker_node
= node
;
3016 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
3017 LTTNG_TRACKER_VPID
);
3022 if (!strcmp((const char *) node
->name
,
3023 config_element_uid_tracker
)) {
3024 uid_tracker_node
= node
;
3025 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3031 if (!strcmp((const char *) node
->name
,
3032 config_element_vuid_tracker
)) {
3033 vuid_tracker_node
= node
;
3034 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3035 LTTNG_TRACKER_VUID
);
3040 if (!strcmp((const char *) node
->name
,
3041 config_element_gid_tracker
)) {
3042 gid_tracker_node
= node
;
3043 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3049 if (!strcmp((const char *) node
->name
,
3050 config_element_vgid_tracker
)) {
3051 vgid_tracker_node
= node
;
3052 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3053 LTTNG_TRACKER_VGID
);
3061 lttng_channel_destroy(channel
);
3062 lttng_destroy_handle(handle
);
3067 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3070 enum lttng_rotation_status status
;
3071 struct lttng_rotation_schedule
*periodic
=
3072 lttng_rotation_schedule_periodic_create();
3075 ret
= -LTTNG_ERR_NOMEM
;
3079 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3081 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3082 ret
= -LTTNG_ERR_INVALID
;
3086 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3088 case LTTNG_ROTATION_STATUS_OK
:
3091 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3092 case LTTNG_ROTATION_STATUS_INVALID
:
3093 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3096 ret
= -LTTNG_ERR_UNK
;
3100 lttng_rotation_schedule_destroy(periodic
);
3105 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3108 enum lttng_rotation_status status
;
3109 struct lttng_rotation_schedule
*size
=
3110 lttng_rotation_schedule_size_threshold_create();
3113 ret
= -LTTNG_ERR_NOMEM
;
3117 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3119 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3120 ret
= -LTTNG_ERR_INVALID
;
3124 status
= lttng_session_add_rotation_schedule(name
, size
);
3126 case LTTNG_ROTATION_STATUS_OK
:
3129 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3130 case LTTNG_ROTATION_STATUS_INVALID
:
3131 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3134 ret
= -LTTNG_ERR_UNK
;
3138 lttng_rotation_schedule_destroy(size
);
3143 int process_session_rotation_schedules_node(
3144 xmlNodePtr schedules_node
,
3145 uint64_t *rotation_timer_interval
,
3146 uint64_t *rotation_size
)
3151 for (child
= xmlFirstElementChild(schedules_node
);
3153 child
= xmlNextElementSibling(child
)) {
3154 if (!strcmp((const char *) child
->name
,
3155 config_element_rotation_schedule_periodic
)) {
3157 xmlNodePtr time_us_node
;
3159 /* periodic rotation schedule */
3160 time_us_node
= xmlFirstElementChild(child
);
3161 if (!time_us_node
||
3162 strcmp((const char *) time_us_node
->name
,
3163 config_element_rotation_schedule_periodic_time_us
)) {
3164 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3169 content
= xmlNodeGetContent(time_us_node
);
3171 ret
= -LTTNG_ERR_NOMEM
;
3174 ret
= parse_uint(content
, rotation_timer_interval
);
3177 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3180 } else if (!strcmp((const char *) child
->name
,
3181 config_element_rotation_schedule_size_threshold
)) {
3183 xmlNodePtr bytes_node
;
3185 /* size_threshold rotation schedule */
3186 bytes_node
= xmlFirstElementChild(child
);
3188 strcmp((const char *) bytes_node
->name
,
3189 config_element_rotation_schedule_size_threshold_bytes
)) {
3190 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3195 content
= xmlNodeGetContent(bytes_node
);
3197 ret
= -LTTNG_ERR_NOMEM
;
3200 ret
= parse_uint(content
, rotation_size
);
3203 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3214 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3216 const struct config_load_session_override_attr
*overrides
)
3218 int ret
, started
= -1, snapshot_mode
= -1;
3219 uint64_t live_timer_interval
= UINT64_MAX
,
3220 rotation_timer_interval
= 0,
3222 xmlChar
*name
= NULL
;
3223 xmlChar
*shm_path
= NULL
;
3224 xmlNodePtr domains_node
= NULL
;
3225 xmlNodePtr output_node
= NULL
;
3227 xmlNodePtr attributes_child
;
3228 struct lttng_domain
*kernel_domain
= NULL
;
3229 struct lttng_domain
*ust_domain
= NULL
;
3230 struct lttng_domain
*jul_domain
= NULL
;
3231 struct lttng_domain
*log4j_domain
= NULL
;
3232 struct lttng_domain
*python_domain
= NULL
;
3234 for (node
= xmlFirstElementChild(session_node
); node
;
3235 node
= xmlNextElementSibling(node
)) {
3236 if (!name
&& !strcmp((const char *) node
->name
,
3237 config_element_name
)) {
3239 xmlChar
*node_content
= xmlNodeGetContent(node
);
3240 if (!node_content
) {
3241 ret
= -LTTNG_ERR_NOMEM
;
3245 name
= node_content
;
3246 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3247 config_element_domains
)) {
3249 domains_node
= node
;
3250 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3251 config_element_started
)) {
3253 xmlChar
*node_content
= xmlNodeGetContent(node
);
3254 if (!node_content
) {
3255 ret
= -LTTNG_ERR_NOMEM
;
3259 ret
= parse_bool(node_content
, &started
);
3262 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3265 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3266 config_element_output
)) {
3269 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3270 config_element_shared_memory_path
)) {
3271 /* shared memory path */
3272 xmlChar
*node_content
= xmlNodeGetContent(node
);
3273 if (!node_content
) {
3274 ret
= -LTTNG_ERR_NOMEM
;
3278 shm_path
= node_content
;
3281 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3282 * rotation_timer_interval.
3284 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3285 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3286 if (!strcmp((const char *) attributes_child
->name
,
3287 config_element_snapshot_mode
)) {
3289 xmlChar
*snapshot_mode_content
=
3290 xmlNodeGetContent(attributes_child
);
3291 if (!snapshot_mode_content
) {
3292 ret
= -LTTNG_ERR_NOMEM
;
3296 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3297 free(snapshot_mode_content
);
3299 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3302 } else if (!strcmp((const char *) attributes_child
->name
,
3303 config_element_live_timer_interval
)) {
3304 /* live_timer_interval */
3305 xmlChar
*timer_interval_content
=
3306 xmlNodeGetContent(attributes_child
);
3307 if (!timer_interval_content
) {
3308 ret
= -LTTNG_ERR_NOMEM
;
3312 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3313 free(timer_interval_content
);
3315 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3318 } else if (!strcmp((const char *) attributes_child
->name
,
3319 config_element_rotation_schedules
)) {
3320 ret
= process_session_rotation_schedules_node(
3322 &rotation_timer_interval
,
3325 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3335 /* Mandatory attribute, as defined in the session XSD */
3336 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3340 if (session_name
&& strcmp((char *) name
, session_name
)) {
3341 /* This is not the session we are looking for */
3342 ret
= -LTTNG_ERR_NO_SESSION
;
3346 /* Init domains to create the session handles */
3347 for (node
= xmlFirstElementChild(domains_node
); node
;
3348 node
= xmlNextElementSibling(node
)) {
3349 struct lttng_domain
*domain
;
3351 domain
= zmalloc(sizeof(*domain
));
3353 ret
= -LTTNG_ERR_NOMEM
;
3357 ret
= init_domain(node
, domain
);
3359 goto domain_init_error
;
3362 switch (domain
->type
) {
3363 case LTTNG_DOMAIN_KERNEL
:
3364 if (kernel_domain
) {
3365 /* Same domain seen twice, invalid! */
3366 goto domain_init_error
;
3368 kernel_domain
= domain
;
3370 case LTTNG_DOMAIN_UST
:
3372 /* Same domain seen twice, invalid! */
3373 goto domain_init_error
;
3375 ust_domain
= domain
;
3377 case LTTNG_DOMAIN_JUL
:
3379 /* Same domain seen twice, invalid! */
3380 goto domain_init_error
;
3382 jul_domain
= domain
;
3384 case LTTNG_DOMAIN_LOG4J
:
3386 /* Same domain seen twice, invalid! */
3387 goto domain_init_error
;
3389 log4j_domain
= domain
;
3391 case LTTNG_DOMAIN_PYTHON
:
3392 if (python_domain
) {
3393 /* Same domain seen twice, invalid! */
3394 goto domain_init_error
;
3396 python_domain
= domain
;
3399 WARN("Invalid domain type");
3400 goto domain_init_error
;
3405 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3409 /* Apply overrides */
3411 if (overrides
->session_name
) {
3412 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3413 if (!name_override
) {
3414 ret
= -LTTNG_ERR_NOMEM
;
3418 /* Overrides the session name to the provided name */
3420 name
= name_override
;
3425 /* Destroy session if it exists */
3426 ret
= lttng_destroy_session((const char *) name
);
3427 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3428 ERR("Failed to destroy existing session.");
3433 /* Create session type depending on output type */
3434 if (snapshot_mode
&& snapshot_mode
!= -1) {
3435 ret
= create_snapshot_session((const char *) name
, output_node
,
3437 } else if (live_timer_interval
&&
3438 live_timer_interval
!= UINT64_MAX
) {
3439 ret
= create_session((const char *) name
,
3440 output_node
, live_timer_interval
, overrides
);
3442 /* regular session */
3443 ret
= create_session((const char *) name
,
3444 output_node
, UINT64_MAX
, overrides
);
3451 ret
= lttng_set_session_shm_path((const char *) name
,
3452 (const char *) shm_path
);
3458 for (node
= xmlFirstElementChild(domains_node
); node
;
3459 node
= xmlNextElementSibling(node
)) {
3460 ret
= process_domain_node(node
, (const char *) name
);
3466 if (rotation_timer_interval
) {
3467 ret
= add_periodic_rotation((const char *) name
,
3468 rotation_timer_interval
);
3473 if (rotation_size
) {
3474 ret
= add_size_rotation((const char *) name
,
3482 ret
= lttng_start_tracing((const char *) name
);
3490 ERR("Failed to load session %s: %s", (const char *) name
,
3491 lttng_strerror(ret
));
3492 lttng_destroy_session((const char *) name
);
3496 free(kernel_domain
);
3500 free(python_domain
);
3507 * Return 1 if the given path is readable by the current UID or 0 if not.
3508 * Return -1 if the path is EPERM.
3510 static int validate_file_read_creds(const char *path
)
3516 /* Can we read the file. */
3517 ret
= access(path
, R_OK
);
3521 if (errno
== EACCES
) {
3532 int load_session_from_file(const char *path
, const char *session_name
,
3533 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3534 const struct config_load_session_override_attr
*overrides
)
3536 int ret
, session_found
= !session_name
;
3537 xmlDocPtr doc
= NULL
;
3538 xmlNodePtr sessions_node
;
3539 xmlNodePtr session_node
;
3542 assert(validation_ctx
);
3544 ret
= validate_file_read_creds(path
);
3547 ret
= -LTTNG_ERR_EPERM
;
3549 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3554 doc
= xmlParseFile(path
);
3556 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3560 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3562 ERR("Session configuration file validation failed");
3563 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3567 sessions_node
= xmlDocGetRootElement(doc
);
3568 if (!sessions_node
) {
3569 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3573 for (session_node
= xmlFirstElementChild(sessions_node
);
3574 session_node
; session_node
=
3575 xmlNextElementSibling(session_node
)) {
3576 ret
= process_session_node(session_node
,
3577 session_name
, overwrite
, overrides
);
3578 if (session_name
&& ret
== 0) {
3579 /* Target session found and loaded */
3587 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3589 if (ret
== -LTTNG_ERR_NO_SESSION
) {
3590 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3596 int load_session_from_path(const char *path
, const char *session_name
,
3597 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3598 const struct config_load_session_override_attr
*overrides
)
3600 int ret
, session_found
= !session_name
;
3601 DIR *directory
= NULL
;
3602 struct lttng_dynamic_buffer file_path
;
3606 assert(validation_ctx
);
3607 path_len
= strlen(path
);
3608 lttng_dynamic_buffer_init(&file_path
);
3609 if (path_len
>= LTTNG_PATH_MAX
) {
3610 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3611 path
, path_len
, LTTNG_PATH_MAX
);
3612 ret
= -LTTNG_ERR_INVALID
;
3616 directory
= opendir(path
);
3620 /* Try the file loading. */
3623 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3626 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3631 size_t file_path_root_len
;
3633 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3636 ret
= -LTTNG_ERR_NOMEM
;
3640 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3642 ret
= -LTTNG_ERR_NOMEM
;
3646 if (file_path
.data
[file_path
.size
- 1] != '/') {
3647 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3649 ret
= -LTTNG_ERR_NOMEM
;
3653 file_path_root_len
= file_path
.size
;
3655 /* Search for *.lttng files */
3657 size_t file_name_len
;
3658 struct dirent
*result
;
3661 * When the end of the directory stream is reached, NULL
3662 * is returned and errno is kept unchanged. When an
3663 * error occurs, NULL is returned and errno is set
3664 * accordingly. To distinguish between the two, set
3665 * errno to zero before calling readdir().
3667 * On success, readdir() returns a pointer to a dirent
3668 * structure. This structure may be statically
3669 * allocated, do not attempt to free(3) it.
3672 result
= readdir(directory
);
3674 /* Reached end of dir stream or error out. */
3677 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3678 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3684 file_name_len
= strlen(result
->d_name
);
3686 if (file_name_len
<=
3687 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3691 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3692 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3694 /* +1 to account for NULL terminator. */
3695 file_path
.size
+ file_name_len
+ 1,
3700 /* Does the file end with .lttng? */
3701 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3702 result
->d_name
+ file_name_len
- sizeof(
3703 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3707 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3710 ret
= -LTTNG_ERR_NOMEM
;
3714 ret
= load_session_from_file(file_path
.data
, session_name
,
3715 validation_ctx
, overwrite
, overrides
);
3717 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3721 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3725 * Reset the buffer's size to the location of the
3726 * path's trailing '/'.
3728 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3729 file_path_root_len
);
3731 ret
= -LTTNG_ERR_UNK
;
3736 ret
= load_session_from_file(path
, session_name
,
3737 validation_ctx
, overwrite
, overrides
);
3747 if (closedir(directory
)) {
3751 if (!ret
&& !session_found
) {
3752 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3754 lttng_dynamic_buffer_reset(&file_path
);
3759 * Validate that the given path's credentials and the current process have the
3760 * same UID. If so, return 1 else return 0 if it does NOT match.
3762 static int validate_path_creds(const char *path
)
3764 int ret
, uid
= getuid();
3773 ret
= stat(path
, &buf
);
3775 if (errno
!= ENOENT
) {
3781 if (buf
.st_uid
!= uid
) {
3792 int config_load_session(const char *path
, const char *session_name
,
3793 int overwrite
, unsigned int autoload
,
3794 const struct config_load_session_override_attr
*overrides
)
3797 bool session_loaded
= false;
3798 const char *path_ptr
= NULL
;
3799 struct session_config_validation_ctx validation_ctx
= { 0 };
3801 ret
= init_session_config_validation_ctx(&validation_ctx
);
3807 const char *home_path
;
3808 const char *sys_path
;
3811 home_path
= utils_get_home_dir();
3813 char path
[PATH_MAX
];
3816 * Try user session configuration path. Ignore error here so we can
3817 * continue loading the system wide sessions.
3820 ret
= snprintf(path
, sizeof(path
),
3821 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3822 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3824 PERROR("snprintf session autoload home config path");
3825 ret
= -LTTNG_ERR_INVALID
;
3830 * Credentials are only validated for the autoload in order to
3831 * avoid any user session daemon to try to load kernel sessions
3832 * automatically and failing all the times.
3834 ret
= validate_path_creds(path
);
3839 ret
= snprintf(path
, sizeof(path
),
3840 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3842 PERROR("snprintf session home config path");
3843 ret
= -LTTNG_ERR_INVALID
;
3849 ret
= load_session_from_path(path_ptr
, session_name
,
3850 &validation_ctx
, overwrite
, overrides
);
3851 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3855 * Continue even if the session was found since we have to try
3856 * the system wide sessions.
3858 session_loaded
= true;
3862 /* Reset path pointer for the system wide dir. */
3865 /* Try system wide configuration directory. */
3867 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3868 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3869 ret
= validate_path_creds(sys_path
);
3871 path_ptr
= sys_path
;
3874 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3875 path_ptr
= sys_path
;
3879 ret
= load_session_from_path(path_ptr
, session_name
,
3880 &validation_ctx
, overwrite
, overrides
);
3882 session_loaded
= true;
3888 ret
= access(path
, F_OK
);
3893 ret
= -LTTNG_ERR_INVALID
;
3894 WARN("Session configuration path does not exist.");
3897 ret
= -LTTNG_ERR_EPERM
;
3900 ret
= -LTTNG_ERR_UNK
;
3906 ret
= load_session_from_path(path
, session_name
,
3907 &validation_ctx
, overwrite
, overrides
);
3910 fini_session_config_validation_ctx(&validation_ctx
);
3911 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3913 * Don't report an error if no sessions are found when called
3914 * without a session_name or a search path.
3919 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3920 /* A matching session was found in one of the search paths. */
3927 void __attribute__((destructor
)) session_config_exit(void)