2 * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <urcu/uatomic.h>
25 #include <common/defaults.h>
26 #include <common/error.h>
27 #include <common/config/session-config.h>
28 #include <common/utils.h>
29 #include <common/runas.h>
30 #include <lttng/save-internal.h>
35 #include "lttng-syscall.h"
36 #include "trace-ust.h"
39 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
41 int save_kernel_channel_attributes(struct config_writer
*writer
,
42 struct lttng_channel_attr
*attr
)
46 ret
= config_writer_write_element_string(writer
,
47 config_element_overwrite_mode
,
48 attr
->overwrite
? config_overwrite_mode_overwrite
:
49 config_overwrite_mode_discard
);
51 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
55 ret
= config_writer_write_element_unsigned_int(writer
,
56 config_element_subbuf_size
, attr
->subbuf_size
);
58 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
62 ret
= config_writer_write_element_unsigned_int(writer
,
63 config_element_num_subbuf
,
66 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
70 ret
= config_writer_write_element_unsigned_int(writer
,
71 config_element_switch_timer_interval
,
72 attr
->switch_timer_interval
);
74 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
78 ret
= config_writer_write_element_unsigned_int(writer
,
79 config_element_read_timer_interval
,
80 attr
->read_timer_interval
);
82 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
86 ret
= config_writer_write_element_string(writer
,
87 config_element_output_type
,
88 attr
->output
== LTTNG_EVENT_SPLICE
?
89 config_output_type_splice
: config_output_type_mmap
);
91 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
95 ret
= config_writer_write_element_unsigned_int(writer
,
96 config_element_tracefile_size
, attr
->tracefile_size
);
98 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
102 ret
= config_writer_write_element_unsigned_int(writer
,
103 config_element_tracefile_count
,
104 attr
->tracefile_count
);
106 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
110 ret
= config_writer_write_element_unsigned_int(writer
,
111 config_element_live_timer_interval
,
112 attr
->live_timer_interval
);
114 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
118 if (attr
->extended
.ptr
) {
119 struct lttng_channel_extended
*ext
= NULL
;
121 ext
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
122 ret
= config_writer_write_element_unsigned_int(writer
,
123 config_element_monitor_timer_interval
,
124 ext
->monitor_timer_interval
);
126 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
130 ret
= config_writer_write_element_signed_int(writer
,
131 config_element_blocking_timeout
,
132 ext
->blocking_timeout
);
134 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
144 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
146 int save_ust_channel_attributes(struct config_writer
*writer
,
147 struct lttng_ust_channel_attr
*attr
)
150 struct ltt_ust_channel
*channel
= NULL
;
152 ret
= config_writer_write_element_string(writer
,
153 config_element_overwrite_mode
,
154 attr
->overwrite
? config_overwrite_mode_overwrite
:
155 config_overwrite_mode_discard
);
157 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
161 ret
= config_writer_write_element_unsigned_int(writer
,
162 config_element_subbuf_size
, attr
->subbuf_size
);
164 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
168 ret
= config_writer_write_element_unsigned_int(writer
,
169 config_element_num_subbuf
,
172 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
176 ret
= config_writer_write_element_unsigned_int(writer
,
177 config_element_switch_timer_interval
,
178 attr
->switch_timer_interval
);
180 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
184 ret
= config_writer_write_element_unsigned_int(writer
,
185 config_element_read_timer_interval
,
186 attr
->read_timer_interval
);
188 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
192 ret
= config_writer_write_element_string(writer
,
193 config_element_output_type
,
194 attr
->output
== LTTNG_UST_MMAP
?
195 config_output_type_mmap
: config_output_type_splice
);
197 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
201 ret
= config_writer_write_element_signed_int(writer
,
202 config_element_blocking_timeout
,
203 attr
->u
.s
.blocking_timeout
);
205 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
210 * Fetch the monitor timer which is located in the parent of
211 * lttng_ust_channel_attr
213 channel
= caa_container_of(attr
, struct ltt_ust_channel
, attr
);
214 ret
= config_writer_write_element_unsigned_int(writer
,
215 config_element_monitor_timer_interval
,
216 channel
->monitor_timer_interval
);
218 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
228 const char *get_kernel_instrumentation_string(
229 enum lttng_kernel_instrumentation instrumentation
)
231 const char *instrumentation_string
;
233 switch (instrumentation
) {
234 case LTTNG_KERNEL_ALL
:
235 instrumentation_string
= config_event_type_all
;
237 case LTTNG_KERNEL_TRACEPOINT
:
238 instrumentation_string
= config_event_type_tracepoint
;
240 case LTTNG_KERNEL_KPROBE
:
241 instrumentation_string
= config_event_type_probe
;
243 case LTTNG_KERNEL_UPROBE
:
244 instrumentation_string
= config_event_type_userspace_probe
;
246 case LTTNG_KERNEL_FUNCTION
:
247 instrumentation_string
= config_event_type_function_entry
;
249 case LTTNG_KERNEL_KRETPROBE
:
250 instrumentation_string
= config_event_type_function
;
252 case LTTNG_KERNEL_NOOP
:
253 instrumentation_string
= config_event_type_noop
;
255 case LTTNG_KERNEL_SYSCALL
:
256 instrumentation_string
= config_event_type_syscall
;
259 instrumentation_string
= NULL
;
262 return instrumentation_string
;
266 const char *get_kernel_context_type_string(
267 enum lttng_kernel_context_type context_type
)
269 const char *context_type_string
;
271 switch (context_type
) {
272 case LTTNG_KERNEL_CONTEXT_PID
:
273 context_type_string
= config_event_context_pid
;
275 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
276 context_type_string
= config_event_context_procname
;
278 case LTTNG_KERNEL_CONTEXT_PRIO
:
279 context_type_string
= config_event_context_prio
;
281 case LTTNG_KERNEL_CONTEXT_NICE
:
282 context_type_string
= config_event_context_nice
;
284 case LTTNG_KERNEL_CONTEXT_VPID
:
285 context_type_string
= config_event_context_vpid
;
287 case LTTNG_KERNEL_CONTEXT_TID
:
288 context_type_string
= config_event_context_tid
;
290 case LTTNG_KERNEL_CONTEXT_VTID
:
291 context_type_string
= config_event_context_vtid
;
293 case LTTNG_KERNEL_CONTEXT_PPID
:
294 context_type_string
= config_event_context_ppid
;
296 case LTTNG_KERNEL_CONTEXT_VPPID
:
297 context_type_string
= config_event_context_vppid
;
299 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
300 context_type_string
= config_event_context_hostname
;
302 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
303 context_type_string
= config_event_context_interruptible
;
305 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
306 context_type_string
= config_event_context_preemptible
;
308 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
309 context_type_string
= config_event_context_need_reschedule
;
311 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
312 context_type_string
= config_event_context_migratable
;
314 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
315 context_type_string
= config_event_context_callstack_user
;
317 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
318 context_type_string
= config_event_context_callstack_kernel
;
320 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
321 context_type_string
= config_event_context_cgroup_ns
;
323 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
324 context_type_string
= config_event_context_ipc_ns
;
326 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
327 context_type_string
= config_event_context_mnt_ns
;
329 case LTTNG_KERNEL_CONTEXT_NET_NS
:
330 context_type_string
= config_event_context_net_ns
;
332 case LTTNG_KERNEL_CONTEXT_PID_NS
:
333 context_type_string
= config_event_context_pid_ns
;
335 case LTTNG_KERNEL_CONTEXT_USER_NS
:
336 context_type_string
= config_event_context_user_ns
;
338 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
339 context_type_string
= config_event_context_uts_ns
;
341 case LTTNG_KERNEL_CONTEXT_UID
:
342 context_type_string
= config_event_context_uid
;
344 case LTTNG_KERNEL_CONTEXT_EUID
:
345 context_type_string
= config_event_context_euid
;
347 case LTTNG_KERNEL_CONTEXT_SUID
:
348 context_type_string
= config_event_context_suid
;
350 case LTTNG_KERNEL_CONTEXT_GID
:
351 context_type_string
= config_event_context_gid
;
353 case LTTNG_KERNEL_CONTEXT_EGID
:
354 context_type_string
= config_event_context_egid
;
356 case LTTNG_KERNEL_CONTEXT_SGID
:
357 context_type_string
= config_event_context_sgid
;
359 case LTTNG_KERNEL_CONTEXT_VUID
:
360 context_type_string
= config_event_context_vuid
;
362 case LTTNG_KERNEL_CONTEXT_VEUID
:
363 context_type_string
= config_event_context_veuid
;
365 case LTTNG_KERNEL_CONTEXT_VSUID
:
366 context_type_string
= config_event_context_vsuid
;
368 case LTTNG_KERNEL_CONTEXT_VGID
:
369 context_type_string
= config_event_context_vgid
;
371 case LTTNG_KERNEL_CONTEXT_VEGID
:
372 context_type_string
= config_event_context_vegid
;
374 case LTTNG_KERNEL_CONTEXT_VSGID
:
375 context_type_string
= config_event_context_vsgid
;
378 context_type_string
= NULL
;
381 return context_type_string
;
385 const char *get_ust_context_type_string(
386 enum lttng_ust_context_type context_type
)
388 const char *context_type_string
;
390 switch (context_type
) {
391 case LTTNG_UST_CONTEXT_PROCNAME
:
392 context_type_string
= config_event_context_procname
;
394 case LTTNG_UST_CONTEXT_VPID
:
395 context_type_string
= config_event_context_vpid
;
397 case LTTNG_UST_CONTEXT_VTID
:
398 context_type_string
= config_event_context_vtid
;
400 case LTTNG_UST_CONTEXT_IP
:
401 context_type_string
= config_event_context_ip
;
403 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
404 context_type_string
= config_event_context_pthread_id
;
406 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
407 context_type_string
= config_event_context_app
;
409 case LTTNG_UST_CONTEXT_CGROUP_NS
:
410 context_type_string
= config_event_context_cgroup_ns
;
412 case LTTNG_UST_CONTEXT_IPC_NS
:
413 context_type_string
= config_event_context_ipc_ns
;
415 case LTTNG_UST_CONTEXT_MNT_NS
:
416 context_type_string
= config_event_context_mnt_ns
;
418 case LTTNG_UST_CONTEXT_NET_NS
:
419 context_type_string
= config_event_context_net_ns
;
421 case LTTNG_UST_CONTEXT_PID_NS
:
422 context_type_string
= config_event_context_pid_ns
;
424 case LTTNG_UST_CONTEXT_USER_NS
:
425 context_type_string
= config_event_context_user_ns
;
427 case LTTNG_UST_CONTEXT_UTS_NS
:
428 context_type_string
= config_event_context_uts_ns
;
430 case LTTNG_UST_CONTEXT_VUID
:
431 context_type_string
= config_event_context_vuid
;
433 case LTTNG_UST_CONTEXT_VEUID
:
434 context_type_string
= config_event_context_veuid
;
436 case LTTNG_UST_CONTEXT_VSUID
:
437 context_type_string
= config_event_context_vsuid
;
439 case LTTNG_UST_CONTEXT_VGID
:
440 context_type_string
= config_event_context_vgid
;
442 case LTTNG_UST_CONTEXT_VEGID
:
443 context_type_string
= config_event_context_vegid
;
445 case LTTNG_UST_CONTEXT_VSGID
:
446 context_type_string
= config_event_context_vsgid
;
448 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
450 * Error, should not be stored in the XML, perf contexts
451 * are stored as a node of type event_perf_context_type.
454 context_type_string
= NULL
;
458 return context_type_string
;
462 const char *get_buffer_type_string(
463 enum lttng_buffer_type buffer_type
)
465 const char *buffer_type_string
;
467 switch (buffer_type
) {
468 case LTTNG_BUFFER_PER_PID
:
469 buffer_type_string
= config_buffer_type_per_pid
;
471 case LTTNG_BUFFER_PER_UID
:
472 buffer_type_string
= config_buffer_type_per_uid
;
474 case LTTNG_BUFFER_GLOBAL
:
475 buffer_type_string
= config_buffer_type_global
;
478 buffer_type_string
= NULL
;
481 return buffer_type_string
;
485 const char *get_loglevel_type_string(
486 enum lttng_ust_loglevel_type loglevel_type
)
488 const char *loglevel_type_string
;
490 switch (loglevel_type
) {
491 case LTTNG_UST_LOGLEVEL_ALL
:
492 loglevel_type_string
= config_loglevel_type_all
;
494 case LTTNG_UST_LOGLEVEL_RANGE
:
495 loglevel_type_string
= config_loglevel_type_range
;
497 case LTTNG_UST_LOGLEVEL_SINGLE
:
498 loglevel_type_string
= config_loglevel_type_single
;
501 loglevel_type_string
= NULL
;
504 return loglevel_type_string
;
507 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
509 int save_kernel_function_event(struct config_writer
*writer
,
510 struct ltt_kernel_event
*event
)
514 ret
= config_writer_open_element(writer
, config_element_function_attributes
);
516 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
520 ret
= config_writer_write_element_string(writer
, config_element_name
,
521 event
->event
->u
.ftrace
.symbol_name
);
523 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
527 /* /function attributes */
528 ret
= config_writer_close_element(writer
);
530 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
538 int save_kernel_kprobe_event(struct config_writer
*writer
,
539 struct ltt_kernel_event
*event
)
542 const char *symbol_name
;
546 switch (event
->event
->instrumentation
) {
547 case LTTNG_KERNEL_KPROBE
:
549 * Comments in lttng-kernel.h mention that
550 * either addr or symbol_name are set, not both.
552 addr
= event
->event
->u
.kprobe
.addr
;
553 offset
= event
->event
->u
.kprobe
.offset
;
554 symbol_name
= addr
? NULL
: event
->event
->u
.kprobe
.symbol_name
;
556 case LTTNG_KERNEL_KRETPROBE
:
557 addr
= event
->event
->u
.kretprobe
.addr
;
558 offset
= event
->event
->u
.kretprobe
.offset
;
559 symbol_name
= addr
? NULL
: event
->event
->u
.kretprobe
.symbol_name
;
563 ERR("Unsupported kernel instrumentation type.");
564 ret
= LTTNG_ERR_INVALID
;
568 ret
= config_writer_open_element(writer
, config_element_probe_attributes
);
570 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
575 ret
= config_writer_write_element_unsigned_int( writer
,
576 config_element_address
, addr
);
578 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
581 } else if (symbol_name
) {
582 ret
= config_writer_write_element_string(writer
,
583 config_element_symbol_name
, symbol_name
);
585 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
588 /* If the offset is non-zero, write it.*/
590 ret
= config_writer_write_element_unsigned_int(writer
,
591 config_element_offset
, offset
);
593 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
599 * This really should not happen as we are either setting the
600 * address or the symbol above.
602 ERR("Invalid probe/function description.");
603 ret
= LTTNG_ERR_INVALID
;
608 ret
= config_writer_close_element(writer
);
610 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
618 * Save the userspace probe tracepoint event associated with the event to the
622 int save_kernel_userspace_probe_tracepoint_event(struct config_writer
*writer
,
623 struct ltt_kernel_event
*event
)
626 const char *probe_name
, *provider_name
, *binary_path
;
627 const struct lttng_userspace_probe_location
*userspace_probe_location
;
628 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
629 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
631 /* Get userspace probe location from the event. */
632 userspace_probe_location
= event
->userspace_probe_location
;
633 if (!userspace_probe_location
) {
634 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
638 /* Get lookup method and lookup method type. */
639 lookup_method
= lttng_userspace_probe_location_get_lookup_method(userspace_probe_location
);
640 if (!lookup_method
) {
641 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
645 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
647 /* Get the binary path, probe name and provider name. */
649 lttng_userspace_probe_location_tracepoint_get_binary_path(
650 userspace_probe_location
);
652 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
657 lttng_userspace_probe_location_tracepoint_get_probe_name(
658 userspace_probe_location
);
660 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
665 lttng_userspace_probe_location_tracepoint_get_provider_name(
666 userspace_probe_location
);
667 if (!provider_name
) {
668 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
672 /* Open a userspace probe tracepoint attribute. */
673 ret
= config_writer_open_element(writer
, config_element_userspace_probe_tracepoint_attributes
);
675 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
679 switch (lookup_type
) {
680 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
681 ret
= config_writer_write_element_string(writer
,
682 config_element_userspace_probe_lookup
,
683 config_element_userspace_probe_lookup_tracepoint_sdt
);
685 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
690 ERR("Unsupported kernel userspace probe tracepoint lookup method.");
691 ret
= LTTNG_ERR_INVALID
;
695 /* Write the binary path, provider name and the probe name. */
696 ret
= config_writer_write_element_string(writer
,
697 config_element_userspace_probe_location_binary_path
,
700 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
704 ret
= config_writer_write_element_string(writer
,
705 config_element_userspace_probe_tracepoint_location_provider_name
,
708 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
712 ret
= config_writer_write_element_string(writer
,
713 config_element_userspace_probe_tracepoint_location_probe_name
,
716 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
720 /* Close the userspace probe tracepoint attribute. */
721 ret
= config_writer_close_element(writer
);
723 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
732 * Save the userspace probe function event associated with the event to the
736 int save_kernel_userspace_probe_function_event(struct config_writer
*writer
,
737 struct ltt_kernel_event
*event
)
740 const char *function_name
, *binary_path
;
741 const struct lttng_userspace_probe_location
*userspace_probe_location
;
742 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
743 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
745 /* Get userspace probe location from the event. */
746 userspace_probe_location
= event
->userspace_probe_location
;
747 if (!userspace_probe_location
) {
748 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
752 /* Get lookup method and lookup method type. */
753 lookup_method
= lttng_userspace_probe_location_get_lookup_method(
754 userspace_probe_location
);
755 if (!lookup_method
) {
756 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
760 /* Get the binary path and the function name. */
762 lttng_userspace_probe_location_function_get_binary_path(
763 userspace_probe_location
);
765 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
770 lttng_userspace_probe_location_function_get_function_name(
771 userspace_probe_location
);
772 if (!function_name
) {
773 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
777 /* Open a userspace probe function attribute. */
778 ret
= config_writer_open_element(writer
,
779 config_element_userspace_probe_function_attributes
);
781 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
785 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
786 switch (lookup_type
) {
787 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
788 ret
= config_writer_write_element_string(writer
,
789 config_element_userspace_probe_lookup
,
790 config_element_userspace_probe_lookup_function_elf
);
792 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
796 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
797 ret
= config_writer_write_element_string(writer
,
798 config_element_userspace_probe_lookup
,
799 config_element_userspace_probe_lookup_function_default
);
801 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
806 ERR("Unsupported kernel userspace probe function lookup method.");
807 ret
= LTTNG_ERR_INVALID
;
811 /* Write the binary path and the function name. */
812 ret
= config_writer_write_element_string(writer
,
813 config_element_userspace_probe_location_binary_path
,
816 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
820 ret
= config_writer_write_element_string(writer
,
821 config_element_userspace_probe_function_location_function_name
,
824 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
828 /* Close the userspace probe function attribute. */
829 ret
= config_writer_close_element(writer
);
831 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
840 int save_kernel_userspace_probe_event(struct config_writer
*writer
,
841 struct ltt_kernel_event
*event
)
844 struct lttng_userspace_probe_location
*userspace_probe_location
;
846 /* Get userspace probe location from the event. */
847 userspace_probe_location
= event
->userspace_probe_location
;
848 if (!userspace_probe_location
) {
849 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
853 switch(lttng_userspace_probe_location_get_type(userspace_probe_location
)) {
854 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
856 ret
= save_kernel_userspace_probe_function_event(writer
, event
);
858 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
863 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
865 ret
= save_kernel_userspace_probe_tracepoint_event(writer
, event
);
867 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
872 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
874 ERR("Unsupported kernel userspace probe location type.");
875 ret
= LTTNG_ERR_INVALID
;
884 int save_kernel_event(struct config_writer
*writer
,
885 struct ltt_kernel_event
*event
)
888 const char *instrumentation_type
;
890 ret
= config_writer_open_element(writer
, config_element_event
);
892 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
896 if (event
->event
->name
[0]) {
897 ret
= config_writer_write_element_string(writer
,
898 config_element_name
, event
->event
->name
);
900 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
905 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
908 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
912 instrumentation_type
= get_kernel_instrumentation_string(
913 event
->event
->instrumentation
);
914 if (!instrumentation_type
) {
915 ret
= LTTNG_ERR_INVALID
;
919 ret
= config_writer_write_element_string(writer
, config_element_type
,
920 instrumentation_type
);
922 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
926 if (event
->filter_expression
) {
927 ret
= config_writer_write_element_string(writer
,
928 config_element_filter
,
929 event
->filter_expression
);
931 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
936 if (event
->event
->instrumentation
== LTTNG_KERNEL_FUNCTION
||
937 event
->event
->instrumentation
== LTTNG_KERNEL_KPROBE
||
938 event
->event
->instrumentation
== LTTNG_KERNEL_UPROBE
||
939 event
->event
->instrumentation
== LTTNG_KERNEL_KRETPROBE
) {
941 ret
= config_writer_open_element(writer
,
942 config_element_attributes
);
944 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
948 switch (event
->event
->instrumentation
) {
949 case LTTNG_KERNEL_SYSCALL
:
950 case LTTNG_KERNEL_FUNCTION
:
951 ret
= save_kernel_function_event(writer
, event
);
956 case LTTNG_KERNEL_KPROBE
:
957 case LTTNG_KERNEL_KRETPROBE
:
958 ret
= save_kernel_kprobe_event(writer
, event
);
963 case LTTNG_KERNEL_UPROBE
:
964 ret
= save_kernel_userspace_probe_event(writer
, event
);
970 ERR("Unsupported kernel instrumentation type.");
971 ret
= LTTNG_ERR_INVALID
;
976 ret
= config_writer_close_element(writer
);
978 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
984 ret
= config_writer_close_element(writer
);
986 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
995 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
997 int save_kernel_events(struct config_writer
*writer
,
998 struct ltt_kernel_channel
*kchan
)
1001 struct ltt_kernel_event
*event
;
1003 ret
= config_writer_open_element(writer
, config_element_events
);
1005 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1009 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
1010 ret
= save_kernel_event(writer
, event
);
1011 if (ret
!= LTTNG_OK
) {
1017 ret
= config_writer_close_element(writer
);
1019 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1028 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1030 int save_ust_event(struct config_writer
*writer
,
1031 struct ltt_ust_event
*event
)
1034 const char *loglevel_type_string
;
1036 ret
= config_writer_open_element(writer
, config_element_event
);
1038 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1042 if (event
->attr
.name
[0]) {
1043 ret
= config_writer_write_element_string(writer
,
1044 config_element_name
, event
->attr
.name
);
1046 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1051 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1054 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1058 if (event
->attr
.instrumentation
!= LTTNG_UST_TRACEPOINT
) {
1059 ERR("Unsupported UST instrumentation type.");
1060 ret
= LTTNG_ERR_INVALID
;
1063 ret
= config_writer_write_element_string(writer
, config_element_type
,
1064 config_event_type_tracepoint
);
1066 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1070 loglevel_type_string
= get_loglevel_type_string(
1071 event
->attr
.loglevel_type
);
1072 if (!loglevel_type_string
) {
1073 ERR("Unsupported UST loglevel type.");
1074 ret
= LTTNG_ERR_INVALID
;
1078 ret
= config_writer_write_element_string(writer
,
1079 config_element_loglevel_type
, loglevel_type_string
);
1081 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1085 /* The log level is irrelevant if no "filtering" is enabled */
1086 if (event
->attr
.loglevel_type
!= LTTNG_UST_LOGLEVEL_ALL
) {
1087 ret
= config_writer_write_element_signed_int(writer
,
1088 config_element_loglevel
, event
->attr
.loglevel
);
1090 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1095 if (event
->filter_expression
) {
1096 ret
= config_writer_write_element_string(writer
,
1097 config_element_filter
, event
->filter_expression
);
1099 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1104 if (event
->exclusion
&& event
->exclusion
->count
) {
1107 ret
= config_writer_open_element(writer
,
1108 config_element_exclusions
);
1110 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1114 for (i
= 0; i
< event
->exclusion
->count
; i
++) {
1115 ret
= config_writer_write_element_string(writer
,
1116 config_element_exclusion
,
1117 LTTNG_EVENT_EXCLUSION_NAME_AT(
1118 event
->exclusion
, i
));
1120 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1126 ret
= config_writer_close_element(writer
);
1128 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1134 ret
= config_writer_close_element(writer
);
1136 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1145 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1147 int save_ust_events(struct config_writer
*writer
,
1148 struct lttng_ht
*events
)
1151 struct ltt_ust_event
*event
;
1152 struct lttng_ht_node_str
*node
;
1153 struct lttng_ht_iter iter
;
1155 ret
= config_writer_open_element(writer
, config_element_events
);
1157 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1162 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
1163 event
= caa_container_of(node
, struct ltt_ust_event
, node
);
1165 if (event
->internal
) {
1166 /* Internal events must not be exposed to clients */
1169 ret
= save_ust_event(writer
, event
);
1170 if (ret
!= LTTNG_OK
) {
1178 ret
= config_writer_close_element(writer
);
1180 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1189 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1191 int init_ust_event_from_agent_event(struct ltt_ust_event
*ust_event
,
1192 struct agent_event
*agent_event
)
1195 enum lttng_ust_loglevel_type ust_loglevel_type
;
1197 ust_event
->enabled
= agent_event
->enabled
;
1198 ust_event
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
1199 if (lttng_strncpy(ust_event
->attr
.name
, agent_event
->name
,
1200 LTTNG_SYMBOL_NAME_LEN
)) {
1201 ret
= LTTNG_ERR_INVALID
;
1204 switch (agent_event
->loglevel_type
) {
1205 case LTTNG_EVENT_LOGLEVEL_ALL
:
1206 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
1208 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
1209 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
1211 case LTTNG_EVENT_LOGLEVEL_RANGE
:
1212 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
1215 ERR("Invalid agent_event loglevel_type.");
1216 ret
= LTTNG_ERR_INVALID
;
1220 ust_event
->attr
.loglevel_type
= ust_loglevel_type
;
1221 ust_event
->attr
.loglevel
= agent_event
->loglevel_value
;
1222 ust_event
->filter_expression
= agent_event
->filter_expression
;
1223 ust_event
->exclusion
= agent_event
->exclusion
;
1230 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1232 int save_agent_events(struct config_writer
*writer
,
1233 struct agent
*agent
)
1236 struct lttng_ht_iter iter
;
1237 struct lttng_ht_node_str
*node
;
1239 ret
= config_writer_open_element(writer
, config_element_events
);
1241 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1246 cds_lfht_for_each_entry(agent
->events
->ht
, &iter
.iter
, node
, node
) {
1248 struct agent_event
*agent_event
;
1249 struct ltt_ust_event fake_event
;
1251 memset(&fake_event
, 0, sizeof(fake_event
));
1252 agent_event
= caa_container_of(node
, struct agent_event
, node
);
1255 * Initialize a fake ust event to reuse the same serialization
1256 * function since UST and agent events contain the same info
1257 * (and one could wonder why they don't reuse the same
1260 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
1261 if (ret
!= LTTNG_OK
) {
1265 ret
= save_ust_event(writer
, &fake_event
);
1266 if (ret
!= LTTNG_OK
) {
1274 ret
= config_writer_close_element(writer
);
1276 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1285 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1287 int save_kernel_context(struct config_writer
*writer
,
1288 struct lttng_kernel_context
*ctx
)
1296 ret
= config_writer_open_element(writer
, config_element_context
);
1298 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1302 if (ctx
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER
) {
1303 ret
= config_writer_open_element(writer
,
1304 config_element_context_perf
);
1306 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1310 ret
= config_writer_write_element_unsigned_int(writer
,
1311 config_element_type
, ctx
->u
.perf_counter
.type
);
1313 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1317 ret
= config_writer_write_element_unsigned_int(writer
,
1318 config_element_config
, ctx
->u
.perf_counter
.config
);
1320 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1324 ret
= config_writer_write_element_string(writer
,
1325 config_element_name
, ctx
->u
.perf_counter
.name
);
1327 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1332 ret
= config_writer_close_element(writer
);
1334 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1338 const char *context_type_string
=
1339 get_kernel_context_type_string(ctx
->ctx
);
1341 if (!context_type_string
) {
1342 ERR("Unsupported kernel context type.");
1343 ret
= LTTNG_ERR_INVALID
;
1347 ret
= config_writer_write_element_string(writer
,
1348 config_element_type
, context_type_string
);
1350 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1356 ret
= config_writer_close_element(writer
);
1358 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1367 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1369 int save_kernel_contexts(struct config_writer
*writer
,
1370 struct ltt_kernel_channel
*kchan
)
1373 struct ltt_kernel_context
*ctx
;
1375 if (cds_list_empty(&kchan
->ctx_list
)) {
1380 ret
= config_writer_open_element(writer
, config_element_contexts
);
1382 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1386 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
1387 ret
= save_kernel_context(writer
, &ctx
->ctx
);
1388 if (ret
!= LTTNG_OK
) {
1394 ret
= config_writer_close_element(writer
);
1396 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1405 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1407 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
1408 struct ltt_ust_context
*ctx
)
1415 /* Perf contexts are saved as event_perf_context_type */
1416 ret
= config_writer_open_element(writer
, config_element_context_perf
);
1418 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1422 ret
= config_writer_write_element_unsigned_int(writer
,
1423 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
1425 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1429 ret
= config_writer_write_element_unsigned_int(writer
,
1430 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
1432 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1436 ret
= config_writer_write_element_string(writer
, config_element_name
,
1437 ctx
->ctx
.u
.perf_counter
.name
);
1439 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1444 ret
= config_writer_close_element(writer
);
1446 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1455 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1457 int save_ust_context_app_ctx(struct config_writer
*writer
,
1458 struct ltt_ust_context
*ctx
)
1465 /* Application contexts are saved as application_context_type */
1466 ret
= config_writer_open_element(writer
, config_element_context_app
);
1468 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1472 ret
= config_writer_write_element_string(writer
,
1473 config_element_context_app_provider_name
,
1474 ctx
->ctx
.u
.app_ctx
.provider_name
);
1476 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1480 ret
= config_writer_write_element_string(writer
,
1481 config_element_context_app_ctx_name
,
1482 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1484 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1489 ret
= config_writer_close_element(writer
);
1491 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1500 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1502 int save_ust_context_generic(struct config_writer
*writer
,
1503 struct ltt_ust_context
*ctx
)
1506 const char *context_type_string
;
1511 /* Save context as event_context_type_type */
1512 context_type_string
= get_ust_context_type_string(
1514 if (!context_type_string
) {
1515 ERR("Unsupported UST context type.");
1516 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1520 ret
= config_writer_write_element_string(writer
,
1521 config_element_type
, context_type_string
);
1523 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1532 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1534 int save_ust_context(struct config_writer
*writer
,
1535 struct cds_list_head
*ctx_list
)
1538 struct ltt_ust_context
*ctx
;
1543 ret
= config_writer_open_element(writer
, config_element_contexts
);
1545 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1549 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1550 ret
= config_writer_open_element(writer
,
1551 config_element_context
);
1553 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1557 switch (ctx
->ctx
.ctx
) {
1558 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1559 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1561 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1562 ret
= save_ust_context_app_ctx(writer
, ctx
);
1565 /* Save generic context. */
1566 ret
= save_ust_context_generic(writer
, ctx
);
1568 if (ret
!= LTTNG_OK
) {
1573 ret
= config_writer_close_element(writer
);
1575 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1581 ret
= config_writer_close_element(writer
);
1583 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1592 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1594 int save_kernel_channel(struct config_writer
*writer
,
1595 struct ltt_kernel_channel
*kchan
)
1602 ret
= config_writer_open_element(writer
, config_element_channel
);
1604 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1608 ret
= config_writer_write_element_string(writer
, config_element_name
,
1609 kchan
->channel
->name
);
1611 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1615 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1616 kchan
->channel
->enabled
);
1618 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1622 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1623 if (ret
!= LTTNG_OK
) {
1627 ret
= save_kernel_events(writer
, kchan
);
1628 if (ret
!= LTTNG_OK
) {
1632 ret
= save_kernel_contexts(writer
, kchan
);
1633 if (ret
!= LTTNG_OK
) {
1638 ret
= config_writer_close_element(writer
);
1640 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1649 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1651 int save_ust_channel(struct config_writer
*writer
,
1652 struct ltt_ust_channel
*ust_chan
,
1653 struct ltt_ust_session
*session
)
1661 ret
= config_writer_open_element(writer
, config_element_channel
);
1663 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1667 ret
= config_writer_write_element_string(writer
, config_element_name
,
1670 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1674 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1677 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1681 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1682 if (ret
!= LTTNG_OK
) {
1686 ret
= config_writer_write_element_unsigned_int(writer
,
1687 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1689 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1693 ret
= config_writer_write_element_unsigned_int(writer
,
1694 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1696 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1700 ret
= config_writer_write_element_unsigned_int(writer
,
1701 config_element_live_timer_interval
,
1702 session
->live_timer_interval
);
1704 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1708 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1709 ret
= save_ust_events(writer
, ust_chan
->events
);
1710 if (ret
!= LTTNG_OK
) {
1714 struct agent
*agent
= NULL
;
1716 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1718 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1719 ERR("Could not find agent associated to UST subdomain");
1724 * Channels associated with a UST sub-domain (such as JUL, Log4j
1725 * or Python) don't have any non-internal events. We retrieve
1726 * the "agent" events associated with this channel and serialize
1729 ret
= save_agent_events(writer
, agent
);
1730 if (ret
!= LTTNG_OK
) {
1735 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1736 if (ret
!= LTTNG_OK
) {
1741 ret
= config_writer_close_element(writer
);
1743 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1752 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1754 int save_kernel_session(struct config_writer
*writer
,
1755 struct ltt_session
*session
)
1758 struct ltt_kernel_channel
*kchan
;
1763 ret
= config_writer_write_element_string(writer
, config_element_type
,
1764 config_domain_type_kernel
);
1766 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1770 ret
= config_writer_write_element_string(writer
,
1771 config_element_buffer_type
, config_buffer_type_global
);
1773 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1777 ret
= config_writer_open_element(writer
,
1778 config_element_channels
);
1780 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1784 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1786 ret
= save_kernel_channel(writer
, kchan
);
1787 if (ret
!= LTTNG_OK
) {
1793 ret
= config_writer_close_element(writer
);
1795 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1805 const char *get_config_domain_str(enum lttng_domain_type domain
)
1807 const char *str_dom
;
1810 case LTTNG_DOMAIN_KERNEL
:
1811 str_dom
= config_domain_type_kernel
;
1813 case LTTNG_DOMAIN_UST
:
1814 str_dom
= config_domain_type_ust
;
1816 case LTTNG_DOMAIN_JUL
:
1817 str_dom
= config_domain_type_jul
;
1819 case LTTNG_DOMAIN_LOG4J
:
1820 str_dom
= config_domain_type_log4j
;
1822 case LTTNG_DOMAIN_PYTHON
:
1823 str_dom
= config_domain_type_python
;
1832 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
1833 static int save_id_tracker(struct config_writer
*writer
,
1834 struct ltt_session
*sess
,
1836 enum lttng_tracker_type tracker_type
)
1839 ssize_t nr_ids
= 0, i
;
1840 struct lttng_tracker_id
*ids
= NULL
;
1841 const char *element_id_tracker
, *element_target_id
, *element_id
;
1843 switch (tracker_type
) {
1844 case LTTNG_TRACKER_PID
:
1845 element_id_tracker
= config_element_pid_tracker
;
1846 element_target_id
= config_element_target_pid
;
1847 element_id
= config_element_pid
;
1849 case LTTNG_TRACKER_VPID
:
1850 element_id_tracker
= config_element_vpid_tracker
;
1851 element_target_id
= config_element_target_vpid
;
1852 element_id
= config_element_id
;
1854 case LTTNG_TRACKER_UID
:
1855 element_id_tracker
= config_element_uid_tracker
;
1856 element_target_id
= config_element_target_uid
;
1857 element_id
= config_element_id
;
1859 case LTTNG_TRACKER_VUID
:
1860 element_id_tracker
= config_element_vuid_tracker
;
1861 element_target_id
= config_element_target_vuid
;
1862 element_id
= config_element_id
;
1864 case LTTNG_TRACKER_GID
:
1865 element_id_tracker
= config_element_gid_tracker
;
1866 element_target_id
= config_element_target_gid
;
1867 element_id
= config_element_id
;
1869 case LTTNG_TRACKER_VGID
:
1870 element_id_tracker
= config_element_vgid_tracker
;
1871 element_target_id
= config_element_target_vgid
;
1872 element_id
= config_element_id
;
1875 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1880 case LTTNG_DOMAIN_KERNEL
:
1882 nr_ids
= kernel_list_tracker_ids(
1883 tracker_type
, sess
->kernel_session
, &ids
);
1885 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
1890 case LTTNG_DOMAIN_UST
:
1892 nr_ids
= trace_ust_list_tracker_ids(
1893 tracker_type
, sess
->ust_session
, &ids
);
1895 ret
= LTTNG_ERR_UST_LIST_FAIL
;
1900 case LTTNG_DOMAIN_JUL
:
1901 case LTTNG_DOMAIN_LOG4J
:
1902 case LTTNG_DOMAIN_PYTHON
:
1904 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1908 if (nr_ids
== 1 && ids
[0].type
== LTTNG_ID_ALL
) {
1909 /* Tracking all, nothing to output. */
1914 ret
= config_writer_open_element(writer
, element_id_tracker
);
1916 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1920 ret
= config_writer_open_element(writer
, config_element_targets
);
1922 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1927 /* Tracking none: empty list. */
1928 ret
= config_writer_open_element(writer
, element_target_id
);
1930 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1934 /* /$element_target_id */
1935 ret
= config_writer_close_element(writer
);
1937 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1941 /* Tracking list. */
1942 for (i
= 0; i
< nr_ids
; i
++) {
1943 switch (ids
[i
].type
) {
1944 case LTTNG_ID_VALUE
:
1945 ret
= config_writer_open_element(
1946 writer
, element_target_id
);
1948 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1951 ret
= config_writer_write_element_unsigned_int(
1955 case LTTNG_ID_STRING
:
1956 ret
= config_writer_open_element(
1957 writer
, element_target_id
);
1959 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1962 ret
= config_writer_write_element_string(writer
,
1963 config_element_name
,
1968 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1972 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1976 /* /$element_target_id */
1977 ret
= config_writer_close_element(writer
);
1979 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1986 ret
= config_writer_close_element(writer
);
1988 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1992 /* /$element_id_tracker */
1993 ret
= config_writer_close_element(writer
);
1995 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2005 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2006 static int save_id_trackers(struct config_writer
*writer
,
2007 struct ltt_session
*sess
,
2013 case LTTNG_DOMAIN_KERNEL
:
2014 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_PID
);
2015 if (ret
!= LTTNG_OK
)
2017 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VPID
);
2018 if (ret
!= LTTNG_OK
)
2020 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_UID
);
2021 if (ret
!= LTTNG_OK
)
2023 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VUID
);
2024 if (ret
!= LTTNG_OK
)
2026 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_GID
);
2027 if (ret
!= LTTNG_OK
)
2029 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VGID
);
2030 if (ret
!= LTTNG_OK
)
2033 case LTTNG_DOMAIN_UST
:
2034 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VPID
);
2035 if (ret
!= LTTNG_OK
)
2037 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VUID
);
2038 if (ret
!= LTTNG_OK
)
2040 ret
= save_id_tracker(writer
, sess
, domain
, LTTNG_TRACKER_VGID
);
2041 if (ret
!= LTTNG_OK
)
2045 return LTTNG_ERR_INVALID
;
2050 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2052 int save_ust_domain(struct config_writer
*writer
,
2053 struct ltt_session
*session
, enum lttng_domain_type domain
)
2056 struct ltt_ust_channel
*ust_chan
;
2057 const char *buffer_type_string
;
2058 struct lttng_ht_node_str
*node
;
2059 struct lttng_ht_iter iter
;
2060 const char *config_domain_name
;
2065 ret
= config_writer_open_element(writer
,
2066 config_element_domain
);
2068 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2072 config_domain_name
= get_config_domain_str(domain
);
2073 if (!config_domain_name
) {
2074 ret
= LTTNG_ERR_INVALID
;
2078 ret
= config_writer_write_element_string(writer
,
2079 config_element_type
, config_domain_name
);
2081 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2085 buffer_type_string
= get_buffer_type_string(
2086 session
->ust_session
->buffer_type
);
2087 if (!buffer_type_string
) {
2088 ERR("Unsupported buffer type.");
2089 ret
= LTTNG_ERR_INVALID
;
2093 ret
= config_writer_write_element_string(writer
,
2094 config_element_buffer_type
, buffer_type_string
);
2096 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2100 ret
= config_writer_open_element(writer
, config_element_channels
);
2102 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2107 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
2108 &iter
.iter
, node
, node
) {
2109 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
2110 if (domain
== ust_chan
->domain
) {
2111 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
2112 if (ret
!= LTTNG_OK
) {
2121 ret
= config_writer_close_element(writer
);
2123 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2127 if (domain
== LTTNG_DOMAIN_UST
) {
2128 ret
= config_writer_open_element(writer
,
2129 config_element_trackers
);
2131 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2135 ret
= save_id_trackers(writer
, session
, LTTNG_DOMAIN_UST
);
2136 if (ret
!= LTTNG_OK
) {
2141 ret
= config_writer_close_element(writer
);
2143 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2149 ret
= config_writer_close_element(writer
);
2151 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2160 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2162 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
2169 if (!session
->kernel_session
&& !session
->ust_session
) {
2173 ret
= config_writer_open_element(writer
, config_element_domains
);
2175 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2179 if (session
->kernel_session
) {
2180 ret
= config_writer_open_element(writer
,
2181 config_element_domain
);
2183 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2187 ret
= save_kernel_session(writer
, session
);
2188 if (ret
!= LTTNG_OK
) {
2192 ret
= config_writer_open_element(writer
,
2193 config_element_trackers
);
2195 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2199 ret
= save_id_trackers(writer
, session
, LTTNG_DOMAIN_KERNEL
);
2200 if (ret
!= LTTNG_OK
) {
2205 ret
= config_writer_close_element(writer
);
2207 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2211 ret
= config_writer_close_element(writer
);
2213 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2218 if (session
->ust_session
) {
2219 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
2220 if (ret
!= LTTNG_OK
) {
2224 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
2225 if (ret
!= LTTNG_OK
) {
2229 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
2230 if (ret
!= LTTNG_OK
) {
2234 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
2235 if (ret
!= LTTNG_OK
) {
2241 ret
= config_writer_close_element(writer
);
2243 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2252 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2254 int save_consumer_output(struct config_writer
*writer
,
2255 struct consumer_output
*output
)
2262 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
2264 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2268 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
2271 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2275 ret
= config_writer_open_element(writer
, config_element_destination
);
2277 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2281 switch (output
->type
) {
2282 case CONSUMER_DST_LOCAL
:
2283 ret
= config_writer_write_element_string(writer
,
2284 config_element_path
, output
->dst
.session_root_path
);
2286 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2290 case CONSUMER_DST_NET
:
2294 uri
= zmalloc(PATH_MAX
);
2296 ret
= LTTNG_ERR_NOMEM
;
2300 ret
= config_writer_open_element(writer
, config_element_net_output
);
2302 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2303 goto end_net_output
;
2306 if (output
->dst
.net
.control_isset
&&
2307 output
->dst
.net
.data_isset
) {
2308 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
2310 ret
= LTTNG_ERR_INVALID
;
2311 goto end_net_output
;
2314 ret
= config_writer_write_element_string(writer
,
2315 config_element_control_uri
, uri
);
2317 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2318 goto end_net_output
;
2321 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
2323 ret
= LTTNG_ERR_INVALID
;
2324 goto end_net_output
;
2327 ret
= config_writer_write_element_string(writer
,
2328 config_element_data_uri
, uri
);
2330 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2331 goto end_net_output
;
2336 if (ret
!= LTTNG_OK
) {
2340 ret
= !output
->dst
.net
.control_isset
?
2341 LTTNG_ERR_URL_CTRL_MISS
:
2342 LTTNG_ERR_URL_DATA_MISS
;
2347 ret
= config_writer_close_element(writer
);
2349 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2355 ERR("Unsupported consumer output type.");
2356 ret
= LTTNG_ERR_INVALID
;
2361 ret
= config_writer_close_element(writer
);
2363 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2367 /* /consumer_output */
2368 ret
= config_writer_close_element(writer
);
2370 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2379 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2381 int save_snapshot_outputs(struct config_writer
*writer
,
2382 struct snapshot
*snapshot
)
2385 struct lttng_ht_iter iter
;
2386 struct snapshot_output
*output
;
2391 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
2393 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2398 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
2400 ret
= config_writer_open_element(writer
,
2401 config_element_output
);
2403 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2407 ret
= config_writer_write_element_string(writer
,
2408 config_element_name
, output
->name
);
2410 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2414 ret
= config_writer_write_element_unsigned_int(writer
,
2415 config_element_max_size
, output
->max_size
);
2417 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2421 ret
= save_consumer_output(writer
, output
->consumer
);
2422 if (ret
!= LTTNG_OK
) {
2427 ret
= config_writer_close_element(writer
);
2429 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2435 /* /snapshot_outputs */
2436 ret
= config_writer_close_element(writer
);
2438 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2450 /* Return LTTNG_OK on success else a LTTNG_ERR* code. */
2452 int save_session_output(struct config_writer
*writer
,
2453 struct ltt_session
*session
)
2460 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
2461 (!session
->snapshot_mode
&& !session
->consumer
)) {
2462 /* Session is in no output mode */
2467 ret
= config_writer_open_element(writer
, config_element_output
);
2469 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2473 if (session
->snapshot_mode
) {
2474 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
2475 if (ret
!= LTTNG_OK
) {
2479 if (session
->consumer
) {
2480 ret
= save_consumer_output(writer
, session
->consumer
);
2481 if (ret
!= LTTNG_OK
) {
2488 ret
= config_writer_close_element(writer
);
2490 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2499 int save_session_rotation_schedule(struct config_writer
*writer
,
2500 enum lttng_rotation_schedule_type type
, uint64_t value
)
2503 const char *element_name
;
2504 const char *value_name
;
2507 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2508 element_name
= config_element_rotation_schedule_periodic
;
2509 value_name
= config_element_rotation_schedule_periodic_time_us
;
2511 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2512 element_name
= config_element_rotation_schedule_size_threshold
;
2513 value_name
= config_element_rotation_schedule_size_threshold_bytes
;
2520 ret
= config_writer_open_element(writer
, element_name
);
2525 ret
= config_writer_write_element_unsigned_int(writer
,
2531 /* Close schedule descriptor element. */
2532 ret
= config_writer_close_element(writer
);
2541 int save_session_rotation_schedules(struct config_writer
*writer
,
2542 struct ltt_session
*session
)
2546 ret
= config_writer_open_element(writer
,
2547 config_element_rotation_schedules
);
2551 if (session
->rotate_timer_period
) {
2552 ret
= save_session_rotation_schedule(writer
,
2553 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
,
2554 session
->rotate_timer_period
);
2556 goto close_schedules
;
2559 if (session
->rotate_size
) {
2560 ret
= save_session_rotation_schedule(writer
,
2561 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
,
2562 session
->rotate_size
);
2564 goto close_schedules
;
2569 /* Close rotation schedules element. */
2570 ret
= config_writer_close_element(writer
);
2579 * Save the given session.
2581 * Return LTTNG_OK on success else a LTTNG_ERR* code.
2584 int save_session(struct ltt_session
*session
,
2585 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
2588 char config_file_path
[LTTNG_PATH_MAX
];
2590 struct config_writer
*writer
= NULL
;
2591 size_t session_name_len
;
2592 const char *provided_path
;
2593 int file_open_flags
= O_CREAT
| O_WRONLY
| O_TRUNC
;
2599 session_name_len
= strlen(session
->name
);
2600 memset(config_file_path
, 0, sizeof(config_file_path
));
2602 if (!session_access_ok(session
,
2603 LTTNG_SOCK_GET_UID_CRED(creds
),
2604 LTTNG_SOCK_GET_GID_CRED(creds
)) || session
->destroyed
) {
2605 ret
= LTTNG_ERR_EPERM
;
2609 provided_path
= lttng_save_session_attr_get_output_url(attr
);
2610 if (provided_path
) {
2611 DBG3("Save session in provided path %s", provided_path
);
2612 len
= strlen(provided_path
);
2613 if (len
>= sizeof(config_file_path
)) {
2614 ret
= LTTNG_ERR_SET_URL
;
2617 strncpy(config_file_path
, provided_path
, sizeof(config_file_path
));
2620 char *home_dir
= utils_get_user_home_dir(
2621 LTTNG_SOCK_GET_UID_CRED(creds
));
2623 ret
= LTTNG_ERR_SET_URL
;
2627 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
2628 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
2631 PERROR("snprintf save session");
2632 ret
= LTTNG_ERR_SET_URL
;
2639 * Check the path fits in the config file path dst including the '/'
2640 * followed by trailing .lttng extension and the NULL terminated string.
2642 if ((len
+ session_name_len
+ 2 +
2643 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
2644 > sizeof(config_file_path
)) {
2645 ret
= LTTNG_ERR_SET_URL
;
2649 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
2650 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2652 ret
= LTTNG_ERR_SET_URL
;
2657 * At this point, we know that everything fits in the buffer. Validation
2658 * was done just above.
2660 config_file_path
[len
++] = '/';
2661 strncpy(config_file_path
+ len
, session
->name
, sizeof(config_file_path
) - len
);
2662 len
+= session_name_len
;
2663 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2664 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2665 config_file_path
[len
] = '\0';
2667 if (!attr
->overwrite
) {
2668 file_open_flags
|= O_EXCL
;
2671 fd
= run_as_open(config_file_path
, file_open_flags
,
2672 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
2673 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2675 PERROR("Could not create configuration file");
2678 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
2681 ret
= LTTNG_ERR_EPERM
;
2684 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2690 writer
= config_writer_create(fd
, 1);
2692 ret
= LTTNG_ERR_NOMEM
;
2696 ret
= config_writer_open_element(writer
, config_element_sessions
);
2698 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2702 ret
= config_writer_open_element(writer
, config_element_session
);
2704 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2708 ret
= config_writer_write_element_string(writer
, config_element_name
,
2711 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2715 if (session
->shm_path
[0] != '\0') {
2716 ret
= config_writer_write_element_string(writer
,
2717 config_element_shared_memory_path
,
2720 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2725 ret
= save_domains(writer
, session
);
2726 if (ret
!= LTTNG_OK
) {
2730 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2733 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2737 if (session
->snapshot_mode
|| session
->live_timer
||
2738 session
->rotate_timer_period
|| session
->rotate_size
) {
2739 ret
= config_writer_open_element(writer
, config_element_attributes
);
2741 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2745 if (session
->snapshot_mode
) {
2746 ret
= config_writer_write_element_bool(writer
,
2747 config_element_snapshot_mode
, 1);
2749 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2752 } else if (session
->live_timer
) {
2753 ret
= config_writer_write_element_unsigned_int(writer
,
2754 config_element_live_timer_interval
, session
->live_timer
);
2756 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2760 if (session
->rotate_timer_period
|| session
->rotate_size
) {
2761 ret
= save_session_rotation_schedules(writer
,
2764 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2770 ret
= config_writer_close_element(writer
);
2772 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2777 ret
= save_session_output(writer
, session
);
2778 if (ret
!= LTTNG_OK
) {
2783 ret
= config_writer_close_element(writer
);
2785 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2790 ret
= config_writer_close_element(writer
);
2792 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2798 if (writer
&& config_writer_destroy(writer
)) {
2799 /* Preserve the original error code */
2800 ret
= ret
!= LTTNG_OK
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2802 if (ret
!= LTTNG_OK
) {
2803 /* Delete file in case of error */
2804 if ((fd
>= 0) && unlink(config_file_path
)) {
2805 PERROR("Unlinking XML session configuration.");
2812 closeret
= close(fd
);
2814 PERROR("Closing XML session configuration");
2821 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2822 lttng_sock_cred
*creds
)
2825 const char *session_name
;
2826 struct ltt_session
*session
;
2828 session_lock_list();
2830 session_name
= lttng_save_session_attr_get_session_name(attr
);
2832 session
= session_find_by_name(session_name
);
2834 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2838 session_lock(session
);
2839 ret
= save_session(session
, attr
, creds
);
2840 session_unlock(session
);
2841 session_put(session
);
2842 if (ret
!= LTTNG_OK
) {
2846 struct ltt_session_list
*list
= session_get_list();
2848 cds_list_for_each_entry(session
, &list
->head
, list
) {
2849 if (!session_get(session
)) {
2852 session_lock(session
);
2853 ret
= save_session(session
, attr
, creds
);
2854 session_unlock(session
);
2855 session_put(session
);
2856 /* Don't abort if we don't have the required permissions. */
2857 if (ret
!= LTTNG_OK
&& ret
!= LTTNG_ERR_EPERM
) {
2865 session_unlock_list();