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_USER_NS
:
326 context_type_string
= config_event_context_user_ns
;
328 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
329 context_type_string
= config_event_context_uts_ns
;
331 case LTTNG_KERNEL_CONTEXT_UID
:
332 context_type_string
= config_event_context_uid
;
334 case LTTNG_KERNEL_CONTEXT_EUID
:
335 context_type_string
= config_event_context_euid
;
337 case LTTNG_KERNEL_CONTEXT_SUID
:
338 context_type_string
= config_event_context_suid
;
340 case LTTNG_KERNEL_CONTEXT_GID
:
341 context_type_string
= config_event_context_gid
;
343 case LTTNG_KERNEL_CONTEXT_EGID
:
344 context_type_string
= config_event_context_egid
;
346 case LTTNG_KERNEL_CONTEXT_SGID
:
347 context_type_string
= config_event_context_sgid
;
349 case LTTNG_KERNEL_CONTEXT_VUID
:
350 context_type_string
= config_event_context_vuid
;
352 case LTTNG_KERNEL_CONTEXT_VEUID
:
353 context_type_string
= config_event_context_veuid
;
355 case LTTNG_KERNEL_CONTEXT_VSUID
:
356 context_type_string
= config_event_context_vsuid
;
358 case LTTNG_KERNEL_CONTEXT_VGID
:
359 context_type_string
= config_event_context_vgid
;
361 case LTTNG_KERNEL_CONTEXT_VEGID
:
362 context_type_string
= config_event_context_vegid
;
364 case LTTNG_KERNEL_CONTEXT_VSGID
:
365 context_type_string
= config_event_context_vsgid
;
368 context_type_string
= NULL
;
371 return context_type_string
;
375 const char *get_ust_context_type_string(
376 enum lttng_ust_context_type context_type
)
378 const char *context_type_string
;
380 switch (context_type
) {
381 case LTTNG_UST_CONTEXT_PROCNAME
:
382 context_type_string
= config_event_context_procname
;
384 case LTTNG_UST_CONTEXT_VPID
:
385 context_type_string
= config_event_context_vpid
;
387 case LTTNG_UST_CONTEXT_VTID
:
388 context_type_string
= config_event_context_vtid
;
390 case LTTNG_UST_CONTEXT_IP
:
391 context_type_string
= config_event_context_ip
;
393 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
394 context_type_string
= config_event_context_pthread_id
;
396 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
397 context_type_string
= config_event_context_app
;
399 case LTTNG_UST_CONTEXT_CGROUP_NS
:
400 context_type_string
= config_event_context_cgroup_ns
;
402 case LTTNG_UST_CONTEXT_IPC_NS
:
403 context_type_string
= config_event_context_ipc_ns
;
405 case LTTNG_UST_CONTEXT_MNT_NS
:
406 context_type_string
= config_event_context_mnt_ns
;
408 case LTTNG_UST_CONTEXT_NET_NS
:
409 context_type_string
= config_event_context_net_ns
;
411 case LTTNG_UST_CONTEXT_PID_NS
:
412 context_type_string
= config_event_context_pid_ns
;
414 case LTTNG_UST_CONTEXT_USER_NS
:
415 context_type_string
= config_event_context_user_ns
;
417 case LTTNG_UST_CONTEXT_UTS_NS
:
418 context_type_string
= config_event_context_uts_ns
;
420 case LTTNG_UST_CONTEXT_VUID
:
421 context_type_string
= config_event_context_vuid
;
423 case LTTNG_UST_CONTEXT_VEUID
:
424 context_type_string
= config_event_context_veuid
;
426 case LTTNG_UST_CONTEXT_VSUID
:
427 context_type_string
= config_event_context_vsuid
;
429 case LTTNG_UST_CONTEXT_VGID
:
430 context_type_string
= config_event_context_vgid
;
432 case LTTNG_UST_CONTEXT_VEGID
:
433 context_type_string
= config_event_context_vegid
;
435 case LTTNG_UST_CONTEXT_VSGID
:
436 context_type_string
= config_event_context_vsgid
;
438 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
440 * Error, should not be stored in the XML, perf contexts
441 * are stored as a node of type event_perf_context_type.
444 context_type_string
= NULL
;
448 return context_type_string
;
452 const char *get_buffer_type_string(
453 enum lttng_buffer_type buffer_type
)
455 const char *buffer_type_string
;
457 switch (buffer_type
) {
458 case LTTNG_BUFFER_PER_PID
:
459 buffer_type_string
= config_buffer_type_per_pid
;
461 case LTTNG_BUFFER_PER_UID
:
462 buffer_type_string
= config_buffer_type_per_uid
;
464 case LTTNG_BUFFER_GLOBAL
:
465 buffer_type_string
= config_buffer_type_global
;
468 buffer_type_string
= NULL
;
471 return buffer_type_string
;
475 const char *get_loglevel_type_string(
476 enum lttng_ust_loglevel_type loglevel_type
)
478 const char *loglevel_type_string
;
480 switch (loglevel_type
) {
481 case LTTNG_UST_LOGLEVEL_ALL
:
482 loglevel_type_string
= config_loglevel_type_all
;
484 case LTTNG_UST_LOGLEVEL_RANGE
:
485 loglevel_type_string
= config_loglevel_type_range
;
487 case LTTNG_UST_LOGLEVEL_SINGLE
:
488 loglevel_type_string
= config_loglevel_type_single
;
491 loglevel_type_string
= NULL
;
494 return loglevel_type_string
;
497 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
499 int save_kernel_function_event(struct config_writer
*writer
,
500 struct ltt_kernel_event
*event
)
504 ret
= config_writer_open_element(writer
, config_element_function_attributes
);
506 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
510 ret
= config_writer_write_element_string(writer
, config_element_name
,
511 event
->event
->u
.ftrace
.symbol_name
);
513 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
517 /* /function attributes */
518 ret
= config_writer_close_element(writer
);
520 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
528 int save_kernel_kprobe_event(struct config_writer
*writer
,
529 struct ltt_kernel_event
*event
)
532 const char *symbol_name
;
536 switch (event
->event
->instrumentation
) {
537 case LTTNG_KERNEL_KPROBE
:
539 * Comments in lttng-kernel.h mention that
540 * either addr or symbol_name are set, not both.
542 addr
= event
->event
->u
.kprobe
.addr
;
543 offset
= event
->event
->u
.kprobe
.offset
;
544 symbol_name
= addr
? NULL
: event
->event
->u
.kprobe
.symbol_name
;
546 case LTTNG_KERNEL_KRETPROBE
:
547 addr
= event
->event
->u
.kretprobe
.addr
;
548 offset
= event
->event
->u
.kretprobe
.offset
;
549 symbol_name
= addr
? NULL
: event
->event
->u
.kretprobe
.symbol_name
;
553 ERR("Unsupported kernel instrumentation type.");
554 ret
= LTTNG_ERR_INVALID
;
558 ret
= config_writer_open_element(writer
, config_element_probe_attributes
);
560 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
565 ret
= config_writer_write_element_unsigned_int( writer
,
566 config_element_address
, addr
);
568 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
571 } else if (symbol_name
) {
572 ret
= config_writer_write_element_string(writer
,
573 config_element_symbol_name
, symbol_name
);
575 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
578 /* If the offset is non-zero, write it.*/
580 ret
= config_writer_write_element_unsigned_int(writer
,
581 config_element_offset
, offset
);
583 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
589 * This really should not happen as we are either setting the
590 * address or the symbol above.
592 ERR("Invalid probe/function description.");
593 ret
= LTTNG_ERR_INVALID
;
598 ret
= config_writer_close_element(writer
);
600 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
608 * Save the userspace probe tracepoint event associated with the event to the
612 int save_kernel_userspace_probe_tracepoint_event(struct config_writer
*writer
,
613 struct ltt_kernel_event
*event
)
616 const char *probe_name
, *provider_name
, *binary_path
;
617 const struct lttng_userspace_probe_location
*userspace_probe_location
;
618 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
619 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
621 /* Get userspace probe location from the event. */
622 userspace_probe_location
= event
->userspace_probe_location
;
623 if (!userspace_probe_location
) {
624 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
628 /* Get lookup method and lookup method type. */
629 lookup_method
= lttng_userspace_probe_location_get_lookup_method(userspace_probe_location
);
630 if (!lookup_method
) {
631 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
635 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
637 /* Get the binary path, probe name and provider name. */
639 lttng_userspace_probe_location_tracepoint_get_binary_path(
640 userspace_probe_location
);
642 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
647 lttng_userspace_probe_location_tracepoint_get_probe_name(
648 userspace_probe_location
);
650 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
655 lttng_userspace_probe_location_tracepoint_get_provider_name(
656 userspace_probe_location
);
657 if (!provider_name
) {
658 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
662 /* Open a userspace probe tracepoint attribute. */
663 ret
= config_writer_open_element(writer
, config_element_userspace_probe_tracepoint_attributes
);
665 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
669 switch (lookup_type
) {
670 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
671 ret
= config_writer_write_element_string(writer
,
672 config_element_userspace_probe_lookup
,
673 config_element_userspace_probe_lookup_tracepoint_sdt
);
675 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
680 ERR("Unsupported kernel userspace probe tracepoint lookup method.");
681 ret
= LTTNG_ERR_INVALID
;
685 /* Write the binary path, provider name and the probe name. */
686 ret
= config_writer_write_element_string(writer
,
687 config_element_userspace_probe_location_binary_path
,
690 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
694 ret
= config_writer_write_element_string(writer
,
695 config_element_userspace_probe_tracepoint_location_provider_name
,
698 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
702 ret
= config_writer_write_element_string(writer
,
703 config_element_userspace_probe_tracepoint_location_probe_name
,
706 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
710 /* Close the userspace probe tracepoint attribute. */
711 ret
= config_writer_close_element(writer
);
713 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
722 * Save the userspace probe function event associated with the event to the
726 int save_kernel_userspace_probe_function_event(struct config_writer
*writer
,
727 struct ltt_kernel_event
*event
)
730 const char *function_name
, *binary_path
;
731 const struct lttng_userspace_probe_location
*userspace_probe_location
;
732 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
733 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
735 /* Get userspace probe location from the event. */
736 userspace_probe_location
= event
->userspace_probe_location
;
737 if (!userspace_probe_location
) {
738 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
742 /* Get lookup method and lookup method type. */
743 lookup_method
= lttng_userspace_probe_location_get_lookup_method(
744 userspace_probe_location
);
745 if (!lookup_method
) {
746 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
750 /* Get the binary path and the function name. */
752 lttng_userspace_probe_location_function_get_binary_path(
753 userspace_probe_location
);
755 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
760 lttng_userspace_probe_location_function_get_function_name(
761 userspace_probe_location
);
762 if (!function_name
) {
763 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
767 /* Open a userspace probe function attribute. */
768 ret
= config_writer_open_element(writer
,
769 config_element_userspace_probe_function_attributes
);
771 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
775 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
776 switch (lookup_type
) {
777 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
778 ret
= config_writer_write_element_string(writer
,
779 config_element_userspace_probe_lookup
,
780 config_element_userspace_probe_lookup_function_elf
);
782 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
786 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
787 ret
= config_writer_write_element_string(writer
,
788 config_element_userspace_probe_lookup
,
789 config_element_userspace_probe_lookup_function_default
);
791 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
796 ERR("Unsupported kernel userspace probe function lookup method.");
797 ret
= LTTNG_ERR_INVALID
;
801 /* Write the binary path and the function name. */
802 ret
= config_writer_write_element_string(writer
,
803 config_element_userspace_probe_location_binary_path
,
806 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
810 ret
= config_writer_write_element_string(writer
,
811 config_element_userspace_probe_function_location_function_name
,
814 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
818 /* Close the userspace probe function attribute. */
819 ret
= config_writer_close_element(writer
);
821 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
830 int save_kernel_userspace_probe_event(struct config_writer
*writer
,
831 struct ltt_kernel_event
*event
)
834 struct lttng_userspace_probe_location
*userspace_probe_location
;
836 /* Get userspace probe location from the event. */
837 userspace_probe_location
= event
->userspace_probe_location
;
838 if (!userspace_probe_location
) {
839 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
843 switch(lttng_userspace_probe_location_get_type(userspace_probe_location
)) {
844 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
846 ret
= save_kernel_userspace_probe_function_event(writer
, event
);
848 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
853 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
855 ret
= save_kernel_userspace_probe_tracepoint_event(writer
, event
);
857 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
862 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
864 ERR("Unsupported kernel userspace probe location type.");
865 ret
= LTTNG_ERR_INVALID
;
874 int save_kernel_event(struct config_writer
*writer
,
875 struct ltt_kernel_event
*event
)
878 const char *instrumentation_type
;
880 ret
= config_writer_open_element(writer
, config_element_event
);
882 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
886 if (event
->event
->name
[0]) {
887 ret
= config_writer_write_element_string(writer
,
888 config_element_name
, event
->event
->name
);
890 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
895 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
898 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
902 instrumentation_type
= get_kernel_instrumentation_string(
903 event
->event
->instrumentation
);
904 if (!instrumentation_type
) {
905 ret
= LTTNG_ERR_INVALID
;
909 ret
= config_writer_write_element_string(writer
, config_element_type
,
910 instrumentation_type
);
912 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
916 if (event
->filter_expression
) {
917 ret
= config_writer_write_element_string(writer
,
918 config_element_filter
,
919 event
->filter_expression
);
921 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
926 if (event
->event
->instrumentation
== LTTNG_KERNEL_FUNCTION
||
927 event
->event
->instrumentation
== LTTNG_KERNEL_KPROBE
||
928 event
->event
->instrumentation
== LTTNG_KERNEL_UPROBE
||
929 event
->event
->instrumentation
== LTTNG_KERNEL_KRETPROBE
) {
931 ret
= config_writer_open_element(writer
,
932 config_element_attributes
);
934 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
938 switch (event
->event
->instrumentation
) {
939 case LTTNG_KERNEL_SYSCALL
:
940 case LTTNG_KERNEL_FUNCTION
:
941 ret
= save_kernel_function_event(writer
, event
);
946 case LTTNG_KERNEL_KPROBE
:
947 case LTTNG_KERNEL_KRETPROBE
:
948 ret
= save_kernel_kprobe_event(writer
, event
);
953 case LTTNG_KERNEL_UPROBE
:
954 ret
= save_kernel_userspace_probe_event(writer
, event
);
960 ERR("Unsupported kernel instrumentation type.");
961 ret
= LTTNG_ERR_INVALID
;
966 ret
= config_writer_close_element(writer
);
968 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
974 ret
= config_writer_close_element(writer
);
976 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
985 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
987 int save_kernel_events(struct config_writer
*writer
,
988 struct ltt_kernel_channel
*kchan
)
991 struct ltt_kernel_event
*event
;
993 ret
= config_writer_open_element(writer
, config_element_events
);
995 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
999 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
1000 ret
= save_kernel_event(writer
, event
);
1001 if (ret
!= LTTNG_OK
) {
1007 ret
= config_writer_close_element(writer
);
1009 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1018 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1020 int save_ust_event(struct config_writer
*writer
,
1021 struct ltt_ust_event
*event
)
1024 const char *loglevel_type_string
;
1026 ret
= config_writer_open_element(writer
, config_element_event
);
1028 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1032 if (event
->attr
.name
[0]) {
1033 ret
= config_writer_write_element_string(writer
,
1034 config_element_name
, event
->attr
.name
);
1036 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1041 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1044 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1048 if (event
->attr
.instrumentation
!= LTTNG_UST_TRACEPOINT
) {
1049 ERR("Unsupported UST instrumentation type.");
1050 ret
= LTTNG_ERR_INVALID
;
1053 ret
= config_writer_write_element_string(writer
, config_element_type
,
1054 config_event_type_tracepoint
);
1056 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1060 loglevel_type_string
= get_loglevel_type_string(
1061 event
->attr
.loglevel_type
);
1062 if (!loglevel_type_string
) {
1063 ERR("Unsupported UST loglevel type.");
1064 ret
= LTTNG_ERR_INVALID
;
1068 ret
= config_writer_write_element_string(writer
,
1069 config_element_loglevel_type
, loglevel_type_string
);
1071 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1075 /* The log level is irrelevant if no "filtering" is enabled */
1076 if (event
->attr
.loglevel_type
!= LTTNG_UST_LOGLEVEL_ALL
) {
1077 ret
= config_writer_write_element_signed_int(writer
,
1078 config_element_loglevel
, event
->attr
.loglevel
);
1080 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1085 if (event
->filter_expression
) {
1086 ret
= config_writer_write_element_string(writer
,
1087 config_element_filter
, event
->filter_expression
);
1089 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1094 if (event
->exclusion
&& event
->exclusion
->count
) {
1097 ret
= config_writer_open_element(writer
,
1098 config_element_exclusions
);
1100 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1104 for (i
= 0; i
< event
->exclusion
->count
; i
++) {
1105 ret
= config_writer_write_element_string(writer
,
1106 config_element_exclusion
,
1107 LTTNG_EVENT_EXCLUSION_NAME_AT(
1108 event
->exclusion
, i
));
1110 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1116 ret
= config_writer_close_element(writer
);
1118 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1124 ret
= config_writer_close_element(writer
);
1126 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1135 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1137 int save_ust_events(struct config_writer
*writer
,
1138 struct lttng_ht
*events
)
1141 struct ltt_ust_event
*event
;
1142 struct lttng_ht_node_str
*node
;
1143 struct lttng_ht_iter iter
;
1145 ret
= config_writer_open_element(writer
, config_element_events
);
1147 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1152 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
1153 event
= caa_container_of(node
, struct ltt_ust_event
, node
);
1155 if (event
->internal
) {
1156 /* Internal events must not be exposed to clients */
1159 ret
= save_ust_event(writer
, event
);
1160 if (ret
!= LTTNG_OK
) {
1168 ret
= config_writer_close_element(writer
);
1170 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1179 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1181 int init_ust_event_from_agent_event(struct ltt_ust_event
*ust_event
,
1182 struct agent_event
*agent_event
)
1185 enum lttng_ust_loglevel_type ust_loglevel_type
;
1187 ust_event
->enabled
= agent_event
->enabled
;
1188 ust_event
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
1189 if (lttng_strncpy(ust_event
->attr
.name
, agent_event
->name
,
1190 LTTNG_SYMBOL_NAME_LEN
)) {
1191 ret
= LTTNG_ERR_INVALID
;
1194 switch (agent_event
->loglevel_type
) {
1195 case LTTNG_EVENT_LOGLEVEL_ALL
:
1196 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
1198 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
1199 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
1201 case LTTNG_EVENT_LOGLEVEL_RANGE
:
1202 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
1205 ERR("Invalid agent_event loglevel_type.");
1206 ret
= LTTNG_ERR_INVALID
;
1210 ust_event
->attr
.loglevel_type
= ust_loglevel_type
;
1211 ust_event
->attr
.loglevel
= agent_event
->loglevel_value
;
1212 ust_event
->filter_expression
= agent_event
->filter_expression
;
1213 ust_event
->exclusion
= agent_event
->exclusion
;
1220 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1222 int save_agent_events(struct config_writer
*writer
,
1223 struct agent
*agent
)
1226 struct lttng_ht_iter iter
;
1227 struct lttng_ht_node_str
*node
;
1229 ret
= config_writer_open_element(writer
, config_element_events
);
1231 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1236 cds_lfht_for_each_entry(agent
->events
->ht
, &iter
.iter
, node
, node
) {
1238 struct agent_event
*agent_event
;
1239 struct ltt_ust_event fake_event
;
1241 memset(&fake_event
, 0, sizeof(fake_event
));
1242 agent_event
= caa_container_of(node
, struct agent_event
, node
);
1245 * Initialize a fake ust event to reuse the same serialization
1246 * function since UST and agent events contain the same info
1247 * (and one could wonder why they don't reuse the same
1250 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
1251 if (ret
!= LTTNG_OK
) {
1255 ret
= save_ust_event(writer
, &fake_event
);
1256 if (ret
!= LTTNG_OK
) {
1264 ret
= config_writer_close_element(writer
);
1266 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1275 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1277 int save_kernel_context(struct config_writer
*writer
,
1278 struct lttng_kernel_context
*ctx
)
1286 ret
= config_writer_open_element(writer
, config_element_context
);
1288 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1292 if (ctx
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER
) {
1293 ret
= config_writer_open_element(writer
,
1294 config_element_context_perf
);
1296 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1300 ret
= config_writer_write_element_unsigned_int(writer
,
1301 config_element_type
, ctx
->u
.perf_counter
.type
);
1303 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1307 ret
= config_writer_write_element_unsigned_int(writer
,
1308 config_element_config
, ctx
->u
.perf_counter
.config
);
1310 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1314 ret
= config_writer_write_element_string(writer
,
1315 config_element_name
, ctx
->u
.perf_counter
.name
);
1317 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1322 ret
= config_writer_close_element(writer
);
1324 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1328 const char *context_type_string
=
1329 get_kernel_context_type_string(ctx
->ctx
);
1331 if (!context_type_string
) {
1332 ERR("Unsupported kernel context type.");
1333 ret
= LTTNG_ERR_INVALID
;
1337 ret
= config_writer_write_element_string(writer
,
1338 config_element_type
, context_type_string
);
1340 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1346 ret
= config_writer_close_element(writer
);
1348 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1357 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1359 int save_kernel_contexts(struct config_writer
*writer
,
1360 struct ltt_kernel_channel
*kchan
)
1363 struct ltt_kernel_context
*ctx
;
1365 if (cds_list_empty(&kchan
->ctx_list
)) {
1370 ret
= config_writer_open_element(writer
, config_element_contexts
);
1372 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1376 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
1377 ret
= save_kernel_context(writer
, &ctx
->ctx
);
1378 if (ret
!= LTTNG_OK
) {
1384 ret
= config_writer_close_element(writer
);
1386 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1395 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1397 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
1398 struct ltt_ust_context
*ctx
)
1405 /* Perf contexts are saved as event_perf_context_type */
1406 ret
= config_writer_open_element(writer
, config_element_context_perf
);
1408 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1412 ret
= config_writer_write_element_unsigned_int(writer
,
1413 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
1415 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1419 ret
= config_writer_write_element_unsigned_int(writer
,
1420 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
1422 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1426 ret
= config_writer_write_element_string(writer
, config_element_name
,
1427 ctx
->ctx
.u
.perf_counter
.name
);
1429 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1434 ret
= config_writer_close_element(writer
);
1436 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1445 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1447 int save_ust_context_app_ctx(struct config_writer
*writer
,
1448 struct ltt_ust_context
*ctx
)
1455 /* Application contexts are saved as application_context_type */
1456 ret
= config_writer_open_element(writer
, config_element_context_app
);
1458 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1462 ret
= config_writer_write_element_string(writer
,
1463 config_element_context_app_provider_name
,
1464 ctx
->ctx
.u
.app_ctx
.provider_name
);
1466 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1470 ret
= config_writer_write_element_string(writer
,
1471 config_element_context_app_ctx_name
,
1472 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1474 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1479 ret
= config_writer_close_element(writer
);
1481 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1490 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1492 int save_ust_context_generic(struct config_writer
*writer
,
1493 struct ltt_ust_context
*ctx
)
1496 const char *context_type_string
;
1501 /* Save context as event_context_type_type */
1502 context_type_string
= get_ust_context_type_string(
1504 if (!context_type_string
) {
1505 ERR("Unsupported UST context type.");
1506 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1510 ret
= config_writer_write_element_string(writer
,
1511 config_element_type
, context_type_string
);
1513 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1522 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1524 int save_ust_context(struct config_writer
*writer
,
1525 struct cds_list_head
*ctx_list
)
1528 struct ltt_ust_context
*ctx
;
1533 ret
= config_writer_open_element(writer
, config_element_contexts
);
1535 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1539 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1540 ret
= config_writer_open_element(writer
,
1541 config_element_context
);
1543 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1547 switch (ctx
->ctx
.ctx
) {
1548 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1549 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1551 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1552 ret
= save_ust_context_app_ctx(writer
, ctx
);
1555 /* Save generic context. */
1556 ret
= save_ust_context_generic(writer
, ctx
);
1558 if (ret
!= LTTNG_OK
) {
1563 ret
= config_writer_close_element(writer
);
1565 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1571 ret
= config_writer_close_element(writer
);
1573 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1582 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1584 int save_kernel_channel(struct config_writer
*writer
,
1585 struct ltt_kernel_channel
*kchan
)
1592 ret
= config_writer_open_element(writer
, config_element_channel
);
1594 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1598 ret
= config_writer_write_element_string(writer
, config_element_name
,
1599 kchan
->channel
->name
);
1601 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1605 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1606 kchan
->channel
->enabled
);
1608 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1612 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1613 if (ret
!= LTTNG_OK
) {
1617 ret
= save_kernel_events(writer
, kchan
);
1618 if (ret
!= LTTNG_OK
) {
1622 ret
= save_kernel_contexts(writer
, kchan
);
1623 if (ret
!= LTTNG_OK
) {
1628 ret
= config_writer_close_element(writer
);
1630 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1639 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1641 int save_ust_channel(struct config_writer
*writer
,
1642 struct ltt_ust_channel
*ust_chan
,
1643 struct ltt_ust_session
*session
)
1651 ret
= config_writer_open_element(writer
, config_element_channel
);
1653 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1657 ret
= config_writer_write_element_string(writer
, config_element_name
,
1660 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1664 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1667 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1671 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1672 if (ret
!= LTTNG_OK
) {
1676 ret
= config_writer_write_element_unsigned_int(writer
,
1677 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1679 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1683 ret
= config_writer_write_element_unsigned_int(writer
,
1684 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1686 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1690 ret
= config_writer_write_element_unsigned_int(writer
,
1691 config_element_live_timer_interval
,
1692 session
->live_timer_interval
);
1694 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1698 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1699 ret
= save_ust_events(writer
, ust_chan
->events
);
1700 if (ret
!= LTTNG_OK
) {
1704 struct agent
*agent
= NULL
;
1706 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1708 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1709 ERR("Could not find agent associated to UST subdomain");
1714 * Channels associated with a UST sub-domain (such as JUL, Log4j
1715 * or Python) don't have any non-internal events. We retrieve
1716 * the "agent" events associated with this channel and serialize
1719 ret
= save_agent_events(writer
, agent
);
1720 if (ret
!= LTTNG_OK
) {
1725 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1726 if (ret
!= LTTNG_OK
) {
1731 ret
= config_writer_close_element(writer
);
1733 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1742 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1744 int save_kernel_session(struct config_writer
*writer
,
1745 struct ltt_session
*session
)
1748 struct ltt_kernel_channel
*kchan
;
1753 ret
= config_writer_write_element_string(writer
, config_element_type
,
1754 config_domain_type_kernel
);
1756 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1760 ret
= config_writer_write_element_string(writer
,
1761 config_element_buffer_type
, config_buffer_type_global
);
1763 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1767 ret
= config_writer_open_element(writer
,
1768 config_element_channels
);
1770 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1774 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1776 ret
= save_kernel_channel(writer
, kchan
);
1777 if (ret
!= LTTNG_OK
) {
1783 ret
= config_writer_close_element(writer
);
1785 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1795 const char *get_config_domain_str(enum lttng_domain_type domain
)
1797 const char *str_dom
;
1800 case LTTNG_DOMAIN_KERNEL
:
1801 str_dom
= config_domain_type_kernel
;
1803 case LTTNG_DOMAIN_UST
:
1804 str_dom
= config_domain_type_ust
;
1806 case LTTNG_DOMAIN_JUL
:
1807 str_dom
= config_domain_type_jul
;
1809 case LTTNG_DOMAIN_LOG4J
:
1810 str_dom
= config_domain_type_log4j
;
1812 case LTTNG_DOMAIN_PYTHON
:
1813 str_dom
= config_domain_type_python
;
1822 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1823 static int save_process_attr_tracker(struct config_writer
*writer
,
1824 struct ltt_session
*sess
,
1826 enum lttng_process_attr process_attr
)
1829 const char *element_id_tracker
, *element_target_id
, *element_id
;
1830 const struct process_attr_tracker
*tracker
;
1831 enum lttng_tracking_policy tracking_policy
;
1832 struct lttng_process_attr_values
*values
= NULL
;
1834 switch (process_attr
) {
1835 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1836 element_id_tracker
= config_element_process_attr_tracker_pid
;
1837 element_target_id
= config_element_process_attr_pid_value
;
1838 element_id
= config_element_process_attr_id
;
1840 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1841 element_id_tracker
= config_element_process_attr_tracker_vpid
;
1842 element_target_id
= config_element_process_attr_vpid_value
;
1843 element_id
= config_element_process_attr_id
;
1845 case LTTNG_PROCESS_ATTR_USER_ID
:
1846 element_id_tracker
= config_element_process_attr_tracker_uid
;
1847 element_target_id
= config_element_process_attr_uid_value
;
1848 element_id
= config_element_process_attr_id
;
1850 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1851 element_id_tracker
= config_element_process_attr_tracker_vuid
;
1852 element_target_id
= config_element_process_attr_vuid_value
;
1853 element_id
= config_element_process_attr_id
;
1855 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1856 element_id_tracker
= config_element_process_attr_tracker_gid
;
1857 element_target_id
= config_element_process_attr_gid_value
;
1858 element_id
= config_element_process_attr_id
;
1860 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1861 element_id_tracker
= config_element_process_attr_tracker_vgid
;
1862 element_target_id
= config_element_process_attr_vgid_value
;
1863 element_id
= config_element_process_attr_id
;
1866 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1871 case LTTNG_DOMAIN_KERNEL
:
1873 tracker
= kernel_get_process_attr_tracker(
1874 sess
->kernel_session
, process_attr
);
1878 case LTTNG_DOMAIN_UST
:
1880 tracker
= trace_ust_get_process_attr_tracker(
1881 sess
->ust_session
, process_attr
);
1885 case LTTNG_DOMAIN_JUL
:
1886 case LTTNG_DOMAIN_LOG4J
:
1887 case LTTNG_DOMAIN_PYTHON
:
1889 ret
= LTTNG_ERR_UNSUPPORTED_DOMAIN
;
1893 tracking_policy
= process_attr_tracker_get_tracking_policy(tracker
);
1894 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_ALL
) {
1895 /* Tracking all, nothing to output. */
1900 ret
= config_writer_open_element(writer
, element_id_tracker
);
1902 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1906 ret
= config_writer_open_element(
1907 writer
, config_element_process_attr_values
);
1909 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1913 if (tracking_policy
== LTTNG_TRACKING_POLICY_INCLUDE_SET
) {
1914 unsigned int i
, count
;
1915 enum process_attr_tracker_status status
=
1916 process_attr_tracker_get_inclusion_set(
1919 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1920 ret
= LTTNG_ERR_NOMEM
;
1924 count
= _lttng_process_attr_values_get_count(values
);
1926 for (i
= 0; i
< count
; i
++) {
1927 unsigned int integral_value
= UINT_MAX
;
1928 const char *name
= NULL
;
1929 const struct process_attr_value
*value
=
1930 lttng_process_attr_tracker_values_get_at_index(
1934 ret
= config_writer_open_element(
1935 writer
, element_target_id
);
1937 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1941 switch (value
->type
) {
1942 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1944 (unsigned int) value
->value
.pid
;
1946 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1948 (unsigned int) value
->value
.uid
;
1950 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1952 (unsigned int) value
->value
.gid
;
1954 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1955 name
= value
->value
.user_name
;
1958 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1959 name
= value
->value
.group_name
;
1967 ret
= config_writer_write_element_string(writer
,
1968 config_element_name
, name
);
1970 ret
= config_writer_write_element_unsigned_int(
1976 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1980 /* /$element_target_id */
1981 ret
= config_writer_close_element(writer
);
1983 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1990 ret
= config_writer_close_element(writer
);
1992 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1996 /* /$element_id_tracker */
1997 ret
= config_writer_close_element(writer
);
1999 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2005 lttng_process_attr_values_destroy(values
);
2009 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2010 static int save_process_attr_trackers(struct config_writer
*writer
,
2011 struct ltt_session
*sess
,
2017 case LTTNG_DOMAIN_KERNEL
:
2018 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2019 LTTNG_PROCESS_ATTR_PROCESS_ID
);
2020 if (ret
!= LTTNG_OK
) {
2023 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2024 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2025 if (ret
!= LTTNG_OK
) {
2028 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2029 LTTNG_PROCESS_ATTR_USER_ID
);
2030 if (ret
!= LTTNG_OK
) {
2033 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2034 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2035 if (ret
!= LTTNG_OK
) {
2038 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2039 LTTNG_PROCESS_ATTR_GROUP_ID
);
2040 if (ret
!= LTTNG_OK
) {
2043 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2044 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2045 if (ret
!= LTTNG_OK
) {
2049 case LTTNG_DOMAIN_UST
:
2050 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2051 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
2052 if (ret
!= LTTNG_OK
) {
2055 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2056 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
2057 if (ret
!= LTTNG_OK
) {
2060 ret
= save_process_attr_tracker(writer
, sess
, domain
,
2061 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
2062 if (ret
!= LTTNG_OK
) {
2067 ret
= LTTNG_ERR_INVALID
;
2075 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2077 int save_ust_domain(struct config_writer
*writer
,
2078 struct ltt_session
*session
, enum lttng_domain_type domain
)
2081 struct ltt_ust_channel
*ust_chan
;
2082 const char *buffer_type_string
;
2083 struct lttng_ht_node_str
*node
;
2084 struct lttng_ht_iter iter
;
2085 const char *config_domain_name
;
2090 ret
= config_writer_open_element(writer
,
2091 config_element_domain
);
2093 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2097 config_domain_name
= get_config_domain_str(domain
);
2098 if (!config_domain_name
) {
2099 ret
= LTTNG_ERR_INVALID
;
2103 ret
= config_writer_write_element_string(writer
,
2104 config_element_type
, config_domain_name
);
2106 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2110 buffer_type_string
= get_buffer_type_string(
2111 session
->ust_session
->buffer_type
);
2112 if (!buffer_type_string
) {
2113 ERR("Unsupported buffer type.");
2114 ret
= LTTNG_ERR_INVALID
;
2118 ret
= config_writer_write_element_string(writer
,
2119 config_element_buffer_type
, buffer_type_string
);
2121 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2125 ret
= config_writer_open_element(writer
, config_element_channels
);
2127 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2132 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
2133 &iter
.iter
, node
, node
) {
2134 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
2135 if (domain
== ust_chan
->domain
) {
2136 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
2137 if (ret
!= LTTNG_OK
) {
2146 ret
= config_writer_close_element(writer
);
2148 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2152 if (domain
== LTTNG_DOMAIN_UST
) {
2153 ret
= config_writer_open_element(
2154 writer
, config_element_process_attr_trackers
);
2156 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2160 ret
= save_process_attr_trackers(
2161 writer
, session
, LTTNG_DOMAIN_UST
);
2162 if (ret
!= LTTNG_OK
) {
2167 ret
= config_writer_close_element(writer
);
2169 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2175 ret
= config_writer_close_element(writer
);
2177 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2186 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2188 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
2195 if (!session
->kernel_session
&& !session
->ust_session
) {
2199 ret
= config_writer_open_element(writer
, config_element_domains
);
2201 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2205 if (session
->kernel_session
) {
2206 ret
= config_writer_open_element(writer
,
2207 config_element_domain
);
2209 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2213 ret
= save_kernel_session(writer
, session
);
2214 if (ret
!= LTTNG_OK
) {
2218 ret
= config_writer_open_element(
2219 writer
, config_element_process_attr_trackers
);
2221 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2225 ret
= save_process_attr_trackers(
2226 writer
, session
, LTTNG_DOMAIN_KERNEL
);
2227 if (ret
!= LTTNG_OK
) {
2232 ret
= config_writer_close_element(writer
);
2234 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2238 ret
= config_writer_close_element(writer
);
2240 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2245 if (session
->ust_session
) {
2246 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
2247 if (ret
!= LTTNG_OK
) {
2251 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
2252 if (ret
!= LTTNG_OK
) {
2256 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
2257 if (ret
!= LTTNG_OK
) {
2261 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
2262 if (ret
!= LTTNG_OK
) {
2268 ret
= config_writer_close_element(writer
);
2270 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2279 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2281 int save_consumer_output(struct config_writer
*writer
,
2282 struct consumer_output
*output
)
2289 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
2291 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2295 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
2298 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2302 ret
= config_writer_open_element(writer
, config_element_destination
);
2304 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2308 switch (output
->type
) {
2309 case CONSUMER_DST_LOCAL
:
2310 ret
= config_writer_write_element_string(writer
,
2311 config_element_path
, output
->dst
.session_root_path
);
2313 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2317 case CONSUMER_DST_NET
:
2321 uri
= zmalloc(PATH_MAX
);
2323 ret
= LTTNG_ERR_NOMEM
;
2327 ret
= config_writer_open_element(writer
, config_element_net_output
);
2329 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2330 goto end_net_output
;
2333 if (output
->dst
.net
.control_isset
&&
2334 output
->dst
.net
.data_isset
) {
2335 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
2337 ret
= LTTNG_ERR_INVALID
;
2338 goto end_net_output
;
2341 ret
= config_writer_write_element_string(writer
,
2342 config_element_control_uri
, uri
);
2344 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2345 goto end_net_output
;
2348 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
2350 ret
= LTTNG_ERR_INVALID
;
2351 goto end_net_output
;
2354 ret
= config_writer_write_element_string(writer
,
2355 config_element_data_uri
, uri
);
2357 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2358 goto end_net_output
;
2363 if (ret
!= LTTNG_OK
) {
2367 ret
= !output
->dst
.net
.control_isset
?
2368 LTTNG_ERR_URL_CTRL_MISS
:
2369 LTTNG_ERR_URL_DATA_MISS
;
2374 ret
= config_writer_close_element(writer
);
2376 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2382 ERR("Unsupported consumer output type.");
2383 ret
= LTTNG_ERR_INVALID
;
2388 ret
= config_writer_close_element(writer
);
2390 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2394 /* /consumer_output */
2395 ret
= config_writer_close_element(writer
);
2397 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2406 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2408 int save_snapshot_outputs(struct config_writer
*writer
,
2409 struct snapshot
*snapshot
)
2412 struct lttng_ht_iter iter
;
2413 struct snapshot_output
*output
;
2418 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
2420 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2425 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
2427 ret
= config_writer_open_element(writer
,
2428 config_element_output
);
2430 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2434 ret
= config_writer_write_element_string(writer
,
2435 config_element_name
, output
->name
);
2437 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2441 ret
= config_writer_write_element_unsigned_int(writer
,
2442 config_element_max_size
, output
->max_size
);
2444 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2448 ret
= save_consumer_output(writer
, output
->consumer
);
2449 if (ret
!= LTTNG_OK
) {
2454 ret
= config_writer_close_element(writer
);
2456 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2462 /* /snapshot_outputs */
2463 ret
= config_writer_close_element(writer
);
2465 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2477 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2479 int save_session_output(struct config_writer
*writer
,
2480 struct ltt_session
*session
)
2487 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
2488 (!session
->snapshot_mode
&& !session
->consumer
)) {
2489 /* Session is in no output mode */
2494 ret
= config_writer_open_element(writer
, config_element_output
);
2496 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2500 if (session
->snapshot_mode
) {
2501 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
2502 if (ret
!= LTTNG_OK
) {
2506 if (session
->consumer
) {
2507 ret
= save_consumer_output(writer
, session
->consumer
);
2508 if (ret
!= LTTNG_OK
) {
2515 ret
= config_writer_close_element(writer
);
2517 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2526 int save_session_rotation_schedule(struct config_writer
*writer
,
2527 enum lttng_rotation_schedule_type type
, uint64_t value
)
2530 const char *element_name
;
2531 const char *value_name
;
2534 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2535 element_name
= config_element_rotation_schedule_periodic
;
2536 value_name
= config_element_rotation_schedule_periodic_time_us
;
2538 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2539 element_name
= config_element_rotation_schedule_size_threshold
;
2540 value_name
= config_element_rotation_schedule_size_threshold_bytes
;
2547 ret
= config_writer_open_element(writer
, element_name
);
2552 ret
= config_writer_write_element_unsigned_int(writer
,
2558 /* Close schedule descriptor element. */
2559 ret
= config_writer_close_element(writer
);
2568 int save_session_rotation_schedules(struct config_writer
*writer
,
2569 struct ltt_session
*session
)
2573 ret
= config_writer_open_element(writer
,
2574 config_element_rotation_schedules
);
2578 if (session
->rotate_timer_period
) {
2579 ret
= save_session_rotation_schedule(writer
,
2580 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
,
2581 session
->rotate_timer_period
);
2583 goto close_schedules
;
2586 if (session
->rotate_size
) {
2587 ret
= save_session_rotation_schedule(writer
,
2588 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
,
2589 session
->rotate_size
);
2591 goto close_schedules
;
2596 /* Close rotation schedules element. */
2597 ret
= config_writer_close_element(writer
);
2606 * Save the given session.
2608 * Return LTTNG_OK on success else a LTTNG_ERR* code.
2611 int save_session(struct ltt_session
*session
,
2612 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
2615 char config_file_path
[LTTNG_PATH_MAX
];
2617 struct config_writer
*writer
= NULL
;
2618 size_t session_name_len
;
2619 const char *provided_path
;
2620 int file_open_flags
= O_CREAT
| O_WRONLY
| O_TRUNC
;
2626 session_name_len
= strlen(session
->name
);
2627 memset(config_file_path
, 0, sizeof(config_file_path
));
2629 if (!session_access_ok(session
,
2630 LTTNG_SOCK_GET_UID_CRED(creds
),
2631 LTTNG_SOCK_GET_GID_CRED(creds
)) || session
->destroyed
) {
2632 ret
= LTTNG_ERR_EPERM
;
2636 provided_path
= lttng_save_session_attr_get_output_url(attr
);
2637 if (provided_path
) {
2638 DBG3("Save session in provided path %s", provided_path
);
2639 len
= strlen(provided_path
);
2640 if (len
>= sizeof(config_file_path
)) {
2641 ret
= LTTNG_ERR_SET_URL
;
2644 strncpy(config_file_path
, provided_path
, sizeof(config_file_path
));
2647 char *home_dir
= utils_get_user_home_dir(
2648 LTTNG_SOCK_GET_UID_CRED(creds
));
2650 ret
= LTTNG_ERR_SET_URL
;
2654 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
2655 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
2658 PERROR("snprintf save session");
2659 ret
= LTTNG_ERR_SET_URL
;
2666 * Check the path fits in the config file path dst including the '/'
2667 * followed by trailing .lttng extension and the NULL terminated string.
2669 if ((len
+ session_name_len
+ 2 +
2670 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
2671 > sizeof(config_file_path
)) {
2672 ret
= LTTNG_ERR_SET_URL
;
2676 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
2677 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2679 ret
= LTTNG_ERR_SET_URL
;
2684 * At this point, we know that everything fits in the buffer. Validation
2685 * was done just above.
2687 config_file_path
[len
++] = '/';
2688 strncpy(config_file_path
+ len
, session
->name
, sizeof(config_file_path
) - len
);
2689 len
+= session_name_len
;
2690 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2691 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2692 config_file_path
[len
] = '\0';
2694 if (!attr
->overwrite
) {
2695 file_open_flags
|= O_EXCL
;
2698 fd
= run_as_open(config_file_path
, file_open_flags
,
2699 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
2700 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2702 PERROR("Could not create configuration file");
2705 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
2708 ret
= LTTNG_ERR_EPERM
;
2711 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2717 writer
= config_writer_create(fd
, 1);
2719 ret
= LTTNG_ERR_NOMEM
;
2723 ret
= config_writer_open_element(writer
, config_element_sessions
);
2725 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2729 ret
= config_writer_open_element(writer
, config_element_session
);
2731 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2735 ret
= config_writer_write_element_string(writer
, config_element_name
,
2738 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2742 if (session
->shm_path
[0] != '\0') {
2743 ret
= config_writer_write_element_string(writer
,
2744 config_element_shared_memory_path
,
2747 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2752 ret
= save_domains(writer
, session
);
2753 if (ret
!= LTTNG_OK
) {
2757 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2760 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2764 if (session
->snapshot_mode
|| session
->live_timer
||
2765 session
->rotate_timer_period
|| session
->rotate_size
) {
2766 ret
= config_writer_open_element(writer
, config_element_attributes
);
2768 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2772 if (session
->snapshot_mode
) {
2773 ret
= config_writer_write_element_bool(writer
,
2774 config_element_snapshot_mode
, 1);
2776 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2779 } else if (session
->live_timer
) {
2780 ret
= config_writer_write_element_unsigned_int(writer
,
2781 config_element_live_timer_interval
, session
->live_timer
);
2783 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2787 if (session
->rotate_timer_period
|| session
->rotate_size
) {
2788 ret
= save_session_rotation_schedules(writer
,
2791 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2797 ret
= config_writer_close_element(writer
);
2799 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2804 ret
= save_session_output(writer
, session
);
2805 if (ret
!= LTTNG_OK
) {
2810 ret
= config_writer_close_element(writer
);
2812 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2817 ret
= config_writer_close_element(writer
);
2819 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2825 if (writer
&& config_writer_destroy(writer
)) {
2826 /* Preserve the original error code */
2827 ret
= ret
!= LTTNG_OK
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2829 if (ret
!= LTTNG_OK
) {
2830 /* Delete file in case of error */
2831 if ((fd
>= 0) && unlink(config_file_path
)) {
2832 PERROR("Unlinking XML session configuration.");
2839 closeret
= close(fd
);
2841 PERROR("Closing XML session configuration");
2848 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2849 lttng_sock_cred
*creds
)
2852 const char *session_name
;
2853 struct ltt_session
*session
;
2855 session_lock_list();
2857 session_name
= lttng_save_session_attr_get_session_name(attr
);
2859 session
= session_find_by_name(session_name
);
2861 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2865 session_lock(session
);
2866 ret
= save_session(session
, attr
, creds
);
2867 session_unlock(session
);
2868 session_put(session
);
2869 if (ret
!= LTTNG_OK
) {
2873 struct ltt_session_list
*list
= session_get_list();
2875 cds_list_for_each_entry(session
, &list
->head
, list
) {
2876 if (!session_get(session
)) {
2879 session_lock(session
);
2880 ret
= save_session(session
, attr
, creds
);
2881 session_unlock(session
);
2882 session_put(session
);
2883 /* Don't abort if we don't have the required permissions. */
2884 if (ret
!= LTTNG_OK
&& ret
!= LTTNG_ERR_EPERM
) {
2892 session_unlock_list();