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_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_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_instrumentation instrumentation
)
221 const char *instrumentation_string
;
223 switch (instrumentation
) {
224 case LTTNG_KERNEL_ALL
:
225 instrumentation_string
= config_event_type_all
;
227 case LTTNG_KERNEL_TRACEPOINT
:
228 instrumentation_string
= config_event_type_tracepoint
;
230 case LTTNG_KERNEL_KPROBE
:
231 instrumentation_string
= config_event_type_probe
;
233 case LTTNG_KERNEL_UPROBE
:
234 instrumentation_string
= config_event_type_userspace_probe
;
236 case LTTNG_KERNEL_FUNCTION
:
237 instrumentation_string
= config_event_type_function_entry
;
239 case LTTNG_KERNEL_KRETPROBE
:
240 instrumentation_string
= config_event_type_function
;
242 case LTTNG_KERNEL_NOOP
:
243 instrumentation_string
= config_event_type_noop
;
245 case LTTNG_KERNEL_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_context_type context_type
)
259 const char *context_type_string
;
261 switch (context_type
) {
262 case LTTNG_KERNEL_CONTEXT_PID
:
263 context_type_string
= config_event_context_pid
;
265 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
266 context_type_string
= config_event_context_procname
;
268 case LTTNG_KERNEL_CONTEXT_PRIO
:
269 context_type_string
= config_event_context_prio
;
271 case LTTNG_KERNEL_CONTEXT_NICE
:
272 context_type_string
= config_event_context_nice
;
274 case LTTNG_KERNEL_CONTEXT_VPID
:
275 context_type_string
= config_event_context_vpid
;
277 case LTTNG_KERNEL_CONTEXT_TID
:
278 context_type_string
= config_event_context_tid
;
280 case LTTNG_KERNEL_CONTEXT_VTID
:
281 context_type_string
= config_event_context_vtid
;
283 case LTTNG_KERNEL_CONTEXT_PPID
:
284 context_type_string
= config_event_context_ppid
;
286 case LTTNG_KERNEL_CONTEXT_VPPID
:
287 context_type_string
= config_event_context_vppid
;
289 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
290 context_type_string
= config_event_context_hostname
;
292 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
293 context_type_string
= config_event_context_interruptible
;
295 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
296 context_type_string
= config_event_context_preemptible
;
298 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
299 context_type_string
= config_event_context_need_reschedule
;
301 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
302 context_type_string
= config_event_context_migratable
;
304 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
305 context_type_string
= config_event_context_callstack_user
;
307 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
308 context_type_string
= config_event_context_callstack_kernel
;
310 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
311 context_type_string
= config_event_context_cgroup_ns
;
313 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
314 context_type_string
= config_event_context_ipc_ns
;
316 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
317 context_type_string
= config_event_context_mnt_ns
;
319 case LTTNG_KERNEL_CONTEXT_NET_NS
:
320 context_type_string
= config_event_context_net_ns
;
322 case LTTNG_KERNEL_CONTEXT_PID_NS
:
323 context_type_string
= config_event_context_pid_ns
;
325 case LTTNG_KERNEL_CONTEXT_TIME_NS
:
326 context_type_string
= config_event_context_time_ns
;
328 case LTTNG_KERNEL_CONTEXT_USER_NS
:
329 context_type_string
= config_event_context_user_ns
;
331 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
332 context_type_string
= config_event_context_uts_ns
;
334 case LTTNG_KERNEL_CONTEXT_UID
:
335 context_type_string
= config_event_context_uid
;
337 case LTTNG_KERNEL_CONTEXT_EUID
:
338 context_type_string
= config_event_context_euid
;
340 case LTTNG_KERNEL_CONTEXT_SUID
:
341 context_type_string
= config_event_context_suid
;
343 case LTTNG_KERNEL_CONTEXT_GID
:
344 context_type_string
= config_event_context_gid
;
346 case LTTNG_KERNEL_CONTEXT_EGID
:
347 context_type_string
= config_event_context_egid
;
349 case LTTNG_KERNEL_CONTEXT_SGID
:
350 context_type_string
= config_event_context_sgid
;
352 case LTTNG_KERNEL_CONTEXT_VUID
:
353 context_type_string
= config_event_context_vuid
;
355 case LTTNG_KERNEL_CONTEXT_VEUID
:
356 context_type_string
= config_event_context_veuid
;
358 case LTTNG_KERNEL_CONTEXT_VSUID
:
359 context_type_string
= config_event_context_vsuid
;
361 case LTTNG_KERNEL_CONTEXT_VGID
:
362 context_type_string
= config_event_context_vgid
;
364 case LTTNG_KERNEL_CONTEXT_VEGID
:
365 context_type_string
= config_event_context_vegid
;
367 case LTTNG_KERNEL_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_context_type context_type
)
381 const char *context_type_string
;
383 switch (context_type
) {
384 case LTTNG_UST_CONTEXT_PROCNAME
:
385 context_type_string
= config_event_context_procname
;
387 case LTTNG_UST_CONTEXT_VPID
:
388 context_type_string
= config_event_context_vpid
;
390 case LTTNG_UST_CONTEXT_VTID
:
391 context_type_string
= config_event_context_vtid
;
393 case LTTNG_UST_CONTEXT_IP
:
394 context_type_string
= config_event_context_ip
;
396 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
397 context_type_string
= config_event_context_pthread_id
;
399 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
400 context_type_string
= config_event_context_app
;
402 case LTTNG_UST_CONTEXT_CGROUP_NS
:
403 context_type_string
= config_event_context_cgroup_ns
;
405 case LTTNG_UST_CONTEXT_IPC_NS
:
406 context_type_string
= config_event_context_ipc_ns
;
408 case LTTNG_UST_CONTEXT_MNT_NS
:
409 context_type_string
= config_event_context_mnt_ns
;
411 case LTTNG_UST_CONTEXT_NET_NS
:
412 context_type_string
= config_event_context_net_ns
;
414 case LTTNG_UST_CONTEXT_TIME_NS
:
415 context_type_string
= config_event_context_time_ns
;
417 case LTTNG_UST_CONTEXT_PID_NS
:
418 context_type_string
= config_event_context_pid_ns
;
420 case LTTNG_UST_CONTEXT_USER_NS
:
421 context_type_string
= config_event_context_user_ns
;
423 case LTTNG_UST_CONTEXT_UTS_NS
:
424 context_type_string
= config_event_context_uts_ns
;
426 case LTTNG_UST_CONTEXT_VUID
:
427 context_type_string
= config_event_context_vuid
;
429 case LTTNG_UST_CONTEXT_VEUID
:
430 context_type_string
= config_event_context_veuid
;
432 case LTTNG_UST_CONTEXT_VSUID
:
433 context_type_string
= config_event_context_vsuid
;
435 case LTTNG_UST_CONTEXT_VGID
:
436 context_type_string
= config_event_context_vgid
;
438 case LTTNG_UST_CONTEXT_VEGID
:
439 context_type_string
= config_event_context_vegid
;
441 case LTTNG_UST_CONTEXT_VSGID
:
442 context_type_string
= config_event_context_vsgid
;
444 case LTTNG_UST_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_loglevel_type loglevel_type
)
484 const char *loglevel_type_string
;
486 switch (loglevel_type
) {
487 case LTTNG_UST_LOGLEVEL_ALL
:
488 loglevel_type_string
= config_loglevel_type_all
;
490 case LTTNG_UST_LOGLEVEL_RANGE
:
491 loglevel_type_string
= config_loglevel_type_range
;
493 case LTTNG_UST_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_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_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_FUNCTION
||
933 event
->event
->instrumentation
== LTTNG_KERNEL_KPROBE
||
934 event
->event
->instrumentation
== LTTNG_KERNEL_UPROBE
||
935 event
->event
->instrumentation
== LTTNG_KERNEL_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_SYSCALL
:
946 case LTTNG_KERNEL_FUNCTION
:
947 ret
= save_kernel_function_event(writer
, event
);
952 case LTTNG_KERNEL_KPROBE
:
953 case LTTNG_KERNEL_KRETPROBE
:
954 ret
= save_kernel_kprobe_event(writer
, event
);
959 case LTTNG_KERNEL_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_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_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_loglevel_type ust_loglevel_type
;
1193 ust_event
->enabled
= agent_event
->enabled
;
1194 ust_event
->attr
.instrumentation
= LTTNG_UST_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_LOGLEVEL_ALL
;
1204 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
1205 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
1207 case LTTNG_EVENT_LOGLEVEL_RANGE
:
1208 ust_loglevel_type
= LTTNG_UST_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
) {
1244 struct agent_event
*agent_event
;
1245 struct ltt_ust_event fake_event
;
1247 memset(&fake_event
, 0, sizeof(fake_event
));
1248 agent_event
= caa_container_of(node
, struct agent_event
, node
);
1251 * Initialize a fake ust event to reuse the same serialization
1252 * function since UST and agent events contain the same info
1253 * (and one could wonder why they don't reuse the same
1256 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
1257 if (ret
!= LTTNG_OK
) {
1261 ret
= save_ust_event(writer
, &fake_event
);
1262 if (ret
!= LTTNG_OK
) {
1270 ret
= config_writer_close_element(writer
);
1272 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1281 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1283 int save_kernel_context(struct config_writer
*writer
,
1284 struct lttng_kernel_context
*ctx
)
1292 ret
= config_writer_open_element(writer
, config_element_context
);
1294 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1298 if (ctx
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER
) {
1299 ret
= config_writer_open_element(writer
,
1300 config_element_context_perf
);
1302 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1306 ret
= config_writer_write_element_unsigned_int(writer
,
1307 config_element_type
, ctx
->u
.perf_counter
.type
);
1309 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1313 ret
= config_writer_write_element_unsigned_int(writer
,
1314 config_element_config
, ctx
->u
.perf_counter
.config
);
1316 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1320 ret
= config_writer_write_element_string(writer
,
1321 config_element_name
, ctx
->u
.perf_counter
.name
);
1323 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1328 ret
= config_writer_close_element(writer
);
1330 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1334 const char *context_type_string
=
1335 get_kernel_context_type_string(ctx
->ctx
);
1337 if (!context_type_string
) {
1338 ERR("Unsupported kernel context type.");
1339 ret
= LTTNG_ERR_INVALID
;
1343 ret
= config_writer_write_element_string(writer
,
1344 config_element_type
, context_type_string
);
1346 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1352 ret
= config_writer_close_element(writer
);
1354 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1363 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1365 int save_kernel_contexts(struct config_writer
*writer
,
1366 struct ltt_kernel_channel
*kchan
)
1369 struct ltt_kernel_context
*ctx
;
1371 if (cds_list_empty(&kchan
->ctx_list
)) {
1376 ret
= config_writer_open_element(writer
, config_element_contexts
);
1378 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1382 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
1383 ret
= save_kernel_context(writer
, &ctx
->ctx
);
1384 if (ret
!= LTTNG_OK
) {
1390 ret
= config_writer_close_element(writer
);
1392 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1401 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1403 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
1404 struct ltt_ust_context
*ctx
)
1411 /* Perf contexts are saved as event_perf_context_type */
1412 ret
= config_writer_open_element(writer
, config_element_context_perf
);
1414 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1418 ret
= config_writer_write_element_unsigned_int(writer
,
1419 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
1421 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1425 ret
= config_writer_write_element_unsigned_int(writer
,
1426 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
1428 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1432 ret
= config_writer_write_element_string(writer
, config_element_name
,
1433 ctx
->ctx
.u
.perf_counter
.name
);
1435 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1440 ret
= config_writer_close_element(writer
);
1442 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1451 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1453 int save_ust_context_app_ctx(struct config_writer
*writer
,
1454 struct ltt_ust_context
*ctx
)
1461 /* Application contexts are saved as application_context_type */
1462 ret
= config_writer_open_element(writer
, config_element_context_app
);
1464 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1468 ret
= config_writer_write_element_string(writer
,
1469 config_element_context_app_provider_name
,
1470 ctx
->ctx
.u
.app_ctx
.provider_name
);
1472 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1476 ret
= config_writer_write_element_string(writer
,
1477 config_element_context_app_ctx_name
,
1478 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1480 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1485 ret
= config_writer_close_element(writer
);
1487 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1496 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1498 int save_ust_context_generic(struct config_writer
*writer
,
1499 struct ltt_ust_context
*ctx
)
1502 const char *context_type_string
;
1507 /* Save context as event_context_type_type */
1508 context_type_string
= get_ust_context_type_string(
1510 if (!context_type_string
) {
1511 ERR("Unsupported UST context type.");
1512 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1516 ret
= config_writer_write_element_string(writer
,
1517 config_element_type
, context_type_string
);
1519 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1528 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1530 int save_ust_context(struct config_writer
*writer
,
1531 struct cds_list_head
*ctx_list
)
1534 struct ltt_ust_context
*ctx
;
1539 ret
= config_writer_open_element(writer
, config_element_contexts
);
1541 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1545 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1546 ret
= config_writer_open_element(writer
,
1547 config_element_context
);
1549 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1553 switch (ctx
->ctx
.ctx
) {
1554 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1555 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1557 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1558 ret
= save_ust_context_app_ctx(writer
, ctx
);
1561 /* Save generic context. */
1562 ret
= save_ust_context_generic(writer
, ctx
);
1564 if (ret
!= LTTNG_OK
) {
1569 ret
= config_writer_close_element(writer
);
1571 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1577 ret
= config_writer_close_element(writer
);
1579 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1588 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1590 int save_kernel_channel(struct config_writer
*writer
,
1591 struct ltt_kernel_channel
*kchan
)
1598 ret
= config_writer_open_element(writer
, config_element_channel
);
1600 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1604 ret
= config_writer_write_element_string(writer
, config_element_name
,
1605 kchan
->channel
->name
);
1607 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1611 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1612 kchan
->channel
->enabled
);
1614 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1618 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1619 if (ret
!= LTTNG_OK
) {
1623 ret
= save_kernel_events(writer
, kchan
);
1624 if (ret
!= LTTNG_OK
) {
1628 ret
= save_kernel_contexts(writer
, kchan
);
1629 if (ret
!= LTTNG_OK
) {
1634 ret
= config_writer_close_element(writer
);
1636 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1645 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1647 int save_ust_channel(struct config_writer
*writer
,
1648 struct ltt_ust_channel
*ust_chan
,
1649 struct ltt_ust_session
*session
)
1657 ret
= config_writer_open_element(writer
, config_element_channel
);
1659 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1663 ret
= config_writer_write_element_string(writer
, config_element_name
,
1666 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1670 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1673 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1677 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1678 if (ret
!= LTTNG_OK
) {
1682 ret
= config_writer_write_element_unsigned_int(writer
,
1683 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1685 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1689 ret
= config_writer_write_element_unsigned_int(writer
,
1690 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1692 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1696 ret
= config_writer_write_element_unsigned_int(writer
,
1697 config_element_live_timer_interval
,
1698 session
->live_timer_interval
);
1700 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1704 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1705 ret
= save_ust_events(writer
, ust_chan
->events
);
1706 if (ret
!= LTTNG_OK
) {
1710 struct agent
*agent
= NULL
;
1712 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1714 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1715 ERR("Could not find agent associated to UST subdomain");
1720 * Channels associated with a UST sub-domain (such as JUL, Log4j
1721 * or Python) don't have any non-internal events. We retrieve
1722 * the "agent" events associated with this channel and serialize
1725 ret
= save_agent_events(writer
, agent
);
1726 if (ret
!= LTTNG_OK
) {
1731 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1732 if (ret
!= LTTNG_OK
) {
1737 ret
= config_writer_close_element(writer
);
1739 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1748 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1750 int save_kernel_session(struct config_writer
*writer
,
1751 struct ltt_session
*session
)
1754 struct ltt_kernel_channel
*kchan
;
1759 ret
= config_writer_write_element_string(writer
, config_element_type
,
1760 config_domain_type_kernel
);
1762 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1766 ret
= config_writer_write_element_string(writer
,
1767 config_element_buffer_type
, config_buffer_type_global
);
1769 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1773 ret
= config_writer_open_element(writer
,
1774 config_element_channels
);
1776 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1780 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1782 ret
= save_kernel_channel(writer
, kchan
);
1783 if (ret
!= LTTNG_OK
) {
1789 ret
= config_writer_close_element(writer
);
1791 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1801 const char *get_config_domain_str(enum lttng_domain_type domain
)
1803 const char *str_dom
;
1806 case LTTNG_DOMAIN_KERNEL
:
1807 str_dom
= config_domain_type_kernel
;
1809 case LTTNG_DOMAIN_UST
:
1810 str_dom
= config_domain_type_ust
;
1812 case LTTNG_DOMAIN_JUL
:
1813 str_dom
= config_domain_type_jul
;
1815 case LTTNG_DOMAIN_LOG4J
:
1816 str_dom
= config_domain_type_log4j
;
1818 case LTTNG_DOMAIN_PYTHON
:
1819 str_dom
= config_domain_type_python
;
1828 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1829 static int save_process_attr_tracker(struct config_writer
*writer
,
1830 struct ltt_session
*sess
,
1832 enum lttng_process_attr process_attr
)
1835 const char *element_id_tracker
, *element_target_id
, *element_id
;
1836 const struct process_attr_tracker
*tracker
;
1837 enum lttng_tracking_policy tracking_policy
;
1838 struct lttng_process_attr_values
*values
= NULL
;
1840 switch (process_attr
) {
1841 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1842 element_id_tracker
= config_element_process_attr_tracker_pid
;
1843 element_target_id
= config_element_process_attr_pid_value
;
1844 element_id
= config_element_process_attr_id
;
1846 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1847 element_id_tracker
= config_element_process_attr_tracker_vpid
;
1848 element_target_id
= config_element_process_attr_vpid_value
;
1849 element_id
= config_element_process_attr_id
;
1851 case LTTNG_PROCESS_ATTR_USER_ID
:
1852 element_id_tracker
= config_element_process_attr_tracker_uid
;
1853 element_target_id
= config_element_process_attr_uid_value
;
1854 element_id
= config_element_process_attr_id
;
1856 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1857 element_id_tracker
= config_element_process_attr_tracker_vuid
;
1858 element_target_id
= config_element_process_attr_vuid_value
;
1859 element_id
= config_element_process_attr_id
;
1861 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1862 element_id_tracker
= config_element_process_attr_tracker_gid
;
1863 element_target_id
= config_element_process_attr_gid_value
;
1864 element_id
= config_element_process_attr_id
;
1866 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1867 element_id_tracker
= config_element_process_attr_tracker_vgid
;
1868 element_target_id
= config_element_process_attr_vgid_value
;
1869 element_id
= config_element_process_attr_id
;
1872 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1877 case LTTNG_DOMAIN_KERNEL
:
1879 tracker
= kernel_get_process_attr_tracker(
1880 sess
->kernel_session
, process_attr
);
1884 case LTTNG_DOMAIN_UST
:
1886 tracker
= trace_ust_get_process_attr_tracker(
1887 sess
->ust_session
, process_attr
);
1891 case LTTNG_DOMAIN_JUL
:
1892 case LTTNG_DOMAIN_LOG4J
:
1893 case LTTNG_DOMAIN_PYTHON
:
1895 ret
= LTTNG_ERR_UNSUPPORTED_DOMAIN
;
1899 tracking_policy
= process_attr_tracker_get_tracking_policy(tracker
);
1900 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_ALL
) {
1901 /* Tracking all, nothing to output. */
1906 ret
= config_writer_open_element(writer
, element_id_tracker
);
1908 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1912 ret
= config_writer_open_element(
1913 writer
, config_element_process_attr_values
);
1915 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1919 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_SET
) {
1920 unsigned int i
, count
;
1921 enum process_attr_tracker_status status
=
1922 process_attr_tracker_get_inclusion_set(
1925 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1926 ret
= LTTNG_ERR_NOMEM
;
1930 count
= _lttng_process_attr_values_get_count(values
);
1932 for (i
= 0; i
< count
; i
++) {
1933 unsigned int integral_value
= UINT_MAX
;
1934 const char *name
= NULL
;
1935 const struct process_attr_value
*value
=
1936 lttng_process_attr_tracker_values_get_at_index(
1940 ret
= config_writer_open_element(
1941 writer
, element_target_id
);
1943 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1947 switch (value
->type
) {
1948 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1950 (unsigned int) value
->value
.pid
;
1952 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1954 (unsigned int) value
->value
.uid
;
1956 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1958 (unsigned int) value
->value
.gid
;
1960 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1961 name
= value
->value
.user_name
;
1964 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1965 name
= value
->value
.group_name
;
1973 ret
= config_writer_write_element_string(writer
,
1974 config_element_name
, name
);
1976 ret
= config_writer_write_element_unsigned_int(
1982 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1986 /* /$element_target_id */
1987 ret
= config_writer_close_element(writer
);
1989 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1996 ret
= config_writer_close_element(writer
);
1998 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2002 /* /$element_id_tracker */
2003 ret
= config_writer_close_element(writer
);
2005 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2011 lttng_process_attr_values_destroy(values
);
2015 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2016 static int save_process_attr_trackers(struct config_writer
*writer
,
2017 struct ltt_session
*sess
,
2023 case LTTNG_DOMAIN_KERNEL
:
2024 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2025 LTTNG_PROCESS_ATTR_PROCESS_ID
);
2026 if (ret
!= LTTNG_OK
) {
2029 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2030 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2031 if (ret
!= LTTNG_OK
) {
2034 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2035 LTTNG_PROCESS_ATTR_USER_ID
);
2036 if (ret
!= LTTNG_OK
) {
2039 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2040 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2041 if (ret
!= LTTNG_OK
) {
2044 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2045 LTTNG_PROCESS_ATTR_GROUP_ID
);
2046 if (ret
!= LTTNG_OK
) {
2049 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2050 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2051 if (ret
!= LTTNG_OK
) {
2055 case LTTNG_DOMAIN_UST
:
2056 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2057 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2058 if (ret
!= LTTNG_OK
) {
2061 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2062 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2063 if (ret
!= LTTNG_OK
) {
2066 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2067 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2068 if (ret
!= LTTNG_OK
) {
2073 ret
= LTTNG_ERR_INVALID
;
2081 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2083 int save_ust_domain(struct config_writer
*writer
,
2084 struct ltt_session
*session
, enum lttng_domain_type domain
)
2087 struct ltt_ust_channel
*ust_chan
;
2088 const char *buffer_type_string
;
2089 struct lttng_ht_node_str
*node
;
2090 struct lttng_ht_iter iter
;
2091 const char *config_domain_name
;
2096 ret
= config_writer_open_element(writer
,
2097 config_element_domain
);
2099 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2103 config_domain_name
= get_config_domain_str(domain
);
2104 if (!config_domain_name
) {
2105 ret
= LTTNG_ERR_INVALID
;
2109 ret
= config_writer_write_element_string(writer
,
2110 config_element_type
, config_domain_name
);
2112 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2116 buffer_type_string
= get_buffer_type_string(
2117 session
->ust_session
->buffer_type
);
2118 if (!buffer_type_string
) {
2119 ERR("Unsupported buffer type.");
2120 ret
= LTTNG_ERR_INVALID
;
2124 ret
= config_writer_write_element_string(writer
,
2125 config_element_buffer_type
, buffer_type_string
);
2127 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2131 ret
= config_writer_open_element(writer
, config_element_channels
);
2133 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2138 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
2139 &iter
.iter
, node
, node
) {
2140 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
2141 if (domain
== ust_chan
->domain
) {
2142 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
2143 if (ret
!= LTTNG_OK
) {
2152 ret
= config_writer_close_element(writer
);
2154 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2158 if (domain
== LTTNG_DOMAIN_UST
) {
2159 ret
= config_writer_open_element(
2160 writer
, config_element_process_attr_trackers
);
2162 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2166 ret
= save_process_attr_trackers(
2167 writer
, session
, LTTNG_DOMAIN_UST
);
2168 if (ret
!= LTTNG_OK
) {
2173 ret
= config_writer_close_element(writer
);
2175 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2181 ret
= config_writer_close_element(writer
);
2183 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2192 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2194 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
2201 if (!session
->kernel_session
&& !session
->ust_session
) {
2205 ret
= config_writer_open_element(writer
, config_element_domains
);
2207 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2211 if (session
->kernel_session
) {
2212 ret
= config_writer_open_element(writer
,
2213 config_element_domain
);
2215 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2219 ret
= save_kernel_session(writer
, session
);
2220 if (ret
!= LTTNG_OK
) {
2224 ret
= config_writer_open_element(
2225 writer
, config_element_process_attr_trackers
);
2227 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2231 ret
= save_process_attr_trackers(
2232 writer
, session
, LTTNG_DOMAIN_KERNEL
);
2233 if (ret
!= LTTNG_OK
) {
2238 ret
= config_writer_close_element(writer
);
2240 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2244 ret
= config_writer_close_element(writer
);
2246 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2251 if (session
->ust_session
) {
2252 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
2253 if (ret
!= LTTNG_OK
) {
2257 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
2258 if (ret
!= LTTNG_OK
) {
2262 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
2263 if (ret
!= LTTNG_OK
) {
2267 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
2268 if (ret
!= LTTNG_OK
) {
2274 ret
= config_writer_close_element(writer
);
2276 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2285 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2287 int save_consumer_output(struct config_writer
*writer
,
2288 struct consumer_output
*output
)
2295 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
2297 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2301 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
2304 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2308 ret
= config_writer_open_element(writer
, config_element_destination
);
2310 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2314 switch (output
->type
) {
2315 case CONSUMER_DST_LOCAL
:
2316 ret
= config_writer_write_element_string(writer
,
2317 config_element_path
, output
->dst
.session_root_path
);
2319 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2323 case CONSUMER_DST_NET
:
2327 uri
= zmalloc(PATH_MAX
);
2329 ret
= LTTNG_ERR_NOMEM
;
2333 ret
= config_writer_open_element(writer
, config_element_net_output
);
2335 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2336 goto end_net_output
;
2339 if (output
->dst
.net
.control_isset
&&
2340 output
->dst
.net
.data_isset
) {
2341 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
2343 ret
= LTTNG_ERR_INVALID
;
2344 goto end_net_output
;
2347 ret
= config_writer_write_element_string(writer
,
2348 config_element_control_uri
, uri
);
2350 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2351 goto end_net_output
;
2354 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
2356 ret
= LTTNG_ERR_INVALID
;
2357 goto end_net_output
;
2360 ret
= config_writer_write_element_string(writer
,
2361 config_element_data_uri
, uri
);
2363 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2364 goto end_net_output
;
2369 if (ret
!= LTTNG_OK
) {
2373 ret
= !output
->dst
.net
.control_isset
?
2374 LTTNG_ERR_URL_CTRL_MISS
:
2375 LTTNG_ERR_URL_DATA_MISS
;
2380 ret
= config_writer_close_element(writer
);
2382 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2388 ERR("Unsupported consumer output type.");
2389 ret
= LTTNG_ERR_INVALID
;
2394 ret
= config_writer_close_element(writer
);
2396 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2400 /* /consumer_output */
2401 ret
= config_writer_close_element(writer
);
2403 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2412 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2414 int save_snapshot_outputs(struct config_writer
*writer
,
2415 struct snapshot
*snapshot
)
2418 struct lttng_ht_iter iter
;
2419 struct snapshot_output
*output
;
2424 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
2426 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2431 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
2433 ret
= config_writer_open_element(writer
,
2434 config_element_output
);
2436 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2440 ret
= config_writer_write_element_string(writer
,
2441 config_element_name
, output
->name
);
2443 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2447 ret
= config_writer_write_element_unsigned_int(writer
,
2448 config_element_max_size
, output
->max_size
);
2450 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2454 ret
= save_consumer_output(writer
, output
->consumer
);
2455 if (ret
!= LTTNG_OK
) {
2460 ret
= config_writer_close_element(writer
);
2462 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2468 /* /snapshot_outputs */
2469 ret
= config_writer_close_element(writer
);
2471 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2483 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2485 int save_session_output(struct config_writer
*writer
,
2486 struct ltt_session
*session
)
2493 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
2494 (!session
->snapshot_mode
&& !session
->consumer
)) {
2495 /* Session is in no output mode */
2500 ret
= config_writer_open_element(writer
, config_element_output
);
2502 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2506 if (session
->snapshot_mode
) {
2507 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
2508 if (ret
!= LTTNG_OK
) {
2512 if (session
->consumer
) {
2513 ret
= save_consumer_output(writer
, session
->consumer
);
2514 if (ret
!= LTTNG_OK
) {
2521 ret
= config_writer_close_element(writer
);
2523 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2532 int save_session_rotation_schedule(struct config_writer
*writer
,
2533 enum lttng_rotation_schedule_type type
, uint64_t value
)
2536 const char *element_name
;
2537 const char *value_name
;
2540 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2541 element_name
= config_element_rotation_schedule_periodic
;
2542 value_name
= config_element_rotation_schedule_periodic_time_us
;
2544 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2545 element_name
= config_element_rotation_schedule_size_threshold
;
2546 value_name
= config_element_rotation_schedule_size_threshold_bytes
;
2553 ret
= config_writer_open_element(writer
, element_name
);
2558 ret
= config_writer_write_element_unsigned_int(writer
,
2564 /* Close schedule descriptor element. */
2565 ret
= config_writer_close_element(writer
);
2574 int save_session_rotation_schedules(struct config_writer
*writer
,
2575 struct ltt_session
*session
)
2579 ret
= config_writer_open_element(writer
,
2580 config_element_rotation_schedules
);
2584 if (session
->rotate_timer_period
) {
2585 ret
= save_session_rotation_schedule(writer
,
2586 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
,
2587 session
->rotate_timer_period
);
2589 goto close_schedules
;
2592 if (session
->rotate_size
) {
2593 ret
= save_session_rotation_schedule(writer
,
2594 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
,
2595 session
->rotate_size
);
2597 goto close_schedules
;
2602 /* Close rotation schedules element. */
2603 ret
= config_writer_close_element(writer
);
2612 * Save the given session.
2614 * Return LTTNG_OK on success else a LTTNG_ERR* code.
2617 int save_session(struct ltt_session
*session
,
2618 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
2621 char config_file_path
[LTTNG_PATH_MAX
];
2623 struct config_writer
*writer
= NULL
;
2624 size_t session_name_len
;
2625 const char *provided_path
;
2626 int file_open_flags
= O_CREAT
| O_WRONLY
| O_TRUNC
;
2632 session_name_len
= strlen(session
->name
);
2633 memset(config_file_path
, 0, sizeof(config_file_path
));
2635 if (!session_access_ok(session
,
2636 LTTNG_SOCK_GET_UID_CRED(creds
),
2637 LTTNG_SOCK_GET_GID_CRED(creds
)) || session
->destroyed
) {
2638 ret
= LTTNG_ERR_EPERM
;
2642 provided_path
= lttng_save_session_attr_get_output_url(attr
);
2643 if (provided_path
) {
2644 DBG3("Save session in provided path %s", provided_path
);
2645 len
= strlen(provided_path
);
2646 if (len
>= sizeof(config_file_path
)) {
2647 ret
= LTTNG_ERR_SET_URL
;
2650 strncpy(config_file_path
, provided_path
, sizeof(config_file_path
));
2653 char *home_dir
= utils_get_user_home_dir(
2654 LTTNG_SOCK_GET_UID_CRED(creds
));
2656 ret
= LTTNG_ERR_SET_URL
;
2660 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
2661 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
2664 PERROR("snprintf save session");
2665 ret
= LTTNG_ERR_SET_URL
;
2672 * Check the path fits in the config file path dst including the '/'
2673 * followed by trailing .lttng extension and the NULL terminated string.
2675 if ((len
+ session_name_len
+ 2 +
2676 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
2677 > sizeof(config_file_path
)) {
2678 ret
= LTTNG_ERR_SET_URL
;
2682 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
2683 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2685 ret
= LTTNG_ERR_SET_URL
;
2690 * At this point, we know that everything fits in the buffer. Validation
2691 * was done just above.
2693 config_file_path
[len
++] = '/';
2694 strncpy(config_file_path
+ len
, session
->name
, sizeof(config_file_path
) - len
);
2695 len
+= session_name_len
;
2696 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2697 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2698 config_file_path
[len
] = '\0';
2700 if (!attr
->overwrite
) {
2701 file_open_flags
|= O_EXCL
;
2704 fd
= run_as_open(config_file_path
, file_open_flags
,
2705 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
2706 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2708 PERROR("Could not create configuration file");
2711 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
2714 ret
= LTTNG_ERR_EPERM
;
2717 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2723 writer
= config_writer_create(fd
, 1);
2725 ret
= LTTNG_ERR_NOMEM
;
2729 ret
= config_writer_open_element(writer
, config_element_sessions
);
2731 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2735 ret
= config_writer_open_element(writer
, config_element_session
);
2737 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2741 ret
= config_writer_write_element_string(writer
, config_element_name
,
2744 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2748 if (session
->shm_path
[0] != '\0') {
2749 ret
= config_writer_write_element_string(writer
,
2750 config_element_shared_memory_path
,
2753 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2758 ret
= save_domains(writer
, session
);
2759 if (ret
!= LTTNG_OK
) {
2763 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2766 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2770 if (session
->snapshot_mode
|| session
->live_timer
||
2771 session
->rotate_timer_period
|| session
->rotate_size
) {
2772 ret
= config_writer_open_element(writer
, config_element_attributes
);
2774 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2778 if (session
->snapshot_mode
) {
2779 ret
= config_writer_write_element_bool(writer
,
2780 config_element_snapshot_mode
, 1);
2782 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2785 } else if (session
->live_timer
) {
2786 ret
= config_writer_write_element_unsigned_int(writer
,
2787 config_element_live_timer_interval
, session
->live_timer
);
2789 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2793 if (session
->rotate_timer_period
|| session
->rotate_size
) {
2794 ret
= save_session_rotation_schedules(writer
,
2797 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2803 ret
= config_writer_close_element(writer
);
2805 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2810 ret
= save_session_output(writer
, session
);
2811 if (ret
!= LTTNG_OK
) {
2816 ret
= config_writer_close_element(writer
);
2818 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2823 ret
= config_writer_close_element(writer
);
2825 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2831 if (writer
&& config_writer_destroy(writer
)) {
2832 /* Preserve the original error code */
2833 ret
= ret
!= LTTNG_OK
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2835 if (ret
!= LTTNG_OK
) {
2836 /* Delete file in case of error */
2837 if ((fd
>= 0) && unlink(config_file_path
)) {
2838 PERROR("Unlinking XML session configuration.");
2845 closeret
= close(fd
);
2847 PERROR("Closing XML session configuration");
2854 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2855 lttng_sock_cred
*creds
)
2858 const char *session_name
;
2859 struct ltt_session
*session
;
2861 session_lock_list();
2863 session_name
= lttng_save_session_attr_get_session_name(attr
);
2865 session
= session_find_by_name(session_name
);
2867 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2871 session_lock(session
);
2872 ret
= save_session(session
, attr
, creds
);
2873 session_unlock(session
);
2874 session_put(session
);
2875 if (ret
!= LTTNG_OK
) {
2879 struct ltt_session_list
*list
= session_get_list();
2881 cds_list_for_each_entry(session
, &list
->head
, list
) {
2882 if (!session_get(session
)) {
2885 session_lock(session
);
2886 ret
= save_session(session
, attr
, creds
);
2887 session_unlock(session
);
2888 session_put(session
);
2889 /* Don't abort if we don't have the required permissions. */
2890 if (ret
!= LTTNG_OK
&& ret
!= LTTNG_ERR_EPERM
) {
2898 session_unlock_list();