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"
40 int save_kernel_channel_attributes(struct config_writer
*writer
,
41 struct lttng_channel_attr
*attr
)
45 ret
= config_writer_write_element_string(writer
,
46 config_element_overwrite_mode
,
47 attr
->overwrite
? config_overwrite_mode_overwrite
:
48 config_overwrite_mode_discard
);
53 ret
= config_writer_write_element_unsigned_int(writer
,
54 config_element_subbuf_size
, attr
->subbuf_size
);
59 ret
= config_writer_write_element_unsigned_int(writer
,
60 config_element_num_subbuf
,
66 ret
= config_writer_write_element_unsigned_int(writer
,
67 config_element_switch_timer_interval
,
68 attr
->switch_timer_interval
);
73 ret
= config_writer_write_element_unsigned_int(writer
,
74 config_element_read_timer_interval
,
75 attr
->read_timer_interval
);
80 ret
= config_writer_write_element_string(writer
,
81 config_element_output_type
,
82 attr
->output
== LTTNG_EVENT_SPLICE
?
83 config_output_type_splice
: config_output_type_mmap
);
88 ret
= config_writer_write_element_unsigned_int(writer
,
89 config_element_tracefile_size
, attr
->tracefile_size
);
94 ret
= config_writer_write_element_unsigned_int(writer
,
95 config_element_tracefile_count
,
96 attr
->tracefile_count
);
101 ret
= config_writer_write_element_unsigned_int(writer
,
102 config_element_live_timer_interval
,
103 attr
->live_timer_interval
);
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
);
119 ret
= config_writer_write_element_signed_int(writer
,
120 config_element_blocking_timeout
,
121 ext
->blocking_timeout
);
128 return ret
? LTTNG_ERR_SAVE_IO_FAIL
: 0;
132 int save_ust_channel_attributes(struct config_writer
*writer
,
133 struct lttng_ust_channel_attr
*attr
)
136 struct ltt_ust_channel
*channel
= NULL
;
138 ret
= config_writer_write_element_string(writer
,
139 config_element_overwrite_mode
,
140 attr
->overwrite
? config_overwrite_mode_overwrite
:
141 config_overwrite_mode_discard
);
146 ret
= config_writer_write_element_unsigned_int(writer
,
147 config_element_subbuf_size
, attr
->subbuf_size
);
152 ret
= config_writer_write_element_unsigned_int(writer
,
153 config_element_num_subbuf
,
159 ret
= config_writer_write_element_unsigned_int(writer
,
160 config_element_switch_timer_interval
,
161 attr
->switch_timer_interval
);
166 ret
= config_writer_write_element_unsigned_int(writer
,
167 config_element_read_timer_interval
,
168 attr
->read_timer_interval
);
173 ret
= config_writer_write_element_string(writer
,
174 config_element_output_type
,
175 attr
->output
== LTTNG_UST_MMAP
?
176 config_output_type_mmap
: config_output_type_splice
);
181 ret
= config_writer_write_element_signed_int(writer
,
182 config_element_blocking_timeout
,
183 attr
->u
.s
.blocking_timeout
);
189 * Fetch the monitor timer which is located in the parent of
190 * lttng_ust_channel_attr
192 channel
= caa_container_of(attr
, struct ltt_ust_channel
, attr
);
193 ret
= config_writer_write_element_unsigned_int(writer
,
194 config_element_monitor_timer_interval
,
195 channel
->monitor_timer_interval
);
201 return ret
? LTTNG_ERR_SAVE_IO_FAIL
: 0;
205 const char *get_kernel_instrumentation_string(
206 enum lttng_kernel_instrumentation instrumentation
)
208 const char *instrumentation_string
;
210 switch (instrumentation
) {
211 case LTTNG_KERNEL_ALL
:
212 instrumentation_string
= config_event_type_all
;
214 case LTTNG_KERNEL_TRACEPOINT
:
215 instrumentation_string
= config_event_type_tracepoint
;
217 case LTTNG_KERNEL_KPROBE
:
218 instrumentation_string
= config_event_type_kprobe
;
220 case LTTNG_KERNEL_FUNCTION
:
221 instrumentation_string
= config_event_type_function
;
223 case LTTNG_KERNEL_KRETPROBE
:
224 instrumentation_string
= config_event_type_kretprobe
;
226 case LTTNG_KERNEL_NOOP
:
227 instrumentation_string
= config_event_type_noop
;
229 case LTTNG_KERNEL_SYSCALL
:
230 instrumentation_string
= config_event_type_syscall
;
233 instrumentation_string
= NULL
;
236 return instrumentation_string
;
240 const char *get_kernel_context_type_string(
241 enum lttng_kernel_context_type context_type
)
243 const char *context_type_string
;
245 switch (context_type
) {
246 case LTTNG_KERNEL_CONTEXT_PID
:
247 context_type_string
= config_event_context_pid
;
249 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
250 context_type_string
= config_event_context_procname
;
252 case LTTNG_KERNEL_CONTEXT_PRIO
:
253 context_type_string
= config_event_context_prio
;
255 case LTTNG_KERNEL_CONTEXT_NICE
:
256 context_type_string
= config_event_context_nice
;
258 case LTTNG_KERNEL_CONTEXT_VPID
:
259 context_type_string
= config_event_context_vpid
;
261 case LTTNG_KERNEL_CONTEXT_TID
:
262 context_type_string
= config_event_context_tid
;
264 case LTTNG_KERNEL_CONTEXT_VTID
:
265 context_type_string
= config_event_context_vtid
;
267 case LTTNG_KERNEL_CONTEXT_PPID
:
268 context_type_string
= config_event_context_ppid
;
270 case LTTNG_KERNEL_CONTEXT_VPPID
:
271 context_type_string
= config_event_context_vppid
;
273 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
274 context_type_string
= config_event_context_hostname
;
276 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
277 context_type_string
= config_event_context_interruptible
;
279 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
280 context_type_string
= config_event_context_preemptible
;
282 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
283 context_type_string
= config_event_context_need_reschedule
;
285 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
286 context_type_string
= config_event_context_migratable
;
289 context_type_string
= NULL
;
292 return context_type_string
;
296 const char *get_ust_context_type_string(
297 enum lttng_ust_context_type context_type
)
299 const char *context_type_string
;
301 switch (context_type
) {
302 case LTTNG_UST_CONTEXT_PROCNAME
:
303 context_type_string
= config_event_context_procname
;
305 case LTTNG_UST_CONTEXT_VPID
:
306 context_type_string
= config_event_context_vpid
;
308 case LTTNG_UST_CONTEXT_VTID
:
309 context_type_string
= config_event_context_vtid
;
311 case LTTNG_UST_CONTEXT_IP
:
312 context_type_string
= config_event_context_ip
;
314 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
315 context_type_string
= config_event_context_pthread_id
;
317 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
318 context_type_string
= config_event_context_app
;
320 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
322 * Error, should not be stored in the XML, perf contexts
323 * are stored as a node of type event_perf_context_type.
326 context_type_string
= NULL
;
330 return context_type_string
;
334 const char *get_buffer_type_string(
335 enum lttng_buffer_type buffer_type
)
337 const char *buffer_type_string
;
339 switch (buffer_type
) {
340 case LTTNG_BUFFER_PER_PID
:
341 buffer_type_string
= config_buffer_type_per_pid
;
343 case LTTNG_BUFFER_PER_UID
:
344 buffer_type_string
= config_buffer_type_per_uid
;
346 case LTTNG_BUFFER_GLOBAL
:
347 buffer_type_string
= config_buffer_type_global
;
350 buffer_type_string
= NULL
;
353 return buffer_type_string
;
357 const char *get_loglevel_type_string(
358 enum lttng_ust_loglevel_type loglevel_type
)
360 const char *loglevel_type_string
;
362 switch (loglevel_type
) {
363 case LTTNG_UST_LOGLEVEL_ALL
:
364 loglevel_type_string
= config_loglevel_type_all
;
366 case LTTNG_UST_LOGLEVEL_RANGE
:
367 loglevel_type_string
= config_loglevel_type_range
;
369 case LTTNG_UST_LOGLEVEL_SINGLE
:
370 loglevel_type_string
= config_loglevel_type_single
;
373 loglevel_type_string
= NULL
;
376 return loglevel_type_string
;
380 int save_kernel_event(struct config_writer
*writer
,
381 struct ltt_kernel_event
*event
)
384 const char *instrumentation_type
;
386 ret
= config_writer_open_element(writer
, config_element_event
);
388 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
392 if (event
->event
->name
[0]) {
393 ret
= config_writer_write_element_string(writer
,
394 config_element_name
, event
->event
->name
);
396 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
401 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
404 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
408 instrumentation_type
= get_kernel_instrumentation_string(
409 event
->event
->instrumentation
);
410 if (!instrumentation_type
) {
411 ret
= LTTNG_ERR_INVALID
;
415 ret
= config_writer_write_element_string(writer
, config_element_type
,
416 instrumentation_type
);
418 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
422 if (event
->filter_expression
) {
423 ret
= config_writer_write_element_string(writer
,
424 config_element_filter
,
425 event
->filter_expression
);
427 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
432 if (event
->event
->instrumentation
== LTTNG_KERNEL_FUNCTION
||
433 event
->event
->instrumentation
== LTTNG_KERNEL_KPROBE
||
434 event
->event
->instrumentation
== LTTNG_KERNEL_KRETPROBE
) {
436 ret
= config_writer_open_element(writer
,
437 config_element_attributes
);
439 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
443 switch (event
->event
->instrumentation
) {
444 case LTTNG_KERNEL_SYSCALL
:
445 case LTTNG_KERNEL_FUNCTION
:
446 ret
= config_writer_open_element(writer
,
447 config_element_function_attributes
);
449 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
453 ret
= config_writer_write_element_string(writer
,
455 event
->event
->u
.ftrace
.symbol_name
);
457 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
461 /* /function attributes */
462 ret
= config_writer_close_element(writer
);
464 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
468 case LTTNG_KERNEL_KPROBE
:
469 case LTTNG_KERNEL_KRETPROBE
:
471 const char *symbol_name
;
475 if (event
->event
->instrumentation
==
476 LTTNG_KERNEL_KPROBE
) {
478 * Comments in lttng-kernel.h mention that
479 * either addr or symbol_name are set, not both.
481 addr
= event
->event
->u
.kprobe
.addr
;
482 offset
= event
->event
->u
.kprobe
.offset
;
483 symbol_name
= addr
? NULL
:
484 event
->event
->u
.kprobe
.symbol_name
;
487 event
->event
->u
.kretprobe
.symbol_name
;
488 addr
= event
->event
->u
.kretprobe
.addr
;
489 offset
= event
->event
->u
.kretprobe
.offset
;
492 ret
= config_writer_open_element(writer
,
493 config_element_probe_attributes
);
495 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
500 ret
= config_writer_write_element_string(writer
,
501 config_element_symbol_name
,
504 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
510 ret
= config_writer_write_element_unsigned_int(
511 writer
, config_element_address
, addr
);
513 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
519 ret
= config_writer_write_element_unsigned_int(
520 writer
, config_element_offset
, offset
);
522 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
527 ret
= config_writer_close_element(writer
);
529 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
535 ERR("Unsupported kernel instrumentation type.");
536 ret
= LTTNG_ERR_INVALID
;
541 ret
= config_writer_close_element(writer
);
543 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
549 ret
= config_writer_close_element(writer
);
551 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
559 int save_kernel_events(struct config_writer
*writer
,
560 struct ltt_kernel_channel
*kchan
)
563 struct ltt_kernel_event
*event
;
565 ret
= config_writer_open_element(writer
, config_element_events
);
567 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
571 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
572 ret
= save_kernel_event(writer
, event
);
579 ret
= config_writer_close_element(writer
);
581 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
589 int save_ust_event(struct config_writer
*writer
,
590 struct ltt_ust_event
*event
)
593 const char *loglevel_type_string
;
595 ret
= config_writer_open_element(writer
, config_element_event
);
597 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
601 if (event
->attr
.name
[0]) {
602 ret
= config_writer_write_element_string(writer
,
603 config_element_name
, event
->attr
.name
);
605 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
610 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
613 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
617 if (event
->attr
.instrumentation
!= LTTNG_UST_TRACEPOINT
) {
618 ERR("Unsupported UST instrumentation type.");
619 ret
= LTTNG_ERR_INVALID
;
622 ret
= config_writer_write_element_string(writer
, config_element_type
,
623 config_event_type_tracepoint
);
625 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
629 loglevel_type_string
= get_loglevel_type_string(
630 event
->attr
.loglevel_type
);
631 if (!loglevel_type_string
) {
632 ERR("Unsupported UST loglevel type.");
633 ret
= LTTNG_ERR_INVALID
;
637 ret
= config_writer_write_element_string(writer
,
638 config_element_loglevel_type
, loglevel_type_string
);
640 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
644 /* The log level is irrelevant if no "filtering" is enabled */
645 if (event
->attr
.loglevel_type
!= LTTNG_UST_LOGLEVEL_ALL
) {
646 ret
= config_writer_write_element_signed_int(writer
,
647 config_element_loglevel
, event
->attr
.loglevel
);
649 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
654 if (event
->filter_expression
) {
655 ret
= config_writer_write_element_string(writer
,
656 config_element_filter
, event
->filter_expression
);
658 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
663 if (event
->exclusion
&& event
->exclusion
->count
) {
666 ret
= config_writer_open_element(writer
,
667 config_element_exclusions
);
669 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
673 for (i
= 0; i
< event
->exclusion
->count
; i
++) {
674 ret
= config_writer_write_element_string(writer
,
675 config_element_exclusion
,
676 LTTNG_EVENT_EXCLUSION_NAME_AT(
677 event
->exclusion
, i
));
679 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
685 ret
= config_writer_close_element(writer
);
687 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
693 ret
= config_writer_close_element(writer
);
695 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
703 int save_ust_events(struct config_writer
*writer
,
704 struct lttng_ht
*events
)
707 struct ltt_ust_event
*event
;
708 struct lttng_ht_node_str
*node
;
709 struct lttng_ht_iter iter
;
711 ret
= config_writer_open_element(writer
, config_element_events
);
713 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
718 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
719 event
= caa_container_of(node
, struct ltt_ust_event
, node
);
721 if (event
->internal
) {
722 /* Internal events must not be exposed to clients */
725 ret
= save_ust_event(writer
, event
);
734 ret
= config_writer_close_element(writer
);
736 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
744 int init_ust_event_from_agent_event(struct ltt_ust_event
*ust_event
,
745 struct agent_event
*agent_event
)
748 enum lttng_ust_loglevel_type ust_loglevel_type
;
750 ust_event
->enabled
= agent_event
->enabled
;
751 ust_event
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
752 if (lttng_strncpy(ust_event
->attr
.name
, agent_event
->name
,
753 LTTNG_SYMBOL_NAME_LEN
)) {
757 switch (agent_event
->loglevel_type
) {
758 case LTTNG_EVENT_LOGLEVEL_ALL
:
759 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
761 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
762 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
764 case LTTNG_EVENT_LOGLEVEL_RANGE
:
765 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
768 ERR("Invalid agent_event loglevel_type.");
773 ust_event
->attr
.loglevel_type
= ust_loglevel_type
;
774 ust_event
->attr
.loglevel
= agent_event
->loglevel_value
;
775 ust_event
->filter_expression
= agent_event
->filter_expression
;
776 ust_event
->exclusion
= agent_event
->exclusion
;
782 int save_agent_events(struct config_writer
*writer
,
786 struct lttng_ht_iter iter
;
787 struct lttng_ht_node_str
*node
;
789 ret
= config_writer_open_element(writer
, config_element_events
);
791 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
796 cds_lfht_for_each_entry(agent
->events
->ht
, &iter
.iter
, node
, node
) {
798 struct agent_event
*agent_event
;
799 struct ltt_ust_event fake_event
;
801 memset(&fake_event
, 0, sizeof(fake_event
));
802 agent_event
= caa_container_of(node
, struct agent_event
, node
);
805 * Initialize a fake ust event to reuse the same serialization
806 * function since UST and agent events contain the same info
807 * (and one could wonder why they don't reuse the same
810 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
815 ret
= save_ust_event(writer
, &fake_event
);
824 ret
= config_writer_close_element(writer
);
826 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
834 int save_kernel_context(struct config_writer
*writer
,
835 struct lttng_kernel_context
*ctx
)
843 ret
= config_writer_open_element(writer
, config_element_context
);
845 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
849 if (ctx
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER
) {
850 ret
= config_writer_open_element(writer
,
851 config_element_context_perf
);
853 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
857 ret
= config_writer_write_element_unsigned_int(writer
,
858 config_element_type
, ctx
->u
.perf_counter
.type
);
860 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
864 ret
= config_writer_write_element_unsigned_int(writer
,
865 config_element_config
, ctx
->u
.perf_counter
.config
);
867 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
871 ret
= config_writer_write_element_string(writer
,
872 config_element_name
, ctx
->u
.perf_counter
.name
);
874 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
879 ret
= config_writer_close_element(writer
);
881 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
885 const char *context_type_string
=
886 get_kernel_context_type_string(ctx
->ctx
);
888 if (!context_type_string
) {
889 ERR("Unsupported kernel context type.");
890 ret
= LTTNG_ERR_INVALID
;
894 ret
= config_writer_write_element_string(writer
,
895 config_element_type
, context_type_string
);
897 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
903 ret
= config_writer_close_element(writer
);
905 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
914 int save_kernel_contexts(struct config_writer
*writer
,
915 struct ltt_kernel_channel
*kchan
)
918 struct ltt_kernel_context
*ctx
;
920 if (cds_list_empty(&kchan
->ctx_list
)) {
925 ret
= config_writer_open_element(writer
, config_element_contexts
);
927 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
931 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
932 ret
= save_kernel_context(writer
, &ctx
->ctx
);
939 ret
= config_writer_close_element(writer
);
941 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
949 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
950 struct ltt_ust_context
*ctx
)
957 /* Perf contexts are saved as event_perf_context_type */
958 ret
= config_writer_open_element(writer
, config_element_context_perf
);
960 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
964 ret
= config_writer_write_element_unsigned_int(writer
,
965 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
967 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
971 ret
= config_writer_write_element_unsigned_int(writer
,
972 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
974 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
978 ret
= config_writer_write_element_string(writer
, config_element_name
,
979 ctx
->ctx
.u
.perf_counter
.name
);
981 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
986 ret
= config_writer_close_element(writer
);
988 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
996 int save_ust_context_app_ctx(struct config_writer
*writer
,
997 struct ltt_ust_context
*ctx
)
1004 /* Application contexts are saved as application_context_type */
1005 ret
= config_writer_open_element(writer
, config_element_context_app
);
1007 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1011 ret
= config_writer_write_element_string(writer
,
1012 config_element_context_app_provider_name
,
1013 ctx
->ctx
.u
.app_ctx
.provider_name
);
1015 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1019 ret
= config_writer_write_element_string(writer
,
1020 config_element_context_app_ctx_name
,
1021 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1023 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1028 ret
= config_writer_close_element(writer
);
1030 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1038 int save_ust_context_generic(struct config_writer
*writer
,
1039 struct ltt_ust_context
*ctx
)
1042 const char *context_type_string
;
1047 /* Save context as event_context_type_type */
1048 context_type_string
= get_ust_context_type_string(
1050 if (!context_type_string
) {
1051 ERR("Unsupported UST context type.");
1052 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1056 ret
= config_writer_write_element_string(writer
,
1057 config_element_type
, context_type_string
);
1059 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1067 int save_ust_context(struct config_writer
*writer
,
1068 struct cds_list_head
*ctx_list
)
1071 struct ltt_ust_context
*ctx
;
1076 ret
= config_writer_open_element(writer
, config_element_contexts
);
1078 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1082 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1083 ret
= config_writer_open_element(writer
,
1084 config_element_context
);
1086 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1090 switch (ctx
->ctx
.ctx
) {
1091 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1092 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1094 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1095 ret
= save_ust_context_app_ctx(writer
, ctx
);
1098 /* Save generic context. */
1099 ret
= save_ust_context_generic(writer
, ctx
);
1106 ret
= config_writer_close_element(writer
);
1108 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1114 ret
= config_writer_close_element(writer
);
1116 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1124 int save_kernel_channel(struct config_writer
*writer
,
1125 struct ltt_kernel_channel
*kchan
)
1132 ret
= config_writer_open_element(writer
, config_element_channel
);
1134 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1138 ret
= config_writer_write_element_string(writer
, config_element_name
,
1139 kchan
->channel
->name
);
1141 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1145 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1146 kchan
->channel
->enabled
);
1148 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1152 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1157 ret
= save_kernel_events(writer
, kchan
);
1162 ret
= save_kernel_contexts(writer
, kchan
);
1168 ret
= config_writer_close_element(writer
);
1170 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1178 int save_ust_channel(struct config_writer
*writer
,
1179 struct ltt_ust_channel
*ust_chan
,
1180 struct ltt_ust_session
*session
)
1188 ret
= config_writer_open_element(writer
, config_element_channel
);
1190 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1194 ret
= config_writer_write_element_string(writer
, config_element_name
,
1197 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1201 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1204 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1208 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1213 ret
= config_writer_write_element_unsigned_int(writer
,
1214 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1216 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1220 ret
= config_writer_write_element_unsigned_int(writer
,
1221 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1223 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1227 ret
= config_writer_write_element_unsigned_int(writer
,
1228 config_element_live_timer_interval
,
1229 session
->live_timer_interval
);
1231 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1235 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1236 ret
= save_ust_events(writer
, ust_chan
->events
);
1241 struct agent
*agent
= NULL
;
1243 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1245 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1246 ERR("Could not find agent associated to UST subdomain");
1251 * Channels associated with a UST sub-domain (such as JUL, Log4j
1252 * or Python) don't have any non-internal events. We retrieve
1253 * the "agent" events associated with this channel and serialize
1256 ret
= save_agent_events(writer
, agent
);
1262 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1268 ret
= config_writer_close_element(writer
);
1270 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1278 int save_kernel_session(struct config_writer
*writer
,
1279 struct ltt_session
*session
)
1282 struct ltt_kernel_channel
*kchan
;
1287 ret
= config_writer_write_element_string(writer
, config_element_type
,
1288 config_domain_type_kernel
);
1290 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1294 ret
= config_writer_write_element_string(writer
,
1295 config_element_buffer_type
, config_buffer_type_global
);
1297 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1301 ret
= config_writer_open_element(writer
,
1302 config_element_channels
);
1304 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1308 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1310 ret
= save_kernel_channel(writer
, kchan
);
1317 ret
= config_writer_close_element(writer
);
1319 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1327 const char *get_config_domain_str(enum lttng_domain_type domain
)
1329 const char *str_dom
;
1332 case LTTNG_DOMAIN_KERNEL
:
1333 str_dom
= config_domain_type_kernel
;
1335 case LTTNG_DOMAIN_UST
:
1336 str_dom
= config_domain_type_ust
;
1338 case LTTNG_DOMAIN_JUL
:
1339 str_dom
= config_domain_type_jul
;
1341 case LTTNG_DOMAIN_LOG4J
:
1342 str_dom
= config_domain_type_log4j
;
1344 case LTTNG_DOMAIN_PYTHON
:
1345 str_dom
= config_domain_type_python
;
1355 int save_pid_tracker(struct config_writer
*writer
,
1356 struct ltt_session
*sess
, int domain
)
1359 ssize_t nr_pids
= 0, i
;
1360 int32_t *pids
= NULL
;
1363 case LTTNG_DOMAIN_KERNEL
:
1365 nr_pids
= kernel_list_tracker_pids(sess
->kernel_session
, &pids
);
1367 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
1372 case LTTNG_DOMAIN_UST
:
1374 nr_pids
= trace_ust_list_tracker_pids(sess
->ust_session
, &pids
);
1376 ret
= LTTNG_ERR_UST_LIST_FAIL
;
1381 case LTTNG_DOMAIN_JUL
:
1382 case LTTNG_DOMAIN_LOG4J
:
1383 case LTTNG_DOMAIN_PYTHON
:
1385 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1389 /* Only create a pid_tracker if enabled or untrack all */
1390 if (nr_pids
!= 1 || (nr_pids
== 1 && pids
[0] != -1)) {
1391 ret
= config_writer_open_element(writer
,
1392 config_element_pid_tracker
);
1394 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1398 ret
= config_writer_open_element(writer
,
1399 config_element_targets
);
1401 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1405 for (i
= 0; i
< nr_pids
; i
++) {
1406 ret
= config_writer_open_element(writer
,
1407 config_element_target_pid
);
1409 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1413 ret
= config_writer_write_element_unsigned_int(writer
,
1414 config_element_pid
, pids
[i
]);
1416 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1421 ret
= config_writer_close_element(writer
);
1423 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1429 ret
= config_writer_close_element(writer
);
1431 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1436 ret
= config_writer_close_element(writer
);
1438 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1448 int save_ust_domain(struct config_writer
*writer
,
1449 struct ltt_session
*session
, enum lttng_domain_type domain
)
1452 struct ltt_ust_channel
*ust_chan
;
1453 const char *buffer_type_string
;
1454 struct lttng_ht_node_str
*node
;
1455 struct lttng_ht_iter iter
;
1456 const char *config_domain_name
;
1461 ret
= config_writer_open_element(writer
,
1462 config_element_domain
);
1464 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1468 config_domain_name
= get_config_domain_str(domain
);
1469 if (!config_domain_name
) {
1470 ret
= LTTNG_ERR_INVALID
;
1474 ret
= config_writer_write_element_string(writer
,
1475 config_element_type
, config_domain_name
);
1477 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1481 buffer_type_string
= get_buffer_type_string(
1482 session
->ust_session
->buffer_type
);
1483 if (!buffer_type_string
) {
1484 ERR("Unsupported buffer type.");
1485 ret
= LTTNG_ERR_INVALID
;
1489 ret
= config_writer_write_element_string(writer
,
1490 config_element_buffer_type
, buffer_type_string
);
1492 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1496 ret
= config_writer_open_element(writer
, config_element_channels
);
1498 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1503 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
1504 &iter
.iter
, node
, node
) {
1505 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
1506 if (domain
== ust_chan
->domain
) {
1507 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
1517 ret
= config_writer_close_element(writer
);
1519 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1523 if (domain
== LTTNG_DOMAIN_UST
) {
1524 ret
= config_writer_open_element(writer
,
1525 config_element_trackers
);
1527 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1531 ret
= save_pid_tracker(writer
, session
, LTTNG_DOMAIN_UST
);
1537 ret
= config_writer_close_element(writer
);
1544 ret
= config_writer_close_element(writer
);
1546 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1555 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
1562 if (!session
->kernel_session
&& !session
->ust_session
) {
1566 ret
= config_writer_open_element(writer
, config_element_domains
);
1568 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1573 if (session
->kernel_session
) {
1574 ret
= config_writer_open_element(writer
,
1575 config_element_domain
);
1577 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1581 ret
= save_kernel_session(writer
, session
);
1586 ret
= config_writer_open_element(writer
,
1587 config_element_trackers
);
1589 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1593 ret
= save_pid_tracker(writer
, session
, LTTNG_DOMAIN_KERNEL
);
1599 ret
= config_writer_close_element(writer
);
1601 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1605 ret
= config_writer_close_element(writer
);
1607 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1612 if (session
->ust_session
) {
1613 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
1618 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
1623 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
1628 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
1635 ret
= config_writer_close_element(writer
);
1637 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1645 int save_consumer_output(struct config_writer
*writer
,
1646 struct consumer_output
*output
)
1653 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
1655 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1659 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1662 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1666 ret
= config_writer_open_element(writer
, config_element_destination
);
1668 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1672 switch (output
->type
) {
1673 case CONSUMER_DST_LOCAL
:
1674 ret
= config_writer_write_element_string(writer
,
1675 config_element_path
, output
->dst
.session_root_path
);
1677 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1681 case CONSUMER_DST_NET
:
1685 uri
= zmalloc(PATH_MAX
);
1687 ret
= LTTNG_ERR_NOMEM
;
1691 ret
= config_writer_open_element(writer
, config_element_net_output
);
1693 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1694 goto end_net_output
;
1697 if (output
->dst
.net
.control_isset
&&
1698 output
->dst
.net
.data_isset
) {
1699 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
1701 ret
= LTTNG_ERR_INVALID
;
1702 goto end_net_output
;
1705 ret
= config_writer_write_element_string(writer
,
1706 config_element_control_uri
, uri
);
1708 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1709 goto end_net_output
;
1712 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
1714 ret
= LTTNG_ERR_INVALID
;
1715 goto end_net_output
;
1718 ret
= config_writer_write_element_string(writer
,
1719 config_element_data_uri
, uri
);
1721 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1722 goto end_net_output
;
1731 ret
= !output
->dst
.net
.control_isset
?
1732 LTTNG_ERR_URL_CTRL_MISS
:
1733 LTTNG_ERR_URL_DATA_MISS
;
1738 ret
= config_writer_close_element(writer
);
1740 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1746 ERR("Unsupported consumer output type.");
1747 ret
= LTTNG_ERR_INVALID
;
1752 ret
= config_writer_close_element(writer
);
1754 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1758 /* /consumer_output */
1759 ret
= config_writer_close_element(writer
);
1761 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1769 int save_snapshot_outputs(struct config_writer
*writer
,
1770 struct snapshot
*snapshot
)
1773 struct lttng_ht_iter iter
;
1774 struct snapshot_output
*output
;
1779 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
1781 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1786 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
1788 ret
= config_writer_open_element(writer
,
1789 config_element_output
);
1791 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1795 ret
= config_writer_write_element_string(writer
,
1796 config_element_name
, output
->name
);
1798 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1802 ret
= config_writer_write_element_unsigned_int(writer
,
1803 config_element_max_size
, output
->max_size
);
1805 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1809 ret
= save_consumer_output(writer
, output
->consumer
);
1815 ret
= config_writer_close_element(writer
);
1817 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1823 /* /snapshot_outputs */
1824 ret
= config_writer_close_element(writer
);
1826 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1838 int save_session_output(struct config_writer
*writer
,
1839 struct ltt_session
*session
)
1846 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
1847 (!session
->snapshot_mode
&& !session
->consumer
)) {
1848 /* Session is in no output mode */
1853 ret
= config_writer_open_element(writer
, config_element_output
);
1855 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1859 if (session
->snapshot_mode
) {
1860 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
1865 if (session
->consumer
) {
1866 ret
= save_consumer_output(writer
, session
->consumer
);
1874 ret
= config_writer_close_element(writer
);
1876 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1884 * Save the given session.
1886 * Return 0 on success else a LTTNG_ERR* code.
1889 int save_session(struct ltt_session
*session
,
1890 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
1893 unsigned int file_opened
= 0; /* Indicate if the file has been opened */
1894 char config_file_path
[PATH_MAX
];
1896 struct config_writer
*writer
= NULL
;
1897 size_t session_name_len
;
1898 const char *provided_path
;
1904 session_name_len
= strlen(session
->name
);
1905 memset(config_file_path
, 0, sizeof(config_file_path
));
1907 if (!session_access_ok(session
,
1908 LTTNG_SOCK_GET_UID_CRED(creds
),
1909 LTTNG_SOCK_GET_GID_CRED(creds
))) {
1910 ret
= LTTNG_ERR_EPERM
;
1914 provided_path
= lttng_save_session_attr_get_output_url(attr
);
1915 if (provided_path
) {
1916 DBG3("Save session in provided path %s", provided_path
);
1917 len
= strlen(provided_path
);
1918 if (len
>= sizeof(config_file_path
)) {
1919 ret
= LTTNG_ERR_SET_URL
;
1922 strncpy(config_file_path
, provided_path
, len
);
1925 char *home_dir
= utils_get_user_home_dir(
1926 LTTNG_SOCK_GET_UID_CRED(creds
));
1928 ret
= LTTNG_ERR_SET_URL
;
1932 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
1933 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
1936 PERROR("snprintf save session");
1937 ret
= LTTNG_ERR_SET_URL
;
1944 * Check the path fits in the config file path dst including the '/'
1945 * followed by trailing .lttng extension and the NULL terminated string.
1947 if ((len
+ session_name_len
+ 2 +
1948 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
1949 > sizeof(config_file_path
)) {
1950 ret
= LTTNG_ERR_SET_URL
;
1954 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
1955 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
1957 ret
= LTTNG_ERR_SET_URL
;
1962 * At this point, we know that everything fits in the buffer. Validation
1963 * was done just above.
1965 config_file_path
[len
++] = '/';
1966 strncpy(config_file_path
+ len
, session
->name
, session_name_len
);
1967 len
+= session_name_len
;
1968 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
1969 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
1970 config_file_path
[len
] = '\0';
1972 if (!access(config_file_path
, F_OK
) && !attr
->overwrite
) {
1973 /* File exists, notify the user since the overwrite flag is off. */
1974 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
1978 fd
= run_as_open(config_file_path
, O_CREAT
| O_WRONLY
| O_TRUNC
,
1979 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
1980 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
1982 PERROR("Could not create configuration file");
1983 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1988 writer
= config_writer_create(fd
, 1);
1990 ret
= LTTNG_ERR_NOMEM
;
1994 ret
= config_writer_open_element(writer
, config_element_sessions
);
1996 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2000 ret
= config_writer_open_element(writer
, config_element_session
);
2002 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2006 ret
= config_writer_write_element_string(writer
, config_element_name
,
2009 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2013 if(session
->shm_path
[0] != '\0') {
2014 ret
= config_writer_write_element_string(writer
,
2015 config_element_shared_memory_path
,
2018 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2023 ret
= save_domains(writer
, session
);
2028 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2031 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2035 if (session
->snapshot_mode
|| session
->live_timer
||
2036 session
->rotate_timer_period
|| session
->rotate_size
) {
2037 ret
= config_writer_open_element(writer
, config_element_attributes
);
2039 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2043 if (session
->snapshot_mode
) {
2044 ret
= config_writer_write_element_bool(writer
,
2045 config_element_snapshot_mode
, 1);
2047 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2050 } else if (session
->live_timer
) {
2051 ret
= config_writer_write_element_unsigned_int(writer
,
2052 config_element_live_timer_interval
, session
->live_timer
);
2054 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2058 if (session
->rotate_timer_period
) {
2059 ret
= config_writer_write_element_unsigned_int(writer
,
2060 config_element_rotation_timer_interval
,
2061 session
->rotate_timer_period
);
2063 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2068 if (session
->rotate_size
) {
2069 ret
= config_writer_write_element_unsigned_int(writer
,
2070 config_element_rotation_size
,
2071 session
->rotate_size
);
2073 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2079 ret
= config_writer_close_element(writer
);
2081 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2086 ret
= save_session_output(writer
, session
);
2092 ret
= config_writer_close_element(writer
);
2094 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2099 ret
= config_writer_close_element(writer
);
2101 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2105 if (writer
&& config_writer_destroy(writer
)) {
2106 /* Preserve the original error code */
2107 ret
= ret
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2110 /* Delete file in case of error */
2111 if (file_opened
&& unlink(config_file_path
)) {
2112 PERROR("Unlinking XML session configuration.");
2119 PERROR("Closing XML session configuration");
2126 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2127 lttng_sock_cred
*creds
)
2130 const char *session_name
;
2131 struct ltt_session
*session
;
2133 session_lock_list();
2135 session_name
= lttng_save_session_attr_get_session_name(attr
);
2137 session
= session_find_by_name(session_name
);
2139 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2143 session_lock(session
);
2144 ret
= save_session(session
, attr
, creds
);
2145 session_unlock(session
);
2150 struct ltt_session_list
*list
= session_get_list();
2152 cds_list_for_each_entry(session
, &list
->head
, list
) {
2153 session_lock(session
);
2154 ret
= save_session(session
, attr
, creds
);
2155 session_unlock(session
);
2157 /* Don't abort if we don't have the required permissions. */
2158 if (ret
&& ret
!= LTTNG_ERR_EPERM
) {
2166 session_unlock_list();