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>
46 #include "session-config.h"
47 #include "config-internal.h"
49 struct handler_filter_args
{
51 config_entry_handler_cb handler
;
55 struct session_config_validation_ctx
{
56 xmlSchemaParserCtxtPtr parser_ctx
;
58 xmlSchemaValidCtxtPtr schema_validation_ctx
;
61 const char * const config_element_all
= "all";
62 const char * const config_str_yes
= "yes";
63 const char * const config_str_true
= "true";
64 const char * const config_str_on
= "on";
65 const char * const config_str_no
= "no";
66 const char * const config_str_false
= "false";
67 const char * const config_str_off
= "off";
68 const char * const config_xml_encoding
= "UTF-8";
69 const size_t config_xml_encoding_bytes_per_char
= 2; /* Size of the encoding's largest character */
70 const char * const config_xml_indent_string
= "\t";
71 const char * const config_xml_true
= "true";
72 const char * const config_xml_false
= "false";
74 const char * const config_element_channel
= "channel";
75 const char * const config_element_channels
= "channels";
76 const char * const config_element_domain
= "domain";
77 const char * const config_element_domains
= "domains";
78 const char * const config_element_event
= "event";
79 const char * const config_element_events
= "events";
80 const char * const config_element_context
= "context";
81 const char * const config_element_contexts
= "contexts";
82 const char * const config_element_attributes
= "attributes";
83 const char * const config_element_exclusion
= "exclusion";
84 const char * const config_element_exclusions
= "exclusions";
85 const char * const config_element_function_attributes
= "function_attributes";
86 const char * const config_element_probe_attributes
= "probe_attributes";
87 const char * const config_element_symbol_name
= "symbol_name";
88 const char * const config_element_address
= "address";
89 const char * const config_element_offset
= "offset";
90 const char * const config_element_enabled
= "enabled";
91 const char * const config_element_overwrite_mode
= "overwrite_mode";
92 const char * const config_element_subbuf_size
= "subbuffer_size";
93 const char * const config_element_num_subbuf
= "subbuffer_count";
94 const char * const config_element_switch_timer_interval
= "switch_timer_interval";
95 const char * const config_element_read_timer_interval
= "read_timer_interval";
96 LTTNG_HIDDEN
const char * const config_element_monitor_timer_interval
= "monitor_timer_interval";
97 LTTNG_HIDDEN
const char * const config_element_blocking_timeout
= "blocking_timeout";
98 const char * const config_element_output
= "output";
99 const char * const config_element_output_type
= "output_type";
100 const char * const config_element_tracefile_size
= "tracefile_size";
101 const char * const config_element_tracefile_count
= "tracefile_count";
102 const char * const config_element_live_timer_interval
= "live_timer_interval";
103 LTTNG_HIDDEN
const char * const config_element_discarded_events
= "discarded_events";
104 LTTNG_HIDDEN
const char * const config_element_lost_packets
= "lost_packets";
105 const char * const config_element_type
= "type";
106 const char * const config_element_buffer_type
= "buffer_type";
107 const char * const config_element_session
= "session";
108 const char * const config_element_sessions
= "sessions";
109 LTTNG_HIDDEN
const char * const config_element_context_perf
= "perf";
110 LTTNG_HIDDEN
const char * const config_element_context_app
= "app";
111 LTTNG_HIDDEN
const char * const config_element_context_app_provider_name
= "provider_name";
112 LTTNG_HIDDEN
const char * const config_element_context_app_ctx_name
= "ctx_name";
113 const char * const config_element_config
= "config";
114 const char * const config_element_started
= "started";
115 const char * const config_element_snapshot_mode
= "snapshot_mode";
116 const char * const config_element_loglevel
= "loglevel";
117 const char * const config_element_loglevel_type
= "loglevel_type";
118 const char * const config_element_filter
= "filter";
119 LTTNG_HIDDEN
const char * const config_element_filter_expression
= "filter_expression";
120 const char * const config_element_snapshot_outputs
= "snapshot_outputs";
121 const char * const config_element_consumer_output
= "consumer_output";
122 const char * const config_element_destination
= "destination";
123 const char * const config_element_path
= "path";
124 const char * const config_element_net_output
= "net_output";
125 const char * const config_element_control_uri
= "control_uri";
126 const char * const config_element_data_uri
= "data_uri";
127 const char * const config_element_max_size
= "max_size";
128 const char * const config_element_pid
= "pid";
129 const char * const config_element_id
= "id";
130 const char * const config_element_pids
= "pids";
131 const char * const config_element_name
= "name";
132 const char * const config_element_shared_memory_path
= "shared_memory_path";
133 const char * const config_element_pid_tracker
= "pid_tracker";
134 const char * const config_element_vpid_tracker
= "vpid_tracker";
135 const char * const config_element_uid_tracker
= "uid_tracker";
136 const char * const config_element_vuid_tracker
= "vuid_tracker";
137 const char * const config_element_gid_tracker
= "gid_tracker";
138 const char * const config_element_vgid_tracker
= "vgid_tracker";
139 const char * const config_element_trackers
= "trackers";
140 const char * const config_element_targets
= "targets";
141 const char * const config_element_target_type
= "target_type";
142 const char * const config_element_target_pid
= "pid_target";
143 const char * const config_element_target_vpid
= "vpid_target";
144 const char * const config_element_target_uid
= "uid_target";
145 const char * const config_element_target_vuid
= "vuid_target";
146 const char * const config_element_target_gid
= "gid_target";
147 const char * const config_element_target_vgid
= "vgid_target";
148 const char * const config_element_tracker_type
= "tracker_type";
150 LTTNG_HIDDEN
const char * const config_element_rotation_timer_interval
= "rotation_schedule_timer_period";
151 LTTNG_HIDDEN
const char * const config_element_rotation_size
= "rotation_schedule_size";
152 LTTNG_HIDDEN
const char * const config_element_rotation_schedule
= "rotation_schedule";
154 const char * const config_domain_type_kernel
= "KERNEL";
155 const char * const config_domain_type_ust
= "UST";
156 const char * const config_domain_type_jul
= "JUL";
157 const char * const config_domain_type_log4j
= "LOG4J";
158 const char * const config_domain_type_python
= "PYTHON";
160 const char * const config_buffer_type_per_pid
= "PER_PID";
161 const char * const config_buffer_type_per_uid
= "PER_UID";
162 const char * const config_buffer_type_global
= "GLOBAL";
164 const char * const config_overwrite_mode_discard
= "DISCARD";
165 const char * const config_overwrite_mode_overwrite
= "OVERWRITE";
167 const char * const config_output_type_splice
= "SPLICE";
168 const char * const config_output_type_mmap
= "MMAP";
170 const char * const config_loglevel_type_all
= "ALL";
171 const char * const config_loglevel_type_range
= "RANGE";
172 const char * const config_loglevel_type_single
= "SINGLE";
174 const char * const config_event_type_all
= "ALL";
175 const char * const config_event_type_tracepoint
= "TRACEPOINT";
176 const char * const config_event_type_probe
= "PROBE";
177 const char * const config_event_type_function
= "FUNCTION";
178 const char * const config_event_type_function_entry
= "FUNCTION_ENTRY";
179 const char * const config_event_type_noop
= "NOOP";
180 const char * const config_event_type_syscall
= "SYSCALL";
181 const char * const config_event_type_kprobe
= "KPROBE";
182 const char * const config_event_type_kretprobe
= "KRETPROBE";
184 const char * const config_event_context_pid
= "PID";
185 const char * const config_event_context_procname
= "PROCNAME";
186 const char * const config_event_context_prio
= "PRIO";
187 const char * const config_event_context_nice
= "NICE";
188 const char * const config_event_context_vpid
= "VPID";
189 const char * const config_event_context_tid
= "TID";
190 const char * const config_event_context_vtid
= "VTID";
191 const char * const config_event_context_ppid
= "PPID";
192 const char * const config_event_context_vppid
= "VPPID";
193 const char * const config_event_context_pthread_id
= "PTHREAD_ID";
194 const char * const config_event_context_hostname
= "HOSTNAME";
195 const char * const config_event_context_ip
= "IP";
196 const char * const config_event_context_perf_thread_counter
= "PERF_THREAD_COUNTER";
197 LTTNG_HIDDEN
const char * const config_event_context_app
= "APP";
198 LTTNG_HIDDEN
const char * const config_event_context_interruptible
= "INTERRUPTIBLE";
199 LTTNG_HIDDEN
const char * const config_event_context_preemptible
= "PREEMPTIBLE";
200 LTTNG_HIDDEN
const char * const config_event_context_need_reschedule
= "NEED_RESCHEDULE";
201 LTTNG_HIDDEN
const char * const config_event_context_migratable
= "MIGRATABLE";
203 /* Deprecated symbols */
204 const char * const config_element_perf
;
206 enum process_event_node_phase
{
211 struct consumer_output
{
218 static int config_entry_handler_filter(struct handler_filter_args
*args
,
219 const char *section
, const char *name
, const char *value
)
222 struct config_entry entry
= { section
, name
, value
};
226 if (!section
|| !name
|| !value
) {
232 if (strcmp(args
->section
, section
)) {
237 ret
= args
->handler(&entry
, args
->user_data
);
243 int config_get_section_entries(const char *override_path
, const char *section
,
244 config_entry_handler_cb handler
, void *user_data
)
248 FILE *config_file
= NULL
;
249 struct handler_filter_args filter
= { section
, handler
, user_data
};
251 /* First, try system-wide conf. file. */
252 path
= DEFAULT_DAEMON_SYSTEM_CONFIGPATH
;
254 config_file
= fopen(path
, "r");
256 DBG("Loading daemon conf file at %s", path
);
258 * Return value is not very important here since error or not, we
259 * continue and try the next possible conf. file.
261 (void) ini_parse_file(config_file
,
262 (ini_entry_handler
) config_entry_handler_filter
,
267 /* Second is the user local configuration. */
268 path
= utils_get_home_dir();
270 char fullpath
[PATH_MAX
];
272 ret
= snprintf(fullpath
, sizeof(fullpath
),
273 DEFAULT_DAEMON_HOME_CONFIGPATH
, path
);
275 PERROR("snprintf user conf. path");
279 config_file
= fopen(fullpath
, "r");
281 DBG("Loading daemon user 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
,
293 /* Final path is the one that the user might have provided. */
295 config_file
= fopen(override_path
, "r");
297 DBG("Loading daemon command line conf file at %s", override_path
);
298 (void) ini_parse_file(config_file
,
299 (ini_entry_handler
) config_entry_handler_filter
,
303 ERR("Failed to open daemon configuration file at %s",
310 /* Everything went well. */
318 int config_parse_value(const char *value
)
321 char *endptr
, *lower_str
;
331 v
= strtoul(value
, &endptr
, 10);
332 if (endptr
!= value
) {
337 lower_str
= zmalloc(len
+ 1);
344 for (i
= 0; i
< len
; i
++) {
345 lower_str
[i
] = tolower(value
[i
]);
348 if (!strcmp(lower_str
, config_str_yes
) ||
349 !strcmp(lower_str
, config_str_true
) ||
350 !strcmp(lower_str
, config_str_on
)) {
352 } else if (!strcmp(lower_str
, config_str_no
) ||
353 !strcmp(lower_str
, config_str_false
) ||
354 !strcmp(lower_str
, config_str_off
)) {
366 * Returns a xmlChar string which must be released using xmlFree().
368 static xmlChar
*encode_string(const char *in_str
)
370 xmlChar
*out_str
= NULL
;
371 xmlCharEncodingHandlerPtr handler
;
372 int out_len
, ret
, in_len
;
376 handler
= xmlFindCharEncodingHandler(config_xml_encoding
);
378 ERR("xmlFindCharEncodingHandler return NULL!. Configure issue!");
382 in_len
= strlen(in_str
);
384 * Add 1 byte for the NULL terminted character. The factor 4 here is
385 * used because UTF-8 characters can take up to 4 bytes.
387 out_len
= (in_len
* 4) + 1;
388 out_str
= xmlMalloc(out_len
);
393 ret
= handler
->input(out_str
, &out_len
, (const xmlChar
*) in_str
, &in_len
);
400 /* out_len is now the size of out_str */
401 out_str
[out_len
] = '\0';
407 struct config_writer
*config_writer_create(int fd_output
, int indent
)
410 struct config_writer
*writer
;
411 xmlOutputBufferPtr buffer
;
413 writer
= zmalloc(sizeof(struct config_writer
));
415 PERROR("zmalloc config_writer_create");
419 buffer
= xmlOutputBufferCreateFd(fd_output
, NULL
);
424 writer
->writer
= xmlNewTextWriter(buffer
);
425 ret
= xmlTextWriterStartDocument(writer
->writer
, NULL
,
426 config_xml_encoding
, NULL
);
431 ret
= xmlTextWriterSetIndentString(writer
->writer
,
432 BAD_CAST config_xml_indent_string
);
437 ret
= xmlTextWriterSetIndent(writer
->writer
, indent
);
445 config_writer_destroy(writer
);
450 int config_writer_destroy(struct config_writer
*writer
)
459 if (xmlTextWriterEndDocument(writer
->writer
) < 0) {
460 WARN("Could not close XML document");
464 if (writer
->writer
) {
465 xmlFreeTextWriter(writer
->writer
);
474 int config_writer_open_element(struct config_writer
*writer
,
475 const char *element_name
)
478 xmlChar
*encoded_element_name
;
480 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
485 encoded_element_name
= encode_string(element_name
);
486 if (!encoded_element_name
) {
491 ret
= xmlTextWriterStartElement(writer
->writer
, encoded_element_name
);
492 xmlFree(encoded_element_name
);
494 return ret
>= 0 ? 0 : ret
;
498 int config_writer_write_attribute(struct config_writer
*writer
,
499 const char *name
, const char *value
)
502 xmlChar
*encoded_name
= NULL
;
503 xmlChar
*encoded_value
= NULL
;
505 if (!writer
|| !writer
->writer
|| !name
|| !name
[0]) {
510 encoded_name
= encode_string(name
);
516 encoded_value
= encode_string(value
);
517 if (!encoded_value
) {
522 ret
= xmlTextWriterWriteAttribute(writer
->writer
, encoded_name
,
525 xmlFree(encoded_name
);
526 xmlFree(encoded_value
);
527 return ret
>= 0 ? 0 : ret
;
531 int config_writer_close_element(struct config_writer
*writer
)
535 if (!writer
|| !writer
->writer
) {
540 ret
= xmlTextWriterEndElement(writer
->writer
);
542 return ret
>= 0 ? 0 : ret
;
546 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
547 const char *element_name
, uint64_t value
)
550 xmlChar
*encoded_element_name
;
552 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0]) {
557 encoded_element_name
= encode_string(element_name
);
558 if (!encoded_element_name
) {
563 ret
= xmlTextWriterWriteFormatElement(writer
->writer
,
564 encoded_element_name
, "%" PRIu64
, value
);
565 xmlFree(encoded_element_name
);
567 return ret
>= 0 ? 0 : ret
;
571 int config_writer_write_element_signed_int(struct config_writer
*writer
,
572 const char *element_name
, int64_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
, "%" PRIi64
, value
);
590 xmlFree(encoded_element_name
);
592 return ret
>= 0 ? 0 : ret
;
596 int config_writer_write_element_bool(struct config_writer
*writer
,
597 const char *element_name
, int value
)
599 return config_writer_write_element_string(writer
, element_name
,
600 value
? config_xml_true
: config_xml_false
);
604 int config_writer_write_element_string(struct config_writer
*writer
,
605 const char *element_name
, const char *value
)
608 xmlChar
*encoded_element_name
= NULL
;
609 xmlChar
*encoded_value
= NULL
;
611 if (!writer
|| !writer
->writer
|| !element_name
|| !element_name
[0] ||
617 encoded_element_name
= encode_string(element_name
);
618 if (!encoded_element_name
) {
623 encoded_value
= encode_string(value
);
624 if (!encoded_value
) {
629 ret
= xmlTextWriterWriteElement(writer
->writer
, encoded_element_name
,
632 xmlFree(encoded_element_name
);
633 xmlFree(encoded_value
);
634 return ret
>= 0 ? 0 : ret
;
638 void xml_error_handler(void *ctx
, const char *format
, ...)
644 va_start(args
, format
);
645 ret
= vasprintf(&errMsg
, format
, args
);
648 ERR("String allocation failed in xml error handler");
652 fprintf(stderr
, "XML Error: %s", errMsg
);
657 void fini_session_config_validation_ctx(
658 struct session_config_validation_ctx
*ctx
)
660 if (ctx
->parser_ctx
) {
661 xmlSchemaFreeParserCtxt(ctx
->parser_ctx
);
665 xmlSchemaFree(ctx
->schema
);
668 if (ctx
->schema_validation_ctx
) {
669 xmlSchemaFreeValidCtxt(ctx
->schema_validation_ctx
);
672 memset(ctx
, 0, sizeof(struct session_config_validation_ctx
));
676 char *get_session_config_xsd_path()
679 const char *base_path
= lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV
);
680 size_t base_path_len
;
684 base_path
= DEFAULT_SESSION_CONFIG_XSD_PATH
;
687 base_path_len
= strlen(base_path
);
688 max_path_len
= base_path_len
+
689 sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME
) + 1;
690 xsd_path
= zmalloc(max_path_len
);
695 strcpy(xsd_path
, base_path
);
696 if (xsd_path
[base_path_len
- 1] != '/') {
697 xsd_path
[base_path_len
++] = '/';
700 strcpy(xsd_path
+ base_path_len
, DEFAULT_SESSION_CONFIG_XSD_FILENAME
);
706 int init_session_config_validation_ctx(
707 struct session_config_validation_ctx
*ctx
)
710 char *xsd_path
= get_session_config_xsd_path();
713 ret
= -LTTNG_ERR_NOMEM
;
717 ctx
->parser_ctx
= xmlSchemaNewParserCtxt(xsd_path
);
718 if (!ctx
->parser_ctx
) {
719 ERR("XSD parser context creation failed");
720 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
723 xmlSchemaSetParserErrors(ctx
->parser_ctx
, xml_error_handler
,
724 xml_error_handler
, NULL
);
726 ctx
->schema
= xmlSchemaParse(ctx
->parser_ctx
);
728 ERR("XSD parsing failed");
729 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
733 ctx
->schema_validation_ctx
= xmlSchemaNewValidCtxt(ctx
->schema
);
734 if (!ctx
->schema_validation_ctx
) {
735 ERR("XSD validation context creation failed");
736 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
740 xmlSchemaSetValidErrors(ctx
->schema_validation_ctx
, xml_error_handler
,
741 xml_error_handler
, NULL
);
746 fini_session_config_validation_ctx(ctx
);
754 int parse_uint(xmlChar
*str
, uint64_t *val
)
764 *val
= strtoull((const char *) str
, &endptr
, 10);
765 if (!endptr
|| *endptr
) {
776 int parse_int(xmlChar
*str
, int64_t *val
)
786 *val
= strtoll((const char *) str
, &endptr
, 10);
787 if (!endptr
|| *endptr
) {
798 int parse_bool(xmlChar
*str
, int *val
)
807 if (!strcmp((const char *) str
, config_xml_true
)) {
809 } else if (!strcmp((const char *) str
, config_xml_false
)) {
812 WARN("Invalid boolean value encoutered (%s).",
821 int get_domain_type(xmlChar
*domain
)
829 if (!strcmp((char *) domain
, config_domain_type_kernel
)) {
830 ret
= LTTNG_DOMAIN_KERNEL
;
831 } else if (!strcmp((char *) domain
, config_domain_type_ust
)) {
832 ret
= LTTNG_DOMAIN_UST
;
833 } else if (!strcmp((char *) domain
, config_domain_type_jul
)) {
834 ret
= LTTNG_DOMAIN_JUL
;
835 } else if (!strcmp((char *) domain
, config_domain_type_log4j
)) {
836 ret
= LTTNG_DOMAIN_LOG4J
;
837 } else if (!strcmp((char *) domain
, config_domain_type_python
)) {
838 ret
= LTTNG_DOMAIN_PYTHON
;
849 int get_buffer_type(xmlChar
*buffer_type
)
857 if (!strcmp((char *) buffer_type
, config_buffer_type_global
)) {
858 ret
= LTTNG_BUFFER_GLOBAL
;
859 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_uid
)) {
860 ret
= LTTNG_BUFFER_PER_UID
;
861 } else if (!strcmp((char *) buffer_type
, config_buffer_type_per_pid
)) {
862 ret
= LTTNG_BUFFER_PER_PID
;
873 int get_overwrite_mode(xmlChar
*overwrite_mode
)
877 if (!overwrite_mode
) {
881 if (!strcmp((char *) overwrite_mode
, config_overwrite_mode_overwrite
)) {
883 } else if (!strcmp((char *) overwrite_mode
,
884 config_overwrite_mode_discard
)) {
896 int get_output_type(xmlChar
*output_type
)
904 if (!strcmp((char *) output_type
, config_output_type_mmap
)) {
905 ret
= LTTNG_EVENT_MMAP
;
906 } else if (!strcmp((char *) output_type
, config_output_type_splice
)) {
907 ret
= LTTNG_EVENT_SPLICE
;
918 int get_event_type(xmlChar
*event_type
)
926 if (!strcmp((char *) event_type
, config_event_type_all
)) {
927 ret
= LTTNG_EVENT_ALL
;
928 } else if (!strcmp((char *) event_type
, config_event_type_tracepoint
)) {
929 ret
= LTTNG_EVENT_TRACEPOINT
;
930 } else if (!strcmp((char *) event_type
, config_event_type_probe
)) {
931 ret
= LTTNG_EVENT_PROBE
;
932 } else if (!strcmp((char *) event_type
, config_event_type_function
)) {
933 ret
= LTTNG_EVENT_FUNCTION
;
934 } else if (!strcmp((char *) event_type
,
935 config_event_type_function_entry
)) {
936 ret
= LTTNG_EVENT_FUNCTION_ENTRY
;
937 } else if (!strcmp((char *) event_type
, config_event_type_noop
)) {
938 ret
= LTTNG_EVENT_NOOP
;
939 } else if (!strcmp((char *) event_type
, config_event_type_syscall
)) {
940 ret
= LTTNG_EVENT_SYSCALL
;
951 int get_loglevel_type(xmlChar
*loglevel_type
)
955 if (!loglevel_type
) {
959 if (!strcmp((char *) loglevel_type
, config_loglevel_type_all
)) {
960 ret
= LTTNG_EVENT_LOGLEVEL_ALL
;
961 } else if (!strcmp((char *) loglevel_type
,
962 config_loglevel_type_range
)) {
963 ret
= LTTNG_EVENT_LOGLEVEL_RANGE
;
964 } else if (!strcmp((char *) loglevel_type
,
965 config_loglevel_type_single
)) {
966 ret
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
977 * Return the context type or -1 on error.
980 int get_context_type(xmlChar
*context_type
)
988 if (!strcmp((char *) context_type
, config_event_context_pid
)) {
989 ret
= LTTNG_EVENT_CONTEXT_PID
;
990 } else if (!strcmp((char *) context_type
,
991 config_event_context_procname
)) {
992 ret
= LTTNG_EVENT_CONTEXT_PROCNAME
;
993 } else if (!strcmp((char *) context_type
,
994 config_event_context_prio
)) {
995 ret
= LTTNG_EVENT_CONTEXT_PRIO
;
996 } else if (!strcmp((char *) context_type
,
997 config_event_context_nice
)) {
998 ret
= LTTNG_EVENT_CONTEXT_NICE
;
999 } else if (!strcmp((char *) context_type
,
1000 config_event_context_vpid
)) {
1001 ret
= LTTNG_EVENT_CONTEXT_VPID
;
1002 } else if (!strcmp((char *) context_type
,
1003 config_event_context_tid
)) {
1004 ret
= LTTNG_EVENT_CONTEXT_TID
;
1005 } else if (!strcmp((char *) context_type
,
1006 config_event_context_vtid
)) {
1007 ret
= LTTNG_EVENT_CONTEXT_VTID
;
1008 } else if (!strcmp((char *) context_type
,
1009 config_event_context_ppid
)) {
1010 ret
= LTTNG_EVENT_CONTEXT_PPID
;
1011 } else if (!strcmp((char *) context_type
,
1012 config_event_context_vppid
)) {
1013 ret
= LTTNG_EVENT_CONTEXT_VPPID
;
1014 } else if (!strcmp((char *) context_type
,
1015 config_event_context_pthread_id
)) {
1016 ret
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
1017 } else if (!strcmp((char *) context_type
,
1018 config_event_context_hostname
)) {
1019 ret
= LTTNG_EVENT_CONTEXT_HOSTNAME
;
1020 } else if (!strcmp((char *) context_type
,
1021 config_event_context_ip
)) {
1022 ret
= LTTNG_EVENT_CONTEXT_IP
;
1023 } else if (!strcmp((char *) context_type
,
1024 config_event_context_interruptible
)) {
1025 ret
= LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
;
1026 } else if (!strcmp((char *) context_type
,
1027 config_event_context_preemptible
)) {
1028 ret
= LTTNG_EVENT_CONTEXT_PREEMPTIBLE
;
1029 } else if (!strcmp((char *) context_type
,
1030 config_event_context_need_reschedule
)) {
1031 ret
= LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
;
1032 } else if (!strcmp((char *) context_type
,
1033 config_event_context_migratable
)) {
1034 ret
= LTTNG_EVENT_CONTEXT_MIGRATABLE
;
1045 int init_domain(xmlNodePtr domain_node
, struct lttng_domain
*domain
)
1050 for (node
= xmlFirstElementChild(domain_node
); node
;
1051 node
= xmlNextElementSibling(node
)) {
1052 if (!strcmp((const char *) node
->name
, config_element_type
)) {
1054 xmlChar
*node_content
= xmlNodeGetContent(node
);
1055 if (!node_content
) {
1056 ret
= -LTTNG_ERR_NOMEM
;
1060 ret
= get_domain_type(node_content
);
1063 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1068 } else if (!strcmp((const char *) node
->name
,
1069 config_element_buffer_type
)) {
1071 xmlChar
*node_content
= xmlNodeGetContent(node
);
1072 if (!node_content
) {
1073 ret
= -LTTNG_ERR_NOMEM
;
1077 ret
= get_buffer_type(node_content
);
1080 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1084 domain
->buf_type
= ret
;
1093 int get_net_output_uris(xmlNodePtr net_output_node
, char **control_uri
,
1098 for (node
= xmlFirstElementChild(net_output_node
); node
;
1099 node
= xmlNextElementSibling(node
)) {
1100 if (!strcmp((const char *) node
->name
, config_element_control_uri
)) {
1102 *control_uri
= (char *) xmlNodeGetContent(node
);
1103 if (!*control_uri
) {
1108 *data_uri
= (char *) xmlNodeGetContent(node
);
1115 return *control_uri
|| *data_uri
? 0 : -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1119 int process_consumer_output(xmlNodePtr consumer_output_node
,
1120 struct consumer_output
*output
)
1127 for (node
= xmlFirstElementChild(consumer_output_node
); node
;
1128 node
= xmlNextElementSibling(node
)) {
1129 if (!strcmp((const char *) node
->name
, config_element_enabled
)) {
1130 xmlChar
*enabled_str
= xmlNodeGetContent(node
);
1134 ret
= -LTTNG_ERR_NOMEM
;
1138 ret
= parse_bool(enabled_str
, &output
->enabled
);
1144 xmlNodePtr output_type_node
;
1147 output_type_node
= xmlFirstElementChild(node
);
1148 if (!output_type_node
) {
1149 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1153 if (!strcmp((const char *) output_type_node
->name
,
1154 config_element_path
)) {
1156 output
->path
= (char *) xmlNodeGetContent(output_type_node
);
1157 if (!output
->path
) {
1158 ret
= -LTTNG_ERR_NOMEM
;
1163 ret
= get_net_output_uris(output_type_node
,
1164 &output
->control_uri
, &output
->data_uri
);
1176 free(output
->control_uri
);
1177 free(output
->data_uri
);
1178 memset(output
, 0, sizeof(struct consumer_output
));
1184 int create_session_net_output(const char *name
, const char *control_uri
,
1185 const char *data_uri
)
1188 struct lttng_handle
*handle
;
1189 const char *uri
= NULL
;
1193 handle
= lttng_create_handle(name
, NULL
);
1195 ret
= -LTTNG_ERR_NOMEM
;
1199 if (!control_uri
|| !data_uri
) {
1200 uri
= control_uri
? control_uri
: data_uri
;
1205 ret
= lttng_set_consumer_url(handle
, control_uri
, data_uri
);
1206 lttng_destroy_handle(handle
);
1212 int create_snapshot_session(const char *session_name
, xmlNodePtr output_node
,
1213 const struct config_load_session_override_attr
*overrides
)
1216 xmlNodePtr node
= NULL
;
1217 xmlNodePtr snapshot_output_list_node
;
1218 xmlNodePtr snapshot_output_node
;
1220 assert(session_name
);
1222 ret
= lttng_create_session_snapshot(session_name
, NULL
);
1231 snapshot_output_list_node
= xmlFirstElementChild(output_node
);
1233 /* Parse and create snapshot outputs */
1235 for (snapshot_output_node
=
1236 xmlFirstElementChild(snapshot_output_list_node
);
1237 snapshot_output_node
; snapshot_output_node
=
1238 xmlNextElementSibling(snapshot_output_node
)) {
1240 uint64_t max_size
= UINT64_MAX
;
1241 struct consumer_output output
= { 0 };
1242 struct lttng_snapshot_output
*snapshot_output
= NULL
;
1243 const char *control_uri
= NULL
;
1244 const char *data_uri
= NULL
;
1245 const char *path
= NULL
;
1247 for (node
= xmlFirstElementChild(snapshot_output_node
); node
;
1248 node
= xmlNextElementSibling(node
)) {
1249 if (!strcmp((const char *) node
->name
,
1250 config_element_name
)) {
1252 name
= (char *) xmlNodeGetContent(node
);
1254 ret
= -LTTNG_ERR_NOMEM
;
1255 goto error_snapshot_output
;
1257 } else if (!strcmp((const char *) node
->name
,
1258 config_element_max_size
)) {
1259 xmlChar
*content
= xmlNodeGetContent(node
);
1263 ret
= -LTTNG_ERR_NOMEM
;
1264 goto error_snapshot_output
;
1266 ret
= parse_uint(content
, &max_size
);
1269 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1270 goto error_snapshot_output
;
1273 /* consumer_output */
1274 ret
= process_consumer_output(node
, &output
);
1276 goto error_snapshot_output
;
1281 control_uri
= output
.control_uri
;
1282 data_uri
= output
.data_uri
;
1286 if (overrides
->path_url
) {
1287 path
= overrides
->path_url
;
1288 /* Control/data_uri are null */
1292 if (overrides
->ctrl_url
) {
1293 control_uri
= overrides
->ctrl_url
;
1297 if (overrides
->data_url
) {
1298 data_uri
= overrides
->data_url
;
1305 snapshot_output
= lttng_snapshot_output_create();
1306 if (!snapshot_output
) {
1307 ret
= -LTTNG_ERR_NOMEM
;
1308 goto error_snapshot_output
;
1311 ret
= lttng_snapshot_output_set_name(name
, snapshot_output
);
1313 goto error_snapshot_output
;
1316 ret
= lttng_snapshot_output_set_size(max_size
, snapshot_output
);
1318 goto error_snapshot_output
;
1322 ret
= lttng_snapshot_output_set_ctrl_url(path
,
1325 goto error_snapshot_output
;
1329 ret
= lttng_snapshot_output_set_ctrl_url(control_uri
,
1332 goto error_snapshot_output
;
1337 ret
= lttng_snapshot_output_set_data_url(data_uri
,
1340 goto error_snapshot_output
;
1345 ret
= lttng_snapshot_add_output(session_name
, snapshot_output
);
1346 error_snapshot_output
:
1349 free(output
.control_uri
);
1350 free(output
.data_uri
);
1351 lttng_snapshot_output_destroy(snapshot_output
);
1361 int create_session(const char *name
,
1362 xmlNodePtr output_node
,
1363 uint64_t live_timer_interval
,
1364 const struct config_load_session_override_attr
*overrides
)
1367 struct consumer_output output
= { 0 };
1368 xmlNodePtr consumer_output_node
;
1369 const char *control_uri
= NULL
;
1370 const char *data_uri
= NULL
;
1371 const char *path
= NULL
;
1376 consumer_output_node
= xmlFirstElementChild(output_node
);
1377 if (!consumer_output_node
) {
1378 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1382 if (strcmp((const char *) consumer_output_node
->name
,
1383 config_element_consumer_output
)) {
1384 WARN("Invalid output type, expected %s node",
1385 config_element_consumer_output
);
1386 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1390 ret
= process_consumer_output(consumer_output_node
, &output
);
1396 control_uri
= output
.control_uri
;
1397 data_uri
= output
.data_uri
;
1400 /* Check for override and apply them */
1402 if (overrides
->path_url
) {
1403 path
= overrides
->path_url
;
1404 /* control/data_uri are null */;
1408 if (overrides
->ctrl_url
) {
1409 control_uri
= overrides
->ctrl_url
;
1413 if (overrides
->data_url
) {
1414 data_uri
= overrides
->data_url
;
1422 if (live_timer_interval
!= UINT64_MAX
&& !control_uri
&& !data_uri
) {
1423 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1427 if (control_uri
|| data_uri
) {
1428 /* network destination */
1429 if (live_timer_interval
&& live_timer_interval
!= UINT64_MAX
) {
1431 * URLs are provided for sure since the test above make sure that
1432 * with a live timer the data and control URIs are provided. So,
1433 * NULL is passed here and will be set right after.
1435 ret
= lttng_create_session_live(name
, NULL
, live_timer_interval
);
1437 ret
= lttng_create_session(name
, NULL
);
1443 ret
= create_session_net_output(name
, control_uri
, data_uri
);
1449 /* either local output or no output */
1450 ret
= lttng_create_session(name
, path
);
1457 free(output
.control_uri
);
1458 free(output
.data_uri
);
1462 int process_probe_attribute_node(xmlNodePtr probe_attribute_node
,
1463 struct lttng_event_probe_attr
*attr
)
1467 assert(probe_attribute_node
);
1470 if (!strcmp((const char *) probe_attribute_node
->name
,
1471 config_element_address
)) {
1476 content
= xmlNodeGetContent(probe_attribute_node
);
1478 ret
= -LTTNG_ERR_NOMEM
;
1482 ret
= parse_uint(content
, &addr
);
1485 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1490 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1491 config_element_offset
)) {
1493 uint64_t offset
= 0;
1496 content
= xmlNodeGetContent(probe_attribute_node
);
1498 ret
= -LTTNG_ERR_NOMEM
;
1502 ret
= parse_uint(content
, &offset
);
1505 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1509 attr
->offset
= offset
;
1510 } else if (!strcmp((const char *) probe_attribute_node
->name
,
1511 config_element_symbol_name
)) {
1515 content
= xmlNodeGetContent(probe_attribute_node
);
1517 ret
= -LTTNG_ERR_NOMEM
;
1521 ret
= lttng_strncpy(attr
->symbol_name
,
1522 (const char *) content
,
1523 LTTNG_SYMBOL_NAME_LEN
);
1525 ERR("symbol name \"%s\"'s length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1526 (const char *) content
,
1527 strlen((const char *) content
),
1528 LTTNG_SYMBOL_NAME_LEN
);
1529 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1541 int process_event_node(xmlNodePtr event_node
, struct lttng_handle
*handle
,
1542 const char *channel_name
, const enum process_event_node_phase phase
)
1546 struct lttng_event event
;
1547 char **exclusions
= NULL
;
1548 unsigned long exclusion_count
= 0;
1549 char *filter_expression
= NULL
;
1553 assert(channel_name
);
1555 memset(&event
, 0, sizeof(event
));
1557 /* Initialize default log level which varies by domain */
1558 switch (handle
->domain
.type
)
1560 case LTTNG_DOMAIN_JUL
:
1561 event
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1563 case LTTNG_DOMAIN_LOG4J
:
1564 event
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1566 case LTTNG_DOMAIN_PYTHON
:
1567 event
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1569 case LTTNG_DOMAIN_UST
:
1570 case LTTNG_DOMAIN_KERNEL
:
1571 event
.loglevel
= LTTNG_LOGLEVEL_DEBUG
;
1577 for (node
= xmlFirstElementChild(event_node
); node
;
1578 node
= xmlNextElementSibling(node
)) {
1579 if (!strcmp((const char *) node
->name
, config_element_name
)) {
1583 content
= xmlNodeGetContent(node
);
1585 ret
= -LTTNG_ERR_NOMEM
;
1589 ret
= lttng_strncpy(event
.name
,
1590 (const char *) content
,
1591 LTTNG_SYMBOL_NAME_LEN
);
1593 WARN("Event \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1594 (const char *) content
,
1595 strlen((const char *) content
),
1596 LTTNG_SYMBOL_NAME_LEN
);
1597 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1602 } else if (!strcmp((const char *) node
->name
,
1603 config_element_enabled
)) {
1604 xmlChar
*content
= xmlNodeGetContent(node
);
1608 ret
= -LTTNG_ERR_NOMEM
;
1612 ret
= parse_bool(content
, &event
.enabled
);
1615 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1618 } else if (!strcmp((const char *) node
->name
,
1619 config_element_type
)) {
1620 xmlChar
*content
= xmlNodeGetContent(node
);
1624 ret
= -LTTNG_ERR_NOMEM
;
1628 ret
= get_event_type(content
);
1631 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1636 } else if (!strcmp((const char *) node
->name
,
1637 config_element_loglevel_type
)) {
1638 xmlChar
*content
= xmlNodeGetContent(node
);
1642 ret
= -LTTNG_ERR_NOMEM
;
1646 ret
= get_loglevel_type(content
);
1649 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1653 event
.loglevel_type
= ret
;
1654 } else if (!strcmp((const char *) node
->name
,
1655 config_element_loglevel
)) {
1657 int64_t loglevel
= 0;
1660 content
= xmlNodeGetContent(node
);
1662 ret
= -LTTNG_ERR_NOMEM
;
1666 ret
= parse_int(content
, &loglevel
);
1669 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1673 if (loglevel
> INT_MAX
|| loglevel
< INT_MIN
) {
1674 WARN("loglevel out of range.");
1675 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1679 event
.loglevel
= loglevel
;
1680 } else if (!strcmp((const char *) node
->name
,
1681 config_element_filter
)) {
1683 xmlNodeGetContent(node
);
1687 ret
= -LTTNG_ERR_NOMEM
;
1691 free(filter_expression
);
1692 filter_expression
= strdup((char *) content
);
1694 if (!filter_expression
) {
1695 ret
= -LTTNG_ERR_NOMEM
;
1698 } else if (!strcmp((const char *) node
->name
,
1699 config_element_exclusions
)) {
1700 xmlNodePtr exclusion_node
;
1701 int exclusion_index
= 0;
1706 * Exclusions has already been initialized,
1709 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1713 exclusion_count
= xmlChildElementCount(node
);
1714 if (!exclusion_count
) {
1718 exclusions
= zmalloc(exclusion_count
* sizeof(char *));
1720 exclusion_count
= 0;
1721 ret
= -LTTNG_ERR_NOMEM
;
1725 for (exclusion_node
= xmlFirstElementChild(node
); exclusion_node
;
1726 exclusion_node
= xmlNextElementSibling(exclusion_node
)) {
1728 xmlNodeGetContent(exclusion_node
);
1731 ret
= -LTTNG_ERR_NOMEM
;
1735 exclusions
[exclusion_index
] = strdup((const char *) content
);
1737 if (!exclusions
[exclusion_index
]) {
1738 ret
= -LTTNG_ERR_NOMEM
;
1744 event
.exclusion
= 1;
1745 } else if (!strcmp((const char *) node
->name
,
1746 config_element_attributes
)) {
1747 xmlNodePtr attribute_node
= xmlFirstElementChild(node
);
1750 if (!attribute_node
) {
1751 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1755 if (!strcmp((const char *) node
->name
,
1756 config_element_probe_attributes
)) {
1757 xmlNodePtr probe_attribute_node
;
1759 /* probe_attributes */
1760 for (probe_attribute_node
=
1761 xmlFirstElementChild(attribute_node
); probe_attribute_node
;
1762 probe_attribute_node
= xmlNextElementSibling(
1763 probe_attribute_node
)) {
1765 ret
= process_probe_attribute_node(probe_attribute_node
,
1774 xmlNodePtr symbol_node
= xmlFirstElementChild(attribute_node
);
1776 /* function_attributes */
1777 content
= xmlNodeGetContent(symbol_node
);
1779 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1783 sym_len
= strlen((char *) content
);
1784 if (sym_len
>= LTTNG_SYMBOL_NAME_LEN
) {
1785 WARN("Function name too long.");
1786 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1791 ret
= lttng_strncpy(
1792 event
.attr
.ftrace
.symbol_name
,
1793 (char *) content
, sym_len
);
1795 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1804 if ((event
.enabled
&& phase
== ENABLE
) || phase
== CREATION
) {
1805 ret
= lttng_enable_event_with_exclusions(handle
, &event
, channel_name
,
1806 filter_expression
, exclusion_count
, exclusions
);
1808 WARN("Enabling event (name:%s) on load failed.", event
.name
);
1809 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1815 for (i
= 0; i
< exclusion_count
; i
++) {
1816 free(exclusions
[i
]);
1820 free(filter_expression
);
1825 int process_events_node(xmlNodePtr events_node
, struct lttng_handle
*handle
,
1826 const char *channel_name
)
1829 struct lttng_event event
;
1832 assert(events_node
);
1834 assert(channel_name
);
1836 for (node
= xmlFirstElementChild(events_node
); node
;
1837 node
= xmlNextElementSibling(node
)) {
1838 ret
= process_event_node(node
, handle
, channel_name
, CREATION
);
1845 * Disable all events to enable only the necessary events.
1846 * Limitations regarding lttng_disable_events and tuple descriptor
1847 * force this approach.
1849 memset(&event
, 0, sizeof(event
));
1850 event
.loglevel
= -1;
1851 event
.type
= LTTNG_EVENT_ALL
;
1852 ret
= lttng_disable_event_ext(handle
, &event
, channel_name
, NULL
);
1857 for (node
= xmlFirstElementChild(events_node
); node
;
1858 node
= xmlNextElementSibling(node
)) {
1859 ret
= process_event_node(node
, handle
, channel_name
, ENABLE
);
1870 int process_channel_attr_node(xmlNodePtr attr_node
,
1871 struct lttng_channel
*channel
, xmlNodePtr
*contexts_node
,
1872 xmlNodePtr
*events_node
)
1878 assert(contexts_node
);
1879 assert(events_node
);
1881 if (!strcmp((const char *) attr_node
->name
, config_element_name
)) {
1885 content
= xmlNodeGetContent(attr_node
);
1887 ret
= -LTTNG_ERR_NOMEM
;
1891 ret
= lttng_strncpy(channel
->name
,
1892 (const char *) content
,
1893 LTTNG_SYMBOL_NAME_LEN
);
1895 WARN("Channel \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
1896 (const char *) content
,
1897 strlen((const char *) content
),
1898 LTTNG_SYMBOL_NAME_LEN
);
1899 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1904 } else if (!strcmp((const char *) attr_node
->name
,
1905 config_element_enabled
)) {
1910 content
= xmlNodeGetContent(attr_node
);
1912 ret
= -LTTNG_ERR_NOMEM
;
1916 ret
= parse_bool(content
, &enabled
);
1919 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1923 channel
->enabled
= enabled
;
1924 } else if (!strcmp((const char *) attr_node
->name
,
1925 config_element_overwrite_mode
)) {
1928 /* overwrite_mode */
1929 content
= xmlNodeGetContent(attr_node
);
1931 ret
= -LTTNG_ERR_NOMEM
;
1935 ret
= get_overwrite_mode(content
);
1938 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1942 channel
->attr
.overwrite
= ret
;
1943 } else if (!strcmp((const char *) attr_node
->name
,
1944 config_element_subbuf_size
)) {
1947 /* subbuffer_size */
1948 content
= xmlNodeGetContent(attr_node
);
1950 ret
= -LTTNG_ERR_NOMEM
;
1954 ret
= parse_uint(content
, &channel
->attr
.subbuf_size
);
1957 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1960 } else if (!strcmp((const char *) attr_node
->name
,
1961 config_element_num_subbuf
)) {
1964 /* subbuffer_count */
1965 content
= xmlNodeGetContent(attr_node
);
1967 ret
= -LTTNG_ERR_NOMEM
;
1971 ret
= parse_uint(content
, &channel
->attr
.num_subbuf
);
1974 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1977 } else if (!strcmp((const char *) attr_node
->name
,
1978 config_element_switch_timer_interval
)) {
1980 uint64_t switch_timer_interval
= 0;
1982 /* switch_timer_interval */
1983 content
= xmlNodeGetContent(attr_node
);
1985 ret
= -LTTNG_ERR_NOMEM
;
1989 ret
= parse_uint(content
, &switch_timer_interval
);
1992 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
1996 if (switch_timer_interval
> UINT_MAX
) {
1997 WARN("switch_timer_interval out of range.");
1998 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2002 channel
->attr
.switch_timer_interval
=
2003 switch_timer_interval
;
2004 } else if (!strcmp((const char *) attr_node
->name
,
2005 config_element_read_timer_interval
)) {
2007 uint64_t read_timer_interval
= 0;
2009 /* read_timer_interval */
2010 content
= xmlNodeGetContent(attr_node
);
2012 ret
= -LTTNG_ERR_NOMEM
;
2016 ret
= parse_uint(content
, &read_timer_interval
);
2019 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2023 if (read_timer_interval
> UINT_MAX
) {
2024 WARN("read_timer_interval out of range.");
2025 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2029 channel
->attr
.read_timer_interval
=
2030 read_timer_interval
;
2031 } else if (!strcmp((const char *) attr_node
->name
,
2032 config_element_output_type
)) {
2036 content
= xmlNodeGetContent(attr_node
);
2038 ret
= -LTTNG_ERR_NOMEM
;
2042 ret
= get_output_type(content
);
2045 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2049 channel
->attr
.output
= ret
;
2050 } else if (!strcmp((const char *) attr_node
->name
,
2051 config_element_tracefile_size
)) {
2054 /* tracefile_size */
2055 content
= xmlNodeGetContent(attr_node
);
2057 ret
= -LTTNG_ERR_NOMEM
;
2061 ret
= parse_uint(content
, &channel
->attr
.tracefile_size
);
2064 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2067 } else if (!strcmp((const char *) attr_node
->name
,
2068 config_element_tracefile_count
)) {
2071 /* tracefile_count */
2072 content
= xmlNodeGetContent(attr_node
);
2074 ret
= -LTTNG_ERR_NOMEM
;
2078 ret
= parse_uint(content
, &channel
->attr
.tracefile_count
);
2081 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2084 } else if (!strcmp((const char *) attr_node
->name
,
2085 config_element_live_timer_interval
)) {
2087 uint64_t live_timer_interval
= 0;
2089 /* live_timer_interval */
2090 content
= xmlNodeGetContent(attr_node
);
2092 ret
= -LTTNG_ERR_NOMEM
;
2096 ret
= parse_uint(content
, &live_timer_interval
);
2099 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2103 if (live_timer_interval
> UINT_MAX
) {
2104 WARN("live_timer_interval out of range.");
2105 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2109 channel
->attr
.live_timer_interval
=
2110 live_timer_interval
;
2111 } else if (!strcmp((const char *) attr_node
->name
,
2112 config_element_monitor_timer_interval
)) {
2114 uint64_t monitor_timer_interval
= 0;
2116 /* monitor_timer_interval */
2117 content
= xmlNodeGetContent(attr_node
);
2119 ret
= -LTTNG_ERR_NOMEM
;
2123 ret
= parse_uint(content
, &monitor_timer_interval
);
2126 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2130 ret
= lttng_channel_set_monitor_timer_interval(channel
,
2131 monitor_timer_interval
);
2133 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2136 } else if (!strcmp((const char *) attr_node
->name
,
2137 config_element_blocking_timeout
)) {
2139 int64_t blocking_timeout
= 0;
2141 /* blocking_timeout */
2142 content
= xmlNodeGetContent(attr_node
);
2144 ret
= -LTTNG_ERR_NOMEM
;
2148 ret
= parse_int(content
, &blocking_timeout
);
2151 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2155 ret
= lttng_channel_set_blocking_timeout(channel
,
2158 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2161 } else if (!strcmp((const char *) attr_node
->name
,
2162 config_element_events
)) {
2164 *events_node
= attr_node
;
2167 *contexts_node
= attr_node
;
2175 int process_context_node(xmlNodePtr context_node
,
2176 struct lttng_handle
*handle
, const char *channel_name
)
2179 struct lttng_event_context context
;
2180 xmlNodePtr context_child_node
= xmlFirstElementChild(context_node
);
2183 assert(channel_name
);
2185 if (!context_child_node
) {
2186 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2190 memset(&context
, 0, sizeof(context
));
2192 if (!strcmp((const char *) context_child_node
->name
,
2193 config_element_type
)) {
2195 xmlChar
*content
= xmlNodeGetContent(context_child_node
);
2198 ret
= -LTTNG_ERR_NOMEM
;
2202 ret
= get_context_type(content
);
2205 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2210 } else if (!strcmp((const char *) context_child_node
->name
,
2211 config_element_context_perf
)) {
2213 xmlNodePtr perf_attr_node
;
2215 context
.ctx
= handle
->domain
.type
== LTTNG_DOMAIN_KERNEL
?
2216 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2217 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
;
2218 for (perf_attr_node
= xmlFirstElementChild(context_child_node
);
2219 perf_attr_node
; perf_attr_node
=
2220 xmlNextElementSibling(perf_attr_node
)) {
2221 if (!strcmp((const char *) perf_attr_node
->name
,
2222 config_element_type
)) {
2227 content
= xmlNodeGetContent(perf_attr_node
);
2229 ret
= -LTTNG_ERR_NOMEM
;
2233 ret
= parse_uint(content
, &type
);
2236 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2240 if (type
> UINT32_MAX
) {
2241 WARN("perf context type out of range.");
2242 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2246 context
.u
.perf_counter
.type
= type
;
2247 } else if (!strcmp((const char *) perf_attr_node
->name
,
2248 config_element_config
)) {
2250 uint64_t config
= 0;
2253 content
= xmlNodeGetContent(perf_attr_node
);
2255 ret
= -LTTNG_ERR_NOMEM
;
2259 ret
= parse_uint(content
, &config
);
2262 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2266 context
.u
.perf_counter
.config
= config
;
2267 } else if (!strcmp((const char *) perf_attr_node
->name
,
2268 config_element_name
)) {
2272 content
= xmlNodeGetContent(perf_attr_node
);
2274 ret
= -LTTNG_ERR_NOMEM
;
2278 ret
= lttng_strncpy(context
.u
.perf_counter
.name
,
2279 (const char *) content
,
2280 LTTNG_SYMBOL_NAME_LEN
);
2282 WARN("Perf counter \"%s\"'s name length (%zu) exceeds the maximal permitted length (%d) in session configuration",
2283 (const char *) content
,
2284 strlen((const char *) content
),
2285 LTTNG_SYMBOL_NAME_LEN
);
2286 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2293 } else if (!strcmp((const char *) context_child_node
->name
,
2294 config_element_context_app
)) {
2295 /* application context */
2296 xmlNodePtr app_ctx_node
;
2298 context
.ctx
= LTTNG_EVENT_CONTEXT_APP_CONTEXT
;
2299 for (app_ctx_node
= xmlFirstElementChild(context_child_node
);
2300 app_ctx_node
; app_ctx_node
=
2301 xmlNextElementSibling(app_ctx_node
)) {
2303 char **target
= strcmp(
2304 (const char *) app_ctx_node
->name
,
2305 config_element_context_app_provider_name
) == 0 ?
2306 &context
.u
.app_ctx
.provider_name
:
2307 &context
.u
.app_ctx
.ctx_name
;
2309 content
= xmlNodeGetContent(app_ctx_node
);
2311 ret
= -LTTNG_ERR_NOMEM
;
2315 *target
= (char *) content
;
2318 /* Unrecognized context type */
2319 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2323 ret
= lttng_add_context(handle
, &context
, NULL
, channel_name
);
2324 if (context
.ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
2325 free(context
.u
.app_ctx
.provider_name
);
2326 free(context
.u
.app_ctx
.ctx_name
);
2333 int process_contexts_node(xmlNodePtr contexts_node
,
2334 struct lttng_handle
*handle
, const char *channel_name
)
2337 xmlNodePtr context_node
;
2339 for (context_node
= xmlFirstElementChild(contexts_node
); context_node
;
2340 context_node
= xmlNextElementSibling(context_node
)) {
2341 ret
= process_context_node(context_node
, handle
, channel_name
);
2351 int get_tracker_elements(enum lttng_tracker_type tracker_type
,
2352 const char **element_id_tracker
,
2353 const char **element_target_id
,
2354 const char **element_id
,
2355 const char **element_id_alias
,
2356 const char **element_name
)
2360 switch (tracker_type
) {
2361 case LTTNG_TRACKER_PID
:
2362 *element_id_tracker
= config_element_pid_tracker
;
2363 *element_target_id
= config_element_target_pid
;
2364 *element_id
= config_element_id
;
2365 *element_id_alias
= config_element_pid
;
2366 *element_name
= NULL
;
2368 case LTTNG_TRACKER_VPID
:
2369 *element_id_tracker
= config_element_vpid_tracker
;
2370 *element_target_id
= config_element_target_vpid
;
2371 *element_id
= config_element_id
;
2372 *element_id_alias
= NULL
;
2373 *element_name
= NULL
;
2375 case LTTNG_TRACKER_UID
:
2376 *element_id_tracker
= config_element_uid_tracker
;
2377 *element_target_id
= config_element_target_uid
;
2378 *element_id
= config_element_id
;
2379 *element_id_alias
= NULL
;
2380 *element_name
= config_element_name
;
2382 case LTTNG_TRACKER_VUID
:
2383 *element_id_tracker
= config_element_vuid_tracker
;
2384 *element_target_id
= config_element_target_vuid
;
2385 *element_id
= config_element_id
;
2386 *element_id_alias
= NULL
;
2387 *element_name
= config_element_name
;
2389 case LTTNG_TRACKER_GID
:
2390 *element_id_tracker
= config_element_gid_tracker
;
2391 *element_target_id
= config_element_target_gid
;
2392 *element_id
= config_element_id
;
2393 *element_id_alias
= NULL
;
2394 *element_name
= config_element_name
;
2396 case LTTNG_TRACKER_VGID
:
2397 *element_id_tracker
= config_element_vgid_tracker
;
2398 *element_target_id
= config_element_target_vgid
;
2399 *element_id
= config_element_id
;
2400 *element_id_alias
= NULL
;
2401 *element_name
= config_element_name
;
2404 ret
= LTTNG_ERR_INVALID
;
2410 int process_id_tracker_node(xmlNodePtr id_tracker_node
,
2411 struct lttng_handle
*handle
, enum lttng_tracker_type tracker_type
)
2414 xmlNodePtr targets_node
= NULL
;
2416 const char *element_id_tracker
;
2417 const char *element_target_id
;
2418 const char *element_id
;
2419 const char *element_id_alias
;
2420 const char *element_name
;
2423 assert(id_tracker_node
);
2425 ret
= get_tracker_elements(tracker_type
, &element_id_tracker
,
2426 &element_target_id
, &element_id
, &element_id_alias
, &element_name
);
2431 /* get the targets node */
2432 for (node
= xmlFirstElementChild(id_tracker_node
); node
;
2433 node
= xmlNextElementSibling(node
)) {
2434 if (!strcmp((const char *) node
->name
,
2435 config_element_targets
)) {
2436 targets_node
= node
;
2441 if (!targets_node
) {
2442 ret
= LTTNG_ERR_INVALID
;
2446 /* Go through all id target node */
2447 child
= xmlChildElementCount(targets_node
);
2449 struct lttng_tracker_id tracker_id
;
2451 tracker_id
.type
= LTTNG_ID_ALL
;
2452 /* The session is explicitly set to target nothing. */
2453 ret
= lttng_untrack_id(handle
, tracker_type
, &tracker_id
);
2458 for (node
= xmlFirstElementChild(targets_node
); node
;
2459 node
= xmlNextElementSibling(node
)) {
2460 xmlNodePtr id_target_node
= node
;
2462 /* get id node and track it */
2463 for (node
= xmlFirstElementChild(id_target_node
); node
;
2464 node
= xmlNextElementSibling(node
)) {
2465 if (!strcmp((const char *) node
->name
, element_id
) ||
2466 (element_id_alias
&& !strcmp((const char *) node
->name
,
2467 element_id_alias
))) {
2469 xmlChar
*content
= NULL
;
2470 struct lttng_tracker_id tracker_id
;
2472 content
= xmlNodeGetContent(node
);
2474 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2478 ret
= parse_int(content
, &id
);
2481 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2485 tracker_id
.type
= LTTNG_ID_VALUE
;
2486 tracker_id
.value
= (int) id
;
2487 ret
= lttng_track_id(handle
, tracker_type
, &tracker_id
);
2492 if (element_name
&& !strcmp((const char *) node
->name
,
2494 xmlChar
*content
= NULL
;
2495 struct lttng_tracker_id tracker_id
;
2497 content
= xmlNodeGetContent(node
);
2499 ret
= LTTNG_ERR_LOAD_INVALID_CONFIG
;
2502 tracker_id
.type
= LTTNG_ID_STRING
;
2503 tracker_id
.string
= (char *) content
;
2504 ret
= lttng_track_id(handle
, tracker_type
, &tracker_id
);
2511 node
= id_target_node
;
2519 int process_domain_node(xmlNodePtr domain_node
, const char *session_name
)
2522 struct lttng_domain domain
= { 0 };
2523 struct lttng_handle
*handle
= NULL
;
2524 struct lttng_channel
*channel
= NULL
;
2525 xmlNodePtr channels_node
= NULL
;
2526 xmlNodePtr trackers_node
= NULL
;
2527 xmlNodePtr pid_tracker_node
= NULL
;
2528 xmlNodePtr vpid_tracker_node
= NULL
;
2529 xmlNodePtr uid_tracker_node
= NULL
;
2530 xmlNodePtr vuid_tracker_node
= NULL
;
2531 xmlNodePtr gid_tracker_node
= NULL
;
2532 xmlNodePtr vgid_tracker_node
= NULL
;
2535 assert(session_name
);
2537 ret
= init_domain(domain_node
, &domain
);
2542 handle
= lttng_create_handle(session_name
, &domain
);
2544 ret
= -LTTNG_ERR_NOMEM
;
2548 /* get the channels node */
2549 for (node
= xmlFirstElementChild(domain_node
); node
;
2550 node
= xmlNextElementSibling(node
)) {
2551 if (!strcmp((const char *) node
->name
,
2552 config_element_channels
)) {
2553 channels_node
= node
;
2558 if (!channels_node
) {
2562 /* create all channels */
2563 for (node
= xmlFirstElementChild(channels_node
); node
;
2564 node
= xmlNextElementSibling(node
)) {
2565 const enum lttng_domain_type original_domain
= domain
.type
;
2566 xmlNodePtr contexts_node
= NULL
;
2567 xmlNodePtr events_node
= NULL
;
2568 xmlNodePtr channel_attr_node
;
2571 * Channels of the "agent" types cannot be created directly.
2572 * They are meant to be created implicitly through the
2573 * activation of events in their domain. However, a user
2574 * can override the default channel configuration attributes
2575 * by creating the underlying UST channel _before_ enabling
2576 * an agent domain event.
2578 * Hence, the channel's type is substituted before the creation
2579 * and restored by the time the events are created.
2581 switch (domain
.type
) {
2582 case LTTNG_DOMAIN_JUL
:
2583 case LTTNG_DOMAIN_LOG4J
:
2584 case LTTNG_DOMAIN_PYTHON
:
2585 domain
.type
= LTTNG_DOMAIN_UST
;
2590 channel
= lttng_channel_create(&domain
);
2596 for (channel_attr_node
= xmlFirstElementChild(node
);
2597 channel_attr_node
; channel_attr_node
=
2598 xmlNextElementSibling(channel_attr_node
)) {
2599 ret
= process_channel_attr_node(channel_attr_node
,
2600 channel
, &contexts_node
, &events_node
);
2606 ret
= lttng_enable_channel(handle
, channel
);
2611 /* Restore the original channel domain. */
2612 domain
.type
= original_domain
;
2614 ret
= process_events_node(events_node
, handle
, channel
->name
);
2619 ret
= process_contexts_node(contexts_node
, handle
,
2625 lttng_channel_destroy(channel
);
2629 /* get the trackers node */
2630 for (node
= xmlFirstElementChild(domain_node
); node
;
2631 node
= xmlNextElementSibling(node
)) {
2632 if (!strcmp((const char *) node
->name
,
2633 config_element_trackers
)) {
2634 trackers_node
= node
;
2639 if (!trackers_node
) {
2643 for (node
= xmlFirstElementChild(trackers_node
); node
;
2644 node
= xmlNextElementSibling(node
)) {
2645 if (!strcmp((const char *)node
->name
, config_element_pid_tracker
)) {
2646 pid_tracker_node
= node
;
2647 ret
= process_id_tracker_node(pid_tracker_node
, handle
,
2653 if (!strcmp((const char *)node
->name
, config_element_vpid_tracker
)) {
2654 vpid_tracker_node
= node
;
2655 ret
= process_id_tracker_node(vpid_tracker_node
, handle
,
2656 LTTNG_TRACKER_VPID
);
2661 if (!strcmp((const char *)node
->name
, config_element_uid_tracker
)) {
2662 uid_tracker_node
= node
;
2663 ret
= process_id_tracker_node(uid_tracker_node
, handle
,
2669 if (!strcmp((const char *)node
->name
, config_element_vuid_tracker
)) {
2670 vuid_tracker_node
= node
;
2671 ret
= process_id_tracker_node(vuid_tracker_node
, handle
,
2672 LTTNG_TRACKER_VUID
);
2677 if (!strcmp((const char *)node
->name
, config_element_gid_tracker
)) {
2678 gid_tracker_node
= node
;
2679 ret
= process_id_tracker_node(gid_tracker_node
, handle
,
2685 if (!strcmp((const char *)node
->name
, config_element_vgid_tracker
)) {
2686 vgid_tracker_node
= node
;
2687 ret
= process_id_tracker_node(vgid_tracker_node
, handle
,
2688 LTTNG_TRACKER_VGID
);
2696 lttng_channel_destroy(channel
);
2697 lttng_destroy_handle(handle
);
2702 int process_session_node(xmlNodePtr session_node
, const char *session_name
,
2704 const struct config_load_session_override_attr
*overrides
)
2706 int ret
, started
= -1, snapshot_mode
= -1;
2707 uint64_t live_timer_interval
= UINT64_MAX
,
2708 rotation_timer_interval
= 0,
2710 xmlChar
*name
= NULL
;
2711 xmlChar
*shm_path
= NULL
;
2712 xmlNodePtr domains_node
= NULL
;
2713 xmlNodePtr output_node
= NULL
;
2715 xmlNodePtr attributes_child
;
2716 struct lttng_domain
*kernel_domain
= NULL
;
2717 struct lttng_domain
*ust_domain
= NULL
;
2718 struct lttng_domain
*jul_domain
= NULL
;
2719 struct lttng_domain
*log4j_domain
= NULL
;
2720 struct lttng_domain
*python_domain
= NULL
;
2722 for (node
= xmlFirstElementChild(session_node
); node
;
2723 node
= xmlNextElementSibling(node
)) {
2724 if (!name
&& !strcmp((const char *) node
->name
,
2725 config_element_name
)) {
2727 xmlChar
*node_content
= xmlNodeGetContent(node
);
2728 if (!node_content
) {
2729 ret
= -LTTNG_ERR_NOMEM
;
2733 name
= node_content
;
2734 } else if (!domains_node
&& !strcmp((const char *) node
->name
,
2735 config_element_domains
)) {
2737 domains_node
= node
;
2738 } else if (started
== -1 && !strcmp((const char *) node
->name
,
2739 config_element_started
)) {
2741 xmlChar
*node_content
= xmlNodeGetContent(node
);
2742 if (!node_content
) {
2743 ret
= -LTTNG_ERR_NOMEM
;
2747 ret
= parse_bool(node_content
, &started
);
2750 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2753 } else if (!output_node
&& !strcmp((const char *) node
->name
,
2754 config_element_output
)) {
2757 } else if (!shm_path
&& !strcmp((const char *) node
->name
,
2758 config_element_shared_memory_path
)) {
2759 /* shared memory path */
2760 xmlChar
*node_content
= xmlNodeGetContent(node
);
2761 if (!node_content
) {
2762 ret
= -LTTNG_ERR_NOMEM
;
2766 shm_path
= node_content
;
2769 * attributes, snapshot_mode, live_timer_interval, rotation_size,
2770 * rotation_timer_interval.
2772 for (attributes_child
= xmlFirstElementChild(node
); attributes_child
;
2773 attributes_child
= xmlNextElementSibling(attributes_child
)) {
2774 if (!strcmp((const char *) attributes_child
->name
,
2775 config_element_snapshot_mode
)) {
2777 xmlChar
*snapshot_mode_content
=
2778 xmlNodeGetContent(attributes_child
);
2779 if (!snapshot_mode_content
) {
2780 ret
= -LTTNG_ERR_NOMEM
;
2784 ret
= parse_bool(snapshot_mode_content
, &snapshot_mode
);
2785 free(snapshot_mode_content
);
2787 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2790 } else if (!strcmp((const char *) attributes_child
->name
,
2791 config_element_live_timer_interval
)) {
2792 /* live_timer_interval */
2793 xmlChar
*timer_interval_content
=
2794 xmlNodeGetContent(attributes_child
);
2795 if (!timer_interval_content
) {
2796 ret
= -LTTNG_ERR_NOMEM
;
2800 ret
= parse_uint(timer_interval_content
, &live_timer_interval
);
2801 free(timer_interval_content
);
2803 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2807 if (!strcmp((const char *) attributes_child
->name
,
2808 config_element_rotation_timer_interval
)) {
2809 /* rotation_timer_interval */
2810 xmlChar
*timer_interval_content
=
2811 xmlNodeGetContent(attributes_child
);
2812 if (!timer_interval_content
) {
2813 ret
= -LTTNG_ERR_NOMEM
;
2817 ret
= parse_uint(timer_interval_content
, &rotation_timer_interval
);
2818 free(timer_interval_content
);
2820 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2824 if (!strcmp((const char *) attributes_child
->name
,
2825 config_element_rotation_size
)) {
2827 xmlChar
*rotation_size_content
=
2828 xmlNodeGetContent(attributes_child
);
2829 if (!rotation_size_content
) {
2830 ret
= -LTTNG_ERR_NOMEM
;
2834 ret
= parse_uint(rotation_size_content
, &rotation_size
);
2835 free(rotation_size_content
);
2837 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2846 /* Mandatory attribute, as defined in the session XSD */
2847 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2851 if (session_name
&& strcmp((char *) name
, session_name
)) {
2852 /* This is not the session we are looking for */
2853 ret
= -LTTNG_ERR_NO_SESSION
;
2857 /* Init domains to create the session handles */
2858 for (node
= xmlFirstElementChild(domains_node
); node
;
2859 node
= xmlNextElementSibling(node
)) {
2860 struct lttng_domain
*domain
;
2862 domain
= zmalloc(sizeof(*domain
));
2864 ret
= -LTTNG_ERR_NOMEM
;
2868 ret
= init_domain(node
, domain
);
2870 goto domain_init_error
;
2873 switch (domain
->type
) {
2874 case LTTNG_DOMAIN_KERNEL
:
2875 if (kernel_domain
) {
2876 /* Same domain seen twice, invalid! */
2877 goto domain_init_error
;
2879 kernel_domain
= domain
;
2881 case LTTNG_DOMAIN_UST
:
2883 /* Same domain seen twice, invalid! */
2884 goto domain_init_error
;
2886 ust_domain
= domain
;
2888 case LTTNG_DOMAIN_JUL
:
2890 /* Same domain seen twice, invalid! */
2891 goto domain_init_error
;
2893 jul_domain
= domain
;
2895 case LTTNG_DOMAIN_LOG4J
:
2897 /* Same domain seen twice, invalid! */
2898 goto domain_init_error
;
2900 log4j_domain
= domain
;
2902 case LTTNG_DOMAIN_PYTHON
:
2903 if (python_domain
) {
2904 /* Same domain seen twice, invalid! */
2905 goto domain_init_error
;
2907 python_domain
= domain
;
2910 WARN("Invalid domain type");
2911 goto domain_init_error
;
2916 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
2920 /* Apply overrides */
2922 if (overrides
->session_name
) {
2923 xmlChar
*name_override
= xmlStrdup(BAD_CAST(overrides
->session_name
));
2924 if (!name_override
) {
2925 ret
= -LTTNG_ERR_NOMEM
;
2929 /* Overrides the session name to the provided name */
2931 name
= name_override
;
2936 /* Destroy session if it exists */
2937 ret
= lttng_destroy_session((const char *) name
);
2938 if (ret
&& ret
!= -LTTNG_ERR_SESS_NOT_FOUND
) {
2939 ERR("Failed to destroy existing session.");
2944 /* Create session type depending on output type */
2945 if (snapshot_mode
&& snapshot_mode
!= -1) {
2946 ret
= create_snapshot_session((const char *) name
, output_node
,
2948 } else if (live_timer_interval
&&
2949 live_timer_interval
!= UINT64_MAX
) {
2950 ret
= create_session((const char *) name
,
2951 output_node
, live_timer_interval
, overrides
);
2953 /* regular session */
2954 ret
= create_session((const char *) name
,
2955 output_node
, UINT64_MAX
, overrides
);
2962 ret
= lttng_set_session_shm_path((const char *) name
,
2963 (const char *) shm_path
);
2969 for (node
= xmlFirstElementChild(domains_node
); node
;
2970 node
= xmlNextElementSibling(node
)) {
2971 ret
= process_domain_node(node
, (const char *) name
);
2977 if (rotation_timer_interval
|| rotation_size
) {
2978 struct lttng_rotation_schedule_attr
*rotation_attr
= lttng_rotation_schedule_attr_create();
2980 if (!rotation_attr
) {
2983 ret
= lttng_rotation_schedule_attr_set_session_name(rotation_attr
, (const char *) name
);
2985 lttng_rotation_schedule_attr_destroy(rotation_attr
);
2988 lttng_rotation_schedule_attr_set_timer_period(rotation_attr
,
2989 rotation_timer_interval
);
2990 lttng_rotation_schedule_attr_set_size(rotation_attr
, rotation_size
);
2991 ret
= lttng_rotation_set_schedule(rotation_attr
);
2992 lttng_rotation_schedule_attr_destroy(rotation_attr
);
2999 ret
= lttng_start_tracing((const char *) name
);
3007 ERR("Failed to load session %s: %s", (const char *) name
,
3008 lttng_strerror(ret
));
3009 lttng_destroy_session((const char *) name
);
3013 free(kernel_domain
);
3017 free(python_domain
);
3024 * Return 1 if the given path is readable by the current UID or 0 if not.
3025 * Return -1 if the path is EPERM.
3027 static int validate_file_read_creds(const char *path
)
3033 /* Can we read the file. */
3034 ret
= access(path
, R_OK
);
3038 if (errno
== EACCES
) {
3049 int load_session_from_file(const char *path
, const char *session_name
,
3050 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3051 const struct config_load_session_override_attr
*overrides
)
3053 int ret
, session_found
= !session_name
;
3054 xmlDocPtr doc
= NULL
;
3055 xmlNodePtr sessions_node
;
3056 xmlNodePtr session_node
;
3059 assert(validation_ctx
);
3061 ret
= validate_file_read_creds(path
);
3064 ret
= -LTTNG_ERR_EPERM
;
3066 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3071 doc
= xmlParseFile(path
);
3073 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3077 ret
= xmlSchemaValidateDoc(validation_ctx
->schema_validation_ctx
, doc
);
3079 ERR("Session configuration file validation failed");
3080 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3084 sessions_node
= xmlDocGetRootElement(doc
);
3085 if (!sessions_node
) {
3086 ret
= -LTTNG_ERR_LOAD_INVALID_CONFIG
;
3090 for (session_node
= xmlFirstElementChild(sessions_node
);
3091 session_node
; session_node
=
3092 xmlNextElementSibling(session_node
)) {
3093 ret
= process_session_node(session_node
,
3094 session_name
, overwrite
, overrides
);
3095 if (session_name
&& ret
== 0) {
3096 /* Target session found and loaded */
3104 ret
= session_found
? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT
;
3106 if (ret
== -LTTNG_ERR_NO_SESSION
) {
3107 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3113 int load_session_from_path(const char *path
, const char *session_name
,
3114 struct session_config_validation_ctx
*validation_ctx
, int overwrite
,
3115 const struct config_load_session_override_attr
*overrides
)
3117 int ret
, session_found
= !session_name
;
3118 DIR *directory
= NULL
;
3119 struct lttng_dynamic_buffer file_path
;
3123 assert(validation_ctx
);
3124 path_len
= strlen(path
);
3125 lttng_dynamic_buffer_init(&file_path
);
3126 if (path_len
>= LTTNG_PATH_MAX
) {
3127 ERR("Session configuration load path \"%s\" length (%zu) exceeds the maximal length allowed (%d)",
3128 path
, path_len
, LTTNG_PATH_MAX
);
3129 ret
= -LTTNG_ERR_INVALID
;
3133 directory
= opendir(path
);
3137 /* Try the file loading. */
3140 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3143 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3148 size_t file_path_root_len
;
3150 ret
= lttng_dynamic_buffer_set_capacity(&file_path
,
3153 ret
= -LTTNG_ERR_NOMEM
;
3157 ret
= lttng_dynamic_buffer_append(&file_path
, path
, path_len
);
3159 ret
= -LTTNG_ERR_NOMEM
;
3163 if (file_path
.data
[file_path
.size
- 1] != '/') {
3164 ret
= lttng_dynamic_buffer_append(&file_path
, "/", 1);
3166 ret
= -LTTNG_ERR_NOMEM
;
3170 file_path_root_len
= file_path
.size
;
3172 /* Search for *.lttng files */
3174 size_t file_name_len
;
3175 struct dirent
*result
;
3178 * When the end of the directory stream is reached, NULL
3179 * is returned and errno is kept unchanged. When an
3180 * error occurs, NULL is returned and errno is set
3181 * accordingly. To distinguish between the two, set
3182 * errno to zero before calling readdir().
3184 * On success, readdir() returns a pointer to a dirent
3185 * structure. This structure may be statically
3186 * allocated, do not attempt to free(3) it.
3189 result
= readdir(directory
);
3191 /* Reached end of dir stream or error out. */
3194 PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path
);
3195 ret
= -LTTNG_ERR_LOAD_IO_FAIL
;
3201 file_name_len
= strlen(result
->d_name
);
3203 if (file_name_len
<=
3204 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
)) {
3208 if (file_path
.size
+ file_name_len
>= LTTNG_PATH_MAX
) {
3209 WARN("Ignoring file \"%s\" since the path's length (%zu) would exceed the maximal permitted size (%d)",
3211 /* +1 to account for NULL terminator. */
3212 file_path
.size
+ file_name_len
+ 1,
3217 /* Does the file end with .lttng? */
3218 if (strcmp(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
,
3219 result
->d_name
+ file_name_len
- sizeof(
3220 DEFAULT_SESSION_CONFIG_FILE_EXTENSION
) + 1)) {
3224 ret
= lttng_dynamic_buffer_append(&file_path
, result
->d_name
,
3227 ret
= -LTTNG_ERR_NOMEM
;
3231 ret
= load_session_from_file(file_path
.data
, session_name
,
3232 validation_ctx
, overwrite
, overrides
);
3233 if (session_name
&& (!ret
|| ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
)) {
3237 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3241 * Reset the buffer's size to the location of the
3242 * path's trailing '/'.
3244 ret
= lttng_dynamic_buffer_set_size(&file_path
,
3245 file_path_root_len
);
3247 ret
= -LTTNG_ERR_UNK
;
3252 ret
= load_session_from_file(path
, session_name
,
3253 validation_ctx
, overwrite
, overrides
);
3263 if (closedir(directory
)) {
3267 if (!ret
&& !session_found
) {
3268 ret
= -LTTNG_ERR_LOAD_SESSION_NOENT
;
3270 lttng_dynamic_buffer_reset(&file_path
);
3275 * Validate that the given path's credentials and the current process have the
3276 * same UID. If so, return 1 else return 0 if it does NOT match.
3278 static int validate_path_creds(const char *path
)
3280 int ret
, uid
= getuid();
3289 ret
= stat(path
, &buf
);
3291 if (errno
!= ENOENT
) {
3297 if (buf
.st_uid
!= uid
) {
3308 int config_load_session(const char *path
, const char *session_name
,
3309 int overwrite
, unsigned int autoload
,
3310 const struct config_load_session_override_attr
*overrides
)
3313 bool session_loaded
= false;
3314 const char *path_ptr
= NULL
;
3315 struct session_config_validation_ctx validation_ctx
= { 0 };
3317 ret
= init_session_config_validation_ctx(&validation_ctx
);
3324 const char *sys_path
;
3327 home_path
= utils_get_home_dir();
3329 char path
[PATH_MAX
];
3332 * Try user session configuration path. Ignore error here so we can
3333 * continue loading the system wide sessions.
3336 ret
= snprintf(path
, sizeof(path
),
3337 DEFAULT_SESSION_HOME_CONFIGPATH
"/"
3338 DEFAULT_SESSION_CONFIG_AUTOLOAD
, home_path
);
3340 PERROR("snprintf session autoload home config path");
3341 ret
= -LTTNG_ERR_INVALID
;
3346 * Credentials are only validated for the autoload in order to
3347 * avoid any user session daemon to try to load kernel sessions
3348 * automatically and failing all the times.
3350 ret
= validate_path_creds(path
);
3355 ret
= snprintf(path
, sizeof(path
),
3356 DEFAULT_SESSION_HOME_CONFIGPATH
, home_path
);
3358 PERROR("snprintf session home config path");
3359 ret
= -LTTNG_ERR_INVALID
;
3365 ret
= load_session_from_path(path_ptr
, session_name
,
3366 &validation_ctx
, overwrite
, overrides
);
3367 if (ret
&& ret
!= -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3371 * Continue even if the session was found since we have to try
3372 * the system wide sessions.
3374 session_loaded
= true;
3378 /* Reset path pointer for the system wide dir. */
3381 /* Try system wide configuration directory. */
3383 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
"/"
3384 DEFAULT_SESSION_CONFIG_AUTOLOAD
;
3385 ret
= validate_path_creds(sys_path
);
3387 path_ptr
= sys_path
;
3390 sys_path
= DEFAULT_SESSION_SYSTEM_CONFIGPATH
;
3391 path_ptr
= sys_path
;
3395 ret
= load_session_from_path(path_ptr
, session_name
,
3396 &validation_ctx
, overwrite
, overrides
);
3398 session_loaded
= true;
3404 ret
= access(path
, F_OK
);
3409 ret
= -LTTNG_ERR_INVALID
;
3410 WARN("Session configuration path does not exist.");
3413 ret
= -LTTNG_ERR_EPERM
;
3416 ret
= -LTTNG_ERR_UNK
;
3422 ret
= load_session_from_path(path
, session_name
,
3423 &validation_ctx
, overwrite
, overrides
);
3426 fini_session_config_validation_ctx(&validation_ctx
);
3427 if (ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
&& !session_name
&& !path
) {
3429 * Don't report an error if no sessions are found when called
3430 * without a session_name or a search path.
3435 if (session_loaded
&& ret
== -LTTNG_ERR_LOAD_SESSION_NOENT
) {
3436 /* A matching session was found in one of the search paths. */
3443 void __attribute__((destructor
)) session_config_exit(void)