2 * Copyright (C) 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
12 #include <urcu/uatomic.h>
15 #include <common/defaults.h>
16 #include <common/error.h>
17 #include <common/config/session-config.h>
18 #include <common/utils.h>
19 #include <common/runas.h>
20 #include <lttng/save-internal.h>
25 #include "lttng-syscall.h"
26 #include "trace-ust.h"
29 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
31 int save_kernel_channel_attributes(struct config_writer
*writer
,
32 struct lttng_channel_attr
*attr
)
36 ret
= config_writer_write_element_string(writer
,
37 config_element_overwrite_mode
,
38 attr
->overwrite
? config_overwrite_mode_overwrite
:
39 config_overwrite_mode_discard
);
41 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
45 ret
= config_writer_write_element_unsigned_int(writer
,
46 config_element_subbuf_size
, attr
->subbuf_size
);
48 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
52 ret
= config_writer_write_element_unsigned_int(writer
,
53 config_element_num_subbuf
,
56 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
60 ret
= config_writer_write_element_unsigned_int(writer
,
61 config_element_switch_timer_interval
,
62 attr
->switch_timer_interval
);
64 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
68 ret
= config_writer_write_element_unsigned_int(writer
,
69 config_element_read_timer_interval
,
70 attr
->read_timer_interval
);
72 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
76 ret
= config_writer_write_element_string(writer
,
77 config_element_output_type
,
78 attr
->output
== LTTNG_EVENT_SPLICE
?
79 config_output_type_splice
: config_output_type_mmap
);
81 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
85 ret
= config_writer_write_element_unsigned_int(writer
,
86 config_element_tracefile_size
, attr
->tracefile_size
);
88 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
92 ret
= config_writer_write_element_unsigned_int(writer
,
93 config_element_tracefile_count
,
94 attr
->tracefile_count
);
96 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
100 ret
= config_writer_write_element_unsigned_int(writer
,
101 config_element_live_timer_interval
,
102 attr
->live_timer_interval
);
104 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
108 if (attr
->extended
.ptr
) {
109 struct lttng_channel_extended
*ext
= NULL
;
111 ext
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
112 ret
= config_writer_write_element_unsigned_int(writer
,
113 config_element_monitor_timer_interval
,
114 ext
->monitor_timer_interval
);
116 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
120 ret
= config_writer_write_element_signed_int(writer
,
121 config_element_blocking_timeout
,
122 ext
->blocking_timeout
);
124 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
134 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
136 int save_ust_channel_attributes(struct config_writer
*writer
,
137 struct lttng_ust_abi_channel_attr
*attr
)
140 struct ltt_ust_channel
*channel
= NULL
;
142 ret
= config_writer_write_element_string(writer
,
143 config_element_overwrite_mode
,
144 attr
->overwrite
? config_overwrite_mode_overwrite
:
145 config_overwrite_mode_discard
);
147 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
151 ret
= config_writer_write_element_unsigned_int(writer
,
152 config_element_subbuf_size
, attr
->subbuf_size
);
154 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
158 ret
= config_writer_write_element_unsigned_int(writer
,
159 config_element_num_subbuf
,
162 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
166 ret
= config_writer_write_element_unsigned_int(writer
,
167 config_element_switch_timer_interval
,
168 attr
->switch_timer_interval
);
170 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
174 ret
= config_writer_write_element_unsigned_int(writer
,
175 config_element_read_timer_interval
,
176 attr
->read_timer_interval
);
178 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
182 ret
= config_writer_write_element_string(writer
,
183 config_element_output_type
,
184 attr
->output
== LTTNG_UST_ABI_MMAP
?
185 config_output_type_mmap
: config_output_type_splice
);
187 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
191 ret
= config_writer_write_element_signed_int(writer
,
192 config_element_blocking_timeout
,
193 attr
->u
.s
.blocking_timeout
);
195 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
200 * Fetch the monitor timer which is located in the parent of
201 * lttng_ust_channel_attr
203 channel
= caa_container_of(attr
, struct ltt_ust_channel
, attr
);
204 ret
= config_writer_write_element_unsigned_int(writer
,
205 config_element_monitor_timer_interval
,
206 channel
->monitor_timer_interval
);
208 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
218 const char *get_kernel_instrumentation_string(
219 enum lttng_kernel_abi_instrumentation instrumentation
)
221 const char *instrumentation_string
;
223 switch (instrumentation
) {
224 case LTTNG_KERNEL_ABI_ALL
:
225 instrumentation_string
= config_event_type_all
;
227 case LTTNG_KERNEL_ABI_TRACEPOINT
:
228 instrumentation_string
= config_event_type_tracepoint
;
230 case LTTNG_KERNEL_ABI_KPROBE
:
231 instrumentation_string
= config_event_type_probe
;
233 case LTTNG_KERNEL_ABI_UPROBE
:
234 instrumentation_string
= config_event_type_userspace_probe
;
236 case LTTNG_KERNEL_ABI_FUNCTION
:
237 instrumentation_string
= config_event_type_function_entry
;
239 case LTTNG_KERNEL_ABI_KRETPROBE
:
240 instrumentation_string
= config_event_type_function
;
242 case LTTNG_KERNEL_ABI_NOOP
:
243 instrumentation_string
= config_event_type_noop
;
245 case LTTNG_KERNEL_ABI_SYSCALL
:
246 instrumentation_string
= config_event_type_syscall
;
249 instrumentation_string
= NULL
;
252 return instrumentation_string
;
256 const char *get_kernel_context_type_string(
257 enum lttng_kernel_abi_context_type context_type
)
259 const char *context_type_string
;
261 switch (context_type
) {
262 case LTTNG_KERNEL_ABI_CONTEXT_PID
:
263 context_type_string
= config_event_context_pid
;
265 case LTTNG_KERNEL_ABI_CONTEXT_PROCNAME
:
266 context_type_string
= config_event_context_procname
;
268 case LTTNG_KERNEL_ABI_CONTEXT_PRIO
:
269 context_type_string
= config_event_context_prio
;
271 case LTTNG_KERNEL_ABI_CONTEXT_NICE
:
272 context_type_string
= config_event_context_nice
;
274 case LTTNG_KERNEL_ABI_CONTEXT_VPID
:
275 context_type_string
= config_event_context_vpid
;
277 case LTTNG_KERNEL_ABI_CONTEXT_TID
:
278 context_type_string
= config_event_context_tid
;
280 case LTTNG_KERNEL_ABI_CONTEXT_VTID
:
281 context_type_string
= config_event_context_vtid
;
283 case LTTNG_KERNEL_ABI_CONTEXT_PPID
:
284 context_type_string
= config_event_context_ppid
;
286 case LTTNG_KERNEL_ABI_CONTEXT_VPPID
:
287 context_type_string
= config_event_context_vppid
;
289 case LTTNG_KERNEL_ABI_CONTEXT_HOSTNAME
:
290 context_type_string
= config_event_context_hostname
;
292 case LTTNG_KERNEL_ABI_CONTEXT_INTERRUPTIBLE
:
293 context_type_string
= config_event_context_interruptible
;
295 case LTTNG_KERNEL_ABI_CONTEXT_PREEMPTIBLE
:
296 context_type_string
= config_event_context_preemptible
;
298 case LTTNG_KERNEL_ABI_CONTEXT_NEED_RESCHEDULE
:
299 context_type_string
= config_event_context_need_reschedule
;
301 case LTTNG_KERNEL_ABI_CONTEXT_MIGRATABLE
:
302 context_type_string
= config_event_context_migratable
;
304 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_USER
:
305 context_type_string
= config_event_context_callstack_user
;
307 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_KERNEL
:
308 context_type_string
= config_event_context_callstack_kernel
;
310 case LTTNG_KERNEL_ABI_CONTEXT_CGROUP_NS
:
311 context_type_string
= config_event_context_cgroup_ns
;
313 case LTTNG_KERNEL_ABI_CONTEXT_IPC_NS
:
314 context_type_string
= config_event_context_ipc_ns
;
316 case LTTNG_KERNEL_ABI_CONTEXT_MNT_NS
:
317 context_type_string
= config_event_context_mnt_ns
;
319 case LTTNG_KERNEL_ABI_CONTEXT_NET_NS
:
320 context_type_string
= config_event_context_net_ns
;
322 case LTTNG_KERNEL_ABI_CONTEXT_PID_NS
:
323 context_type_string
= config_event_context_pid_ns
;
325 case LTTNG_KERNEL_ABI_CONTEXT_TIME_NS
:
326 context_type_string
= config_event_context_time_ns
;
328 case LTTNG_KERNEL_ABI_CONTEXT_USER_NS
:
329 context_type_string
= config_event_context_user_ns
;
331 case LTTNG_KERNEL_ABI_CONTEXT_UTS_NS
:
332 context_type_string
= config_event_context_uts_ns
;
334 case LTTNG_KERNEL_ABI_CONTEXT_UID
:
335 context_type_string
= config_event_context_uid
;
337 case LTTNG_KERNEL_ABI_CONTEXT_EUID
:
338 context_type_string
= config_event_context_euid
;
340 case LTTNG_KERNEL_ABI_CONTEXT_SUID
:
341 context_type_string
= config_event_context_suid
;
343 case LTTNG_KERNEL_ABI_CONTEXT_GID
:
344 context_type_string
= config_event_context_gid
;
346 case LTTNG_KERNEL_ABI_CONTEXT_EGID
:
347 context_type_string
= config_event_context_egid
;
349 case LTTNG_KERNEL_ABI_CONTEXT_SGID
:
350 context_type_string
= config_event_context_sgid
;
352 case LTTNG_KERNEL_ABI_CONTEXT_VUID
:
353 context_type_string
= config_event_context_vuid
;
355 case LTTNG_KERNEL_ABI_CONTEXT_VEUID
:
356 context_type_string
= config_event_context_veuid
;
358 case LTTNG_KERNEL_ABI_CONTEXT_VSUID
:
359 context_type_string
= config_event_context_vsuid
;
361 case LTTNG_KERNEL_ABI_CONTEXT_VGID
:
362 context_type_string
= config_event_context_vgid
;
364 case LTTNG_KERNEL_ABI_CONTEXT_VEGID
:
365 context_type_string
= config_event_context_vegid
;
367 case LTTNG_KERNEL_ABI_CONTEXT_VSGID
:
368 context_type_string
= config_event_context_vsgid
;
371 context_type_string
= NULL
;
374 return context_type_string
;
378 const char *get_ust_context_type_string(
379 enum lttng_ust_abi_context_type context_type
)
381 const char *context_type_string
;
383 switch (context_type
) {
384 case LTTNG_UST_ABI_CONTEXT_PROCNAME
:
385 context_type_string
= config_event_context_procname
;
387 case LTTNG_UST_ABI_CONTEXT_VPID
:
388 context_type_string
= config_event_context_vpid
;
390 case LTTNG_UST_ABI_CONTEXT_VTID
:
391 context_type_string
= config_event_context_vtid
;
393 case LTTNG_UST_ABI_CONTEXT_IP
:
394 context_type_string
= config_event_context_ip
;
396 case LTTNG_UST_ABI_CONTEXT_PTHREAD_ID
:
397 context_type_string
= config_event_context_pthread_id
;
399 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT
:
400 context_type_string
= config_event_context_app
;
402 case LTTNG_UST_ABI_CONTEXT_CGROUP_NS
:
403 context_type_string
= config_event_context_cgroup_ns
;
405 case LTTNG_UST_ABI_CONTEXT_IPC_NS
:
406 context_type_string
= config_event_context_ipc_ns
;
408 case LTTNG_UST_ABI_CONTEXT_MNT_NS
:
409 context_type_string
= config_event_context_mnt_ns
;
411 case LTTNG_UST_ABI_CONTEXT_NET_NS
:
412 context_type_string
= config_event_context_net_ns
;
414 case LTTNG_UST_ABI_CONTEXT_TIME_NS
:
415 context_type_string
= config_event_context_time_ns
;
417 case LTTNG_UST_ABI_CONTEXT_PID_NS
:
418 context_type_string
= config_event_context_pid_ns
;
420 case LTTNG_UST_ABI_CONTEXT_USER_NS
:
421 context_type_string
= config_event_context_user_ns
;
423 case LTTNG_UST_ABI_CONTEXT_UTS_NS
:
424 context_type_string
= config_event_context_uts_ns
;
426 case LTTNG_UST_ABI_CONTEXT_VUID
:
427 context_type_string
= config_event_context_vuid
;
429 case LTTNG_UST_ABI_CONTEXT_VEUID
:
430 context_type_string
= config_event_context_veuid
;
432 case LTTNG_UST_ABI_CONTEXT_VSUID
:
433 context_type_string
= config_event_context_vsuid
;
435 case LTTNG_UST_ABI_CONTEXT_VGID
:
436 context_type_string
= config_event_context_vgid
;
438 case LTTNG_UST_ABI_CONTEXT_VEGID
:
439 context_type_string
= config_event_context_vegid
;
441 case LTTNG_UST_ABI_CONTEXT_VSGID
:
442 context_type_string
= config_event_context_vsgid
;
444 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER
:
446 * Error, should not be stored in the XML, perf contexts
447 * are stored as a node of type event_perf_context_type.
450 context_type_string
= NULL
;
454 return context_type_string
;
458 const char *get_buffer_type_string(
459 enum lttng_buffer_type buffer_type
)
461 const char *buffer_type_string
;
463 switch (buffer_type
) {
464 case LTTNG_BUFFER_PER_PID
:
465 buffer_type_string
= config_buffer_type_per_pid
;
467 case LTTNG_BUFFER_PER_UID
:
468 buffer_type_string
= config_buffer_type_per_uid
;
470 case LTTNG_BUFFER_GLOBAL
:
471 buffer_type_string
= config_buffer_type_global
;
474 buffer_type_string
= NULL
;
477 return buffer_type_string
;
481 const char *get_loglevel_type_string(
482 enum lttng_ust_abi_loglevel_type loglevel_type
)
484 const char *loglevel_type_string
;
486 switch (loglevel_type
) {
487 case LTTNG_UST_ABI_LOGLEVEL_ALL
:
488 loglevel_type_string
= config_loglevel_type_all
;
490 case LTTNG_UST_ABI_LOGLEVEL_RANGE
:
491 loglevel_type_string
= config_loglevel_type_range
;
493 case LTTNG_UST_ABI_LOGLEVEL_SINGLE
:
494 loglevel_type_string
= config_loglevel_type_single
;
497 loglevel_type_string
= NULL
;
500 return loglevel_type_string
;
503 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
505 int save_kernel_function_event(struct config_writer
*writer
,
506 struct ltt_kernel_event
*event
)
510 ret
= config_writer_open_element(writer
, config_element_function_attributes
);
512 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
516 ret
= config_writer_write_element_string(writer
, config_element_name
,
517 event
->event
->u
.ftrace
.symbol_name
);
519 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
523 /* /function attributes */
524 ret
= config_writer_close_element(writer
);
526 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
534 int save_kernel_kprobe_event(struct config_writer
*writer
,
535 struct ltt_kernel_event
*event
)
538 const char *symbol_name
;
542 switch (event
->event
->instrumentation
) {
543 case LTTNG_KERNEL_ABI_KPROBE
:
545 * Comments in lttng-kernel.h mention that
546 * either addr or symbol_name are set, not both.
548 addr
= event
->event
->u
.kprobe
.addr
;
549 offset
= event
->event
->u
.kprobe
.offset
;
550 symbol_name
= addr
? NULL
: event
->event
->u
.kprobe
.symbol_name
;
552 case LTTNG_KERNEL_ABI_KRETPROBE
:
553 addr
= event
->event
->u
.kretprobe
.addr
;
554 offset
= event
->event
->u
.kretprobe
.offset
;
555 symbol_name
= addr
? NULL
: event
->event
->u
.kretprobe
.symbol_name
;
559 ERR("Unsupported kernel instrumentation type.");
560 ret
= LTTNG_ERR_INVALID
;
564 ret
= config_writer_open_element(writer
, config_element_probe_attributes
);
566 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
571 ret
= config_writer_write_element_unsigned_int( writer
,
572 config_element_address
, addr
);
574 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
577 } else if (symbol_name
) {
578 ret
= config_writer_write_element_string(writer
,
579 config_element_symbol_name
, symbol_name
);
581 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
584 /* If the offset is non-zero, write it.*/
586 ret
= config_writer_write_element_unsigned_int(writer
,
587 config_element_offset
, offset
);
589 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
595 * This really should not happen as we are either setting the
596 * address or the symbol above.
598 ERR("Invalid probe/function description.");
599 ret
= LTTNG_ERR_INVALID
;
604 ret
= config_writer_close_element(writer
);
606 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
614 * Save the userspace probe tracepoint event associated with the event to the
618 int save_kernel_userspace_probe_tracepoint_event(struct config_writer
*writer
,
619 struct ltt_kernel_event
*event
)
622 const char *probe_name
, *provider_name
, *binary_path
;
623 const struct lttng_userspace_probe_location
*userspace_probe_location
;
624 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
625 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
627 /* Get userspace probe location from the event. */
628 userspace_probe_location
= event
->userspace_probe_location
;
629 if (!userspace_probe_location
) {
630 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
634 /* Get lookup method and lookup method type. */
635 lookup_method
= lttng_userspace_probe_location_get_lookup_method(userspace_probe_location
);
636 if (!lookup_method
) {
637 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
641 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
643 /* Get the binary path, probe name and provider name. */
645 lttng_userspace_probe_location_tracepoint_get_binary_path(
646 userspace_probe_location
);
648 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
653 lttng_userspace_probe_location_tracepoint_get_probe_name(
654 userspace_probe_location
);
656 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
661 lttng_userspace_probe_location_tracepoint_get_provider_name(
662 userspace_probe_location
);
663 if (!provider_name
) {
664 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
668 /* Open a userspace probe tracepoint attribute. */
669 ret
= config_writer_open_element(writer
, config_element_userspace_probe_tracepoint_attributes
);
671 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
675 switch (lookup_type
) {
676 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
677 ret
= config_writer_write_element_string(writer
,
678 config_element_userspace_probe_lookup
,
679 config_element_userspace_probe_lookup_tracepoint_sdt
);
681 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
686 ERR("Unsupported kernel userspace probe tracepoint lookup method.");
687 ret
= LTTNG_ERR_INVALID
;
691 /* Write the binary path, provider name and the probe name. */
692 ret
= config_writer_write_element_string(writer
,
693 config_element_userspace_probe_location_binary_path
,
696 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
700 ret
= config_writer_write_element_string(writer
,
701 config_element_userspace_probe_tracepoint_location_provider_name
,
704 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
708 ret
= config_writer_write_element_string(writer
,
709 config_element_userspace_probe_tracepoint_location_probe_name
,
712 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
716 /* Close the userspace probe tracepoint attribute. */
717 ret
= config_writer_close_element(writer
);
719 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
728 * Save the userspace probe function event associated with the event to the
732 int save_kernel_userspace_probe_function_event(struct config_writer
*writer
,
733 struct ltt_kernel_event
*event
)
736 const char *function_name
, *binary_path
;
737 const struct lttng_userspace_probe_location
*userspace_probe_location
;
738 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
739 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
741 /* Get userspace probe location from the event. */
742 userspace_probe_location
= event
->userspace_probe_location
;
743 if (!userspace_probe_location
) {
744 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
748 /* Get lookup method and lookup method type. */
749 lookup_method
= lttng_userspace_probe_location_get_lookup_method(
750 userspace_probe_location
);
751 if (!lookup_method
) {
752 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
756 /* Get the binary path and the function name. */
758 lttng_userspace_probe_location_function_get_binary_path(
759 userspace_probe_location
);
761 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
766 lttng_userspace_probe_location_function_get_function_name(
767 userspace_probe_location
);
768 if (!function_name
) {
769 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
773 /* Open a userspace probe function attribute. */
774 ret
= config_writer_open_element(writer
,
775 config_element_userspace_probe_function_attributes
);
777 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
781 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
782 switch (lookup_type
) {
783 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
784 ret
= config_writer_write_element_string(writer
,
785 config_element_userspace_probe_lookup
,
786 config_element_userspace_probe_lookup_function_elf
);
788 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
792 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
793 ret
= config_writer_write_element_string(writer
,
794 config_element_userspace_probe_lookup
,
795 config_element_userspace_probe_lookup_function_default
);
797 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
802 ERR("Unsupported kernel userspace probe function lookup method.");
803 ret
= LTTNG_ERR_INVALID
;
807 /* Write the binary path and the function name. */
808 ret
= config_writer_write_element_string(writer
,
809 config_element_userspace_probe_location_binary_path
,
812 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
816 ret
= config_writer_write_element_string(writer
,
817 config_element_userspace_probe_function_location_function_name
,
820 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
824 /* Close the userspace probe function attribute. */
825 ret
= config_writer_close_element(writer
);
827 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
836 int save_kernel_userspace_probe_event(struct config_writer
*writer
,
837 struct ltt_kernel_event
*event
)
840 struct lttng_userspace_probe_location
*userspace_probe_location
;
842 /* Get userspace probe location from the event. */
843 userspace_probe_location
= event
->userspace_probe_location
;
844 if (!userspace_probe_location
) {
845 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
849 switch(lttng_userspace_probe_location_get_type(userspace_probe_location
)) {
850 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
852 ret
= save_kernel_userspace_probe_function_event(writer
, event
);
854 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
859 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
861 ret
= save_kernel_userspace_probe_tracepoint_event(writer
, event
);
863 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
868 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
870 ERR("Unsupported kernel userspace probe location type.");
871 ret
= LTTNG_ERR_INVALID
;
880 int save_kernel_event(struct config_writer
*writer
,
881 struct ltt_kernel_event
*event
)
884 const char *instrumentation_type
;
886 ret
= config_writer_open_element(writer
, config_element_event
);
888 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
892 if (event
->event
->name
[0]) {
893 ret
= config_writer_write_element_string(writer
,
894 config_element_name
, event
->event
->name
);
896 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
901 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
904 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
908 instrumentation_type
= get_kernel_instrumentation_string(
909 event
->event
->instrumentation
);
910 if (!instrumentation_type
) {
911 ret
= LTTNG_ERR_INVALID
;
915 ret
= config_writer_write_element_string(writer
, config_element_type
,
916 instrumentation_type
);
918 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
922 if (event
->filter_expression
) {
923 ret
= config_writer_write_element_string(writer
,
924 config_element_filter
,
925 event
->filter_expression
);
927 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
932 if (event
->event
->instrumentation
== LTTNG_KERNEL_ABI_FUNCTION
||
933 event
->event
->instrumentation
== LTTNG_KERNEL_ABI_KPROBE
||
934 event
->event
->instrumentation
== LTTNG_KERNEL_ABI_UPROBE
||
935 event
->event
->instrumentation
== LTTNG_KERNEL_ABI_KRETPROBE
) {
937 ret
= config_writer_open_element(writer
,
938 config_element_attributes
);
940 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
944 switch (event
->event
->instrumentation
) {
945 case LTTNG_KERNEL_ABI_SYSCALL
:
946 case LTTNG_KERNEL_ABI_FUNCTION
:
947 ret
= save_kernel_function_event(writer
, event
);
952 case LTTNG_KERNEL_ABI_KPROBE
:
953 case LTTNG_KERNEL_ABI_KRETPROBE
:
954 ret
= save_kernel_kprobe_event(writer
, event
);
959 case LTTNG_KERNEL_ABI_UPROBE
:
960 ret
= save_kernel_userspace_probe_event(writer
, event
);
966 ERR("Unsupported kernel instrumentation type.");
967 ret
= LTTNG_ERR_INVALID
;
972 ret
= config_writer_close_element(writer
);
974 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
980 ret
= config_writer_close_element(writer
);
982 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
991 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
993 int save_kernel_events(struct config_writer
*writer
,
994 struct ltt_kernel_channel
*kchan
)
997 struct ltt_kernel_event
*event
;
999 ret
= config_writer_open_element(writer
, config_element_events
);
1001 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1005 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
1006 ret
= save_kernel_event(writer
, event
);
1007 if (ret
!= LTTNG_OK
) {
1013 ret
= config_writer_close_element(writer
);
1015 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1024 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1026 int save_ust_event(struct config_writer
*writer
,
1027 struct ltt_ust_event
*event
)
1030 const char *loglevel_type_string
;
1032 ret
= config_writer_open_element(writer
, config_element_event
);
1034 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1038 if (event
->attr
.name
[0]) {
1039 ret
= config_writer_write_element_string(writer
,
1040 config_element_name
, event
->attr
.name
);
1042 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1047 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1050 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1054 if (event
->attr
.instrumentation
!= LTTNG_UST_ABI_TRACEPOINT
) {
1055 ERR("Unsupported UST instrumentation type.");
1056 ret
= LTTNG_ERR_INVALID
;
1059 ret
= config_writer_write_element_string(writer
, config_element_type
,
1060 config_event_type_tracepoint
);
1062 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1066 loglevel_type_string
= get_loglevel_type_string(
1067 event
->attr
.loglevel_type
);
1068 if (!loglevel_type_string
) {
1069 ERR("Unsupported UST loglevel type.");
1070 ret
= LTTNG_ERR_INVALID
;
1074 ret
= config_writer_write_element_string(writer
,
1075 config_element_loglevel_type
, loglevel_type_string
);
1077 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1081 /* The log level is irrelevant if no "filtering" is enabled */
1082 if (event
->attr
.loglevel_type
!= LTTNG_UST_ABI_LOGLEVEL_ALL
) {
1083 ret
= config_writer_write_element_signed_int(writer
,
1084 config_element_loglevel
, event
->attr
.loglevel
);
1086 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1091 if (event
->filter_expression
) {
1092 ret
= config_writer_write_element_string(writer
,
1093 config_element_filter
, event
->filter_expression
);
1095 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1100 if (event
->exclusion
&& event
->exclusion
->count
) {
1103 ret
= config_writer_open_element(writer
,
1104 config_element_exclusions
);
1106 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1110 for (i
= 0; i
< event
->exclusion
->count
; i
++) {
1111 ret
= config_writer_write_element_string(writer
,
1112 config_element_exclusion
,
1113 LTTNG_EVENT_EXCLUSION_NAME_AT(
1114 event
->exclusion
, i
));
1116 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1122 ret
= config_writer_close_element(writer
);
1124 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1130 ret
= config_writer_close_element(writer
);
1132 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1141 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1143 int save_ust_events(struct config_writer
*writer
,
1144 struct lttng_ht
*events
)
1147 struct ltt_ust_event
*event
;
1148 struct lttng_ht_node_str
*node
;
1149 struct lttng_ht_iter iter
;
1151 ret
= config_writer_open_element(writer
, config_element_events
);
1153 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1158 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
1159 event
= caa_container_of(node
, struct ltt_ust_event
, node
);
1161 if (event
->internal
) {
1162 /* Internal events must not be exposed to clients */
1165 ret
= save_ust_event(writer
, event
);
1166 if (ret
!= LTTNG_OK
) {
1174 ret
= config_writer_close_element(writer
);
1176 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1185 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1187 int init_ust_event_from_agent_event(struct ltt_ust_event
*ust_event
,
1188 struct agent_event
*agent_event
)
1191 enum lttng_ust_abi_loglevel_type ust_loglevel_type
;
1193 ust_event
->enabled
= AGENT_EVENT_IS_ENABLED(agent_event
);
1194 ust_event
->attr
.instrumentation
= LTTNG_UST_ABI_TRACEPOINT
;
1195 if (lttng_strncpy(ust_event
->attr
.name
, agent_event
->name
,
1196 LTTNG_SYMBOL_NAME_LEN
)) {
1197 ret
= LTTNG_ERR_INVALID
;
1200 switch (agent_event
->loglevel_type
) {
1201 case LTTNG_EVENT_LOGLEVEL_ALL
:
1202 ust_loglevel_type
= LTTNG_UST_ABI_LOGLEVEL_ALL
;
1204 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
1205 ust_loglevel_type
= LTTNG_UST_ABI_LOGLEVEL_SINGLE
;
1207 case LTTNG_EVENT_LOGLEVEL_RANGE
:
1208 ust_loglevel_type
= LTTNG_UST_ABI_LOGLEVEL_RANGE
;
1211 ERR("Invalid agent_event loglevel_type.");
1212 ret
= LTTNG_ERR_INVALID
;
1216 ust_event
->attr
.loglevel_type
= ust_loglevel_type
;
1217 ust_event
->attr
.loglevel
= agent_event
->loglevel_value
;
1218 ust_event
->filter_expression
= agent_event
->filter_expression
;
1219 ust_event
->exclusion
= agent_event
->exclusion
;
1226 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1228 int save_agent_events(struct config_writer
*writer
,
1229 struct agent
*agent
)
1232 struct lttng_ht_iter iter
;
1233 struct lttng_ht_node_str
*node
;
1235 ret
= config_writer_open_element(writer
, config_element_events
);
1237 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1242 cds_lfht_for_each_entry(agent
->events
->ht
, &iter
.iter
, node
, node
) {
1243 struct agent_event
*agent_event
;
1244 struct ltt_ust_event fake_event
;
1246 memset(&fake_event
, 0, sizeof(fake_event
));
1247 agent_event
= caa_container_of(node
, struct agent_event
, node
);
1250 * Initialize a fake ust event to reuse the same serialization
1251 * function since UST and agent events contain the same info
1252 * (and one could wonder why they don't reuse the same
1255 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
1256 if (ret
!= LTTNG_OK
) {
1260 ret
= save_ust_event(writer
, &fake_event
);
1261 if (ret
!= LTTNG_OK
) {
1269 ret
= config_writer_close_element(writer
);
1271 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1280 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1282 int save_kernel_context(struct config_writer
*writer
,
1283 struct lttng_kernel_abi_context
*ctx
)
1291 ret
= config_writer_open_element(writer
, config_element_context
);
1293 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1297 if (ctx
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_CPU_COUNTER
) {
1298 ret
= config_writer_open_element(writer
,
1299 config_element_context_perf
);
1301 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1305 ret
= config_writer_write_element_unsigned_int(writer
,
1306 config_element_type
, ctx
->u
.perf_counter
.type
);
1308 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1312 ret
= config_writer_write_element_unsigned_int(writer
,
1313 config_element_config
, ctx
->u
.perf_counter
.config
);
1315 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1319 ret
= config_writer_write_element_string(writer
,
1320 config_element_name
, ctx
->u
.perf_counter
.name
);
1322 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1327 ret
= config_writer_close_element(writer
);
1329 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1333 const char *context_type_string
=
1334 get_kernel_context_type_string(ctx
->ctx
);
1336 if (!context_type_string
) {
1337 ERR("Unsupported kernel context type.");
1338 ret
= LTTNG_ERR_INVALID
;
1342 ret
= config_writer_write_element_string(writer
,
1343 config_element_type
, context_type_string
);
1345 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1351 ret
= config_writer_close_element(writer
);
1353 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1362 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1364 int save_kernel_contexts(struct config_writer
*writer
,
1365 struct ltt_kernel_channel
*kchan
)
1368 struct ltt_kernel_context
*ctx
;
1370 if (cds_list_empty(&kchan
->ctx_list
)) {
1375 ret
= config_writer_open_element(writer
, config_element_contexts
);
1377 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1381 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
1382 ret
= save_kernel_context(writer
, &ctx
->ctx
);
1383 if (ret
!= LTTNG_OK
) {
1389 ret
= config_writer_close_element(writer
);
1391 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1400 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1402 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
1403 struct ltt_ust_context
*ctx
)
1410 /* Perf contexts are saved as event_perf_context_type */
1411 ret
= config_writer_open_element(writer
, config_element_context_perf
);
1413 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1417 ret
= config_writer_write_element_unsigned_int(writer
,
1418 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
1420 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1424 ret
= config_writer_write_element_unsigned_int(writer
,
1425 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
1427 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1431 ret
= config_writer_write_element_string(writer
, config_element_name
,
1432 ctx
->ctx
.u
.perf_counter
.name
);
1434 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1439 ret
= config_writer_close_element(writer
);
1441 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1450 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1452 int save_ust_context_app_ctx(struct config_writer
*writer
,
1453 struct ltt_ust_context
*ctx
)
1460 /* Application contexts are saved as application_context_type */
1461 ret
= config_writer_open_element(writer
, config_element_context_app
);
1463 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1467 ret
= config_writer_write_element_string(writer
,
1468 config_element_context_app_provider_name
,
1469 ctx
->ctx
.u
.app_ctx
.provider_name
);
1471 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1475 ret
= config_writer_write_element_string(writer
,
1476 config_element_context_app_ctx_name
,
1477 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1479 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1484 ret
= config_writer_close_element(writer
);
1486 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1495 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1497 int save_ust_context_generic(struct config_writer
*writer
,
1498 struct ltt_ust_context
*ctx
)
1501 const char *context_type_string
;
1506 /* Save context as event_context_type_type */
1507 context_type_string
= get_ust_context_type_string(
1509 if (!context_type_string
) {
1510 ERR("Unsupported UST context type.");
1511 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1515 ret
= config_writer_write_element_string(writer
,
1516 config_element_type
, context_type_string
);
1518 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1527 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1529 int save_ust_context(struct config_writer
*writer
,
1530 struct cds_list_head
*ctx_list
)
1533 struct ltt_ust_context
*ctx
;
1538 ret
= config_writer_open_element(writer
, config_element_contexts
);
1540 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1544 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1545 ret
= config_writer_open_element(writer
,
1546 config_element_context
);
1548 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1552 switch (ctx
->ctx
.ctx
) {
1553 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER
:
1554 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1556 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT
:
1557 ret
= save_ust_context_app_ctx(writer
, ctx
);
1560 /* Save generic context. */
1561 ret
= save_ust_context_generic(writer
, ctx
);
1563 if (ret
!= LTTNG_OK
) {
1568 ret
= config_writer_close_element(writer
);
1570 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1576 ret
= config_writer_close_element(writer
);
1578 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1587 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1589 int save_kernel_channel(struct config_writer
*writer
,
1590 struct ltt_kernel_channel
*kchan
)
1597 ret
= config_writer_open_element(writer
, config_element_channel
);
1599 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1603 ret
= config_writer_write_element_string(writer
, config_element_name
,
1604 kchan
->channel
->name
);
1606 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1610 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1611 kchan
->channel
->enabled
);
1613 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1617 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1618 if (ret
!= LTTNG_OK
) {
1622 ret
= save_kernel_events(writer
, kchan
);
1623 if (ret
!= LTTNG_OK
) {
1627 ret
= save_kernel_contexts(writer
, kchan
);
1628 if (ret
!= LTTNG_OK
) {
1633 ret
= config_writer_close_element(writer
);
1635 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1644 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1646 int save_ust_channel(struct config_writer
*writer
,
1647 struct ltt_ust_channel
*ust_chan
,
1648 struct ltt_ust_session
*session
)
1656 ret
= config_writer_open_element(writer
, config_element_channel
);
1658 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1662 ret
= config_writer_write_element_string(writer
, config_element_name
,
1665 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1669 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1672 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1676 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1677 if (ret
!= LTTNG_OK
) {
1681 ret
= config_writer_write_element_unsigned_int(writer
,
1682 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1684 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1688 ret
= config_writer_write_element_unsigned_int(writer
,
1689 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1691 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1695 ret
= config_writer_write_element_unsigned_int(writer
,
1696 config_element_live_timer_interval
,
1697 session
->live_timer_interval
);
1699 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1703 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1704 ret
= save_ust_events(writer
, ust_chan
->events
);
1705 if (ret
!= LTTNG_OK
) {
1709 struct agent
*agent
= NULL
;
1711 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1713 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1714 ERR("Could not find agent associated to UST subdomain");
1719 * Channels associated with a UST sub-domain (such as JUL, Log4j
1720 * or Python) don't have any non-internal events. We retrieve
1721 * the "agent" events associated with this channel and serialize
1724 ret
= save_agent_events(writer
, agent
);
1725 if (ret
!= LTTNG_OK
) {
1730 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1731 if (ret
!= LTTNG_OK
) {
1736 ret
= config_writer_close_element(writer
);
1738 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1747 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1749 int save_kernel_session(struct config_writer
*writer
,
1750 struct ltt_session
*session
)
1753 struct ltt_kernel_channel
*kchan
;
1758 ret
= config_writer_write_element_string(writer
, config_element_type
,
1759 config_domain_type_kernel
);
1761 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1765 ret
= config_writer_write_element_string(writer
,
1766 config_element_buffer_type
, config_buffer_type_global
);
1768 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1772 ret
= config_writer_open_element(writer
,
1773 config_element_channels
);
1775 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1779 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1781 ret
= save_kernel_channel(writer
, kchan
);
1782 if (ret
!= LTTNG_OK
) {
1788 ret
= config_writer_close_element(writer
);
1790 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1800 const char *get_config_domain_str(enum lttng_domain_type domain
)
1802 const char *str_dom
;
1805 case LTTNG_DOMAIN_KERNEL
:
1806 str_dom
= config_domain_type_kernel
;
1808 case LTTNG_DOMAIN_UST
:
1809 str_dom
= config_domain_type_ust
;
1811 case LTTNG_DOMAIN_JUL
:
1812 str_dom
= config_domain_type_jul
;
1814 case LTTNG_DOMAIN_LOG4J
:
1815 str_dom
= config_domain_type_log4j
;
1817 case LTTNG_DOMAIN_PYTHON
:
1818 str_dom
= config_domain_type_python
;
1827 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1828 static int save_process_attr_tracker(struct config_writer
*writer
,
1829 struct ltt_session
*sess
,
1831 enum lttng_process_attr process_attr
)
1834 const char *element_id_tracker
, *element_target_id
, *element_id
;
1835 const struct process_attr_tracker
*tracker
;
1836 enum lttng_tracking_policy tracking_policy
;
1837 struct lttng_process_attr_values
*values
= NULL
;
1839 switch (process_attr
) {
1840 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1841 element_id_tracker
= config_element_process_attr_tracker_pid
;
1842 element_target_id
= config_element_process_attr_pid_value
;
1843 element_id
= config_element_process_attr_id
;
1845 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1846 element_id_tracker
= config_element_process_attr_tracker_vpid
;
1847 element_target_id
= config_element_process_attr_vpid_value
;
1848 element_id
= config_element_process_attr_id
;
1850 case LTTNG_PROCESS_ATTR_USER_ID
:
1851 element_id_tracker
= config_element_process_attr_tracker_uid
;
1852 element_target_id
= config_element_process_attr_uid_value
;
1853 element_id
= config_element_process_attr_id
;
1855 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1856 element_id_tracker
= config_element_process_attr_tracker_vuid
;
1857 element_target_id
= config_element_process_attr_vuid_value
;
1858 element_id
= config_element_process_attr_id
;
1860 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1861 element_id_tracker
= config_element_process_attr_tracker_gid
;
1862 element_target_id
= config_element_process_attr_gid_value
;
1863 element_id
= config_element_process_attr_id
;
1865 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1866 element_id_tracker
= config_element_process_attr_tracker_vgid
;
1867 element_target_id
= config_element_process_attr_vgid_value
;
1868 element_id
= config_element_process_attr_id
;
1871 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1876 case LTTNG_DOMAIN_KERNEL
:
1878 tracker
= kernel_get_process_attr_tracker(
1879 sess
->kernel_session
, process_attr
);
1883 case LTTNG_DOMAIN_UST
:
1885 tracker
= trace_ust_get_process_attr_tracker(
1886 sess
->ust_session
, process_attr
);
1890 case LTTNG_DOMAIN_JUL
:
1891 case LTTNG_DOMAIN_LOG4J
:
1892 case LTTNG_DOMAIN_PYTHON
:
1894 ret
= LTTNG_ERR_UNSUPPORTED_DOMAIN
;
1898 tracking_policy
= process_attr_tracker_get_tracking_policy(tracker
);
1899 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_ALL
) {
1900 /* Tracking all, nothing to output. */
1905 ret
= config_writer_open_element(writer
, element_id_tracker
);
1907 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1911 ret
= config_writer_open_element(
1912 writer
, config_element_process_attr_values
);
1914 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1918 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_SET
) {
1919 unsigned int i
, count
;
1920 enum process_attr_tracker_status status
=
1921 process_attr_tracker_get_inclusion_set(
1924 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1925 ret
= LTTNG_ERR_NOMEM
;
1929 count
= _lttng_process_attr_values_get_count(values
);
1931 for (i
= 0; i
< count
; i
++) {
1932 unsigned int integral_value
= UINT_MAX
;
1933 const char *name
= NULL
;
1934 const struct process_attr_value
*value
=
1935 lttng_process_attr_tracker_values_get_at_index(
1939 ret
= config_writer_open_element(
1940 writer
, element_target_id
);
1942 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1946 switch (value
->type
) {
1947 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1949 (unsigned int) value
->value
.pid
;
1951 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1953 (unsigned int) value
->value
.uid
;
1955 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1957 (unsigned int) value
->value
.gid
;
1959 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1960 name
= value
->value
.user_name
;
1963 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1964 name
= value
->value
.group_name
;
1972 ret
= config_writer_write_element_string(writer
,
1973 config_element_name
, name
);
1975 ret
= config_writer_write_element_unsigned_int(
1981 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1985 /* /$element_target_id */
1986 ret
= config_writer_close_element(writer
);
1988 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1995 ret
= config_writer_close_element(writer
);
1997 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2001 /* /$element_id_tracker */
2002 ret
= config_writer_close_element(writer
);
2004 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2010 lttng_process_attr_values_destroy(values
);
2014 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2015 static int save_process_attr_trackers(struct config_writer
*writer
,
2016 struct ltt_session
*sess
,
2022 case LTTNG_DOMAIN_KERNEL
:
2023 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2024 LTTNG_PROCESS_ATTR_PROCESS_ID
);
2025 if (ret
!= LTTNG_OK
) {
2028 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2029 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2030 if (ret
!= LTTNG_OK
) {
2033 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2034 LTTNG_PROCESS_ATTR_USER_ID
);
2035 if (ret
!= LTTNG_OK
) {
2038 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2039 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2040 if (ret
!= LTTNG_OK
) {
2043 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2044 LTTNG_PROCESS_ATTR_GROUP_ID
);
2045 if (ret
!= LTTNG_OK
) {
2048 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2049 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2050 if (ret
!= LTTNG_OK
) {
2054 case LTTNG_DOMAIN_UST
:
2055 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2056 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2057 if (ret
!= LTTNG_OK
) {
2060 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2061 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2062 if (ret
!= LTTNG_OK
) {
2065 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2066 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2067 if (ret
!= LTTNG_OK
) {
2072 ret
= LTTNG_ERR_INVALID
;
2080 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2082 int save_ust_domain(struct config_writer
*writer
,
2083 struct ltt_session
*session
, enum lttng_domain_type domain
)
2086 struct ltt_ust_channel
*ust_chan
;
2087 const char *buffer_type_string
;
2088 struct lttng_ht_node_str
*node
;
2089 struct lttng_ht_iter iter
;
2090 const char *config_domain_name
;
2095 ret
= config_writer_open_element(writer
,
2096 config_element_domain
);
2098 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2102 config_domain_name
= get_config_domain_str(domain
);
2103 if (!config_domain_name
) {
2104 ret
= LTTNG_ERR_INVALID
;
2108 ret
= config_writer_write_element_string(writer
,
2109 config_element_type
, config_domain_name
);
2111 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2115 buffer_type_string
= get_buffer_type_string(
2116 session
->ust_session
->buffer_type
);
2117 if (!buffer_type_string
) {
2118 ERR("Unsupported buffer type.");
2119 ret
= LTTNG_ERR_INVALID
;
2123 ret
= config_writer_write_element_string(writer
,
2124 config_element_buffer_type
, buffer_type_string
);
2126 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2130 ret
= config_writer_open_element(writer
, config_element_channels
);
2132 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2137 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
2138 &iter
.iter
, node
, node
) {
2139 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
2140 if (domain
== ust_chan
->domain
) {
2141 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
2142 if (ret
!= LTTNG_OK
) {
2151 ret
= config_writer_close_element(writer
);
2153 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2157 if (domain
== LTTNG_DOMAIN_UST
) {
2158 ret
= config_writer_open_element(
2159 writer
, config_element_process_attr_trackers
);
2161 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2165 ret
= save_process_attr_trackers(
2166 writer
, session
, LTTNG_DOMAIN_UST
);
2167 if (ret
!= LTTNG_OK
) {
2172 ret
= config_writer_close_element(writer
);
2174 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2180 ret
= config_writer_close_element(writer
);
2182 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2191 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2193 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
2200 if (!session
->kernel_session
&& !session
->ust_session
) {
2204 ret
= config_writer_open_element(writer
, config_element_domains
);
2206 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2210 if (session
->kernel_session
) {
2211 ret
= config_writer_open_element(writer
,
2212 config_element_domain
);
2214 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2218 ret
= save_kernel_session(writer
, session
);
2219 if (ret
!= LTTNG_OK
) {
2223 ret
= config_writer_open_element(
2224 writer
, config_element_process_attr_trackers
);
2226 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2230 ret
= save_process_attr_trackers(
2231 writer
, session
, LTTNG_DOMAIN_KERNEL
);
2232 if (ret
!= LTTNG_OK
) {
2237 ret
= config_writer_close_element(writer
);
2239 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2243 ret
= config_writer_close_element(writer
);
2245 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2250 if (session
->ust_session
) {
2251 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
2252 if (ret
!= LTTNG_OK
) {
2256 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
2257 if (ret
!= LTTNG_OK
) {
2261 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
2262 if (ret
!= LTTNG_OK
) {
2266 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
2267 if (ret
!= LTTNG_OK
) {
2273 ret
= config_writer_close_element(writer
);
2275 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2284 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2286 int save_consumer_output(struct config_writer
*writer
,
2287 struct consumer_output
*output
)
2294 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
2296 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2300 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
2303 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2307 ret
= config_writer_open_element(writer
, config_element_destination
);
2309 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2313 switch (output
->type
) {
2314 case CONSUMER_DST_LOCAL
:
2315 ret
= config_writer_write_element_string(writer
,
2316 config_element_path
, output
->dst
.session_root_path
);
2318 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2322 case CONSUMER_DST_NET
:
2326 uri
= zmalloc(PATH_MAX
);
2328 ret
= LTTNG_ERR_NOMEM
;
2332 ret
= config_writer_open_element(writer
, config_element_net_output
);
2334 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2335 goto end_net_output
;
2338 if (output
->dst
.net
.control_isset
&&
2339 output
->dst
.net
.data_isset
) {
2340 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
2342 ret
= LTTNG_ERR_INVALID
;
2343 goto end_net_output
;
2346 ret
= config_writer_write_element_string(writer
,
2347 config_element_control_uri
, uri
);
2349 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2350 goto end_net_output
;
2353 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
2355 ret
= LTTNG_ERR_INVALID
;
2356 goto end_net_output
;
2359 ret
= config_writer_write_element_string(writer
,
2360 config_element_data_uri
, uri
);
2362 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2363 goto end_net_output
;
2368 if (ret
!= LTTNG_OK
) {
2372 ret
= !output
->dst
.net
.control_isset
?
2373 LTTNG_ERR_URL_CTRL_MISS
:
2374 LTTNG_ERR_URL_DATA_MISS
;
2379 ret
= config_writer_close_element(writer
);
2381 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2387 ERR("Unsupported consumer output type.");
2388 ret
= LTTNG_ERR_INVALID
;
2393 ret
= config_writer_close_element(writer
);
2395 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2399 /* /consumer_output */
2400 ret
= config_writer_close_element(writer
);
2402 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2411 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2413 int save_snapshot_outputs(struct config_writer
*writer
,
2414 struct snapshot
*snapshot
)
2417 struct lttng_ht_iter iter
;
2418 struct snapshot_output
*output
;
2423 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
2425 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2430 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
2432 ret
= config_writer_open_element(writer
,
2433 config_element_output
);
2435 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2439 ret
= config_writer_write_element_string(writer
,
2440 config_element_name
, output
->name
);
2442 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2446 ret
= config_writer_write_element_unsigned_int(writer
,
2447 config_element_max_size
, output
->max_size
);
2449 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2453 ret
= save_consumer_output(writer
, output
->consumer
);
2454 if (ret
!= LTTNG_OK
) {
2459 ret
= config_writer_close_element(writer
);
2461 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2467 /* /snapshot_outputs */
2468 ret
= config_writer_close_element(writer
);
2470 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2482 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2484 int save_session_output(struct config_writer
*writer
,
2485 struct ltt_session
*session
)
2492 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
2493 (!session
->snapshot_mode
&& !session
->consumer
)) {
2494 /* Session is in no output mode */
2499 ret
= config_writer_open_element(writer
, config_element_output
);
2501 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2505 if (session
->snapshot_mode
) {
2506 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
2507 if (ret
!= LTTNG_OK
) {
2511 if (session
->consumer
) {
2512 ret
= save_consumer_output(writer
, session
->consumer
);
2513 if (ret
!= LTTNG_OK
) {
2520 ret
= config_writer_close_element(writer
);
2522 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2531 int save_session_rotation_schedule(struct config_writer
*writer
,
2532 enum lttng_rotation_schedule_type type
, uint64_t value
)
2535 const char *element_name
;
2536 const char *value_name
;
2539 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2540 element_name
= config_element_rotation_schedule_periodic
;
2541 value_name
= config_element_rotation_schedule_periodic_time_us
;
2543 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2544 element_name
= config_element_rotation_schedule_size_threshold
;
2545 value_name
= config_element_rotation_schedule_size_threshold_bytes
;
2552 ret
= config_writer_open_element(writer
, element_name
);
2557 ret
= config_writer_write_element_unsigned_int(writer
,
2563 /* Close schedule descriptor element. */
2564 ret
= config_writer_close_element(writer
);
2573 int save_session_rotation_schedules(struct config_writer
*writer
,
2574 struct ltt_session
*session
)
2578 ret
= config_writer_open_element(writer
,
2579 config_element_rotation_schedules
);
2583 if (session
->rotate_timer_period
) {
2584 ret
= save_session_rotation_schedule(writer
,
2585 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
,
2586 session
->rotate_timer_period
);
2588 goto close_schedules
;
2591 if (session
->rotate_size
) {
2592 ret
= save_session_rotation_schedule(writer
,
2593 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
,
2594 session
->rotate_size
);
2596 goto close_schedules
;
2601 /* Close rotation schedules element. */
2602 ret
= config_writer_close_element(writer
);
2611 * Save the given session.
2613 * Return LTTNG_OK on success else a LTTNG_ERR* code.
2616 int save_session(struct ltt_session
*session
,
2617 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
2620 char config_file_path
[LTTNG_PATH_MAX
];
2622 struct config_writer
*writer
= NULL
;
2623 size_t session_name_len
;
2624 const char *provided_path
;
2625 int file_open_flags
= O_CREAT
| O_WRONLY
| O_TRUNC
;
2631 session_name_len
= strlen(session
->name
);
2632 memset(config_file_path
, 0, sizeof(config_file_path
));
2634 if (!session_access_ok(session
,
2635 LTTNG_SOCK_GET_UID_CRED(creds
)) || session
->destroyed
) {
2636 ret
= LTTNG_ERR_EPERM
;
2640 provided_path
= lttng_save_session_attr_get_output_url(attr
);
2641 if (provided_path
) {
2642 DBG3("Save session in provided path %s", provided_path
);
2643 len
= strlen(provided_path
);
2644 if (len
>= sizeof(config_file_path
)) {
2645 ret
= LTTNG_ERR_SET_URL
;
2648 strncpy(config_file_path
, provided_path
, sizeof(config_file_path
));
2651 char *home_dir
= utils_get_user_home_dir(
2652 LTTNG_SOCK_GET_UID_CRED(creds
));
2654 ret
= LTTNG_ERR_SET_URL
;
2658 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
2659 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
2662 PERROR("snprintf save session");
2663 ret
= LTTNG_ERR_SET_URL
;
2670 * Check the path fits in the config file path dst including the '/'
2671 * followed by trailing .lttng extension and the NULL terminated string.
2673 if ((len
+ session_name_len
+ 2 +
2674 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
2675 > sizeof(config_file_path
)) {
2676 ret
= LTTNG_ERR_SET_URL
;
2680 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
2681 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2683 ret
= LTTNG_ERR_SET_URL
;
2688 * At this point, we know that everything fits in the buffer. Validation
2689 * was done just above.
2691 config_file_path
[len
++] = '/';
2692 strncpy(config_file_path
+ len
, session
->name
, sizeof(config_file_path
) - len
);
2693 len
+= session_name_len
;
2694 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2695 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2696 config_file_path
[len
] = '\0';
2698 if (!attr
->overwrite
) {
2699 file_open_flags
|= O_EXCL
;
2702 fd
= run_as_open(config_file_path
, file_open_flags
,
2703 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
2704 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2706 PERROR("Could not create configuration file");
2709 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
2712 ret
= LTTNG_ERR_EPERM
;
2715 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2721 writer
= config_writer_create(fd
, 1);
2723 ret
= LTTNG_ERR_NOMEM
;
2727 ret
= config_writer_open_element(writer
, config_element_sessions
);
2729 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2733 ret
= config_writer_open_element(writer
, config_element_session
);
2735 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2739 ret
= config_writer_write_element_string(writer
, config_element_name
,
2742 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2746 if (session
->shm_path
[0] != '\0') {
2747 ret
= config_writer_write_element_string(writer
,
2748 config_element_shared_memory_path
,
2751 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2756 ret
= save_domains(writer
, session
);
2757 if (ret
!= LTTNG_OK
) {
2761 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2764 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2768 if (session
->snapshot_mode
|| session
->live_timer
||
2769 session
->rotate_timer_period
|| session
->rotate_size
) {
2770 ret
= config_writer_open_element(writer
, config_element_attributes
);
2772 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2776 if (session
->snapshot_mode
) {
2777 ret
= config_writer_write_element_bool(writer
,
2778 config_element_snapshot_mode
, 1);
2780 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2783 } else if (session
->live_timer
) {
2784 ret
= config_writer_write_element_unsigned_int(writer
,
2785 config_element_live_timer_interval
, session
->live_timer
);
2787 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2791 if (session
->rotate_timer_period
|| session
->rotate_size
) {
2792 ret
= save_session_rotation_schedules(writer
,
2795 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2801 ret
= config_writer_close_element(writer
);
2803 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2808 ret
= save_session_output(writer
, session
);
2809 if (ret
!= LTTNG_OK
) {
2814 ret
= config_writer_close_element(writer
);
2816 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2821 ret
= config_writer_close_element(writer
);
2823 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2829 if (writer
&& config_writer_destroy(writer
)) {
2830 /* Preserve the original error code */
2831 ret
= ret
!= LTTNG_OK
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2833 if (ret
!= LTTNG_OK
) {
2834 /* Delete file in case of error */
2835 if ((fd
>= 0) && unlink(config_file_path
)) {
2836 PERROR("Unlinking XML session configuration.");
2843 closeret
= close(fd
);
2845 PERROR("Closing XML session configuration");
2852 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2853 lttng_sock_cred
*creds
)
2856 const char *session_name
;
2857 struct ltt_session
*session
;
2859 session_lock_list();
2861 session_name
= lttng_save_session_attr_get_session_name(attr
);
2863 session
= session_find_by_name(session_name
);
2865 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2869 session_lock(session
);
2870 ret
= save_session(session
, attr
, creds
);
2871 session_unlock(session
);
2872 session_put(session
);
2873 if (ret
!= LTTNG_OK
) {
2877 struct ltt_session_list
*list
= session_get_list();
2879 cds_list_for_each_entry(session
, &list
->head
, list
) {
2880 if (!session_get(session
)) {
2883 session_lock(session
);
2884 ret
= save_session(session
, attr
, creds
);
2885 session_unlock(session
);
2886 session_put(session
);
2887 /* Don't abort if we don't have the required permissions. */
2888 if (ret
!= LTTNG_OK
&& ret
!= LTTNG_ERR_EPERM
) {
2896 session_unlock_list();