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_element_all
= "all";
65 const char * const config_str_yes
= "yes";
66 const char * const config_str_true
= "true";
67 const char * const config_str_on
= "on";
68 const char * const config_str_no
= "no";
69 const char * const config_str_false
= "false";
70 const char * const config_str_off
= "off";
71 const char * const config_xml_encoding
= "UTF-8";
72 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
73 const char * const config_xml_indent_string
= "\t";
74 const char * const config_xml_true
= "true";
75 const char * const config_xml_false
= "false";
77 const char * const config_element_channel
= "channel";
78 const char * const config_element_channels
= "channels";
79 const char * const config_element_domain
= "domain";
80 const char * const config_element_domains
= "domains";
81 const char * const config_element_event
= "event";
82 const char * const config_element_events
= "events";
83 const char * const config_element_context
= "context";
84 const char * const config_element_contexts
= "contexts";
85 const char * const config_element_attributes
= "attributes";
86 const char * const config_element_exclusion
= "exclusion";
87 const char * const config_element_exclusions
= "exclusions";
88 const char * const config_element_function_attributes
= "function_attributes";
89 const char * const config_element_probe_attributes
= "probe_attributes";
90 const char * const config_element_symbol_name
= "symbol_name";
91 const char * const config_element_address
= "address";
92 const char * const config_element_offset
= "offset";
94 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup
= "lookup_method";
95 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_default
= "DEFAULT";
96 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_function_elf
= "ELF";
97 LTTNG_HIDDEN
const char * const config_element_userspace_probe_lookup_tracepoint_sdt
= "SDT";
98 LTTNG_HIDDEN
const char * const config_element_userspace_probe_location_binary_path
= "binary_path";
99 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_attributes
= "userspace_probe_function_attributes";
100 LTTNG_HIDDEN
const char * const config_element_userspace_probe_function_location_function_name
= "function_name";
101 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_attributes
= "userspace_probe_tracepoint_attributes";
102 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_provider_name
= "provider_name";
103 LTTNG_HIDDEN
const char * const config_element_userspace_probe_tracepoint_location_probe_name
= "probe_name";
105 const char * const config_element_name
= "name";
106 const char * const config_element_enabled
= "enabled";
107 const char * const config_element_overwrite_mode
= "overwrite_mode";
108 const char * const config_element_subbuf_size
= "subbuffer_size";
109 const char * const config_element_num_subbuf
= "subbuffer_count";
110 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
111 const char * const config_element_read_timer_interval
= "read_timer_interval";
112 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
113 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
114 const char * const config_element_output
= "output";
115 const char * const config_element_output_type
= "output_type";
116 const char * const config_element_tracefile_size
= "tracefile_size";
117 const char * const config_element_tracefile_count
= "tracefile_count";
118 const char * const config_element_live_timer_interval
= "live_timer_interval";
119 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
120 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
121 const char * const config_element_type
= "type";
122 const char * const config_element_buffer_type
= "buffer_type";
123 const char * const config_element_session
= "session";
124 const char * const config_element_sessions
= "sessions";
125 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
126 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
127 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
128 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
129 const char * const config_element_config
= "config";
130 const char * const config_element_started
= "started";
131 const char * const config_element_snapshot_mode
= "snapshot_mode";
132 const char * const config_element_loglevel
= "loglevel";
133 const char * const config_element_loglevel_type
= "loglevel_type";
134 const char * const config_element_filter
= "filter";
135 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
136 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
137 const char * const config_element_consumer_output
= "consumer_output";
138 const char * const config_element_destination
= "destination";
139 const char * const config_element_path
= "path";
140 const char * const config_element_net_output
= "net_output";
141 const char * const config_element_control_uri
= "control_uri";
142 const char * const config_element_data_uri
= "data_uri";
143 const char * const config_element_max_size
= "max_size";
144 const char * const config_element_pid
= "pid";
145 const char * const config_element_id
= "id";
146 const char * const config_element_pids
= "pids";
147 const char * const config_element_shared_memory_path
= "shared_memory_path";
148 const char * const config_element_pid_tracker
= "pid_tracker";
149 const char * const config_element_vpid_tracker
= "vpid_tracker";
150 const char * const config_element_uid_tracker
= "uid_tracker";
151 const char * const config_element_vuid_tracker
= "vuid_tracker";
152 const char * const config_element_gid_tracker
= "gid_tracker";
153 const char * const config_element_vgid_tracker
= "vgid_tracker";
154 const char * const config_element_trackers
= "trackers";
155 const char * const config_element_targets
= "targets";
156 const char * const config_element_target_type
= "target_type";
157 const char * const config_element_target_pid
= "pid_target";
158 const char * const config_element_target_vpid
= "vpid_target";
159 const char * const config_element_target_uid
= "uid_target";
160 const char * const config_element_target_vuid
= "vuid_target";
161 const char * const config_element_target_gid
= "gid_target";
162 const char * const config_element_target_vgid
= "vgid_target";
163 const char * const config_element_tracker_type
= "tracker_type";
165 LTTNG_HIDDEN
const char * const config_element_rotation_schedules
= "rotation_schedules";
166 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic
= "periodic";
167 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_periodic_time_us
= "time_us";
168 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold
= "size_threshold";
169 LTTNG_HIDDEN
const char * const config_element_rotation_schedule_size_threshold_bytes
= "bytes";
171 const char * const config_domain_type_kernel
= "KERNEL";
172 const char * const config_domain_type_ust
= "UST";
173 const char * const config_domain_type_jul
= "JUL";
174 const char * const config_domain_type_log4j
= "LOG4J";
175 const char * const config_domain_type_python
= "PYTHON";
177 const char * const config_buffer_type_per_pid
= "PER_PID";
178 const char * const config_buffer_type_per_uid
= "PER_UID";
179 const char * const config_buffer_type_global
= "GLOBAL";
181 const char * const config_overwrite_mode_discard
= "DISCARD";
182 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
184 const char * const config_output_type_splice
= "SPLICE";
185 const char * const config_output_type_mmap
= "MMAP";
187 const char * const config_loglevel_type_all
= "ALL";
188 const char * const config_loglevel_type_range
= "RANGE";
189 const char * const config_loglevel_type_single
= "SINGLE";
191 const char * const config_event_type_all
= "ALL";
192 const char * const config_event_type_tracepoint
= "TRACEPOINT";
193 const char * const config_event_type_probe
= "PROBE";
194 LTTNG_HIDDEN
const char * const config_event_type_userspace_probe
= "USERSPACE_PROBE";
195 const char * const config_event_type_function
= "FUNCTION";
196 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
197 const char * const config_event_type_noop
= "NOOP";
198 const char * const config_event_type_syscall
= "SYSCALL";
199 const char * const config_event_type_kprobe
= "KPROBE";
200 const char * const config_event_type_kretprobe
= "KRETPROBE";
202 const char * const config_event_context_pid
= "PID";
203 const char * const config_event_context_procname
= "PROCNAME";
204 const char * const config_event_context_prio
= "PRIO";
205 const char * const config_event_context_nice
= "NICE";
206 const char * const config_event_context_vpid
= "VPID";
207 const char * const config_event_context_tid
= "TID";
208 const char * const config_event_context_vtid
= "VTID";
209 const char * const config_event_context_ppid
= "PPID";
210 const char * const config_event_context_vppid
= "VPPID";
211 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
212 const char * const config_event_context_hostname
= "HOSTNAME";
213 const char * const config_event_context_ip
= "IP";
214 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
215 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
216 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
217 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
218 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
219 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
220 LTTNG_HIDDEN
const char * const config_event_context_callstack_user
= "CALLSTACK_USER";
221 LTTNG_HIDDEN
const char * const config_event_context_callstack_kernel
= "CALLSTACK_KERNEL";
222 LTTNG_HIDDEN
const char * const config_event_context_cgroup_ns
= "CGROUP_NS";
223 LTTNG_HIDDEN
const char * const config_event_context_ipc_ns
= "IPC_NS";
224 LTTNG_HIDDEN
const char * const config_event_context_mnt_ns
= "MNT_NS";
225 LTTNG_HIDDEN
const char * const config_event_context_net_ns
= "NET_NS";
226 LTTNG_HIDDEN
const char * const config_event_context_pid_ns
= "PID_NS";
227 LTTNG_HIDDEN
const char * const config_event_context_user_ns
= "USER_NS";
228 LTTNG_HIDDEN
const char * const config_event_context_uts_ns
= "UTS_NS";
229 LTTNG_HIDDEN
const char * const config_event_context_uid
= "UID";
230 LTTNG_HIDDEN
const char * const config_event_context_euid
= "EUID";
231 LTTNG_HIDDEN
const char * const config_event_context_suid
= "SUID";
232 LTTNG_HIDDEN
const char * const config_event_context_gid
= "GID";
233 LTTNG_HIDDEN
const char * const config_event_context_egid
= "EGID";
234 LTTNG_HIDDEN
const char * const config_event_context_sgid
= "SGID";
235 LTTNG_HIDDEN
const char * const config_event_context_vuid
= "VUID";
236 LTTNG_HIDDEN
const char * const config_event_context_veuid
= "VEUID";
237 LTTNG_HIDDEN
const char * const config_event_context_vsuid
= "VSUID";
238 LTTNG_HIDDEN
const char * const config_event_context_vgid
= "VGID";
239 LTTNG_HIDDEN
const char * const config_event_context_vegid
= "VEGID";
240 LTTNG_HIDDEN
const char * const config_event_context_vsgid
= "VSGID";
242 /* Deprecated symbols */
243 const char * const config_element_perf
;
245 enum process_event_node_phase
{
250 struct consumer_output
{
257 static int config_entry_handler_filter(struct handler_filter_args
*args
,
258 const char *section
, const char *name
, const char *value
)
261 struct config_entry entry
= { section
, name
, value
};
265 if (!section
|| !name
|| !value
) {
271 if (strcmp(args
->section
, section
)) {
276 ret
= args
->handler(&entry
, args
->user_data
);
282 int config_get_section_entries(const char *override_path
, const char *section
,
283 config_entry_handler_cb handler
, void *user_data
)
287 FILE *config_file
= NULL
;
288 struct handler_filter_args filter
= { section
, handler
, user_data
};
290 /* First, try system-wide conf. file. */
291 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
293 config_file
= fopen(path
, "r");
295 DBG("Loading daemon conf file at %s", path
);
297 * Return value is not very important here since error or not, we
298 * continue and try the next possible conf. file.
300 (void) ini_parse_file(config_file
,
301 (ini_entry_handler
) config_entry_handler_filter
,
306 /* Second is the user local configuration. */
307 path
= utils_get_home_dir();
309 char fullpath
[PATH_MAX
];
311 ret
= snprintf(fullpath
, sizeof(fullpath
),
312 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
314 PERROR("snprintf user conf. path");
318 config_file
= fopen(fullpath
, "r");
320 DBG("Loading daemon user conf file at %s", path
);
322 * Return value is not very important here since error or not, we
323 * continue and try the next possible conf. file.
325 (void) ini_parse_file(config_file
,
326 (ini_entry_handler
) config_entry_handler_filter
,
332 /* Final path is the one that the user might have provided. */
334 config_file
= fopen(override_path
, "r");
336 DBG("Loading daemon command line conf file at %s", override_path
);
337 (void) ini_parse_file(config_file
,
338 (ini_entry_handler
) config_entry_handler_filter
,
342 ERR("Failed to open daemon configuration file at %s",
349 /* Everything went well. */
357 int config_parse_value(const char *value
)
360 char *endptr
, *lower_str
;
370 v
= strtoul(value
, &endptr
, 10);
371 if (endptr
!= value
) {
376 lower_str
= zmalloc(len
+ 1);
383 for (i
= 0; i
< len
; i
++) {
384 lower_str
[i
] = tolower(value
[i
]);
387 if (!strcmp(lower_str
, config_str_yes
) ||
388 !strcmp(lower_str
, config_str_true
) ||
389 !strcmp(lower_str
, config_str_on
)) {
391 } else if (!strcmp(lower_str
, config_str_no
) ||
392 !strcmp(lower_str
, config_str_false
) ||
393 !strcmp(lower_str
, config_str_off
)) {
405 * Returns a xmlChar string which must be released using xmlFree().
407 static xmlChar
*encode_string(const char *in_str
)
409 xmlChar
*out_str
= NULL
;
410 xmlCharEncodingHandlerPtr handler
;
411 int out_len
, ret
, in_len
;
415 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
417 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
421 in_len
= strlen(in_str
);
423 * Add 1 byte for the NULL terminted character. The factor 4 here is
424 * used because UTF-8 characters can take up to 4 bytes.
426 out_len
= (in_len
* 4) + 1;
427 out_str
= xmlMalloc(out_len
);
432 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
439 /* out_len is now the size of out_str */
440 out_str
[out_len
] = '\0';
446 struct config_writer
*config_writer_create(int fd_output
, int indent
)
449 struct config_writer
*writer
;
450 xmlOutputBufferPtr buffer
;
452 writer
= zmalloc(sizeof(struct config_writer
));
454 PERROR("zmalloc config_writer_create");
458 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
463 writer
->writer
= xmlNewTextWriter(buffer
);
464 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
465 config_xml_encoding
, NULL
);
470 ret
= xmlTextWriterSetIndentString(writer
->writer
,
471 BAD_CAST config_xml_indent_string
);
476 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
484 config_writer_destroy(writer
);
489 int config_writer_destroy(struct config_writer
*writer
)
498 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
499 WARN("Could not close XML document");
503 if (writer
->writer
) {
504 xmlFreeTextWriter(writer
->writer
);
513 int config_writer_open_element(struct config_writer
*writer
,
514 const char *element_name
)
517 xmlChar
*encoded_element_name
;
519 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
524 encoded_element_name
= encode_string(element_name
);
525 if (!encoded_element_name
) {
530 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
531 xmlFree(encoded_element_name
);
533 return ret
>= 0 ? 0 : ret
;
537 int config_writer_write_attribute(struct config_writer
*writer
,
538 const char *name
, const char *value
)
541 xmlChar
*encoded_name
= NULL
;
542 xmlChar
*encoded_value
= NULL
;
544 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
549 encoded_name
= encode_string(name
);
555 encoded_value
= encode_string(value
);
556 if (!encoded_value
) {
561 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
564 xmlFree(encoded_name
);
565 xmlFree(encoded_value
);
566 return ret
>= 0 ? 0 : ret
;
570 int config_writer_close_element(struct config_writer
*writer
)
574 if (!writer
|| !writer
->writer
) {
579 ret
= xmlTextWriterEndElement(writer
->writer
);
581 return ret
>= 0 ? 0 : ret
;
585 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
586 const char *element_name
, uint64_t value
)
589 xmlChar
*encoded_element_name
;
591 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
596 encoded_element_name
= encode_string(element_name
);
597 if (!encoded_element_name
) {
602 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
603 encoded_element_name
, "%" PRIu64
, value
);
604 xmlFree(encoded_element_name
);
606 return ret
>= 0 ? 0 : ret
;
610 int config_writer_write_element_signed_int(struct config_writer
*writer
,
611 const char *element_name
, int64_t value
)
614 xmlChar
*encoded_element_name
;
616 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
621 encoded_element_name
= encode_string(element_name
);
622 if (!encoded_element_name
) {
627 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
628 encoded_element_name
, "%" PRIi64
, value
);
629 xmlFree(encoded_element_name
);
631 return ret
>= 0 ? 0 : ret
;
635 int config_writer_write_element_bool(struct config_writer
*writer
,
636 const char *element_name
, int value
)
638 return config_writer_write_element_string(writer
, element_name
,
639 value
? config_xml_true
: config_xml_false
);
643 int config_writer_write_element_string(struct config_writer
*writer
,
644 const char *element_name
, const char *value
)
647 xmlChar
*encoded_element_name
= NULL
;
648 xmlChar
*encoded_value
= NULL
;
650 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
656 encoded_element_name
= encode_string(element_name
);
657 if (!encoded_element_name
) {
662 encoded_value
= encode_string(value
);
663 if (!encoded_value
) {
668 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
671 xmlFree(encoded_element_name
);
672 xmlFree(encoded_value
);
673 return ret
>= 0 ? 0 : ret
;
677 void xml_error_handler(void *ctx
, const char *format
, ...)
683 va_start(args
, format
);
684 ret
= vasprintf(&errMsg
, format
, args
);
687 ERR("String allocation failed in xml error handler");
691 fprintf(stderr
, "XML Error: %s", errMsg
);
696 void fini_session_config_validation_ctx(
697 struct session_config_validation_ctx
*ctx
)
699 if (ctx
->parser_ctx
) {
700 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
704 xmlSchemaFree(ctx
->schema
);
707 if (ctx
->schema_validation_ctx
) {
708 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
711 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
715 char *get_session_config_xsd_path()
718 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
719 size_t base_path_len
;
723 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
726 base_path_len
= strlen(base_path
);
727 max_path_len
= base_path_len
+
728 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
729 xsd_path
= zmalloc(max_path_len
);
734 strcpy(xsd_path
, base_path
);
735 if (xsd_path
[base_path_len
- 1] != '/') {
736 xsd_path
[base_path_len
++] = '/';
739 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
745 int init_session_config_validation_ctx(
746 struct session_config_validation_ctx
*ctx
)
749 char *xsd_path
= get_session_config_xsd_path();
752 ret
= -LTTNG_ERR_NOMEM
;
756 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
757 if (!ctx
->parser_ctx
) {
758 ERR("XSD parser context creation failed");
759 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
762 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
763 xml_error_handler
, NULL
);
765 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
767 ERR("XSD parsing failed");
768 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
772 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
773 if (!ctx
->schema_validation_ctx
) {
774 ERR("XSD validation context creation failed");
775 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
779 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
780 xml_error_handler
, NULL
);
785 fini_session_config_validation_ctx(ctx
);
793 int parse_uint(xmlChar
*str
, uint64_t *val
)
803 *val
= strtoull((const char *) str
, &endptr
, 10);
804 if (!endptr
|| *endptr
) {
815 int parse_int(xmlChar
*str
, int64_t *val
)
825 *val
= strtoll((const char *) str
, &endptr
, 10);
826 if (!endptr
|| *endptr
) {
837 int parse_bool(xmlChar
*str
, int *val
)
846 if (!strcmp((const char *) str
, config_xml_true
)) {
848 } else if (!strcmp((const char *) str
, config_xml_false
)) {
851 WARN("Invalid boolean value encoutered (%s).",
860 int get_domain_type(xmlChar
*domain
)
868 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
869 ret
= LTTNG_DOMAIN_KERNEL
;
870 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
871 ret
= LTTNG_DOMAIN_UST
;
872 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
873 ret
= LTTNG_DOMAIN_JUL
;
874 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
875 ret
= LTTNG_DOMAIN_LOG4J
;
876 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
877 ret
= LTTNG_DOMAIN_PYTHON
;
888 int get_buffer_type(xmlChar
*buffer_type
)
896 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
897 ret
= LTTNG_BUFFER_GLOBAL
;
898 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
899 ret
= LTTNG_BUFFER_PER_UID
;
900 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
901 ret
= LTTNG_BUFFER_PER_PID
;
912 int get_overwrite_mode(xmlChar
*overwrite_mode
)
916 if (!overwrite_mode
) {
920 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
922 } else if (!strcmp((char *) overwrite_mode
,
923 config_overwrite_mode_discard
)) {
935 int get_output_type(xmlChar
*output_type
)
943 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
944 ret
= LTTNG_EVENT_MMAP
;
945 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
946 ret
= LTTNG_EVENT_SPLICE
;
957 int get_event_type(xmlChar
*event_type
)
965 if (!strcmp((char *) event_type
, config_event_type_all
)) {
966 ret
= LTTNG_EVENT_ALL
;
967 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
968 ret
= LTTNG_EVENT_TRACEPOINT
;
969 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
970 ret
= LTTNG_EVENT_PROBE
;
971 } else if (!strcmp((char *) event_type
,
972 config_event_type_userspace_probe
)) {
973 ret
= LTTNG_EVENT_USERSPACE_PROBE
;
974 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
975 ret
= LTTNG_EVENT_FUNCTION
;
976 } else if (!strcmp((char *) event_type
,
977 config_event_type_function_entry
)) {
978 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
979 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
980 ret
= LTTNG_EVENT_NOOP
;
981 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
982 ret
= LTTNG_EVENT_SYSCALL
;
993 int get_loglevel_type(xmlChar
*loglevel_type
)
997 if (!loglevel_type
) {
1001 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
1002 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
1003 } else if (!strcmp((char *) loglevel_type
,
1004 config_loglevel_type_range
)) {
1005 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1006 } else if (!strcmp((char *) loglevel_type
,
1007 config_loglevel_type_single
)) {
1008 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1019 * Return the context type or -1 on error.
1022 int get_context_type(xmlChar
*context_type
)
1026 if (!context_type
) {
1030 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
1031 ret
= LTTNG_EVENT_CONTEXT_PID
;
1032 } else if (!strcmp((char *) context_type
,
1033 config_event_context_procname
)) {
1034 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1035 } else if (!strcmp((char *) context_type
,
1036 config_event_context_prio
)) {
1037 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
1038 } else if (!strcmp((char *) context_type
,
1039 config_event_context_nice
)) {
1040 ret
= LTTNG_EVENT_CONTEXT_NICE
;
1041 } else if (!strcmp((char *) context_type
,
1042 config_event_context_vpid
)) {
1043 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1044 } else if (!strcmp((char *) context_type
,
1045 config_event_context_tid
)) {
1046 ret
= LTTNG_EVENT_CONTEXT_TID
;
1047 } else if (!strcmp((char *) context_type
,
1048 config_event_context_vtid
)) {
1049 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1050 } else if (!strcmp((char *) context_type
,
1051 config_event_context_ppid
)) {
1052 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1053 } else if (!strcmp((char *) context_type
,
1054 config_event_context_vppid
)) {
1055 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1056 } else if (!strcmp((char *) context_type
,
1057 config_event_context_pthread_id
)) {
1058 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1059 } else if (!strcmp((char *) context_type
,
1060 config_event_context_hostname
)) {
1061 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1062 } else if (!strcmp((char *) context_type
,
1063 config_event_context_ip
)) {
1064 ret
= LTTNG_EVENT_CONTEXT_IP
;
1065 } else if (!strcmp((char *) context_type
,
1066 config_event_context_interruptible
)) {
1067 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1068 } else if (!strcmp((char *) context_type
,
1069 config_event_context_preemptible
)) {
1070 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1071 } else if (!strcmp((char *) context_type
,
1072 config_event_context_need_reschedule
)) {
1073 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1074 } else if (!strcmp((char *) context_type
,
1075 config_event_context_migratable
)) {
1076 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1077 } else if (!strcmp((char *) context_type
,
1078 config_event_context_callstack_user
)) {
1079 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_USER
;
1080 } else if (!strcmp((char *) context_type
,
1081 config_event_context_callstack_kernel
)) {
1082 ret
= LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
;
1083 } else if (!strcmp((char *) context_type
,
1084 config_event_context_cgroup_ns
)) {
1085 ret
= LTTNG_EVENT_CONTEXT_CGROUP_NS
;
1086 } else if (!strcmp((char *) context_type
,
1087 config_event_context_ipc_ns
)) {
1088 ret
= LTTNG_EVENT_CONTEXT_IPC_NS
;
1089 } else if (!strcmp((char *) context_type
,
1090 config_event_context_mnt_ns
)) {
1091 ret
= LTTNG_EVENT_CONTEXT_MNT_NS
;
1092 } else if (!strcmp((char *) context_type
,
1093 config_event_context_net_ns
)) {
1094 ret
= LTTNG_EVENT_CONTEXT_NET_NS
;
1095 } else if (!strcmp((char *) context_type
,
1096 config_event_context_pid_ns
)) {
1097 ret
= LTTNG_EVENT_CONTEXT_PID_NS
;
1098 } else if (!strcmp((char *) context_type
,
1099 config_event_context_user_ns
)) {
1100 ret
= LTTNG_EVENT_CONTEXT_USER_NS
;
1101 } else if (!strcmp((char *) context_type
,
1102 config_event_context_uts_ns
)) {
1103 ret
= LTTNG_EVENT_CONTEXT_UTS_NS
;
1104 } else if (!strcmp((char *) context_type
,
1105 config_event_context_uid
)) {
1106 ret
= LTTNG_EVENT_CONTEXT_UID
;
1107 } else if (!strcmp((char *) context_type
,
1108 config_event_context_euid
)) {
1109 ret
= LTTNG_EVENT_CONTEXT_EUID
;
1110 } else if (!strcmp((char *) context_type
,
1111 config_event_context_suid
)) {
1112 ret
= LTTNG_EVENT_CONTEXT_SUID
;
1113 } else if (!strcmp((char *) context_type
,
1114 config_event_context_gid
)) {
1115 ret
= LTTNG_EVENT_CONTEXT_GID
;
1116 } else if (!strcmp((char *) context_type
,
1117 config_event_context_egid
)) {
1118 ret
= LTTNG_EVENT_CONTEXT_EGID
;
1119 } else if (!strcmp((char *) context_type
,
1120 config_event_context_sgid
)) {
1121 ret
= LTTNG_EVENT_CONTEXT_SGID
;
1122 } else if (!strcmp((char *) context_type
,
1123 config_event_context_vuid
)) {
1124 ret
= LTTNG_EVENT_CONTEXT_VUID
;
1125 } else if (!strcmp((char *) context_type
,
1126 config_event_context_veuid
)) {
1127 ret
= LTTNG_EVENT_CONTEXT_VEUID
;
1128 } else if (!strcmp((char *) context_type
,
1129 config_event_context_vsuid
)) {
1130 ret
= LTTNG_EVENT_CONTEXT_VSUID
;
1131 } else if (!strcmp((char *) context_type
,
1132 config_event_context_vgid
)) {
1133 ret
= LTTNG_EVENT_CONTEXT_VGID
;
1134 } else if (!strcmp((char *) context_type
,
1135 config_event_context_vegid
)) {
1136 ret
= LTTNG_EVENT_CONTEXT_VEGID
;
1137 } else if (!strcmp((char *) context_type
,
1138 config_event_context_vsgid
)) {
1139 ret
= LTTNG_EVENT_CONTEXT_VSGID
;
1150 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1155 for (node
= xmlFirstElementChild(domain_node
); node
;
1156 node
= xmlNextElementSibling(node
)) {
1157 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1159 xmlChar
*node_content
= xmlNodeGetContent(node
);
1160 if (!node_content
) {
1161 ret
= -LTTNG_ERR_NOMEM
;
1165 ret
= get_domain_type(node_content
);
1168 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1173 } else if (!strcmp((const char *) node
->name
,
1174 config_element_buffer_type
)) {
1176 xmlChar
*node_content
= xmlNodeGetContent(node
);
1177 if (!node_content
) {
1178 ret
= -LTTNG_ERR_NOMEM
;
1182 ret
= get_buffer_type(node_content
);
1185 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1189 domain
->buf_type
= ret
;
1198 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1203 for (node
= xmlFirstElementChild(net_output_node
); node
;
1204 node
= xmlNextElementSibling(node
)) {
1205 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1207 *control_uri
= (char *) xmlNodeGetContent(node
);
1208 if (!*control_uri
) {
1213 *data_uri
= (char *) xmlNodeGetContent(node
);
1220 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1224 int process_consumer_output(xmlNodePtr consumer_output_node
,
1225 struct consumer_output
*output
)
1232 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1233 node
= xmlNextElementSibling(node
)) {
1234 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1235 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1239 ret
= -LTTNG_ERR_NOMEM
;
1243 ret
= parse_bool(enabled_str
, &output
->enabled
);
1249 xmlNodePtr output_type_node
;
1252 output_type_node
= xmlFirstElementChild(node
);
1253 if (!output_type_node
) {
1254 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1258 if (!strcmp((const char *) output_type_node
->name
,
1259 config_element_path
)) {
1261 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1262 if (!output
->path
) {
1263 ret
= -LTTNG_ERR_NOMEM
;
1268 ret
= get_net_output_uris(output_type_node
,
1269 &output
->control_uri
, &output
->data_uri
);
1281 free(output
->control_uri
);
1282 free(output
->data_uri
);
1283 memset(output
, 0, sizeof(struct consumer_output
));
1289 int create_session_net_output(const char *name
, const char *control_uri
,
1290 const char *data_uri
)
1293 struct lttng_handle
*handle
;
1294 const char *uri
= NULL
;
1298 handle
= lttng_create_handle(name
, NULL
);
1300 ret
= -LTTNG_ERR_NOMEM
;
1304 if (!control_uri
|| !data_uri
) {
1305 uri
= control_uri
? control_uri
: data_uri
;
1310 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1311 lttng_destroy_handle(handle
);
1317 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1318 const struct config_load_session_override_attr
*overrides
)
1321 xmlNodePtr node
= NULL
;
1322 xmlNodePtr snapshot_output_list_node
;
1323 xmlNodePtr snapshot_output_node
;
1325 assert(session_name
);
1327 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1336 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1338 /* Parse and create snapshot outputs */
1340 for (snapshot_output_node
=
1341 xmlFirstElementChild(snapshot_output_list_node
);
1342 snapshot_output_node
; snapshot_output_node
=
1343 xmlNextElementSibling(snapshot_output_node
)) {
1345 uint64_t max_size
= UINT64_MAX
;
1346 struct consumer_output output
= { 0 };
1347 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1348 const char *control_uri
= NULL
;
1349 const char *data_uri
= NULL
;
1350 const char *path
= NULL
;
1352 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1353 node
= xmlNextElementSibling(node
)) {
1354 if (!strcmp((const char *) node
->name
,
1355 config_element_name
)) {
1357 name
= (char *) xmlNodeGetContent(node
);
1359 ret
= -LTTNG_ERR_NOMEM
;
1360 goto error_snapshot_output
;
1362 } else if (!strcmp((const char *) node
->name
,
1363 config_element_max_size
)) {
1364 xmlChar
*content
= xmlNodeGetContent(node
);
1368 ret
= -LTTNG_ERR_NOMEM
;
1369 goto error_snapshot_output
;
1371 ret
= parse_uint(content
, &max_size
);
1374 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1375 goto error_snapshot_output
;
1378 /* consumer_output */
1379 ret
= process_consumer_output(node
, &output
);
1381 goto error_snapshot_output
;
1386 control_uri
= output
.control_uri
;
1387 data_uri
= output
.data_uri
;
1391 if (overrides
->path_url
) {
1392 path
= overrides
->path_url
;
1393 /* Control/data_uri are null */
1397 if (overrides
->ctrl_url
) {
1398 control_uri
= overrides
->ctrl_url
;
1402 if (overrides
->data_url
) {
1403 data_uri
= overrides
->data_url
;
1410 snapshot_output
= lttng_snapshot_output_create();
1411 if (!snapshot_output
) {
1412 ret
= -LTTNG_ERR_NOMEM
;
1413 goto error_snapshot_output
;
1416 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1418 goto error_snapshot_output
;
1421 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1423 goto error_snapshot_output
;
1427 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1430 goto error_snapshot_output
;
1434 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1437 goto error_snapshot_output
;
1442 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1445 goto error_snapshot_output
;
1450 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1451 error_snapshot_output
:
1454 free(output
.control_uri
);
1455 free(output
.data_uri
);
1456 lttng_snapshot_output_destroy(snapshot_output
);
1466 int create_session(const char *name
,
1467 xmlNodePtr output_node
,
1468 uint64_t live_timer_interval
,
1469 const struct config_load_session_override_attr
*overrides
)
1472 struct consumer_output output
= { 0 };
1473 xmlNodePtr consumer_output_node
;
1474 const char *control_uri
= NULL
;
1475 const char *data_uri
= NULL
;
1476 const char *path
= NULL
;
1481 consumer_output_node
= xmlFirstElementChild(output_node
);
1482 if (!consumer_output_node
) {
1483 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1487 if (strcmp((const char *) consumer_output_node
->name
,
1488 config_element_consumer_output
)) {
1489 WARN("Invalid output type, expected %s node",
1490 config_element_consumer_output
);
1491 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1495 ret
= process_consumer_output(consumer_output_node
, &output
);
1501 control_uri
= output
.control_uri
;
1502 data_uri
= output
.data_uri
;
1505 /* Check for override and apply them */
1507 if (overrides
->path_url
) {
1508 path
= overrides
->path_url
;
1509 /* control/data_uri are null */;
1513 if (overrides
->ctrl_url
) {
1514 control_uri
= overrides
->ctrl_url
;
1518 if (overrides
->data_url
) {
1519 data_uri
= overrides
->data_url
;
1527 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1528 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1532 if (control_uri
|| data_uri
) {
1533 /* network destination */
1534 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1536 * URLs are provided for sure since the test above make sure that
1537 * with a live timer the data and control URIs are provided. So,
1538 * NULL is passed here and will be set right after.
1540 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1542 ret
= lttng_create_session(name
, NULL
);
1548 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1554 /* either local output or no output */
1555 ret
= lttng_create_session(name
, path
);
1562 free(output
.control_uri
);
1563 free(output
.data_uri
);
1568 struct lttng_userspace_probe_location
*
1569 process_userspace_probe_function_attribute_node(
1570 xmlNodePtr attribute_node
)
1572 xmlNodePtr function_attribute_node
;
1573 char *function_name
= NULL
, *binary_path
= NULL
;
1574 struct lttng_userspace_probe_location
*location
= NULL
;
1575 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1578 * Process userspace probe location function attributes. The order of
1579 * the fields are not guaranteed so we need to iterate over all fields
1580 * and check at the end if everything we need for this location type is
1583 for (function_attribute_node
=
1584 xmlFirstElementChild(attribute_node
);
1585 function_attribute_node
;
1586 function_attribute_node
= xmlNextElementSibling(
1587 function_attribute_node
)) {
1588 /* Handle function name, binary path and lookup method. */
1589 if (!strcmp((const char *) function_attribute_node
->name
,
1590 config_element_userspace_probe_function_location_function_name
)) {
1591 function_name
= (char *) xmlNodeGetContent(function_attribute_node
);
1592 if (!function_name
) {
1595 } else if (!strcmp((const char *) function_attribute_node
->name
,
1596 config_element_userspace_probe_location_binary_path
)) {
1597 binary_path
= (char *) xmlNodeGetContent(function_attribute_node
);
1601 } else if (!strcmp((const char *) function_attribute_node
->name
,
1602 config_element_userspace_probe_lookup
)) {
1603 char *lookup_method_name
;
1605 lookup_method_name
= (char *) xmlNodeGetContent(
1606 function_attribute_node
);
1607 if (!lookup_method_name
) {
1612 * function_default lookup method defaults to
1613 * function_elf lookup method at the moment.
1615 if (!strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_elf
)
1616 || !strcmp(lookup_method_name
, config_element_userspace_probe_lookup_function_default
)) {
1617 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1618 if (!lookup_method
) {
1619 PERROR("Error creating function default/ELF lookup method");
1622 WARN("Unknown function lookup method");
1625 free(lookup_method_name
);
1626 if (!lookup_method
) {
1633 /* Check if all the necessary fields were found. */
1634 if (binary_path
&& function_name
&& lookup_method
) {
1635 /* Ownership of lookup_method is transferred. */
1637 lttng_userspace_probe_location_function_create(
1638 binary_path
, function_name
,
1640 lookup_method
= NULL
;
1645 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1647 free(function_name
);
1652 struct lttng_userspace_probe_location
*
1653 process_userspace_probe_tracepoint_attribute_node(
1654 xmlNodePtr attribute_node
)
1656 xmlNodePtr tracepoint_attribute_node
;
1657 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1658 struct lttng_userspace_probe_location
*location
= NULL
;
1659 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
1662 * Process userspace probe location tracepoint attributes. The order of
1663 * the fields are not guaranteed so we need to iterate over all fields
1664 * and check at the end if everything we need for this location type is
1667 for (tracepoint_attribute_node
=
1668 xmlFirstElementChild(attribute_node
); tracepoint_attribute_node
;
1669 tracepoint_attribute_node
= xmlNextElementSibling(
1670 tracepoint_attribute_node
)) {
1671 if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1672 config_element_userspace_probe_tracepoint_location_probe_name
)) {
1673 probe_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1677 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1678 config_element_userspace_probe_tracepoint_location_provider_name
)) {
1679 provider_name
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1680 if (!provider_name
) {
1683 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1684 config_element_userspace_probe_location_binary_path
)) {
1685 binary_path
= (char *) xmlNodeGetContent(tracepoint_attribute_node
);
1689 } else if (!strcmp((const char *) tracepoint_attribute_node
->name
,
1690 config_element_userspace_probe_lookup
)) {
1691 char *lookup_method_name
;
1693 lookup_method_name
= (char *) xmlNodeGetContent(
1694 tracepoint_attribute_node
);
1695 if (!lookup_method_name
) {
1699 if (!strcmp(lookup_method_name
,
1700 config_element_userspace_probe_lookup_tracepoint_sdt
)) {
1702 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1703 if (!lookup_method
) {
1704 PERROR("Error creating tracepoint SDT lookup method");
1707 WARN("Unknown tracepoint lookup method");
1710 free(lookup_method_name
);
1711 if (!lookup_method
) {
1715 WARN("Unknown tracepoint attribute");
1719 /* Check if all the necessary fields were found. */
1720 if (binary_path
&& provider_name
&& probe_name
&& lookup_method
) {
1721 /* Ownership of lookup_method is transferred. */
1723 lttng_userspace_probe_location_tracepoint_create(
1724 binary_path
, provider_name
,
1725 probe_name
, lookup_method
);
1726 lookup_method
= NULL
;
1731 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
1733 free(provider_name
);
1739 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1740 struct lttng_event_probe_attr
*attr
)
1744 assert(probe_attribute_node
);
1747 if (!strcmp((const char *) probe_attribute_node
->name
,
1748 config_element_address
)) {
1753 content
= xmlNodeGetContent(probe_attribute_node
);
1755 ret
= -LTTNG_ERR_NOMEM
;
1759 ret
= parse_uint(content
, &addr
);
1762 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1767 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1768 config_element_offset
)) {
1770 uint64_t offset
= 0;
1773 content
= xmlNodeGetContent(probe_attribute_node
);
1775 ret
= -LTTNG_ERR_NOMEM
;
1779 ret
= parse_uint(content
, &offset
);
1782 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1786 attr
->offset
= offset
;
1787 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1788 config_element_symbol_name
)) {
1792 content
= xmlNodeGetContent(probe_attribute_node
);
1794 ret
= -LTTNG_ERR_NOMEM
;
1798 ret
= lttng_strncpy(attr
->symbol_name
,
1799 (const char *) content
,
1800 LTTNG_SYMBOL_NAME_LEN
);
1802 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1803 (const char *) content
,
1804 strlen((const char *) content
),
1805 LTTNG_SYMBOL_NAME_LEN
);
1806 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1818 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1819 const char *channel_name
, const enum process_event_node_phase phase
)
1823 struct lttng_event
*event
;
1824 char **exclusions
= NULL
;
1825 unsigned long exclusion_count
= 0;
1826 char *filter_expression
= NULL
;
1830 assert(channel_name
);
1832 event
= lttng_event_create();
1834 ret
= -LTTNG_ERR_NOMEM
;
1838 /* Initialize default log level which varies by domain */
1839 switch (handle
->domain
.type
)
1841 case LTTNG_DOMAIN_JUL
:
1842 event
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1844 case LTTNG_DOMAIN_LOG4J
:
1845 event
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1847 case LTTNG_DOMAIN_PYTHON
:
1848 event
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1850 case LTTNG_DOMAIN_UST
:
1851 case LTTNG_DOMAIN_KERNEL
:
1852 event
->loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1858 for (node
= xmlFirstElementChild(event_node
); node
;
1859 node
= xmlNextElementSibling(node
)) {
1860 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1864 content
= xmlNodeGetContent(node
);
1866 ret
= -LTTNG_ERR_NOMEM
;
1870 ret
= lttng_strncpy(event
->name
,
1871 (const char *) content
,
1872 LTTNG_SYMBOL_NAME_LEN
);
1874 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1875 (const char *) content
,
1876 strlen((const char *) content
),
1877 LTTNG_SYMBOL_NAME_LEN
);
1878 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1883 } else if (!strcmp((const char *) node
->name
,
1884 config_element_enabled
)) {
1885 xmlChar
*content
= xmlNodeGetContent(node
);
1889 ret
= -LTTNG_ERR_NOMEM
;
1893 ret
= parse_bool(content
, &event
->enabled
);
1896 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1899 } else if (!strcmp((const char *) node
->name
,
1900 config_element_type
)) {
1901 xmlChar
*content
= xmlNodeGetContent(node
);
1905 ret
= -LTTNG_ERR_NOMEM
;
1909 ret
= get_event_type(content
);
1912 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1917 } else if (!strcmp((const char *) node
->name
,
1918 config_element_loglevel_type
)) {
1919 xmlChar
*content
= xmlNodeGetContent(node
);
1923 ret
= -LTTNG_ERR_NOMEM
;
1927 ret
= get_loglevel_type(content
);
1930 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1934 event
->loglevel_type
= ret
;
1935 } else if (!strcmp((const char *) node
->name
,
1936 config_element_loglevel
)) {
1938 int64_t loglevel
= 0;
1941 content
= xmlNodeGetContent(node
);
1943 ret
= -LTTNG_ERR_NOMEM
;
1947 ret
= parse_int(content
, &loglevel
);
1950 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1954 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1955 WARN("loglevel out of range.");
1956 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1960 event
->loglevel
= loglevel
;
1961 } else if (!strcmp((const char *) node
->name
,
1962 config_element_filter
)) {
1964 xmlNodeGetContent(node
);
1968 ret
= -LTTNG_ERR_NOMEM
;
1972 free(filter_expression
);
1973 filter_expression
= strdup((char *) content
);
1975 if (!filter_expression
) {
1976 ret
= -LTTNG_ERR_NOMEM
;
1979 } else if (!strcmp((const char *) node
->name
,
1980 config_element_exclusions
)) {
1981 xmlNodePtr exclusion_node
;
1982 int exclusion_index
= 0;
1987 * Exclusions has already been initialized,
1990 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1994 exclusion_count
= xmlChildElementCount(node
);
1995 if (!exclusion_count
) {
1999 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
2001 exclusion_count
= 0;
2002 ret
= -LTTNG_ERR_NOMEM
;
2006 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
2007 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
2009 xmlNodeGetContent(exclusion_node
);
2012 ret
= -LTTNG_ERR_NOMEM
;
2016 exclusions
[exclusion_index
] = strdup((const char *) content
);
2018 if (!exclusions
[exclusion_index
]) {
2019 ret
= -LTTNG_ERR_NOMEM
;
2025 event
->exclusion
= 1;
2026 } else if (!strcmp((const char *) node
->name
,
2027 config_element_attributes
)) {
2028 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
2031 if (!attribute_node
) {
2032 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2036 if (!strcmp((const char *) attribute_node
->name
,
2037 config_element_probe_attributes
)) {
2038 xmlNodePtr probe_attribute_node
;
2040 /* probe_attributes */
2041 for (probe_attribute_node
=
2042 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
2043 probe_attribute_node
= xmlNextElementSibling(
2044 probe_attribute_node
)) {
2046 ret
= process_probe_attribute_node(probe_attribute_node
,
2047 &event
->attr
.probe
);
2052 } else if (!strcmp((const char *) attribute_node
->name
,
2053 config_element_function_attributes
)) {
2056 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
2058 /* function_attributes */
2059 content
= xmlNodeGetContent(symbol_node
);
2061 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2065 sym_len
= strlen((char *) content
);
2066 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
2067 WARN("Function name too long.");
2068 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2073 ret
= lttng_strncpy(
2074 event
->attr
.ftrace
.symbol_name
,
2075 (char *) content
, sym_len
);
2077 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2082 } else if (!strcmp((const char *) attribute_node
->name
,
2083 config_element_userspace_probe_tracepoint_attributes
)) {
2084 struct lttng_userspace_probe_location
*location
;
2086 location
= process_userspace_probe_tracepoint_attribute_node(attribute_node
);
2088 WARN("Error processing userspace probe tracepoint attribute");
2089 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2092 ret
= lttng_event_set_userspace_probe_location(
2095 WARN("Error setting userspace probe location field");
2096 lttng_userspace_probe_location_destroy(
2098 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2101 } else if (!strcmp((const char *) attribute_node
->name
,
2102 config_element_userspace_probe_function_attributes
)) {
2103 struct lttng_userspace_probe_location
*location
;
2106 process_userspace_probe_function_attribute_node(
2109 WARN("Error processing userspace probe function attribute");
2110 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2114 ret
= lttng_event_set_userspace_probe_location(
2117 WARN("Error setting userspace probe location field");
2118 lttng_userspace_probe_location_destroy(
2120 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2124 /* Unknown event attribute. */
2125 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2131 if ((event
->enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
2132 ret
= lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
2133 filter_expression
, exclusion_count
, exclusions
);
2135 WARN("Enabling event (name:%s) on load failed.", event
->name
);
2136 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2142 for (i
= 0; i
< exclusion_count
; i
++) {
2143 free(exclusions
[i
]);
2146 lttng_event_destroy(event
);
2148 free(filter_expression
);
2153 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
2154 const char *channel_name
)
2157 struct lttng_event event
;
2160 assert(events_node
);
2162 assert(channel_name
);
2164 for (node
= xmlFirstElementChild(events_node
); node
;
2165 node
= xmlNextElementSibling(node
)) {
2166 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
2173 * Disable all events to enable only the necessary events.
2174 * Limitations regarding lttng_disable_events and tuple descriptor
2175 * force this approach.
2177 memset(&event
, 0, sizeof(event
));
2178 event
.loglevel
= -1;
2179 event
.type
= LTTNG_EVENT_ALL
;
2180 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
2185 for (node
= xmlFirstElementChild(events_node
); node
;
2186 node
= xmlNextElementSibling(node
)) {
2187 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
2198 int process_channel_attr_node(xmlNodePtr attr_node
,
2199 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
2200 xmlNodePtr
*events_node
)
2206 assert(contexts_node
);
2207 assert(events_node
);
2209 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
2213 content
= xmlNodeGetContent(attr_node
);
2215 ret
= -LTTNG_ERR_NOMEM
;
2219 ret
= lttng_strncpy(channel
->name
,
2220 (const char *) content
,
2221 LTTNG_SYMBOL_NAME_LEN
);
2223 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2224 (const char *) content
,
2225 strlen((const char *) content
),
2226 LTTNG_SYMBOL_NAME_LEN
);
2227 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2232 } else if (!strcmp((const char *) attr_node
->name
,
2233 config_element_enabled
)) {
2238 content
= xmlNodeGetContent(attr_node
);
2240 ret
= -LTTNG_ERR_NOMEM
;
2244 ret
= parse_bool(content
, &enabled
);
2247 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2251 channel
->enabled
= enabled
;
2252 } else if (!strcmp((const char *) attr_node
->name
,
2253 config_element_overwrite_mode
)) {
2256 /* overwrite_mode */
2257 content
= xmlNodeGetContent(attr_node
);
2259 ret
= -LTTNG_ERR_NOMEM
;
2263 ret
= get_overwrite_mode(content
);
2266 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2270 channel
->attr
.overwrite
= ret
;
2271 } else if (!strcmp((const char *) attr_node
->name
,
2272 config_element_subbuf_size
)) {
2275 /* subbuffer_size */
2276 content
= xmlNodeGetContent(attr_node
);
2278 ret
= -LTTNG_ERR_NOMEM
;
2282 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
2285 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2288 } else if (!strcmp((const char *) attr_node
->name
,
2289 config_element_num_subbuf
)) {
2292 /* subbuffer_count */
2293 content
= xmlNodeGetContent(attr_node
);
2295 ret
= -LTTNG_ERR_NOMEM
;
2299 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
2302 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2305 } else if (!strcmp((const char *) attr_node
->name
,
2306 config_element_switch_timer_interval
)) {
2308 uint64_t switch_timer_interval
= 0;
2310 /* switch_timer_interval */
2311 content
= xmlNodeGetContent(attr_node
);
2313 ret
= -LTTNG_ERR_NOMEM
;
2317 ret
= parse_uint(content
, &switch_timer_interval
);
2320 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2324 if (switch_timer_interval
> UINT_MAX
) {
2325 WARN("switch_timer_interval out of range.");
2326 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2330 channel
->attr
.switch_timer_interval
=
2331 switch_timer_interval
;
2332 } else if (!strcmp((const char *) attr_node
->name
,
2333 config_element_read_timer_interval
)) {
2335 uint64_t read_timer_interval
= 0;
2337 /* read_timer_interval */
2338 content
= xmlNodeGetContent(attr_node
);
2340 ret
= -LTTNG_ERR_NOMEM
;
2344 ret
= parse_uint(content
, &read_timer_interval
);
2347 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2351 if (read_timer_interval
> UINT_MAX
) {
2352 WARN("read_timer_interval out of range.");
2353 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2357 channel
->attr
.read_timer_interval
=
2358 read_timer_interval
;
2359 } else if (!strcmp((const char *) attr_node
->name
,
2360 config_element_output_type
)) {
2364 content
= xmlNodeGetContent(attr_node
);
2366 ret
= -LTTNG_ERR_NOMEM
;
2370 ret
= get_output_type(content
);
2373 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2377 channel
->attr
.output
= ret
;
2378 } else if (!strcmp((const char *) attr_node
->name
,
2379 config_element_tracefile_size
)) {
2382 /* tracefile_size */
2383 content
= xmlNodeGetContent(attr_node
);
2385 ret
= -LTTNG_ERR_NOMEM
;
2389 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2392 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2395 } else if (!strcmp((const char *) attr_node
->name
,
2396 config_element_tracefile_count
)) {
2399 /* tracefile_count */
2400 content
= xmlNodeGetContent(attr_node
);
2402 ret
= -LTTNG_ERR_NOMEM
;
2406 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2409 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2412 } else if (!strcmp((const char *) attr_node
->name
,
2413 config_element_live_timer_interval
)) {
2415 uint64_t live_timer_interval
= 0;
2417 /* live_timer_interval */
2418 content
= xmlNodeGetContent(attr_node
);
2420 ret
= -LTTNG_ERR_NOMEM
;
2424 ret
= parse_uint(content
, &live_timer_interval
);
2427 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2431 if (live_timer_interval
> UINT_MAX
) {
2432 WARN("live_timer_interval out of range.");
2433 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2437 channel
->attr
.live_timer_interval
=
2438 live_timer_interval
;
2439 } else if (!strcmp((const char *) attr_node
->name
,
2440 config_element_monitor_timer_interval
)) {
2442 uint64_t monitor_timer_interval
= 0;
2444 /* monitor_timer_interval */
2445 content
= xmlNodeGetContent(attr_node
);
2447 ret
= -LTTNG_ERR_NOMEM
;
2451 ret
= parse_uint(content
, &monitor_timer_interval
);
2454 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2458 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2459 monitor_timer_interval
);
2461 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2464 } else if (!strcmp((const char *) attr_node
->name
,
2465 config_element_blocking_timeout
)) {
2467 int64_t blocking_timeout
= 0;
2469 /* blocking_timeout */
2470 content
= xmlNodeGetContent(attr_node
);
2472 ret
= -LTTNG_ERR_NOMEM
;
2476 ret
= parse_int(content
, &blocking_timeout
);
2479 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2483 ret
= lttng_channel_set_blocking_timeout(channel
,
2486 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2489 } else if (!strcmp((const char *) attr_node
->name
,
2490 config_element_events
)) {
2492 *events_node
= attr_node
;
2495 *contexts_node
= attr_node
;
2503 int process_context_node(xmlNodePtr context_node
,
2504 struct lttng_handle
*handle
, const char *channel_name
)
2507 struct lttng_event_context context
;
2508 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2511 assert(channel_name
);
2513 if (!context_child_node
) {
2514 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2518 memset(&context
, 0, sizeof(context
));
2520 if (!strcmp((const char *) context_child_node
->name
,
2521 config_element_type
)) {
2523 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2526 ret
= -LTTNG_ERR_NOMEM
;
2530 ret
= get_context_type(content
);
2533 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2538 } else if (!strcmp((const char *) context_child_node
->name
,
2539 config_element_context_perf
)) {
2541 xmlNodePtr perf_attr_node
;
2543 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2544 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2545 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2546 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2547 perf_attr_node
; perf_attr_node
=
2548 xmlNextElementSibling(perf_attr_node
)) {
2549 if (!strcmp((const char *) perf_attr_node
->name
,
2550 config_element_type
)) {
2555 content
= xmlNodeGetContent(perf_attr_node
);
2557 ret
= -LTTNG_ERR_NOMEM
;
2561 ret
= parse_uint(content
, &type
);
2564 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2568 if (type
> UINT32_MAX
) {
2569 WARN("perf context type out of range.");
2570 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2574 context
.u
.perf_counter
.type
= type
;
2575 } else if (!strcmp((const char *) perf_attr_node
->name
,
2576 config_element_config
)) {
2578 uint64_t config
= 0;
2581 content
= xmlNodeGetContent(perf_attr_node
);
2583 ret
= -LTTNG_ERR_NOMEM
;
2587 ret
= parse_uint(content
, &config
);
2590 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2594 context
.u
.perf_counter
.config
= config
;
2595 } else if (!strcmp((const char *) perf_attr_node
->name
,
2596 config_element_name
)) {
2600 content
= xmlNodeGetContent(perf_attr_node
);
2602 ret
= -LTTNG_ERR_NOMEM
;
2606 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2607 (const char *) content
,
2608 LTTNG_SYMBOL_NAME_LEN
);
2610 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2611 (const char *) content
,
2612 strlen((const char *) content
),
2613 LTTNG_SYMBOL_NAME_LEN
);
2614 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2621 } else if (!strcmp((const char *) context_child_node
->name
,
2622 config_element_context_app
)) {
2623 /* application context */
2624 xmlNodePtr app_ctx_node
;
2626 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2627 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2628 app_ctx_node
; app_ctx_node
=
2629 xmlNextElementSibling(app_ctx_node
)) {
2631 char **target
= strcmp(
2632 (const char *) app_ctx_node
->name
,
2633 config_element_context_app_provider_name
) == 0 ?
2634 &context
.u
.app_ctx
.provider_name
:
2635 &context
.u
.app_ctx
.ctx_name
;
2637 content
= xmlNodeGetContent(app_ctx_node
);
2639 ret
= -LTTNG_ERR_NOMEM
;
2643 *target
= (char *) content
;
2646 /* Unrecognized context type */
2647 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2651 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2652 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2653 free(context
.u
.app_ctx
.provider_name
);
2654 free(context
.u
.app_ctx
.ctx_name
);
2661 int process_contexts_node(xmlNodePtr contexts_node
,
2662 struct lttng_handle
*handle
, const char *channel_name
)
2665 xmlNodePtr context_node
;
2667 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2668 context_node
= xmlNextElementSibling(context_node
)) {
2669 ret
= process_context_node(context_node
, handle
, channel_name
);
2678 static int get_tracker_elements(enum lttng_tracker_type tracker_type
,
2679 const char **element_id_tracker
,
2680 const char **element_target_id
,
2681 const char **element_id
,
2682 const char **element_id_alias
,
2683 const char **element_name
)
2687 switch (tracker_type
) {
2688 case LTTNG_TRACKER_PID
:
2689 *element_id_tracker
= config_element_pid_tracker
;
2690 *element_target_id
= config_element_target_pid
;
2691 *element_id
= config_element_id
;
2692 *element_id_alias
= config_element_pid
;
2693 *element_name
= NULL
;
2695 case LTTNG_TRACKER_VPID
:
2696 *element_id_tracker
= config_element_vpid_tracker
;
2697 *element_target_id
= config_element_target_vpid
;
2698 *element_id
= config_element_id
;
2699 *element_id_alias
= NULL
;
2700 *element_name
= NULL
;
2702 case LTTNG_TRACKER_UID
:
2703 *element_id_tracker
= config_element_uid_tracker
;
2704 *element_target_id
= config_element_target_uid
;
2705 *element_id
= config_element_id
;
2706 *element_id_alias
= NULL
;
2707 *element_name
= config_element_name
;
2709 case LTTNG_TRACKER_VUID
:
2710 *element_id_tracker
= config_element_vuid_tracker
;
2711 *element_target_id
= config_element_target_vuid
;
2712 *element_id
= config_element_id
;
2713 *element_id_alias
= NULL
;
2714 *element_name
= config_element_name
;
2716 case LTTNG_TRACKER_GID
:
2717 *element_id_tracker
= config_element_gid_tracker
;
2718 *element_target_id
= config_element_target_gid
;
2719 *element_id
= config_element_id
;
2720 *element_id_alias
= NULL
;
2721 *element_name
= config_element_name
;
2723 case LTTNG_TRACKER_VGID
:
2724 *element_id_tracker
= config_element_vgid_tracker
;
2725 *element_target_id
= config_element_target_vgid
;
2726 *element_id
= config_element_id
;
2727 *element_id_alias
= NULL
;
2728 *element_name
= config_element_name
;
2731 ret
= LTTNG_ERR_INVALID
;
2736 static int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2737 struct lttng_handle
*handle
,
2738 enum lttng_tracker_type tracker_type
)
2741 xmlNodePtr targets_node
= NULL
;
2743 const char *element_id_tracker
;
2744 const char *element_target_id
;
2745 const char *element_id
;
2746 const char *element_id_alias
;
2747 const char *element_name
;
2750 assert(id_tracker_node
);
2752 ret
= get_tracker_elements(tracker_type
, &element_id_tracker
,
2753 &element_target_id
, &element_id
, &element_id_alias
,
2759 /* get the targets node */
2760 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2761 node
= xmlNextElementSibling(node
)) {
2762 if (!strcmp((const char *) node
->name
,
2763 config_element_targets
)) {
2764 targets_node
= node
;
2769 if (!targets_node
) {
2770 ret
= LTTNG_ERR_INVALID
;
2774 /* Go through all id target node */
2775 child
= xmlChildElementCount(targets_node
);
2777 struct lttng_tracker_id tracker_id
;
2779 tracker_id
.type
= LTTNG_ID_ALL
;
2780 /* The session is explicitly set to target nothing. */
2781 ret
= lttng_untrack_id(handle
, tracker_type
, &tracker_id
);
2786 for (node
= xmlFirstElementChild(targets_node
); node
;
2787 node
= xmlNextElementSibling(node
)) {
2788 xmlNodePtr id_target_node
= node
;
2790 /* get id node and track it */
2791 for (node
= xmlFirstElementChild(id_target_node
); node
;
2792 node
= xmlNextElementSibling(node
)) {
2793 if (!strcmp((const char *) node
->name
, element_id
) ||
2794 (element_id_alias
&&
2795 !strcmp((const char *) node
->name
,
2796 element_id_alias
))) {
2798 xmlChar
*content
= NULL
;
2799 struct lttng_tracker_id tracker_id
;
2801 content
= xmlNodeGetContent(node
);
2803 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2807 ret
= parse_int(content
, &id
);
2810 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2814 tracker_id
.type
= LTTNG_ID_VALUE
;
2815 tracker_id
.value
= (int) id
;
2816 ret
= lttng_track_id(handle
, tracker_type
,
2822 if (element_name
&& !strcmp((const char *) node
->name
,
2824 xmlChar
*content
= NULL
;
2825 struct lttng_tracker_id tracker_id
;
2827 content
= xmlNodeGetContent(node
);
2829 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2832 tracker_id
.type
= LTTNG_ID_STRING
;
2833 tracker_id
.string
= (char *) content
;
2834 ret
= lttng_track_id(handle
, tracker_type
,
2842 node
= id_target_node
;
2850 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2853 struct lttng_domain domain
= { 0 };
2854 struct lttng_handle
*handle
= NULL
;
2855 struct lttng_channel
*channel
= NULL
;
2856 xmlNodePtr channels_node
= NULL
;
2857 xmlNodePtr trackers_node
= NULL
;
2858 xmlNodePtr pid_tracker_node
= NULL
;
2859 xmlNodePtr vpid_tracker_node
= NULL
;
2860 xmlNodePtr uid_tracker_node
= NULL
;
2861 xmlNodePtr vuid_tracker_node
= NULL
;
2862 xmlNodePtr gid_tracker_node
= NULL
;
2863 xmlNodePtr vgid_tracker_node
= NULL
;
2866 assert(session_name
);
2868 ret
= init_domain(domain_node
, &domain
);
2873 handle
= lttng_create_handle(session_name
, &domain
);
2875 ret
= -LTTNG_ERR_NOMEM
;
2879 /* get the channels node */
2880 for (node
= xmlFirstElementChild(domain_node
); node
;
2881 node
= xmlNextElementSibling(node
)) {
2882 if (!strcmp((const char *) node
->name
,
2883 config_element_channels
)) {
2884 channels_node
= node
;
2889 if (!channels_node
) {
2893 /* create all channels */
2894 for (node
= xmlFirstElementChild(channels_node
); node
;
2895 node
= xmlNextElementSibling(node
)) {
2896 const enum lttng_domain_type original_domain
= domain
.type
;
2897 xmlNodePtr contexts_node
= NULL
;
2898 xmlNodePtr events_node
= NULL
;
2899 xmlNodePtr channel_attr_node
;
2902 * Channels of the "agent" types cannot be created directly.
2903 * They are meant to be created implicitly through the
2904 * activation of events in their domain. However, a user
2905 * can override the default channel configuration attributes
2906 * by creating the underlying UST channel _before_ enabling
2907 * an agent domain event.
2909 * Hence, the channel's type is substituted before the creation
2910 * and restored by the time the events are created.
2912 switch (domain
.type
) {
2913 case LTTNG_DOMAIN_JUL
:
2914 case LTTNG_DOMAIN_LOG4J
:
2915 case LTTNG_DOMAIN_PYTHON
:
2916 domain
.type
= LTTNG_DOMAIN_UST
;
2921 channel
= lttng_channel_create(&domain
);
2927 for (channel_attr_node
= xmlFirstElementChild(node
);
2928 channel_attr_node
; channel_attr_node
=
2929 xmlNextElementSibling(channel_attr_node
)) {
2930 ret
= process_channel_attr_node(channel_attr_node
,
2931 channel
, &contexts_node
, &events_node
);
2937 ret
= lttng_enable_channel(handle
, channel
);
2942 /* Restore the original channel domain. */
2943 domain
.type
= original_domain
;
2945 ret
= process_events_node(events_node
, handle
, channel
->name
);
2950 ret
= process_contexts_node(contexts_node
, handle
,
2956 lttng_channel_destroy(channel
);
2960 /* get the trackers node */
2961 for (node
= xmlFirstElementChild(domain_node
); node
;
2962 node
= xmlNextElementSibling(node
)) {
2963 if (!strcmp((const char *) node
->name
,
2964 config_element_trackers
)) {
2965 trackers_node
= node
;
2970 if (!trackers_node
) {
2974 for (node
= xmlFirstElementChild(trackers_node
); node
;
2975 node
= xmlNextElementSibling(node
)) {
2976 if (!strcmp((const char *) node
->name
,
2977 config_element_pid_tracker
)) {
2978 pid_tracker_node
= node
;
2979 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
2985 if (!strcmp((const char *) node
->name
,
2986 config_element_vpid_tracker
)) {
2987 vpid_tracker_node
= node
;
2988 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
2989 LTTNG_TRACKER_VPID
);
2994 if (!strcmp((const char *) node
->name
,
2995 config_element_uid_tracker
)) {
2996 uid_tracker_node
= node
;
2997 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
3003 if (!strcmp((const char *) node
->name
,
3004 config_element_vuid_tracker
)) {
3005 vuid_tracker_node
= node
;
3006 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
3007 LTTNG_TRACKER_VUID
);
3012 if (!strcmp((const char *) node
->name
,
3013 config_element_gid_tracker
)) {
3014 gid_tracker_node
= node
;
3015 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
3021 if (!strcmp((const char *) node
->name
,
3022 config_element_vgid_tracker
)) {
3023 vgid_tracker_node
= node
;
3024 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
3025 LTTNG_TRACKER_VGID
);
3033 lttng_channel_destroy(channel
);
3034 lttng_destroy_handle(handle
);
3039 int add_periodic_rotation(const char *name
, uint64_t time_us
)
3042 enum lttng_rotation_status status
;
3043 struct lttng_rotation_schedule
*periodic
=
3044 lttng_rotation_schedule_periodic_create();
3047 ret
= -LTTNG_ERR_NOMEM
;
3051 status
= lttng_rotation_schedule_periodic_set_period(periodic
,
3053 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3054 ret
= -LTTNG_ERR_INVALID
;
3058 status
= lttng_session_add_rotation_schedule(name
, periodic
);
3060 case LTTNG_ROTATION_STATUS_OK
:
3063 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3064 case LTTNG_ROTATION_STATUS_INVALID
:
3065 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3068 ret
= -LTTNG_ERR_UNK
;
3072 lttng_rotation_schedule_destroy(periodic
);
3077 int add_size_rotation(const char *name
, uint64_t size_bytes
)
3080 enum lttng_rotation_status status
;
3081 struct lttng_rotation_schedule
*size
=
3082 lttng_rotation_schedule_size_threshold_create();
3085 ret
= -LTTNG_ERR_NOMEM
;
3089 status
= lttng_rotation_schedule_size_threshold_set_threshold(size
,
3091 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
3092 ret
= -LTTNG_ERR_INVALID
;
3096 status
= lttng_session_add_rotation_schedule(name
, size
);
3098 case LTTNG_ROTATION_STATUS_OK
:
3101 case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET
:
3102 case LTTNG_ROTATION_STATUS_INVALID
:
3103 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3106 ret
= -LTTNG_ERR_UNK
;
3110 lttng_rotation_schedule_destroy(size
);
3115 int process_session_rotation_schedules_node(
3116 xmlNodePtr schedules_node
,
3117 uint64_t *rotation_timer_interval
,
3118 uint64_t *rotation_size
)
3123 for (child
= xmlFirstElementChild(schedules_node
);
3125 child
= xmlNextElementSibling(child
)) {
3126 if (!strcmp((const char *) child
->name
,
3127 config_element_rotation_schedule_periodic
)) {
3129 xmlNodePtr time_us_node
;
3131 /* periodic rotation schedule */
3132 time_us_node
= xmlFirstElementChild(child
);
3133 if (!time_us_node
||
3134 strcmp((const char *) time_us_node
->name
,
3135 config_element_rotation_schedule_periodic_time_us
)) {
3136 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3141 content
= xmlNodeGetContent(time_us_node
);
3143 ret
= -LTTNG_ERR_NOMEM
;
3146 ret
= parse_uint(content
, rotation_timer_interval
);
3149 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3152 } else if (!strcmp((const char *) child
->name
,
3153 config_element_rotation_schedule_size_threshold
)) {
3155 xmlNodePtr bytes_node
;
3157 /* size_threshold rotation schedule */
3158 bytes_node
= xmlFirstElementChild(child
);
3160 strcmp((const char *) bytes_node
->name
,
3161 config_element_rotation_schedule_size_threshold_bytes
)) {
3162 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3167 content
= xmlNodeGetContent(bytes_node
);
3169 ret
= -LTTNG_ERR_NOMEM
;
3172 ret
= parse_uint(content
, rotation_size
);
3175 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3186 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
3188 const struct config_load_session_override_attr
*overrides
)
3190 int ret
, started
= -1, snapshot_mode
= -1;
3191 uint64_t live_timer_interval
= UINT64_MAX
,
3192 rotation_timer_interval
= 0,
3194 xmlChar
*name
= NULL
;
3195 xmlChar
*shm_path
= NULL
;
3196 xmlNodePtr domains_node
= NULL
;
3197 xmlNodePtr output_node
= NULL
;
3199 xmlNodePtr attributes_child
;
3200 struct lttng_domain
*kernel_domain
= NULL
;
3201 struct lttng_domain
*ust_domain
= NULL
;
3202 struct lttng_domain
*jul_domain
= NULL
;
3203 struct lttng_domain
*log4j_domain
= NULL
;
3204 struct lttng_domain
*python_domain
= NULL
;
3206 for (node
= xmlFirstElementChild(session_node
); node
;
3207 node
= xmlNextElementSibling(node
)) {
3208 if (!name
&& !strcmp((const char *) node
->name
,
3209 config_element_name
)) {
3211 xmlChar
*node_content
= xmlNodeGetContent(node
);
3212 if (!node_content
) {
3213 ret
= -LTTNG_ERR_NOMEM
;
3217 name
= node_content
;
3218 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
3219 config_element_domains
)) {
3221 domains_node
= node
;
3222 } else if (started
== -1 && !strcmp((const char *) node
->name
,
3223 config_element_started
)) {
3225 xmlChar
*node_content
= xmlNodeGetContent(node
);
3226 if (!node_content
) {
3227 ret
= -LTTNG_ERR_NOMEM
;
3231 ret
= parse_bool(node_content
, &started
);
3234 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3237 } else if (!output_node
&& !strcmp((const char *) node
->name
,
3238 config_element_output
)) {
3241 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
3242 config_element_shared_memory_path
)) {
3243 /* shared memory path */
3244 xmlChar
*node_content
= xmlNodeGetContent(node
);
3245 if (!node_content
) {
3246 ret
= -LTTNG_ERR_NOMEM
;
3250 shm_path
= node_content
;
3253 * attributes, snapshot_mode, live_timer_interval, rotation_size,
3254 * rotation_timer_interval.
3256 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
3257 attributes_child
= xmlNextElementSibling(attributes_child
)) {
3258 if (!strcmp((const char *) attributes_child
->name
,
3259 config_element_snapshot_mode
)) {
3261 xmlChar
*snapshot_mode_content
=
3262 xmlNodeGetContent(attributes_child
);
3263 if (!snapshot_mode_content
) {
3264 ret
= -LTTNG_ERR_NOMEM
;
3268 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
3269 free(snapshot_mode_content
);
3271 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3274 } else if (!strcmp((const char *) attributes_child
->name
,
3275 config_element_live_timer_interval
)) {
3276 /* live_timer_interval */
3277 xmlChar
*timer_interval_content
=
3278 xmlNodeGetContent(attributes_child
);
3279 if (!timer_interval_content
) {
3280 ret
= -LTTNG_ERR_NOMEM
;
3284 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
3285 free(timer_interval_content
);
3287 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3290 } else if (!strcmp((const char *) attributes_child
->name
,
3291 config_element_rotation_schedules
)) {
3292 ret
= process_session_rotation_schedules_node(
3294 &rotation_timer_interval
,
3297 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3307 /* Mandatory attribute, as defined in the session XSD */
3308 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3312 if (session_name
&& strcmp((char *) name
, session_name
)) {
3313 /* This is not the session we are looking for */
3314 ret
= -LTTNG_ERR_NO_SESSION
;
3318 /* Init domains to create the session handles */
3319 for (node
= xmlFirstElementChild(domains_node
); node
;
3320 node
= xmlNextElementSibling(node
)) {
3321 struct lttng_domain
*domain
;
3323 domain
= zmalloc(sizeof(*domain
));
3325 ret
= -LTTNG_ERR_NOMEM
;
3329 ret
= init_domain(node
, domain
);
3331 goto domain_init_error
;
3334 switch (domain
->type
) {
3335 case LTTNG_DOMAIN_KERNEL
:
3336 if (kernel_domain
) {
3337 /* Same domain seen twice, invalid! */
3338 goto domain_init_error
;
3340 kernel_domain
= domain
;
3342 case LTTNG_DOMAIN_UST
:
3344 /* Same domain seen twice, invalid! */
3345 goto domain_init_error
;
3347 ust_domain
= domain
;
3349 case LTTNG_DOMAIN_JUL
:
3351 /* Same domain seen twice, invalid! */
3352 goto domain_init_error
;
3354 jul_domain
= domain
;
3356 case LTTNG_DOMAIN_LOG4J
:
3358 /* Same domain seen twice, invalid! */
3359 goto domain_init_error
;
3361 log4j_domain
= domain
;
3363 case LTTNG_DOMAIN_PYTHON
:
3364 if (python_domain
) {
3365 /* Same domain seen twice, invalid! */
3366 goto domain_init_error
;
3368 python_domain
= domain
;
3371 WARN("Invalid domain type");
3372 goto domain_init_error
;
3377 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3381 /* Apply overrides */
3383 if (overrides
->session_name
) {
3384 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
3385 if (!name_override
) {
3386 ret
= -LTTNG_ERR_NOMEM
;
3390 /* Overrides the session name to the provided name */
3392 name
= name_override
;
3397 /* Destroy session if it exists */
3398 ret
= lttng_destroy_session((const char *) name
);
3399 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
3400 ERR("Failed to destroy existing session.");
3405 /* Create session type depending on output type */
3406 if (snapshot_mode
&& snapshot_mode
!= -1) {
3407 ret
= create_snapshot_session((const char *) name
, output_node
,
3409 } else if (live_timer_interval
&&
3410 live_timer_interval
!= UINT64_MAX
) {
3411 ret
= create_session((const char *) name
,
3412 output_node
, live_timer_interval
, overrides
);
3414 /* regular session */
3415 ret
= create_session((const char *) name
,
3416 output_node
, UINT64_MAX
, overrides
);
3423 ret
= lttng_set_session_shm_path((const char *) name
,
3424 (const char *) shm_path
);
3430 for (node
= xmlFirstElementChild(domains_node
); node
;
3431 node
= xmlNextElementSibling(node
)) {
3432 ret
= process_domain_node(node
, (const char *) name
);
3438 if (rotation_timer_interval
) {
3439 ret
= add_periodic_rotation((const char *) name
,
3440 rotation_timer_interval
);
3445 if (rotation_size
) {
3446 ret
= add_size_rotation((const char *) name
,
3454 ret
= lttng_start_tracing((const char *) name
);
3462 ERR("Failed to load session %s: %s", (const char *) name
,
3463 lttng_strerror(ret
));
3464 lttng_destroy_session((const char *) name
);
3468 free(kernel_domain
);
3472 free(python_domain
);
3479 * Return 1 if the given path is readable by the current UID or 0 if not.
3480 * Return -1 if the path is EPERM.
3482 static int validate_file_read_creds(const char *path
)
3488 /* Can we read the file. */
3489 ret
= access(path
, R_OK
);
3493 if (errno
== EACCES
) {
3504 int load_session_from_file(const char *path
, const char *session_name
,
3505 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3506 const struct config_load_session_override_attr
*overrides
)
3508 int ret
, session_found
= !session_name
;
3509 xmlDocPtr doc
= NULL
;
3510 xmlNodePtr sessions_node
;
3511 xmlNodePtr session_node
;
3514 assert(validation_ctx
);
3516 ret
= validate_file_read_creds(path
);
3519 ret
= -LTTNG_ERR_EPERM
;
3521 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3526 doc
= xmlParseFile(path
);
3528 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3532 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3534 ERR("Session configuration file validation failed");
3535 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3539 sessions_node
= xmlDocGetRootElement(doc
);
3540 if (!sessions_node
) {
3541 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3545 for (session_node
= xmlFirstElementChild(sessions_node
);
3546 session_node
; session_node
=
3547 xmlNextElementSibling(session_node
)) {
3548 ret
= process_session_node(session_node
,
3549 session_name
, overwrite
, overrides
);
3550 if (session_name
&& ret
== 0) {
3551 /* Target session found and loaded */
3559 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3561 if (ret
== -LTTNG_ERR_NO_SESSION
) {
3562 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3568 int load_session_from_path(const char *path
, const char *session_name
,
3569 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3570 const struct config_load_session_override_attr
*overrides
)
3572 int ret
, session_found
= !session_name
;
3573 DIR *directory
= NULL
;
3574 struct lttng_dynamic_buffer file_path
;
3578 assert(validation_ctx
);
3579 path_len
= strlen(path
);
3580 lttng_dynamic_buffer_init(&file_path
);
3581 if (path_len
>= LTTNG_PATH_MAX
) {
3582 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3583 path
, path_len
, LTTNG_PATH_MAX
);
3584 ret
= -LTTNG_ERR_INVALID
;
3588 directory
= opendir(path
);
3592 /* Try the file loading. */
3595 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3598 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3603 size_t file_path_root_len
;
3605 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3608 ret
= -LTTNG_ERR_NOMEM
;
3612 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3614 ret
= -LTTNG_ERR_NOMEM
;
3618 if (file_path
.data
[file_path
.size
- 1] != '/') {
3619 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3621 ret
= -LTTNG_ERR_NOMEM
;
3625 file_path_root_len
= file_path
.size
;
3627 /* Search for *.lttng files */
3629 size_t file_name_len
;
3630 struct dirent
*result
;
3633 * When the end of the directory stream is reached, NULL
3634 * is returned and errno is kept unchanged. When an
3635 * error occurs, NULL is returned and errno is set
3636 * accordingly. To distinguish between the two, set
3637 * errno to zero before calling readdir().
3639 * On success, readdir() returns a pointer to a dirent
3640 * structure. This structure may be statically
3641 * allocated, do not attempt to free(3) it.
3644 result
= readdir(directory
);
3646 /* Reached end of dir stream or error out. */
3649 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3650 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3656 file_name_len
= strlen(result
->d_name
);
3658 if (file_name_len
<=
3659 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3663 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3664 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3666 /* +1 to account for NULL terminator. */
3667 file_path
.size
+ file_name_len
+ 1,
3672 /* Does the file end with .lttng? */
3673 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3674 result
->d_name
+ file_name_len
- sizeof(
3675 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3679 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3682 ret
= -LTTNG_ERR_NOMEM
;
3686 ret
= load_session_from_file(file_path
.data
, session_name
,
3687 validation_ctx
, overwrite
, overrides
);
3689 (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3693 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3697 * Reset the buffer's size to the location of the
3698 * path's trailing '/'.
3700 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3701 file_path_root_len
);
3703 ret
= -LTTNG_ERR_UNK
;
3708 ret
= load_session_from_file(path
, session_name
,
3709 validation_ctx
, overwrite
, overrides
);
3719 if (closedir(directory
)) {
3723 if (!ret
&& !session_found
) {
3724 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3726 lttng_dynamic_buffer_reset(&file_path
);
3731 * Validate that the given path's credentials and the current process have the
3732 * same UID. If so, return 1 else return 0 if it does NOT match.
3734 static int validate_path_creds(const char *path
)
3736 int ret
, uid
= getuid();
3745 ret
= stat(path
, &buf
);
3747 if (errno
!= ENOENT
) {
3753 if (buf
.st_uid
!= uid
) {
3764 int config_load_session(const char *path
, const char *session_name
,
3765 int overwrite
, unsigned int autoload
,
3766 const struct config_load_session_override_attr
*overrides
)
3769 bool session_loaded
= false;
3770 const char *path_ptr
= NULL
;
3771 struct session_config_validation_ctx validation_ctx
= { 0 };
3773 ret
= init_session_config_validation_ctx(&validation_ctx
);
3779 const char *home_path
;
3780 const char *sys_path
;
3783 home_path
= utils_get_home_dir();
3785 char path
[PATH_MAX
];
3788 * Try user session configuration path. Ignore error here so we can
3789 * continue loading the system wide sessions.
3792 ret
= snprintf(path
, sizeof(path
),
3793 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3794 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3796 PERROR("snprintf session autoload home config path");
3797 ret
= -LTTNG_ERR_INVALID
;
3802 * Credentials are only validated for the autoload in order to
3803 * avoid any user session daemon to try to load kernel sessions
3804 * automatically and failing all the times.
3806 ret
= validate_path_creds(path
);
3811 ret
= snprintf(path
, sizeof(path
),
3812 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3814 PERROR("snprintf session home config path");
3815 ret
= -LTTNG_ERR_INVALID
;
3821 ret
= load_session_from_path(path_ptr
, session_name
,
3822 &validation_ctx
, overwrite
, overrides
);
3823 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3827 * Continue even if the session was found since we have to try
3828 * the system wide sessions.
3830 session_loaded
= true;
3834 /* Reset path pointer for the system wide dir. */
3837 /* Try system wide configuration directory. */
3839 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3840 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3841 ret
= validate_path_creds(sys_path
);
3843 path_ptr
= sys_path
;
3846 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3847 path_ptr
= sys_path
;
3851 ret
= load_session_from_path(path_ptr
, session_name
,
3852 &validation_ctx
, overwrite
, overrides
);
3854 session_loaded
= true;
3860 ret
= access(path
, F_OK
);
3865 ret
= -LTTNG_ERR_INVALID
;
3866 WARN("Session configuration path does not exist.");
3869 ret
= -LTTNG_ERR_EPERM
;
3872 ret
= -LTTNG_ERR_UNK
;
3878 ret
= load_session_from_path(path
, session_name
,
3879 &validation_ctx
, overwrite
, overrides
);
3882 fini_session_config_validation_ctx(&validation_ctx
);
3883 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3885 * Don't report an error if no sessions are found when called
3886 * without a session_name or a search path.
3891 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3892 /* A matching session was found in one of the search paths. */
3899 void __attribute__((destructor
)) session_config_exit(void)