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";
215 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
216 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
217 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
218 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
219 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
220 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
221 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
222 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
223 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
224 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
225 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
226 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
228 /* Deprecated symbols */
229 const char * const config_element_perf
;
231 enum process_event_node_phase
{
236 struct consumer_output
{
243 static int config_entry_handler_filter(struct handler_filter_args
*args
,
244 const char *section
, const char *name
, const char *value
)
247 struct config_entry entry
= { section
, name
, value
};
251 if (!section
|| !name
|| !value
) {
257 if (strcmp(args
->section
, section
)) {
262 ret
= args
->handler(&entry
, args
->user_data
);
268 int config_get_section_entries(const char *override_path
, const char *section
,
269 config_entry_handler_cb handler
, void *user_data
)
273 FILE *config_file
= NULL
;
274 struct handler_filter_args filter
= { section
, handler
, user_data
};
276 /* First, try system-wide conf. file. */
277 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
279 config_file
= fopen(path
, "r");
281 DBG("Loading daemon conf file at %s", path
);
283 * Return value is not very important here since error or not, we
284 * continue and try the next possible conf. file.
286 (void) ini_parse_file(config_file
,
287 (ini_entry_handler
) config_entry_handler_filter
,
292 /* Second is the user local configuration. */
293 path
= utils_get_home_dir();
295 char fullpath
[PATH_MAX
];
297 ret
= snprintf(fullpath
, sizeof(fullpath
),
298 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
300 PERROR("snprintf user conf. path");
304 config_file
= fopen(fullpath
, "r");
306 DBG("Loading daemon user conf file at %s", path
);
308 * Return value is not very important here since error or not, we
309 * continue and try the next possible conf. file.
311 (void) ini_parse_file(config_file
,
312 (ini_entry_handler
) config_entry_handler_filter
,
318 /* Final path is the one that the user might have provided. */
320 config_file
= fopen(override_path
, "r");
322 DBG("Loading daemon command line conf file at %s", override_path
);
323 (void) ini_parse_file(config_file
,
324 (ini_entry_handler
) config_entry_handler_filter
,
328 ERR("Failed to open daemon configuration file at %s",
335 /* Everything went well. */
343 int config_parse_value(const char *value
)
346 char *endptr
, *lower_str
;
356 v
= strtoul(value
, &endptr
, 10);
357 if (endptr
!= value
) {
362 lower_str
= zmalloc(len
+ 1);
369 for (i
= 0; i
< len
; i
++) {
370 lower_str
[i
] = tolower(value
[i
]);
373 if (!strcmp(lower_str
, config_str_yes
) ||
374 !strcmp(lower_str
, config_str_true
) ||
375 !strcmp(lower_str
, config_str_on
)) {
377 } else if (!strcmp(lower_str
, config_str_no
) ||
378 !strcmp(lower_str
, config_str_false
) ||
379 !strcmp(lower_str
, config_str_off
)) {
391 * Returns a xmlChar string which must be released using xmlFree().
393 static xmlChar
*encode_string(const char *in_str
)
395 xmlChar
*out_str
= NULL
;
396 xmlCharEncodingHandlerPtr handler
;
397 int out_len
, ret
, in_len
;
401 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
403 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
407 in_len
= strlen(in_str
);
409 * Add 1 byte for the NULL terminted character. The factor 4 here is
410 * used because UTF-8 characters can take up to 4 bytes.
412 out_len
= (in_len
* 4) + 1;
413 out_str
= xmlMalloc(out_len
);
418 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
425 /* out_len is now the size of out_str */
426 out_str
[out_len
] = '\0';
432 struct config_writer
*config_writer_create(int fd_output
, int indent
)
435 struct config_writer
*writer
;
436 xmlOutputBufferPtr buffer
;
438 writer
= zmalloc(sizeof(struct config_writer
));
440 PERROR("zmalloc config_writer_create");
444 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
449 writer
->writer
= xmlNewTextWriter(buffer
);
450 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
451 config_xml_encoding
, NULL
);
456 ret
= xmlTextWriterSetIndentString(writer
->writer
,
457 BAD_CAST config_xml_indent_string
);
462 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
470 config_writer_destroy(writer
);
475 int config_writer_destroy(struct config_writer
*writer
)
484 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
485 WARN("Could not close XML document");
489 if (writer
->writer
) {
490 xmlFreeTextWriter(writer
->writer
);
499 int config_writer_open_element(struct config_writer
*writer
,
500 const char *element_name
)
503 xmlChar
*encoded_element_name
;
505 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
510 encoded_element_name
= encode_string(element_name
);
511 if (!encoded_element_name
) {
516 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
517 xmlFree(encoded_element_name
);
519 return ret
>= 0 ? 0 : ret
;
523 int config_writer_write_attribute(struct config_writer
*writer
,
524 const char *name
, const char *value
)
527 xmlChar
*encoded_name
= NULL
;
528 xmlChar
*encoded_value
= NULL
;
530 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
535 encoded_name
= encode_string(name
);
541 encoded_value
= encode_string(value
);
542 if (!encoded_value
) {
547 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
550 xmlFree(encoded_name
);
551 xmlFree(encoded_value
);
552 return ret
>= 0 ? 0 : ret
;
556 int config_writer_close_element(struct config_writer
*writer
)
560 if (!writer
|| !writer
->writer
) {
565 ret
= xmlTextWriterEndElement(writer
->writer
);
567 return ret
>= 0 ? 0 : ret
;
571 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
572 const char *element_name
, uint64_t value
)
575 xmlChar
*encoded_element_name
;
577 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
582 encoded_element_name
= encode_string(element_name
);
583 if (!encoded_element_name
) {
588 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
589 encoded_element_name
, "%" PRIu64
, value
);
590 xmlFree(encoded_element_name
);
592 return ret
>= 0 ? 0 : ret
;
596 int config_writer_write_element_signed_int(struct config_writer
*writer
,
597 const char *element_name
, int64_t value
)
600 xmlChar
*encoded_element_name
;
602 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
607 encoded_element_name
= encode_string(element_name
);
608 if (!encoded_element_name
) {
613 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
614 encoded_element_name
, "%" PRIi64
, value
);
615 xmlFree(encoded_element_name
);
617 return ret
>= 0 ? 0 : ret
;
621 int config_writer_write_element_bool(struct config_writer
*writer
,
622 const char *element_name
, int value
)
624 return config_writer_write_element_string(writer
, element_name
,
625 value
? config_xml_true
: config_xml_false
);
629 int config_writer_write_element_string(struct config_writer
*writer
,
630 const char *element_name
, const char *value
)
633 xmlChar
*encoded_element_name
= NULL
;
634 xmlChar
*encoded_value
= NULL
;
636 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
642 encoded_element_name
= encode_string(element_name
);
643 if (!encoded_element_name
) {
648 encoded_value
= encode_string(value
);
649 if (!encoded_value
) {
654 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
657 xmlFree(encoded_element_name
);
658 xmlFree(encoded_value
);
659 return ret
>= 0 ? 0 : ret
;
663 void xml_error_handler(void *ctx
, const char *format
, ...)
669 va_start(args
, format
);
670 ret
= vasprintf(&errMsg
, format
, args
);
673 ERR("String allocation failed in xml error handler");
677 fprintf(stderr
, "XML Error: %s", errMsg
);
682 void fini_session_config_validation_ctx(
683 struct session_config_validation_ctx
*ctx
)
685 if (ctx
->parser_ctx
) {
686 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
690 xmlSchemaFree(ctx
->schema
);
693 if (ctx
->schema_validation_ctx
) {
694 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
697 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
701 char *get_session_config_xsd_path()
704 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
705 size_t base_path_len
;
709 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
712 base_path_len
= strlen(base_path
);
713 max_path_len
= base_path_len
+
714 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
715 xsd_path
= zmalloc(max_path_len
);
720 strcpy(xsd_path
, base_path
);
721 if (xsd_path
[base_path_len
- 1] != '/') {
722 xsd_path
[base_path_len
++] = '/';
725 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
731 int init_session_config_validation_ctx(
732 struct session_config_validation_ctx
*ctx
)
735 char *xsd_path
= get_session_config_xsd_path();
738 ret
= -LTTNG_ERR_NOMEM
;
742 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
743 if (!ctx
->parser_ctx
) {
744 ERR("XSD parser context creation failed");
745 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
748 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
749 xml_error_handler
, NULL
);
751 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
753 ERR("XSD parsing failed");
754 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
758 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
759 if (!ctx
->schema_validation_ctx
) {
760 ERR("XSD validation context creation failed");
761 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
765 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
766 xml_error_handler
, NULL
);
771 fini_session_config_validation_ctx(ctx
);
779 int parse_uint(xmlChar
*str
, uint64_t *val
)
789 *val
= strtoull((const char *) str
, &endptr
, 10);
790 if (!endptr
|| *endptr
) {
801 int parse_int(xmlChar
*str
, int64_t *val
)
811 *val
= strtoll((const char *) str
, &endptr
, 10);
812 if (!endptr
|| *endptr
) {
823 int parse_bool(xmlChar
*str
, int *val
)
832 if (!strcmp((const char *) str
, config_xml_true
)) {
834 } else if (!strcmp((const char *) str
, config_xml_false
)) {
837 WARN("Invalid boolean value encoutered (%s).",
846 int get_domain_type(xmlChar
*domain
)
854 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
855 ret
= LTTNG_DOMAIN_KERNEL
;
856 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
857 ret
= LTTNG_DOMAIN_UST
;
858 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
859 ret
= LTTNG_DOMAIN_JUL
;
860 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
861 ret
= LTTNG_DOMAIN_LOG4J
;
862 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
863 ret
= LTTNG_DOMAIN_PYTHON
;
874 int get_buffer_type(xmlChar
*buffer_type
)
882 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
883 ret
= LTTNG_BUFFER_GLOBAL
;
884 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
885 ret
= LTTNG_BUFFER_PER_UID
;
886 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
887 ret
= LTTNG_BUFFER_PER_PID
;
898 int get_overwrite_mode(xmlChar
*overwrite_mode
)
902 if (!overwrite_mode
) {
906 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
908 } else if (!strcmp((char *) overwrite_mode
,
909 config_overwrite_mode_discard
)) {
921 int get_output_type(xmlChar
*output_type
)
929 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
930 ret
= LTTNG_EVENT_MMAP
;
931 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
932 ret
= LTTNG_EVENT_SPLICE
;
943 int get_event_type(xmlChar
*event_type
)
951 if (!strcmp((char *) event_type
, config_event_type_all
)) {
952 ret
= LTTNG_EVENT_ALL
;
953 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
954 ret
= LTTNG_EVENT_TRACEPOINT
;
955 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
956 ret
= LTTNG_EVENT_PROBE
;
957 } else if (!strcmp((char *) event_type
,
958 config_event_type_userspace_probe
)) {
959 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
960 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
961 ret
= LTTNG_EVENT_FUNCTION
;
962 } else if (!strcmp((char *) event_type
,
963 config_event_type_function_entry
)) {
964 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
965 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
966 ret
= LTTNG_EVENT_NOOP
;
967 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
968 ret
= LTTNG_EVENT_SYSCALL
;
979 int get_loglevel_type(xmlChar
*loglevel_type
)
983 if (!loglevel_type
) {
987 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
988 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
989 } else if (!strcmp((char *) loglevel_type
,
990 config_loglevel_type_range
)) {
991 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
992 } else if (!strcmp((char *) loglevel_type
,
993 config_loglevel_type_single
)) {
994 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1005 * Return the context type or -1 on error.
1008 int get_context_type(xmlChar
*context_type
)
1012 if (!context_type
) {
1016 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1017 ret
= LTTNG_EVENT_CONTEXT_PID
;
1018 } else if (!strcmp((char *) context_type
,
1019 config_event_context_procname
)) {
1020 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1021 } else if (!strcmp((char *) context_type
,
1022 config_event_context_prio
)) {
1023 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1024 } else if (!strcmp((char *) context_type
,
1025 config_event_context_nice
)) {
1026 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1027 } else if (!strcmp((char *) context_type
,
1028 config_event_context_vpid
)) {
1029 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1030 } else if (!strcmp((char *) context_type
,
1031 config_event_context_tid
)) {
1032 ret
= LTTNG_EVENT_CONTEXT_TID
;
1033 } else if (!strcmp((char *) context_type
,
1034 config_event_context_vtid
)) {
1035 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1036 } else if (!strcmp((char *) context_type
,
1037 config_event_context_ppid
)) {
1038 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1039 } else if (!strcmp((char *) context_type
,
1040 config_event_context_vppid
)) {
1041 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1042 } else if (!strcmp((char *) context_type
,
1043 config_event_context_pthread_id
)) {
1044 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1045 } else if (!strcmp((char *) context_type
,
1046 config_event_context_hostname
)) {
1047 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1048 } else if (!strcmp((char *) context_type
,
1049 config_event_context_ip
)) {
1050 ret
= LTTNG_EVENT_CONTEXT_IP
;
1051 } else if (!strcmp((char *) context_type
,
1052 config_event_context_interruptible
)) {
1053 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1054 } else if (!strcmp((char *) context_type
,
1055 config_event_context_preemptible
)) {
1056 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1057 } else if (!strcmp((char *) context_type
,
1058 config_event_context_need_reschedule
)) {
1059 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1060 } else if (!strcmp((char *) context_type
,
1061 config_event_context_migratable
)) {
1062 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1063 } else if (!strcmp((char *) context_type
,
1064 config_event_context_callstack_user
)) {
1065 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1066 } else if (!strcmp((char *) context_type
,
1067 config_event_context_callstack_kernel
)) {
1068 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1069 } else if (!strcmp((char *) context_type
,
1070 config_event_context_cgroup_ns
)) {
1071 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1072 } else if (!strcmp((char *) context_type
,
1073 config_event_context_ipc_ns
)) {
1074 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1075 } else if (!strcmp((char *) context_type
,
1076 config_event_context_mnt_ns
)) {
1077 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1078 } else if (!strcmp((char *) context_type
,
1079 config_event_context_net_ns
)) {
1080 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1081 } else if (!strcmp((char *) context_type
,
1082 config_event_context_pid_ns
)) {
1083 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1084 } else if (!strcmp((char *) context_type
,
1085 config_event_context_user_ns
)) {
1086 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1087 } else if (!strcmp((char *) context_type
,
1088 config_event_context_uts_ns
)) {
1089 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1090 } else if (!strcmp((char *) context_type
,
1091 config_event_context_uid
)) {
1092 ret
= LTTNG_EVENT_CONTEXT_UID
;
1093 } else if (!strcmp((char *) context_type
,
1094 config_event_context_euid
)) {
1095 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1096 } else if (!strcmp((char *) context_type
,
1097 config_event_context_suid
)) {
1098 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1099 } else if (!strcmp((char *) context_type
,
1100 config_event_context_gid
)) {
1101 ret
= LTTNG_EVENT_CONTEXT_GID
;
1102 } else if (!strcmp((char *) context_type
,
1103 config_event_context_egid
)) {
1104 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1105 } else if (!strcmp((char *) context_type
,
1106 config_event_context_sgid
)) {
1107 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1108 } else if (!strcmp((char *) context_type
,
1109 config_event_context_vuid
)) {
1110 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1111 } else if (!strcmp((char *) context_type
,
1112 config_event_context_veuid
)) {
1113 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1114 } else if (!strcmp((char *) context_type
,
1115 config_event_context_vsuid
)) {
1116 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1117 } else if (!strcmp((char *) context_type
,
1118 config_event_context_vgid
)) {
1119 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1120 } else if (!strcmp((char *) context_type
,
1121 config_event_context_vegid
)) {
1122 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1123 } else if (!strcmp((char *) context_type
,
1124 config_event_context_vsgid
)) {
1125 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1136 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1141 for (node
= xmlFirstElementChild(domain_node
); node
;
1142 node
= xmlNextElementSibling(node
)) {
1143 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1145 xmlChar
*node_content
= xmlNodeGetContent(node
);
1146 if (!node_content
) {
1147 ret
= -LTTNG_ERR_NOMEM
;
1151 ret
= get_domain_type(node_content
);
1154 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1159 } else if (!strcmp((const char *) node
->name
,
1160 config_element_buffer_type
)) {
1162 xmlChar
*node_content
= xmlNodeGetContent(node
);
1163 if (!node_content
) {
1164 ret
= -LTTNG_ERR_NOMEM
;
1168 ret
= get_buffer_type(node_content
);
1171 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1175 domain
->buf_type
= ret
;
1184 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1189 for (node
= xmlFirstElementChild(net_output_node
); node
;
1190 node
= xmlNextElementSibling(node
)) {
1191 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1193 *control_uri
= (char *) xmlNodeGetContent(node
);
1194 if (!*control_uri
) {
1199 *data_uri
= (char *) xmlNodeGetContent(node
);
1206 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1210 int process_consumer_output(xmlNodePtr consumer_output_node
,
1211 struct consumer_output
*output
)
1218 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1219 node
= xmlNextElementSibling(node
)) {
1220 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1221 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1225 ret
= -LTTNG_ERR_NOMEM
;
1229 ret
= parse_bool(enabled_str
, &output
->enabled
);
1235 xmlNodePtr output_type_node
;
1238 output_type_node
= xmlFirstElementChild(node
);
1239 if (!output_type_node
) {
1240 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1244 if (!strcmp((const char *) output_type_node
->name
,
1245 config_element_path
)) {
1247 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1248 if (!output
->path
) {
1249 ret
= -LTTNG_ERR_NOMEM
;
1254 ret
= get_net_output_uris(output_type_node
,
1255 &output
->control_uri
, &output
->data_uri
);
1267 free(output
->control_uri
);
1268 free(output
->data_uri
);
1269 memset(output
, 0, sizeof(struct consumer_output
));
1275 int create_session_net_output(const char *name
, const char *control_uri
,
1276 const char *data_uri
)
1279 struct lttng_handle
*handle
;
1280 const char *uri
= NULL
;
1284 handle
= lttng_create_handle(name
, NULL
);
1286 ret
= -LTTNG_ERR_NOMEM
;
1290 if (!control_uri
|| !data_uri
) {
1291 uri
= control_uri
? control_uri
: data_uri
;
1296 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1297 lttng_destroy_handle(handle
);
1303 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1304 const struct config_load_session_override_attr
*overrides
)
1307 xmlNodePtr node
= NULL
;
1308 xmlNodePtr snapshot_output_list_node
;
1309 xmlNodePtr snapshot_output_node
;
1311 assert(session_name
);
1313 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1322 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1324 /* Parse and create snapshot outputs */
1326 for (snapshot_output_node
=
1327 xmlFirstElementChild(snapshot_output_list_node
);
1328 snapshot_output_node
; snapshot_output_node
=
1329 xmlNextElementSibling(snapshot_output_node
)) {
1331 uint64_t max_size
= UINT64_MAX
;
1332 struct consumer_output output
= { 0 };
1333 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1334 const char *control_uri
= NULL
;
1335 const char *data_uri
= NULL
;
1336 const char *path
= NULL
;
1338 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1339 node
= xmlNextElementSibling(node
)) {
1340 if (!strcmp((const char *) node
->name
,
1341 config_element_name
)) {
1343 name
= (char *) xmlNodeGetContent(node
);
1345 ret
= -LTTNG_ERR_NOMEM
;
1346 goto error_snapshot_output
;
1348 } else if (!strcmp((const char *) node
->name
,
1349 config_element_max_size
)) {
1350 xmlChar
*content
= xmlNodeGetContent(node
);
1354 ret
= -LTTNG_ERR_NOMEM
;
1355 goto error_snapshot_output
;
1357 ret
= parse_uint(content
, &max_size
);
1360 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1361 goto error_snapshot_output
;
1364 /* consumer_output */
1365 ret
= process_consumer_output(node
, &output
);
1367 goto error_snapshot_output
;
1372 control_uri
= output
.control_uri
;
1373 data_uri
= output
.data_uri
;
1377 if (overrides
->path_url
) {
1378 path
= overrides
->path_url
;
1379 /* Control/data_uri are null */
1383 if (overrides
->ctrl_url
) {
1384 control_uri
= overrides
->ctrl_url
;
1388 if (overrides
->data_url
) {
1389 data_uri
= overrides
->data_url
;
1396 snapshot_output
= lttng_snapshot_output_create();
1397 if (!snapshot_output
) {
1398 ret
= -LTTNG_ERR_NOMEM
;
1399 goto error_snapshot_output
;
1402 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1404 goto error_snapshot_output
;
1407 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1409 goto error_snapshot_output
;
1413 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1416 goto error_snapshot_output
;
1420 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1423 goto error_snapshot_output
;
1428 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1431 goto error_snapshot_output
;
1436 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1437 error_snapshot_output
:
1440 free(output
.control_uri
);
1441 free(output
.data_uri
);
1442 lttng_snapshot_output_destroy(snapshot_output
);
1452 int create_session(const char *name
,
1453 xmlNodePtr output_node
,
1454 uint64_t live_timer_interval
,
1455 const struct config_load_session_override_attr
*overrides
)
1458 struct consumer_output output
= { 0 };
1459 xmlNodePtr consumer_output_node
;
1460 const char *control_uri
= NULL
;
1461 const char *data_uri
= NULL
;
1462 const char *path
= NULL
;
1467 consumer_output_node
= xmlFirstElementChild(output_node
);
1468 if (!consumer_output_node
) {
1469 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1473 if (strcmp((const char *) consumer_output_node
->name
,
1474 config_element_consumer_output
)) {
1475 WARN("Invalid output type, expected %s node",
1476 config_element_consumer_output
);
1477 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1481 ret
= process_consumer_output(consumer_output_node
, &output
);
1487 control_uri
= output
.control_uri
;
1488 data_uri
= output
.data_uri
;
1491 /* Check for override and apply them */
1493 if (overrides
->path_url
) {
1494 path
= overrides
->path_url
;
1495 /* control/data_uri are null */;
1499 if (overrides
->ctrl_url
) {
1500 control_uri
= overrides
->ctrl_url
;
1504 if (overrides
->data_url
) {
1505 data_uri
= overrides
->data_url
;
1513 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1514 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1518 if (control_uri
|| data_uri
) {
1519 /* network destination */
1520 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1522 * URLs are provided for sure since the test above make sure that
1523 * with a live timer the data and control URIs are provided. So,
1524 * NULL is passed here and will be set right after.
1526 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1528 ret
= lttng_create_session(name
, NULL
);
1534 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1540 /* either local output or no output */
1541 ret
= lttng_create_session(name
, path
);
1548 free(output
.control_uri
);
1549 free(output
.data_uri
);
1554 struct lttng_userspace_probe_location
*
1555 process_userspace_probe_function_attribute_node(
1556 xmlNodePtr attribute_node
)
1558 xmlNodePtr function_attribute_node
;
1559 char *function_name
= NULL
, *binary_path
= NULL
;
1560 struct lttng_userspace_probe_location
*location
= NULL
;
1561 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1564 * Process userspace probe location function attributes. The order of
1565 * the fields are not guaranteed so we need to iterate over all fields
1566 * and check at the end if everything we need for this location type is
1569 for (function_attribute_node
=
1570 xmlFirstElementChild(attribute_node
);
1571 function_attribute_node
;
1572 function_attribute_node
= xmlNextElementSibling(
1573 function_attribute_node
)) {
1574 /* Handle function name, binary path and lookup method. */
1575 if (!strcmp((const char *) function_attribute_node
->name
,
1576 config_element_userspace_probe_function_location_function_name
)) {
1577 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1578 if (!function_name
) {
1581 } else if (!strcmp((const char *) function_attribute_node
->name
,
1582 config_element_userspace_probe_location_binary_path
)) {
1583 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1587 } else if (!strcmp((const char *) function_attribute_node
->name
,
1588 config_element_userspace_probe_lookup
)) {
1589 char *lookup_method_name
;
1591 lookup_method_name
= (char *) xmlNodeGetContent(
1592 function_attribute_node
);
1593 if (!lookup_method_name
) {
1598 * function_default lookup method defaults to
1599 * function_elf lookup method at the moment.
1601 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1602 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1603 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1604 if (!lookup_method
) {
1605 PERROR("Error creating function default/ELF lookup method");
1608 WARN("Unknown function lookup method");
1611 free(lookup_method_name
);
1612 if (!lookup_method
) {
1619 /* Check if all the necessary fields were found. */
1620 if (binary_path
&& function_name
&& lookup_method
) {
1621 /* Ownership of lookup_method is transferred. */
1623 lttng_userspace_probe_location_function_create(
1624 binary_path
, function_name
,
1626 lookup_method
= NULL
;
1631 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1633 free(function_name
);
1638 struct lttng_userspace_probe_location
*
1639 process_userspace_probe_tracepoint_attribute_node(
1640 xmlNodePtr attribute_node
)
1642 xmlNodePtr tracepoint_attribute_node
;
1643 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1644 struct lttng_userspace_probe_location
*location
= NULL
;
1645 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1648 * Process userspace probe location tracepoint attributes. The order of
1649 * the fields are not guaranteed so we need to iterate over all fields
1650 * and check at the end if everything we need for this location type is
1653 for (tracepoint_attribute_node
=
1654 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1655 tracepoint_attribute_node
= xmlNextElementSibling(
1656 tracepoint_attribute_node
)) {
1657 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1658 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1659 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1663 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1664 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1665 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1666 if (!provider_name
) {
1669 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1670 config_element_userspace_probe_location_binary_path
)) {
1671 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1675 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1676 config_element_userspace_probe_lookup
)) {
1677 char *lookup_method_name
;
1679 lookup_method_name
= (char *) xmlNodeGetContent(
1680 tracepoint_attribute_node
);
1681 if (!lookup_method_name
) {
1685 if (!strcmp(lookup_method_name
,
1686 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1688 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1689 if (!lookup_method
) {
1690 PERROR("Error creating tracepoint SDT lookup method");
1693 WARN("Unknown tracepoint lookup method");
1696 free(lookup_method_name
);
1697 if (!lookup_method
) {
1701 WARN("Unknown tracepoint attribute");
1705 /* Check if all the necessary fields were found. */
1706 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1707 /* Ownership of lookup_method is transferred. */
1709 lttng_userspace_probe_location_tracepoint_create(
1710 binary_path
, provider_name
,
1711 probe_name
, lookup_method
);
1712 lookup_method
= NULL
;
1717 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1719 free(provider_name
);
1725 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1726 struct lttng_event_probe_attr
*attr
)
1730 assert(probe_attribute_node
);
1733 if (!strcmp((const char *) probe_attribute_node
->name
,
1734 config_element_address
)) {
1739 content
= xmlNodeGetContent(probe_attribute_node
);
1741 ret
= -LTTNG_ERR_NOMEM
;
1745 ret
= parse_uint(content
, &addr
);
1748 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1753 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1754 config_element_offset
)) {
1756 uint64_t offset
= 0;
1759 content
= xmlNodeGetContent(probe_attribute_node
);
1761 ret
= -LTTNG_ERR_NOMEM
;
1765 ret
= parse_uint(content
, &offset
);
1768 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1772 attr
->offset
= offset
;
1773 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1774 config_element_symbol_name
)) {
1778 content
= xmlNodeGetContent(probe_attribute_node
);
1780 ret
= -LTTNG_ERR_NOMEM
;
1784 ret
= lttng_strncpy(attr
->symbol_name
,
1785 (const char *) content
,
1786 LTTNG_SYMBOL_NAME_LEN
);
1788 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1789 (const char *) content
,
1790 strlen((const char *) content
),
1791 LTTNG_SYMBOL_NAME_LEN
);
1792 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1804 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1805 const char *channel_name
, const enum process_event_node_phase phase
)
1809 struct lttng_event
*event
;
1810 char **exclusions
= NULL
;
1811 unsigned long exclusion_count
= 0;
1812 char *filter_expression
= NULL
;
1816 assert(channel_name
);
1818 event
= lttng_event_create();
1820 ret
= -LTTNG_ERR_NOMEM
;
1824 /* Initialize default log level which varies by domain */
1825 switch (handle
->domain
.type
)
1827 case LTTNG_DOMAIN_JUL
:
1828 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1830 case LTTNG_DOMAIN_LOG4J
:
1831 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1833 case LTTNG_DOMAIN_PYTHON
:
1834 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1836 case LTTNG_DOMAIN_UST
:
1837 case LTTNG_DOMAIN_KERNEL
:
1838 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1844 for (node
= xmlFirstElementChild(event_node
); node
;
1845 node
= xmlNextElementSibling(node
)) {
1846 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1850 content
= xmlNodeGetContent(node
);
1852 ret
= -LTTNG_ERR_NOMEM
;
1856 ret
= lttng_strncpy(event
->name
,
1857 (const char *) content
,
1858 LTTNG_SYMBOL_NAME_LEN
);
1860 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1861 (const char *) content
,
1862 strlen((const char *) content
),
1863 LTTNG_SYMBOL_NAME_LEN
);
1864 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1869 } else if (!strcmp((const char *) node
->name
,
1870 config_element_enabled
)) {
1871 xmlChar
*content
= xmlNodeGetContent(node
);
1875 ret
= -LTTNG_ERR_NOMEM
;
1879 ret
= parse_bool(content
, &event
->enabled
);
1882 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1885 } else if (!strcmp((const char *) node
->name
,
1886 config_element_type
)) {
1887 xmlChar
*content
= xmlNodeGetContent(node
);
1891 ret
= -LTTNG_ERR_NOMEM
;
1895 ret
= get_event_type(content
);
1898 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1903 } else if (!strcmp((const char *) node
->name
,
1904 config_element_loglevel_type
)) {
1905 xmlChar
*content
= xmlNodeGetContent(node
);
1909 ret
= -LTTNG_ERR_NOMEM
;
1913 ret
= get_loglevel_type(content
);
1916 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1920 event
->loglevel_type
= ret
;
1921 } else if (!strcmp((const char *) node
->name
,
1922 config_element_loglevel
)) {
1924 int64_t loglevel
= 0;
1927 content
= xmlNodeGetContent(node
);
1929 ret
= -LTTNG_ERR_NOMEM
;
1933 ret
= parse_int(content
, &loglevel
);
1936 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1940 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1941 WARN("loglevel out of range.");
1942 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1946 event
->loglevel
= loglevel
;
1947 } else if (!strcmp((const char *) node
->name
,
1948 config_element_filter
)) {
1950 xmlNodeGetContent(node
);
1954 ret
= -LTTNG_ERR_NOMEM
;
1958 free(filter_expression
);
1959 filter_expression
= strdup((char *) content
);
1961 if (!filter_expression
) {
1962 ret
= -LTTNG_ERR_NOMEM
;
1965 } else if (!strcmp((const char *) node
->name
,
1966 config_element_exclusions
)) {
1967 xmlNodePtr exclusion_node
;
1968 int exclusion_index
= 0;
1973 * Exclusions has already been initialized,
1976 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1980 exclusion_count
= xmlChildElementCount(node
);
1981 if (!exclusion_count
) {
1985 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1987 exclusion_count
= 0;
1988 ret
= -LTTNG_ERR_NOMEM
;
1992 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1993 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1995 xmlNodeGetContent(exclusion_node
);
1998 ret
= -LTTNG_ERR_NOMEM
;
2002 exclusions
[exclusion_index
] = strdup((const char *) content
);
2004 if (!exclusions
[exclusion_index
]) {
2005 ret
= -LTTNG_ERR_NOMEM
;
2011 event
->exclusion
= 1;
2012 } else if (!strcmp((const char *) node
->name
,
2013 config_element_attributes
)) {
2014 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2017 if (!attribute_node
) {
2018 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2022 if (!strcmp((const char *) attribute_node
->name
,
2023 config_element_probe_attributes
)) {
2024 xmlNodePtr probe_attribute_node
;
2026 /* probe_attributes */
2027 for (probe_attribute_node
=
2028 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2029 probe_attribute_node
= xmlNextElementSibling(
2030 probe_attribute_node
)) {
2032 ret
= process_probe_attribute_node(probe_attribute_node
,
2033 &event
->attr
.probe
);
2038 } else if (!strcmp((const char *) attribute_node
->name
,
2039 config_element_function_attributes
)) {
2042 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2044 /* function_attributes */
2045 content
= xmlNodeGetContent(symbol_node
);
2047 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2051 sym_len
= strlen((char *) content
);
2052 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2053 WARN("Function name too long.");
2054 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2059 ret
= lttng_strncpy(
2060 event
->attr
.ftrace
.symbol_name
,
2061 (char *) content
, sym_len
);
2063 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2068 } else if (!strcmp((const char *) attribute_node
->name
,
2069 config_element_userspace_probe_tracepoint_attributes
)) {
2070 struct lttng_userspace_probe_location
*location
;
2072 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2074 WARN("Error processing userspace probe tracepoint attribute");
2075 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2078 ret
= lttng_event_set_userspace_probe_location(
2081 WARN("Error setting userspace probe location field");
2082 lttng_userspace_probe_location_destroy(
2084 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2087 } else if (!strcmp((const char *) attribute_node
->name
,
2088 config_element_userspace_probe_function_attributes
)) {
2089 struct lttng_userspace_probe_location
*location
;
2092 process_userspace_probe_function_attribute_node(
2095 WARN("Error processing userspace probe function attribute");
2096 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2100 ret
= lttng_event_set_userspace_probe_location(
2103 WARN("Error setting userspace probe location field");
2104 lttng_userspace_probe_location_destroy(
2106 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2110 /* Unknown event attribute. */
2111 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2117 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2118 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2119 filter_expression
, exclusion_count
, exclusions
);
2121 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2122 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2128 for (i
= 0; i
< exclusion_count
; i
++) {
2129 free(exclusions
[i
]);
2132 lttng_event_destroy(event
);
2134 free(filter_expression
);
2139 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2140 const char *channel_name
)
2143 struct lttng_event event
;
2146 assert(events_node
);
2148 assert(channel_name
);
2150 for (node
= xmlFirstElementChild(events_node
); node
;
2151 node
= xmlNextElementSibling(node
)) {
2152 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2159 * Disable all events to enable only the necessary events.
2160 * Limitations regarding lttng_disable_events and tuple descriptor
2161 * force this approach.
2163 memset(&event
, 0, sizeof(event
));
2164 event
.loglevel
= -1;
2165 event
.type
= LTTNG_EVENT_ALL
;
2166 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2171 for (node
= xmlFirstElementChild(events_node
); node
;
2172 node
= xmlNextElementSibling(node
)) {
2173 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2184 int process_channel_attr_node(xmlNodePtr attr_node
,
2185 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2186 xmlNodePtr
*events_node
)
2192 assert(contexts_node
);
2193 assert(events_node
);
2195 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2199 content
= xmlNodeGetContent(attr_node
);
2201 ret
= -LTTNG_ERR_NOMEM
;
2205 ret
= lttng_strncpy(channel
->name
,
2206 (const char *) content
,
2207 LTTNG_SYMBOL_NAME_LEN
);
2209 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2210 (const char *) content
,
2211 strlen((const char *) content
),
2212 LTTNG_SYMBOL_NAME_LEN
);
2213 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2218 } else if (!strcmp((const char *) attr_node
->name
,
2219 config_element_enabled
)) {
2224 content
= xmlNodeGetContent(attr_node
);
2226 ret
= -LTTNG_ERR_NOMEM
;
2230 ret
= parse_bool(content
, &enabled
);
2233 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2237 channel
->enabled
= enabled
;
2238 } else if (!strcmp((const char *) attr_node
->name
,
2239 config_element_overwrite_mode
)) {
2242 /* overwrite_mode */
2243 content
= xmlNodeGetContent(attr_node
);
2245 ret
= -LTTNG_ERR_NOMEM
;
2249 ret
= get_overwrite_mode(content
);
2252 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2256 channel
->attr
.overwrite
= ret
;
2257 } else if (!strcmp((const char *) attr_node
->name
,
2258 config_element_subbuf_size
)) {
2261 /* subbuffer_size */
2262 content
= xmlNodeGetContent(attr_node
);
2264 ret
= -LTTNG_ERR_NOMEM
;
2268 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2271 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2274 } else if (!strcmp((const char *) attr_node
->name
,
2275 config_element_num_subbuf
)) {
2278 /* subbuffer_count */
2279 content
= xmlNodeGetContent(attr_node
);
2281 ret
= -LTTNG_ERR_NOMEM
;
2285 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2288 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2291 } else if (!strcmp((const char *) attr_node
->name
,
2292 config_element_switch_timer_interval
)) {
2294 uint64_t switch_timer_interval
= 0;
2296 /* switch_timer_interval */
2297 content
= xmlNodeGetContent(attr_node
);
2299 ret
= -LTTNG_ERR_NOMEM
;
2303 ret
= parse_uint(content
, &switch_timer_interval
);
2306 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2310 if (switch_timer_interval
> UINT_MAX
) {
2311 WARN("switch_timer_interval out of range.");
2312 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2316 channel
->attr
.switch_timer_interval
=
2317 switch_timer_interval
;
2318 } else if (!strcmp((const char *) attr_node
->name
,
2319 config_element_read_timer_interval
)) {
2321 uint64_t read_timer_interval
= 0;
2323 /* read_timer_interval */
2324 content
= xmlNodeGetContent(attr_node
);
2326 ret
= -LTTNG_ERR_NOMEM
;
2330 ret
= parse_uint(content
, &read_timer_interval
);
2333 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2337 if (read_timer_interval
> UINT_MAX
) {
2338 WARN("read_timer_interval out of range.");
2339 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2343 channel
->attr
.read_timer_interval
=
2344 read_timer_interval
;
2345 } else if (!strcmp((const char *) attr_node
->name
,
2346 config_element_output_type
)) {
2350 content
= xmlNodeGetContent(attr_node
);
2352 ret
= -LTTNG_ERR_NOMEM
;
2356 ret
= get_output_type(content
);
2359 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2363 channel
->attr
.output
= ret
;
2364 } else if (!strcmp((const char *) attr_node
->name
,
2365 config_element_tracefile_size
)) {
2368 /* tracefile_size */
2369 content
= xmlNodeGetContent(attr_node
);
2371 ret
= -LTTNG_ERR_NOMEM
;
2375 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2381 } else if (!strcmp((const char *) attr_node
->name
,
2382 config_element_tracefile_count
)) {
2385 /* tracefile_count */
2386 content
= xmlNodeGetContent(attr_node
);
2388 ret
= -LTTNG_ERR_NOMEM
;
2392 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2395 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2398 } else if (!strcmp((const char *) attr_node
->name
,
2399 config_element_live_timer_interval
)) {
2401 uint64_t live_timer_interval
= 0;
2403 /* live_timer_interval */
2404 content
= xmlNodeGetContent(attr_node
);
2406 ret
= -LTTNG_ERR_NOMEM
;
2410 ret
= parse_uint(content
, &live_timer_interval
);
2413 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2417 if (live_timer_interval
> UINT_MAX
) {
2418 WARN("live_timer_interval out of range.");
2419 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2423 channel
->attr
.live_timer_interval
=
2424 live_timer_interval
;
2425 } else if (!strcmp((const char *) attr_node
->name
,
2426 config_element_monitor_timer_interval
)) {
2428 uint64_t monitor_timer_interval
= 0;
2430 /* monitor_timer_interval */
2431 content
= xmlNodeGetContent(attr_node
);
2433 ret
= -LTTNG_ERR_NOMEM
;
2437 ret
= parse_uint(content
, &monitor_timer_interval
);
2440 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2444 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2445 monitor_timer_interval
);
2447 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2450 } else if (!strcmp((const char *) attr_node
->name
,
2451 config_element_blocking_timeout
)) {
2453 int64_t blocking_timeout
= 0;
2455 /* blocking_timeout */
2456 content
= xmlNodeGetContent(attr_node
);
2458 ret
= -LTTNG_ERR_NOMEM
;
2462 ret
= parse_int(content
, &blocking_timeout
);
2465 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2469 ret
= lttng_channel_set_blocking_timeout(channel
,
2472 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2475 } else if (!strcmp((const char *) attr_node
->name
,
2476 config_element_events
)) {
2478 *events_node
= attr_node
;
2481 *contexts_node
= attr_node
;
2489 int process_context_node(xmlNodePtr context_node
,
2490 struct lttng_handle
*handle
, const char *channel_name
)
2493 struct lttng_event_context context
;
2494 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2497 assert(channel_name
);
2499 if (!context_child_node
) {
2500 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2504 memset(&context
, 0, sizeof(context
));
2506 if (!strcmp((const char *) context_child_node
->name
,
2507 config_element_type
)) {
2509 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2512 ret
= -LTTNG_ERR_NOMEM
;
2516 ret
= get_context_type(content
);
2519 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2524 } else if (!strcmp((const char *) context_child_node
->name
,
2525 config_element_context_perf
)) {
2527 xmlNodePtr perf_attr_node
;
2529 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2530 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2531 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2532 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2533 perf_attr_node
; perf_attr_node
=
2534 xmlNextElementSibling(perf_attr_node
)) {
2535 if (!strcmp((const char *) perf_attr_node
->name
,
2536 config_element_type
)) {
2541 content
= xmlNodeGetContent(perf_attr_node
);
2543 ret
= -LTTNG_ERR_NOMEM
;
2547 ret
= parse_uint(content
, &type
);
2550 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2554 if (type
> UINT32_MAX
) {
2555 WARN("perf context type out of range.");
2556 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2560 context
.u
.perf_counter
.type
= type
;
2561 } else if (!strcmp((const char *) perf_attr_node
->name
,
2562 config_element_config
)) {
2564 uint64_t config
= 0;
2567 content
= xmlNodeGetContent(perf_attr_node
);
2569 ret
= -LTTNG_ERR_NOMEM
;
2573 ret
= parse_uint(content
, &config
);
2576 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2580 context
.u
.perf_counter
.config
= config
;
2581 } else if (!strcmp((const char *) perf_attr_node
->name
,
2582 config_element_name
)) {
2586 content
= xmlNodeGetContent(perf_attr_node
);
2588 ret
= -LTTNG_ERR_NOMEM
;
2592 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2593 (const char *) content
,
2594 LTTNG_SYMBOL_NAME_LEN
);
2596 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2597 (const char *) content
,
2598 strlen((const char *) content
),
2599 LTTNG_SYMBOL_NAME_LEN
);
2600 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2607 } else if (!strcmp((const char *) context_child_node
->name
,
2608 config_element_context_app
)) {
2609 /* application context */
2610 xmlNodePtr app_ctx_node
;
2612 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2613 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2614 app_ctx_node
; app_ctx_node
=
2615 xmlNextElementSibling(app_ctx_node
)) {
2617 char **target
= strcmp(
2618 (const char *) app_ctx_node
->name
,
2619 config_element_context_app_provider_name
) == 0 ?
2620 &context
.u
.app_ctx
.provider_name
:
2621 &context
.u
.app_ctx
.ctx_name
;
2623 content
= xmlNodeGetContent(app_ctx_node
);
2625 ret
= -LTTNG_ERR_NOMEM
;
2629 *target
= (char *) content
;
2632 /* Unrecognized context type */
2633 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2637 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2638 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2639 free(context
.u
.app_ctx
.provider_name
);
2640 free(context
.u
.app_ctx
.ctx_name
);
2647 int process_contexts_node(xmlNodePtr contexts_node
,
2648 struct lttng_handle
*handle
, const char *channel_name
)
2651 xmlNodePtr context_node
;
2653 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2654 context_node
= xmlNextElementSibling(context_node
)) {
2655 ret
= process_context_node(context_node
, handle
, channel_name
);
2665 int process_pid_tracker_node(xmlNodePtr pid_tracker_node
,
2666 struct lttng_handle
*handle
)
2669 xmlNodePtr targets_node
= NULL
;
2673 assert(pid_tracker_node
);
2674 /* get the targets node */
2675 for (node
= xmlFirstElementChild(pid_tracker_node
); node
;
2676 node
= xmlNextElementSibling(node
)) {
2677 if (!strcmp((const char *) node
->name
,
2678 config_element_targets
)) {
2679 targets_node
= node
;
2684 if (!targets_node
) {
2685 ret
= LTTNG_ERR_INVALID
;
2689 /* Go through all pid_target node */
2690 child
= xmlChildElementCount(targets_node
);
2692 /* The session is explicitly set to target nothing. */
2693 ret
= lttng_untrack_pid(handle
, -1);
2698 for (node
= xmlFirstElementChild(targets_node
); node
;
2699 node
= xmlNextElementSibling(node
)) {
2700 xmlNodePtr pid_target_node
= node
;
2702 /* get pid node and track it */
2703 for (node
= xmlFirstElementChild(pid_target_node
); node
;
2704 node
= xmlNextElementSibling(node
)) {
2705 if (!strcmp((const char *) node
->name
,
2706 config_element_pid
)) {
2708 xmlChar
*content
= NULL
;
2710 content
= xmlNodeGetContent(node
);
2712 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2716 ret
= parse_int(content
, &pid
);
2719 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2723 ret
= lttng_track_pid(handle
, (int) pid
);
2729 node
= pid_target_node
;
2737 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2740 struct lttng_domain domain
= { 0 };
2741 struct lttng_handle
*handle
= NULL
;
2742 struct lttng_channel
*channel
= NULL
;
2743 xmlNodePtr channels_node
= NULL
;
2744 xmlNodePtr trackers_node
= NULL
;
2745 xmlNodePtr pid_tracker_node
= NULL
;
2748 assert(session_name
);
2750 ret
= init_domain(domain_node
, &domain
);
2755 handle
= lttng_create_handle(session_name
, &domain
);
2757 ret
= -LTTNG_ERR_NOMEM
;
2761 /* get the channels node */
2762 for (node
= xmlFirstElementChild(domain_node
); node
;
2763 node
= xmlNextElementSibling(node
)) {
2764 if (!strcmp((const char *) node
->name
,
2765 config_element_channels
)) {
2766 channels_node
= node
;
2771 if (!channels_node
) {
2775 /* create all channels */
2776 for (node
= xmlFirstElementChild(channels_node
); node
;
2777 node
= xmlNextElementSibling(node
)) {
2778 const enum lttng_domain_type original_domain
= domain
.type
;
2779 xmlNodePtr contexts_node
= NULL
;
2780 xmlNodePtr events_node
= NULL
;
2781 xmlNodePtr channel_attr_node
;
2784 * Channels of the "agent" types cannot be created directly.
2785 * They are meant to be created implicitly through the
2786 * activation of events in their domain. However, a user
2787 * can override the default channel configuration attributes
2788 * by creating the underlying UST channel _before_ enabling
2789 * an agent domain event.
2791 * Hence, the channel's type is substituted before the creation
2792 * and restored by the time the events are created.
2794 switch (domain
.type
) {
2795 case LTTNG_DOMAIN_JUL
:
2796 case LTTNG_DOMAIN_LOG4J
:
2797 case LTTNG_DOMAIN_PYTHON
:
2798 domain
.type
= LTTNG_DOMAIN_UST
;
2803 channel
= lttng_channel_create(&domain
);
2809 for (channel_attr_node
= xmlFirstElementChild(node
);
2810 channel_attr_node
; channel_attr_node
=
2811 xmlNextElementSibling(channel_attr_node
)) {
2812 ret
= process_channel_attr_node(channel_attr_node
,
2813 channel
, &contexts_node
, &events_node
);
2819 ret
= lttng_enable_channel(handle
, channel
);
2824 /* Restore the original channel domain. */
2825 domain
.type
= original_domain
;
2827 ret
= process_events_node(events_node
, handle
, channel
->name
);
2832 ret
= process_contexts_node(contexts_node
, handle
,
2838 lttng_channel_destroy(channel
);
2842 /* get the trackers node */
2843 for (node
= xmlFirstElementChild(domain_node
); node
;
2844 node
= xmlNextElementSibling(node
)) {
2845 if (!strcmp((const char *) node
->name
,
2846 config_element_trackers
)) {
2847 trackers_node
= node
;
2852 if (!trackers_node
) {
2856 for (node
= xmlFirstElementChild(trackers_node
); node
;
2857 node
= xmlNextElementSibling(node
)) {
2858 if (!strcmp((const char *)node
->name
,config_element_pid_tracker
)) {
2859 pid_tracker_node
= node
;
2860 ret
= process_pid_tracker_node(pid_tracker_node
, handle
);
2867 if (!pid_tracker_node
) {
2868 lttng_track_pid(handle
, -1);
2872 lttng_channel_destroy(channel
);
2873 lttng_destroy_handle(handle
);
2878 int add_periodic_rotation(const char *name
, uint64_t time_us
)
2881 enum lttng_rotation_status status
;
2882 struct lttng_rotation_schedule
*periodic
=
2883 lttng_rotation_schedule_periodic_create();
2886 ret
= -LTTNG_ERR_NOMEM
;
2890 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
2892 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2893 ret
= -LTTNG_ERR_INVALID
;
2897 status
= lttng_session_add_rotation_schedule(name
, periodic
);
2899 case LTTNG_ROTATION_STATUS_OK
:
2902 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
2903 case LTTNG_ROTATION_STATUS_INVALID
:
2904 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2907 ret
= -LTTNG_ERR_UNK
;
2911 lttng_rotation_schedule_destroy(periodic
);
2916 int add_size_rotation(const char *name
, uint64_t size_bytes
)
2919 enum lttng_rotation_status status
;
2920 struct lttng_rotation_schedule
*size
=
2921 lttng_rotation_schedule_size_threshold_create();
2924 ret
= -LTTNG_ERR_NOMEM
;
2928 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
2930 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2931 ret
= -LTTNG_ERR_INVALID
;
2935 status
= lttng_session_add_rotation_schedule(name
, size
);
2937 case LTTNG_ROTATION_STATUS_OK
:
2940 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
2941 case LTTNG_ROTATION_STATUS_INVALID
:
2942 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2945 ret
= -LTTNG_ERR_UNK
;
2949 lttng_rotation_schedule_destroy(size
);
2954 int process_session_rotation_schedules_node(
2955 xmlNodePtr schedules_node
,
2956 uint64_t *rotation_timer_interval
,
2957 uint64_t *rotation_size
)
2962 for (child
= xmlFirstElementChild(schedules_node
);
2964 child
= xmlNextElementSibling(child
)) {
2965 if (!strcmp((const char *) child
->name
,
2966 config_element_rotation_schedule_periodic
)) {
2968 xmlNodePtr time_us_node
;
2970 /* periodic rotation schedule */
2971 time_us_node
= xmlFirstElementChild(child
);
2972 if (!time_us_node
||
2973 strcmp((const char *) time_us_node
->name
,
2974 config_element_rotation_schedule_periodic_time_us
)) {
2975 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2980 content
= xmlNodeGetContent(time_us_node
);
2982 ret
= -LTTNG_ERR_NOMEM
;
2985 ret
= parse_uint(content
, rotation_timer_interval
);
2988 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2991 } else if (!strcmp((const char *) child
->name
,
2992 config_element_rotation_schedule_size_threshold
)) {
2994 xmlNodePtr bytes_node
;
2996 /* size_threshold rotation schedule */
2997 bytes_node
= xmlFirstElementChild(child
);
2999 strcmp((const char *) bytes_node
->name
,
3000 config_element_rotation_schedule_size_threshold_bytes
)) {
3001 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3006 content
= xmlNodeGetContent(bytes_node
);
3008 ret
= -LTTNG_ERR_NOMEM
;
3011 ret
= parse_uint(content
, rotation_size
);
3014 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3025 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3027 const struct config_load_session_override_attr
*overrides
)
3029 int ret
, started
= -1, snapshot_mode
= -1;
3030 uint64_t live_timer_interval
= UINT64_MAX
,
3031 rotation_timer_interval
= 0,
3033 xmlChar
*name
= NULL
;
3034 xmlChar
*shm_path
= NULL
;
3035 xmlNodePtr domains_node
= NULL
;
3036 xmlNodePtr output_node
= NULL
;
3038 xmlNodePtr attributes_child
;
3039 struct lttng_domain
*kernel_domain
= NULL
;
3040 struct lttng_domain
*ust_domain
= NULL
;
3041 struct lttng_domain
*jul_domain
= NULL
;
3042 struct lttng_domain
*log4j_domain
= NULL
;
3043 struct lttng_domain
*python_domain
= NULL
;
3045 for (node
= xmlFirstElementChild(session_node
); node
;
3046 node
= xmlNextElementSibling(node
)) {
3047 if (!name
&& !strcmp((const char *) node
->name
,
3048 config_element_name
)) {
3050 xmlChar
*node_content
= xmlNodeGetContent(node
);
3051 if (!node_content
) {
3052 ret
= -LTTNG_ERR_NOMEM
;
3056 name
= node_content
;
3057 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3058 config_element_domains
)) {
3060 domains_node
= node
;
3061 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3062 config_element_started
)) {
3064 xmlChar
*node_content
= xmlNodeGetContent(node
);
3065 if (!node_content
) {
3066 ret
= -LTTNG_ERR_NOMEM
;
3070 ret
= parse_bool(node_content
, &started
);
3073 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3076 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3077 config_element_output
)) {
3080 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3081 config_element_shared_memory_path
)) {
3082 /* shared memory path */
3083 xmlChar
*node_content
= xmlNodeGetContent(node
);
3084 if (!node_content
) {
3085 ret
= -LTTNG_ERR_NOMEM
;
3089 shm_path
= node_content
;
3092 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3093 * rotation_timer_interval.
3095 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3096 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3097 if (!strcmp((const char *) attributes_child
->name
,
3098 config_element_snapshot_mode
)) {
3100 xmlChar
*snapshot_mode_content
=
3101 xmlNodeGetContent(attributes_child
);
3102 if (!snapshot_mode_content
) {
3103 ret
= -LTTNG_ERR_NOMEM
;
3107 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3108 free(snapshot_mode_content
);
3110 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3113 } else if (!strcmp((const char *) attributes_child
->name
,
3114 config_element_live_timer_interval
)) {
3115 /* live_timer_interval */
3116 xmlChar
*timer_interval_content
=
3117 xmlNodeGetContent(attributes_child
);
3118 if (!timer_interval_content
) {
3119 ret
= -LTTNG_ERR_NOMEM
;
3123 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3124 free(timer_interval_content
);
3126 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3129 } else if (!strcmp((const char *) attributes_child
->name
,
3130 config_element_rotation_schedules
)) {
3131 ret
= process_session_rotation_schedules_node(
3133 &rotation_timer_interval
,
3136 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3146 /* Mandatory attribute, as defined in the session XSD */
3147 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3151 if (session_name
&& strcmp((char *) name
, session_name
)) {
3152 /* This is not the session we are looking for */
3153 ret
= -LTTNG_ERR_NO_SESSION
;
3157 /* Init domains to create the session handles */
3158 for (node
= xmlFirstElementChild(domains_node
); node
;
3159 node
= xmlNextElementSibling(node
)) {
3160 struct lttng_domain
*domain
;
3162 domain
= zmalloc(sizeof(*domain
));
3164 ret
= -LTTNG_ERR_NOMEM
;
3168 ret
= init_domain(node
, domain
);
3170 goto domain_init_error
;
3173 switch (domain
->type
) {
3174 case LTTNG_DOMAIN_KERNEL
:
3175 if (kernel_domain
) {
3176 /* Same domain seen twice, invalid! */
3177 goto domain_init_error
;
3179 kernel_domain
= domain
;
3181 case LTTNG_DOMAIN_UST
:
3183 /* Same domain seen twice, invalid! */
3184 goto domain_init_error
;
3186 ust_domain
= domain
;
3188 case LTTNG_DOMAIN_JUL
:
3190 /* Same domain seen twice, invalid! */
3191 goto domain_init_error
;
3193 jul_domain
= domain
;
3195 case LTTNG_DOMAIN_LOG4J
:
3197 /* Same domain seen twice, invalid! */
3198 goto domain_init_error
;
3200 log4j_domain
= domain
;
3202 case LTTNG_DOMAIN_PYTHON
:
3203 if (python_domain
) {
3204 /* Same domain seen twice, invalid! */
3205 goto domain_init_error
;
3207 python_domain
= domain
;
3210 WARN("Invalid domain type");
3211 goto domain_init_error
;
3216 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3220 /* Apply overrides */
3222 if (overrides
->session_name
) {
3223 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3224 if (!name_override
) {
3225 ret
= -LTTNG_ERR_NOMEM
;
3229 /* Overrides the session name to the provided name */
3231 name
= name_override
;
3236 /* Destroy session if it exists */
3237 ret
= lttng_destroy_session((const char *) name
);
3238 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3239 ERR("Failed to destroy existing session.");
3244 /* Create session type depending on output type */
3245 if (snapshot_mode
&& snapshot_mode
!= -1) {
3246 ret
= create_snapshot_session((const char *) name
, output_node
,
3248 } else if (live_timer_interval
&&
3249 live_timer_interval
!= UINT64_MAX
) {
3250 ret
= create_session((const char *) name
,
3251 output_node
, live_timer_interval
, overrides
);
3253 /* regular session */
3254 ret
= create_session((const char *) name
,
3255 output_node
, UINT64_MAX
, overrides
);
3262 ret
= lttng_set_session_shm_path((const char *) name
,
3263 (const char *) shm_path
);
3269 for (node
= xmlFirstElementChild(domains_node
); node
;
3270 node
= xmlNextElementSibling(node
)) {
3271 ret
= process_domain_node(node
, (const char *) name
);
3277 if (rotation_timer_interval
) {
3278 ret
= add_periodic_rotation((const char *) name
,
3279 rotation_timer_interval
);
3284 if (rotation_size
) {
3285 ret
= add_size_rotation((const char *) name
,
3293 ret
= lttng_start_tracing((const char *) name
);
3301 ERR("Failed to load session %s: %s", (const char *) name
,
3302 lttng_strerror(ret
));
3303 lttng_destroy_session((const char *) name
);
3307 free(kernel_domain
);
3311 free(python_domain
);
3318 * Return 1 if the given path is readable by the current UID or 0 if not.
3319 * Return -1 if the path is EPERM.
3321 static int validate_file_read_creds(const char *path
)
3327 /* Can we read the file. */
3328 ret
= access(path
, R_OK
);
3332 if (errno
== EACCES
) {
3343 int load_session_from_file(const char *path
, const char *session_name
,
3344 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3345 const struct config_load_session_override_attr
*overrides
)
3347 int ret
, session_found
= !session_name
;
3348 xmlDocPtr doc
= NULL
;
3349 xmlNodePtr sessions_node
;
3350 xmlNodePtr session_node
;
3353 assert(validation_ctx
);
3355 ret
= validate_file_read_creds(path
);
3358 ret
= -LTTNG_ERR_EPERM
;
3360 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3365 doc
= xmlParseFile(path
);
3367 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3371 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3373 ERR("Session configuration file validation failed");
3374 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3378 sessions_node
= xmlDocGetRootElement(doc
);
3379 if (!sessions_node
) {
3383 for (session_node
= xmlFirstElementChild(sessions_node
);
3384 session_node
; session_node
=
3385 xmlNextElementSibling(session_node
)) {
3386 ret
= process_session_node(session_node
,
3387 session_name
, overwrite
, overrides
);
3388 if (session_name
&& ret
== 0) {
3389 /* Target session found and loaded */
3397 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3403 int load_session_from_path(const char *path
, const char *session_name
,
3404 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3405 const struct config_load_session_override_attr
*overrides
)
3407 int ret
, session_found
= !session_name
;
3408 DIR *directory
= NULL
;
3409 struct lttng_dynamic_buffer file_path
;
3413 assert(validation_ctx
);
3414 path_len
= strlen(path
);
3415 lttng_dynamic_buffer_init(&file_path
);
3416 if (path_len
>= LTTNG_PATH_MAX
) {
3417 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3418 path
, path_len
, LTTNG_PATH_MAX
);
3419 ret
= -LTTNG_ERR_INVALID
;
3423 directory
= opendir(path
);
3427 /* Try the file loading. */
3430 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3433 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3438 size_t file_path_root_len
;
3440 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3443 ret
= -LTTNG_ERR_NOMEM
;
3447 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3449 ret
= -LTTNG_ERR_NOMEM
;
3453 if (file_path
.data
[file_path
.size
- 1] != '/') {
3454 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3456 ret
= -LTTNG_ERR_NOMEM
;
3460 file_path_root_len
= file_path
.size
;
3462 /* Search for *.lttng files */
3464 size_t file_name_len
;
3465 struct dirent
*result
;
3468 * When the end of the directory stream is reached, NULL
3469 * is returned and errno is kept unchanged. When an
3470 * error occurs, NULL is returned and errno is set
3471 * accordingly. To distinguish between the two, set
3472 * errno to zero before calling readdir().
3474 * On success, readdir() returns a pointer to a dirent
3475 * structure. This structure may be statically
3476 * allocated, do not attempt to free(3) it.
3479 result
= readdir(directory
);
3481 /* Reached end of dir stream or error out. */
3484 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3485 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3491 file_name_len
= strlen(result
->d_name
);
3493 if (file_name_len
<=
3494 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3498 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3499 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3501 /* +1 to account for NULL terminator. */
3502 file_path
.size
+ file_name_len
+ 1,
3507 /* Does the file end with .lttng? */
3508 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3509 result
->d_name
+ file_name_len
- sizeof(
3510 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3514 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3517 ret
= -LTTNG_ERR_NOMEM
;
3521 ret
= load_session_from_file(file_path
.data
, session_name
,
3522 validation_ctx
, overwrite
, overrides
);
3523 if (session_name
&& !ret
) {
3528 * Reset the buffer's size to the location of the
3529 * path's trailing '/'.
3531 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3532 file_path_root_len
);
3534 ret
= -LTTNG_ERR_UNK
;
3540 ret
= load_session_from_file(path
, session_name
,
3541 validation_ctx
, overwrite
, overrides
);
3551 if (closedir(directory
)) {
3555 if (session_found
&& !ret
) {
3558 lttng_dynamic_buffer_reset(&file_path
);
3563 * Validate that the given path's credentials and the current process have the
3564 * same UID. If so, return 1 else return 0 if it does NOT match.
3566 static int validate_path_creds(const char *path
)
3568 int ret
, uid
= getuid();
3577 ret
= stat(path
, &buf
);
3579 if (errno
!= ENOENT
) {
3585 if (buf
.st_uid
!= uid
) {
3596 int config_load_session(const char *path
, const char *session_name
,
3597 int overwrite
, unsigned int autoload
,
3598 const struct config_load_session_override_attr
*overrides
)
3601 bool session_loaded
= false;
3602 const char *path_ptr
= NULL
;
3603 struct session_config_validation_ctx validation_ctx
= { 0 };
3605 ret
= init_session_config_validation_ctx(&validation_ctx
);
3611 const char *home_path
;
3612 const char *sys_path
;
3615 home_path
= utils_get_home_dir();
3617 char path
[PATH_MAX
];
3620 * Try user session configuration path. Ignore error here so we can
3621 * continue loading the system wide sessions.
3624 ret
= snprintf(path
, sizeof(path
),
3625 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3626 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3628 PERROR("snprintf session autoload home config path");
3633 * Credentials are only validated for the autoload in order to
3634 * avoid any user session daemon to try to load kernel sessions
3635 * automatically and failing all the times.
3637 ret
= validate_path_creds(path
);
3642 ret
= snprintf(path
, sizeof(path
),
3643 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3645 PERROR("snprintf session home config path");
3651 ret
= load_session_from_path(path_ptr
, session_name
,
3652 &validation_ctx
, overwrite
, overrides
);
3653 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3657 * Continue even if the session was found since we have to try
3658 * the system wide sessions.
3660 session_loaded
= true;
3664 /* Reset path pointer for the system wide dir. */
3667 /* Try system wide configuration directory. */
3669 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3670 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3671 ret
= validate_path_creds(sys_path
);
3673 path_ptr
= sys_path
;
3676 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3677 path_ptr
= sys_path
;
3681 ret
= load_session_from_path(path_ptr
, session_name
,
3682 &validation_ctx
, overwrite
, overrides
);
3684 session_loaded
= true;
3688 ret
= access(path
, F_OK
);
3693 ret
= -LTTNG_ERR_INVALID
;
3694 WARN("Session configuration path does not exist.");
3697 ret
= -LTTNG_ERR_EPERM
;
3700 ret
= -LTTNG_ERR_UNK
;
3706 ret
= load_session_from_path(path
, session_name
,
3707 &validation_ctx
, overwrite
, overrides
);
3710 fini_session_config_validation_ctx(&validation_ctx
);
3711 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3713 * Don't report an error if no sessions are found when called
3714 * without a session_name or a search path.
3719 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3720 /* A matching session was found in one of the search paths. */
3727 void __attribute__((destructor
)) session_config_exit(void)