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
;
288 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
289 context_type_string
= config_event_context_callstack_user
;
291 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
292 context_type_string
= config_event_context_callstack_kernel
;
295 context_type_string
= NULL
;
298 return context_type_string
;
302 const char *get_ust_context_type_string(
303 enum lttng_ust_context_type context_type
)
305 const char *context_type_string
;
307 switch (context_type
) {
308 case LTTNG_UST_CONTEXT_PROCNAME
:
309 context_type_string
= config_event_context_procname
;
311 case LTTNG_UST_CONTEXT_VPID
:
312 context_type_string
= config_event_context_vpid
;
314 case LTTNG_UST_CONTEXT_VTID
:
315 context_type_string
= config_event_context_vtid
;
317 case LTTNG_UST_CONTEXT_IP
:
318 context_type_string
= config_event_context_ip
;
320 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
321 context_type_string
= config_event_context_pthread_id
;
323 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
324 context_type_string
= config_event_context_app
;
326 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
328 * Error, should not be stored in the XML, perf contexts
329 * are stored as a node of type event_perf_context_type.
332 context_type_string
= NULL
;
336 return context_type_string
;
340 const char *get_buffer_type_string(
341 enum lttng_buffer_type buffer_type
)
343 const char *buffer_type_string
;
345 switch (buffer_type
) {
346 case LTTNG_BUFFER_PER_PID
:
347 buffer_type_string
= config_buffer_type_per_pid
;
349 case LTTNG_BUFFER_PER_UID
:
350 buffer_type_string
= config_buffer_type_per_uid
;
352 case LTTNG_BUFFER_GLOBAL
:
353 buffer_type_string
= config_buffer_type_global
;
356 buffer_type_string
= NULL
;
359 return buffer_type_string
;
363 const char *get_loglevel_type_string(
364 enum lttng_ust_loglevel_type loglevel_type
)
366 const char *loglevel_type_string
;
368 switch (loglevel_type
) {
369 case LTTNG_UST_LOGLEVEL_ALL
:
370 loglevel_type_string
= config_loglevel_type_all
;
372 case LTTNG_UST_LOGLEVEL_RANGE
:
373 loglevel_type_string
= config_loglevel_type_range
;
375 case LTTNG_UST_LOGLEVEL_SINGLE
:
376 loglevel_type_string
= config_loglevel_type_single
;
379 loglevel_type_string
= NULL
;
382 return loglevel_type_string
;
386 int save_kernel_event(struct config_writer
*writer
,
387 struct ltt_kernel_event
*event
)
390 const char *instrumentation_type
;
392 ret
= config_writer_open_element(writer
, config_element_event
);
394 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
398 if (event
->event
->name
[0]) {
399 ret
= config_writer_write_element_string(writer
,
400 config_element_name
, event
->event
->name
);
402 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
407 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
410 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
414 instrumentation_type
= get_kernel_instrumentation_string(
415 event
->event
->instrumentation
);
416 if (!instrumentation_type
) {
417 ret
= LTTNG_ERR_INVALID
;
421 ret
= config_writer_write_element_string(writer
, config_element_type
,
422 instrumentation_type
);
424 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
428 if (event
->filter_expression
) {
429 ret
= config_writer_write_element_string(writer
,
430 config_element_filter
,
431 event
->filter_expression
);
433 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
438 if (event
->event
->instrumentation
== LTTNG_KERNEL_FUNCTION
||
439 event
->event
->instrumentation
== LTTNG_KERNEL_KPROBE
||
440 event
->event
->instrumentation
== LTTNG_KERNEL_KRETPROBE
) {
442 ret
= config_writer_open_element(writer
,
443 config_element_attributes
);
445 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
449 switch (event
->event
->instrumentation
) {
450 case LTTNG_KERNEL_SYSCALL
:
451 case LTTNG_KERNEL_FUNCTION
:
452 ret
= config_writer_open_element(writer
,
453 config_element_function_attributes
);
455 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
459 ret
= config_writer_write_element_string(writer
,
461 event
->event
->u
.ftrace
.symbol_name
);
463 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
467 /* /function attributes */
468 ret
= config_writer_close_element(writer
);
470 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
474 case LTTNG_KERNEL_KPROBE
:
475 case LTTNG_KERNEL_KRETPROBE
:
477 const char *symbol_name
;
481 if (event
->event
->instrumentation
==
482 LTTNG_KERNEL_KPROBE
) {
484 * Comments in lttng-kernel.h mention that
485 * either addr or symbol_name are set, not both.
487 addr
= event
->event
->u
.kprobe
.addr
;
488 offset
= event
->event
->u
.kprobe
.offset
;
489 symbol_name
= addr
? NULL
:
490 event
->event
->u
.kprobe
.symbol_name
;
493 event
->event
->u
.kretprobe
.symbol_name
;
494 addr
= event
->event
->u
.kretprobe
.addr
;
495 offset
= event
->event
->u
.kretprobe
.offset
;
498 ret
= config_writer_open_element(writer
,
499 config_element_probe_attributes
);
501 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
506 ret
= config_writer_write_element_string(writer
,
507 config_element_symbol_name
,
510 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
516 ret
= config_writer_write_element_unsigned_int(
517 writer
, config_element_address
, addr
);
519 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
525 ret
= config_writer_write_element_unsigned_int(
526 writer
, config_element_offset
, offset
);
528 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
533 ret
= config_writer_close_element(writer
);
535 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
541 ERR("Unsupported kernel instrumentation type.");
542 ret
= LTTNG_ERR_INVALID
;
547 ret
= config_writer_close_element(writer
);
549 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
555 ret
= config_writer_close_element(writer
);
557 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
565 int save_kernel_events(struct config_writer
*writer
,
566 struct ltt_kernel_channel
*kchan
)
569 struct ltt_kernel_event
*event
;
571 ret
= config_writer_open_element(writer
, config_element_events
);
573 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
577 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
578 ret
= save_kernel_event(writer
, event
);
585 ret
= config_writer_close_element(writer
);
587 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
595 int save_ust_event(struct config_writer
*writer
,
596 struct ltt_ust_event
*event
)
599 const char *loglevel_type_string
;
601 ret
= config_writer_open_element(writer
, config_element_event
);
603 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
607 if (event
->attr
.name
[0]) {
608 ret
= config_writer_write_element_string(writer
,
609 config_element_name
, event
->attr
.name
);
611 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
616 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
619 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
623 if (event
->attr
.instrumentation
!= LTTNG_UST_TRACEPOINT
) {
624 ERR("Unsupported UST instrumentation type.");
625 ret
= LTTNG_ERR_INVALID
;
628 ret
= config_writer_write_element_string(writer
, config_element_type
,
629 config_event_type_tracepoint
);
631 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
635 loglevel_type_string
= get_loglevel_type_string(
636 event
->attr
.loglevel_type
);
637 if (!loglevel_type_string
) {
638 ERR("Unsupported UST loglevel type.");
639 ret
= LTTNG_ERR_INVALID
;
643 ret
= config_writer_write_element_string(writer
,
644 config_element_loglevel_type
, loglevel_type_string
);
646 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
650 /* The log level is irrelevant if no "filtering" is enabled */
651 if (event
->attr
.loglevel_type
!= LTTNG_UST_LOGLEVEL_ALL
) {
652 ret
= config_writer_write_element_signed_int(writer
,
653 config_element_loglevel
, event
->attr
.loglevel
);
655 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
660 if (event
->filter_expression
) {
661 ret
= config_writer_write_element_string(writer
,
662 config_element_filter
, event
->filter_expression
);
664 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
669 if (event
->exclusion
&& event
->exclusion
->count
) {
672 ret
= config_writer_open_element(writer
,
673 config_element_exclusions
);
675 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
679 for (i
= 0; i
< event
->exclusion
->count
; i
++) {
680 ret
= config_writer_write_element_string(writer
,
681 config_element_exclusion
,
682 LTTNG_EVENT_EXCLUSION_NAME_AT(
683 event
->exclusion
, i
));
685 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
691 ret
= config_writer_close_element(writer
);
693 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
699 ret
= config_writer_close_element(writer
);
701 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
709 int save_ust_events(struct config_writer
*writer
,
710 struct lttng_ht
*events
)
713 struct ltt_ust_event
*event
;
714 struct lttng_ht_node_str
*node
;
715 struct lttng_ht_iter iter
;
717 ret
= config_writer_open_element(writer
, config_element_events
);
719 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
724 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
725 event
= caa_container_of(node
, struct ltt_ust_event
, node
);
727 if (event
->internal
) {
728 /* Internal events must not be exposed to clients */
731 ret
= save_ust_event(writer
, event
);
740 ret
= config_writer_close_element(writer
);
742 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
750 int init_ust_event_from_agent_event(struct ltt_ust_event
*ust_event
,
751 struct agent_event
*agent_event
)
754 enum lttng_ust_loglevel_type ust_loglevel_type
;
756 ust_event
->enabled
= agent_event
->enabled
;
757 ust_event
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
758 if (lttng_strncpy(ust_event
->attr
.name
, agent_event
->name
,
759 LTTNG_SYMBOL_NAME_LEN
)) {
763 switch (agent_event
->loglevel_type
) {
764 case LTTNG_EVENT_LOGLEVEL_ALL
:
765 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
767 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
768 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
770 case LTTNG_EVENT_LOGLEVEL_RANGE
:
771 ust_loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
774 ERR("Invalid agent_event loglevel_type.");
779 ust_event
->attr
.loglevel_type
= ust_loglevel_type
;
780 ust_event
->attr
.loglevel
= agent_event
->loglevel_value
;
781 ust_event
->filter_expression
= agent_event
->filter_expression
;
782 ust_event
->exclusion
= agent_event
->exclusion
;
788 int save_agent_events(struct config_writer
*writer
,
792 struct lttng_ht_iter iter
;
793 struct lttng_ht_node_str
*node
;
795 ret
= config_writer_open_element(writer
, config_element_events
);
797 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
802 cds_lfht_for_each_entry(agent
->events
->ht
, &iter
.iter
, node
, node
) {
804 struct agent_event
*agent_event
;
805 struct ltt_ust_event fake_event
;
807 memset(&fake_event
, 0, sizeof(fake_event
));
808 agent_event
= caa_container_of(node
, struct agent_event
, node
);
811 * Initialize a fake ust event to reuse the same serialization
812 * function since UST and agent events contain the same info
813 * (and one could wonder why they don't reuse the same
816 ret
= init_ust_event_from_agent_event(&fake_event
, agent_event
);
821 ret
= save_ust_event(writer
, &fake_event
);
830 ret
= config_writer_close_element(writer
);
832 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
840 int save_kernel_context(struct config_writer
*writer
,
841 struct lttng_kernel_context
*ctx
)
849 ret
= config_writer_open_element(writer
, config_element_context
);
851 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
855 if (ctx
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER
) {
856 ret
= config_writer_open_element(writer
,
857 config_element_context_perf
);
859 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
863 ret
= config_writer_write_element_unsigned_int(writer
,
864 config_element_type
, ctx
->u
.perf_counter
.type
);
866 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
870 ret
= config_writer_write_element_unsigned_int(writer
,
871 config_element_config
, ctx
->u
.perf_counter
.config
);
873 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
877 ret
= config_writer_write_element_string(writer
,
878 config_element_name
, ctx
->u
.perf_counter
.name
);
880 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
885 ret
= config_writer_close_element(writer
);
887 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
891 const char *context_type_string
=
892 get_kernel_context_type_string(ctx
->ctx
);
894 if (!context_type_string
) {
895 ERR("Unsupported kernel context type.");
896 ret
= LTTNG_ERR_INVALID
;
900 ret
= config_writer_write_element_string(writer
,
901 config_element_type
, context_type_string
);
903 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
909 ret
= config_writer_close_element(writer
);
911 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
920 int save_kernel_contexts(struct config_writer
*writer
,
921 struct ltt_kernel_channel
*kchan
)
924 struct ltt_kernel_context
*ctx
;
926 if (cds_list_empty(&kchan
->ctx_list
)) {
931 ret
= config_writer_open_element(writer
, config_element_contexts
);
933 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
937 cds_list_for_each_entry(ctx
, &kchan
->ctx_list
, list
) {
938 ret
= save_kernel_context(writer
, &ctx
->ctx
);
945 ret
= config_writer_close_element(writer
);
947 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
955 int save_ust_context_perf_thread_counter(struct config_writer
*writer
,
956 struct ltt_ust_context
*ctx
)
963 /* Perf contexts are saved as event_perf_context_type */
964 ret
= config_writer_open_element(writer
, config_element_context_perf
);
966 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
970 ret
= config_writer_write_element_unsigned_int(writer
,
971 config_element_type
, ctx
->ctx
.u
.perf_counter
.type
);
973 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
977 ret
= config_writer_write_element_unsigned_int(writer
,
978 config_element_config
, ctx
->ctx
.u
.perf_counter
.config
);
980 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
984 ret
= config_writer_write_element_string(writer
, config_element_name
,
985 ctx
->ctx
.u
.perf_counter
.name
);
987 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
992 ret
= config_writer_close_element(writer
);
994 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1002 int save_ust_context_app_ctx(struct config_writer
*writer
,
1003 struct ltt_ust_context
*ctx
)
1010 /* Application contexts are saved as application_context_type */
1011 ret
= config_writer_open_element(writer
, config_element_context_app
);
1013 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1017 ret
= config_writer_write_element_string(writer
,
1018 config_element_context_app_provider_name
,
1019 ctx
->ctx
.u
.app_ctx
.provider_name
);
1021 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1025 ret
= config_writer_write_element_string(writer
,
1026 config_element_context_app_ctx_name
,
1027 ctx
->ctx
.u
.app_ctx
.ctx_name
);
1029 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1034 ret
= config_writer_close_element(writer
);
1036 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1044 int save_ust_context_generic(struct config_writer
*writer
,
1045 struct ltt_ust_context
*ctx
)
1048 const char *context_type_string
;
1053 /* Save context as event_context_type_type */
1054 context_type_string
= get_ust_context_type_string(
1056 if (!context_type_string
) {
1057 ERR("Unsupported UST context type.");
1058 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1062 ret
= config_writer_write_element_string(writer
,
1063 config_element_type
, context_type_string
);
1065 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1073 int save_ust_context(struct config_writer
*writer
,
1074 struct cds_list_head
*ctx_list
)
1077 struct ltt_ust_context
*ctx
;
1082 ret
= config_writer_open_element(writer
, config_element_contexts
);
1084 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1088 cds_list_for_each_entry(ctx
, ctx_list
, list
) {
1089 ret
= config_writer_open_element(writer
,
1090 config_element_context
);
1092 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1096 switch (ctx
->ctx
.ctx
) {
1097 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1098 ret
= save_ust_context_perf_thread_counter(writer
, ctx
);
1100 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1101 ret
= save_ust_context_app_ctx(writer
, ctx
);
1104 /* Save generic context. */
1105 ret
= save_ust_context_generic(writer
, ctx
);
1112 ret
= config_writer_close_element(writer
);
1114 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1120 ret
= config_writer_close_element(writer
);
1122 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1130 int save_kernel_channel(struct config_writer
*writer
,
1131 struct ltt_kernel_channel
*kchan
)
1138 ret
= config_writer_open_element(writer
, config_element_channel
);
1140 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1144 ret
= config_writer_write_element_string(writer
, config_element_name
,
1145 kchan
->channel
->name
);
1147 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1151 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1152 kchan
->channel
->enabled
);
1154 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1158 ret
= save_kernel_channel_attributes(writer
, &kchan
->channel
->attr
);
1163 ret
= save_kernel_events(writer
, kchan
);
1168 ret
= save_kernel_contexts(writer
, kchan
);
1174 ret
= config_writer_close_element(writer
);
1176 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1184 int save_ust_channel(struct config_writer
*writer
,
1185 struct ltt_ust_channel
*ust_chan
,
1186 struct ltt_ust_session
*session
)
1194 ret
= config_writer_open_element(writer
, config_element_channel
);
1196 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1200 ret
= config_writer_write_element_string(writer
, config_element_name
,
1203 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1207 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1210 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1214 ret
= save_ust_channel_attributes(writer
, &ust_chan
->attr
);
1219 ret
= config_writer_write_element_unsigned_int(writer
,
1220 config_element_tracefile_size
, ust_chan
->tracefile_size
);
1222 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1226 ret
= config_writer_write_element_unsigned_int(writer
,
1227 config_element_tracefile_count
, ust_chan
->tracefile_count
);
1229 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1233 ret
= config_writer_write_element_unsigned_int(writer
,
1234 config_element_live_timer_interval
,
1235 session
->live_timer_interval
);
1237 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1241 if (ust_chan
->domain
== LTTNG_DOMAIN_UST
) {
1242 ret
= save_ust_events(writer
, ust_chan
->events
);
1247 struct agent
*agent
= NULL
;
1249 agent
= trace_ust_find_agent(session
, ust_chan
->domain
);
1251 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1252 ERR("Could not find agent associated to UST subdomain");
1257 * Channels associated with a UST sub-domain (such as JUL, Log4j
1258 * or Python) don't have any non-internal events. We retrieve
1259 * the "agent" events associated with this channel and serialize
1262 ret
= save_agent_events(writer
, agent
);
1268 ret
= save_ust_context(writer
, &ust_chan
->ctx_list
);
1274 ret
= config_writer_close_element(writer
);
1276 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1284 int save_kernel_session(struct config_writer
*writer
,
1285 struct ltt_session
*session
)
1288 struct ltt_kernel_channel
*kchan
;
1293 ret
= config_writer_write_element_string(writer
, config_element_type
,
1294 config_domain_type_kernel
);
1296 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1300 ret
= config_writer_write_element_string(writer
,
1301 config_element_buffer_type
, config_buffer_type_global
);
1303 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1307 ret
= config_writer_open_element(writer
,
1308 config_element_channels
);
1310 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1314 cds_list_for_each_entry(kchan
, &session
->kernel_session
->channel_list
.head
,
1316 ret
= save_kernel_channel(writer
, kchan
);
1323 ret
= config_writer_close_element(writer
);
1325 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1333 const char *get_config_domain_str(enum lttng_domain_type domain
)
1335 const char *str_dom
;
1338 case LTTNG_DOMAIN_KERNEL
:
1339 str_dom
= config_domain_type_kernel
;
1341 case LTTNG_DOMAIN_UST
:
1342 str_dom
= config_domain_type_ust
;
1344 case LTTNG_DOMAIN_JUL
:
1345 str_dom
= config_domain_type_jul
;
1347 case LTTNG_DOMAIN_LOG4J
:
1348 str_dom
= config_domain_type_log4j
;
1350 case LTTNG_DOMAIN_PYTHON
:
1351 str_dom
= config_domain_type_python
;
1361 int save_pid_tracker(struct config_writer
*writer
,
1362 struct ltt_session
*sess
, int domain
)
1365 ssize_t nr_pids
= 0, i
;
1366 int32_t *pids
= NULL
;
1369 case LTTNG_DOMAIN_KERNEL
:
1371 nr_pids
= kernel_list_tracker_pids(sess
->kernel_session
, &pids
);
1373 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
1378 case LTTNG_DOMAIN_UST
:
1380 nr_pids
= trace_ust_list_tracker_pids(sess
->ust_session
, &pids
);
1382 ret
= LTTNG_ERR_UST_LIST_FAIL
;
1387 case LTTNG_DOMAIN_JUL
:
1388 case LTTNG_DOMAIN_LOG4J
:
1389 case LTTNG_DOMAIN_PYTHON
:
1391 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1395 /* Only create a pid_tracker if enabled or untrack all */
1396 if (nr_pids
!= 1 || (nr_pids
== 1 && pids
[0] != -1)) {
1397 ret
= config_writer_open_element(writer
,
1398 config_element_pid_tracker
);
1400 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1404 ret
= config_writer_open_element(writer
,
1405 config_element_targets
);
1407 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1411 for (i
= 0; i
< nr_pids
; i
++) {
1412 ret
= config_writer_open_element(writer
,
1413 config_element_target_pid
);
1415 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1419 ret
= config_writer_write_element_unsigned_int(writer
,
1420 config_element_pid
, pids
[i
]);
1422 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1427 ret
= config_writer_close_element(writer
);
1429 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1435 ret
= config_writer_close_element(writer
);
1437 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1442 ret
= config_writer_close_element(writer
);
1444 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1454 int save_ust_domain(struct config_writer
*writer
,
1455 struct ltt_session
*session
, enum lttng_domain_type domain
)
1458 struct ltt_ust_channel
*ust_chan
;
1459 const char *buffer_type_string
;
1460 struct lttng_ht_node_str
*node
;
1461 struct lttng_ht_iter iter
;
1462 const char *config_domain_name
;
1467 ret
= config_writer_open_element(writer
,
1468 config_element_domain
);
1470 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1474 config_domain_name
= get_config_domain_str(domain
);
1475 if (!config_domain_name
) {
1476 ret
= LTTNG_ERR_INVALID
;
1480 ret
= config_writer_write_element_string(writer
,
1481 config_element_type
, config_domain_name
);
1483 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1487 buffer_type_string
= get_buffer_type_string(
1488 session
->ust_session
->buffer_type
);
1489 if (!buffer_type_string
) {
1490 ERR("Unsupported buffer type.");
1491 ret
= LTTNG_ERR_INVALID
;
1495 ret
= config_writer_write_element_string(writer
,
1496 config_element_buffer_type
, buffer_type_string
);
1498 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1502 ret
= config_writer_open_element(writer
, config_element_channels
);
1504 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1509 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
1510 &iter
.iter
, node
, node
) {
1511 ust_chan
= caa_container_of(node
, struct ltt_ust_channel
, node
);
1512 if (domain
== ust_chan
->domain
) {
1513 ret
= save_ust_channel(writer
, ust_chan
, session
->ust_session
);
1523 ret
= config_writer_close_element(writer
);
1525 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1529 if (domain
== LTTNG_DOMAIN_UST
) {
1530 ret
= config_writer_open_element(writer
,
1531 config_element_trackers
);
1533 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1537 ret
= save_pid_tracker(writer
, session
, LTTNG_DOMAIN_UST
);
1543 ret
= config_writer_close_element(writer
);
1550 ret
= config_writer_close_element(writer
);
1552 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1561 int save_domains(struct config_writer
*writer
, struct ltt_session
*session
)
1568 if (!session
->kernel_session
&& !session
->ust_session
) {
1572 ret
= config_writer_open_element(writer
, config_element_domains
);
1574 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1579 if (session
->kernel_session
) {
1580 ret
= config_writer_open_element(writer
,
1581 config_element_domain
);
1583 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1587 ret
= save_kernel_session(writer
, session
);
1592 ret
= config_writer_open_element(writer
,
1593 config_element_trackers
);
1595 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1599 ret
= save_pid_tracker(writer
, session
, LTTNG_DOMAIN_KERNEL
);
1605 ret
= config_writer_close_element(writer
);
1607 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1611 ret
= config_writer_close_element(writer
);
1613 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1618 if (session
->ust_session
) {
1619 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_UST
);
1624 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_JUL
);
1629 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_LOG4J
);
1634 ret
= save_ust_domain(writer
, session
, LTTNG_DOMAIN_PYTHON
);
1641 ret
= config_writer_close_element(writer
);
1643 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1651 int save_consumer_output(struct config_writer
*writer
,
1652 struct consumer_output
*output
)
1659 ret
= config_writer_open_element(writer
, config_element_consumer_output
);
1661 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1665 ret
= config_writer_write_element_bool(writer
, config_element_enabled
,
1668 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1672 ret
= config_writer_open_element(writer
, config_element_destination
);
1674 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1678 switch (output
->type
) {
1679 case CONSUMER_DST_LOCAL
:
1680 ret
= config_writer_write_element_string(writer
,
1681 config_element_path
, output
->dst
.session_root_path
);
1683 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1687 case CONSUMER_DST_NET
:
1691 uri
= zmalloc(PATH_MAX
);
1693 ret
= LTTNG_ERR_NOMEM
;
1697 ret
= config_writer_open_element(writer
, config_element_net_output
);
1699 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1700 goto end_net_output
;
1703 if (output
->dst
.net
.control_isset
&&
1704 output
->dst
.net
.data_isset
) {
1705 ret
= uri_to_str_url(&output
->dst
.net
.control
, uri
, PATH_MAX
);
1707 ret
= LTTNG_ERR_INVALID
;
1708 goto end_net_output
;
1711 ret
= config_writer_write_element_string(writer
,
1712 config_element_control_uri
, uri
);
1714 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1715 goto end_net_output
;
1718 ret
= uri_to_str_url(&output
->dst
.net
.data
, uri
, PATH_MAX
);
1720 ret
= LTTNG_ERR_INVALID
;
1721 goto end_net_output
;
1724 ret
= config_writer_write_element_string(writer
,
1725 config_element_data_uri
, uri
);
1727 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1728 goto end_net_output
;
1737 ret
= !output
->dst
.net
.control_isset
?
1738 LTTNG_ERR_URL_CTRL_MISS
:
1739 LTTNG_ERR_URL_DATA_MISS
;
1744 ret
= config_writer_close_element(writer
);
1746 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1752 ERR("Unsupported consumer output type.");
1753 ret
= LTTNG_ERR_INVALID
;
1758 ret
= config_writer_close_element(writer
);
1760 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1764 /* /consumer_output */
1765 ret
= config_writer_close_element(writer
);
1767 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1775 int save_snapshot_outputs(struct config_writer
*writer
,
1776 struct snapshot
*snapshot
)
1779 struct lttng_ht_iter iter
;
1780 struct snapshot_output
*output
;
1785 ret
= config_writer_open_element(writer
, config_element_snapshot_outputs
);
1787 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1792 cds_lfht_for_each_entry(snapshot
->output_ht
->ht
, &iter
.iter
, output
,
1794 ret
= config_writer_open_element(writer
,
1795 config_element_output
);
1797 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1801 ret
= config_writer_write_element_string(writer
,
1802 config_element_name
, output
->name
);
1804 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1808 ret
= config_writer_write_element_unsigned_int(writer
,
1809 config_element_max_size
, output
->max_size
);
1811 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1815 ret
= save_consumer_output(writer
, output
->consumer
);
1821 ret
= config_writer_close_element(writer
);
1823 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1829 /* /snapshot_outputs */
1830 ret
= config_writer_close_element(writer
);
1832 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1844 int save_session_output(struct config_writer
*writer
,
1845 struct ltt_session
*session
)
1852 if ((session
->snapshot_mode
&& session
->snapshot
.nb_output
== 0) ||
1853 (!session
->snapshot_mode
&& !session
->consumer
)) {
1854 /* Session is in no output mode */
1859 ret
= config_writer_open_element(writer
, config_element_output
);
1861 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1865 if (session
->snapshot_mode
) {
1866 ret
= save_snapshot_outputs(writer
, &session
->snapshot
);
1871 if (session
->consumer
) {
1872 ret
= save_consumer_output(writer
, session
->consumer
);
1880 ret
= config_writer_close_element(writer
);
1882 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1890 int save_session_rotation_schedule(struct config_writer
*writer
,
1891 enum lttng_rotation_schedule_type type
, uint64_t value
)
1894 const char *element_name
;
1895 const char *value_name
;
1898 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1899 element_name
= config_element_rotation_schedule_periodic
;
1900 value_name
= config_element_rotation_schedule_periodic_time_us
;
1902 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1903 element_name
= config_element_rotation_schedule_size_threshold
;
1904 value_name
= config_element_rotation_schedule_size_threshold_bytes
;
1911 ret
= config_writer_open_element(writer
, element_name
);
1916 ret
= config_writer_write_element_unsigned_int(writer
,
1922 /* Close schedule descriptor element. */
1923 ret
= config_writer_close_element(writer
);
1932 int save_session_rotation_schedules(struct config_writer
*writer
,
1933 struct ltt_session
*session
)
1937 ret
= config_writer_open_element(writer
,
1938 config_element_rotation_schedules
);
1939 if (session
->rotate_timer_period
) {
1940 ret
= save_session_rotation_schedule(writer
,
1941 LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
,
1942 session
->rotate_timer_period
);
1944 goto close_schedules
;
1947 if (session
->rotate_size
) {
1948 ret
= save_session_rotation_schedule(writer
,
1949 LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
,
1950 session
->rotate_size
);
1952 goto close_schedules
;
1957 /* Close rotation schedules element. */
1958 ret
= config_writer_close_element(writer
);
1967 * Save the given session.
1969 * Return 0 on success else a LTTNG_ERR* code.
1972 int save_session(struct ltt_session
*session
,
1973 struct lttng_save_session_attr
*attr
, lttng_sock_cred
*creds
)
1976 unsigned int file_opened
= 0; /* Indicate if the file has been opened */
1977 char config_file_path
[PATH_MAX
];
1979 struct config_writer
*writer
= NULL
;
1980 size_t session_name_len
;
1981 const char *provided_path
;
1987 session_name_len
= strlen(session
->name
);
1988 memset(config_file_path
, 0, sizeof(config_file_path
));
1990 if (!session_access_ok(session
,
1991 LTTNG_SOCK_GET_UID_CRED(creds
),
1992 LTTNG_SOCK_GET_GID_CRED(creds
))) {
1993 ret
= LTTNG_ERR_EPERM
;
1997 provided_path
= lttng_save_session_attr_get_output_url(attr
);
1998 if (provided_path
) {
1999 DBG3("Save session in provided path %s", provided_path
);
2000 len
= strlen(provided_path
);
2001 if (len
>= sizeof(config_file_path
)) {
2002 ret
= LTTNG_ERR_SET_URL
;
2005 strncpy(config_file_path
, provided_path
, len
);
2008 char *home_dir
= utils_get_user_home_dir(
2009 LTTNG_SOCK_GET_UID_CRED(creds
));
2011 ret
= LTTNG_ERR_SET_URL
;
2015 ret_len
= snprintf(config_file_path
, sizeof(config_file_path
),
2016 DEFAULT_SESSION_HOME_CONFIGPATH
, home_dir
);
2019 PERROR("snprintf save session");
2020 ret
= LTTNG_ERR_SET_URL
;
2027 * Check the path fits in the config file path dst including the '/'
2028 * followed by trailing .lttng extension and the NULL terminated string.
2030 if ((len
+ session_name_len
+ 2 +
2031 sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
))
2032 > sizeof(config_file_path
)) {
2033 ret
= LTTNG_ERR_SET_URL
;
2037 ret
= run_as_mkdir_recursive(config_file_path
, S_IRWXU
| S_IRWXG
,
2038 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2040 ret
= LTTNG_ERR_SET_URL
;
2045 * At this point, we know that everything fits in the buffer. Validation
2046 * was done just above.
2048 config_file_path
[len
++] = '/';
2049 strncpy(config_file_path
+ len
, session
->name
, session_name_len
);
2050 len
+= session_name_len
;
2051 strcpy(config_file_path
+ len
, DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2052 len
+= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION
);
2053 config_file_path
[len
] = '\0';
2055 if (!access(config_file_path
, F_OK
) && !attr
->overwrite
) {
2056 /* File exists, notify the user since the overwrite flag is off. */
2057 ret
= LTTNG_ERR_SAVE_FILE_EXIST
;
2061 fd
= run_as_open(config_file_path
, O_CREAT
| O_WRONLY
| O_TRUNC
,
2062 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
,
2063 LTTNG_SOCK_GET_UID_CRED(creds
), LTTNG_SOCK_GET_GID_CRED(creds
));
2065 PERROR("Could not create configuration file");
2066 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2071 writer
= config_writer_create(fd
, 1);
2073 ret
= LTTNG_ERR_NOMEM
;
2077 ret
= config_writer_open_element(writer
, config_element_sessions
);
2079 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2083 ret
= config_writer_open_element(writer
, config_element_session
);
2085 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2089 ret
= config_writer_write_element_string(writer
, config_element_name
,
2092 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2096 if(session
->shm_path
[0] != '\0') {
2097 ret
= config_writer_write_element_string(writer
,
2098 config_element_shared_memory_path
,
2101 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2106 ret
= save_domains(writer
, session
);
2111 ret
= config_writer_write_element_bool(writer
, config_element_started
,
2114 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2118 if (session
->snapshot_mode
|| session
->live_timer
||
2119 session
->rotate_timer_period
|| session
->rotate_size
) {
2120 ret
= config_writer_open_element(writer
, config_element_attributes
);
2122 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2126 if (session
->snapshot_mode
) {
2127 ret
= config_writer_write_element_bool(writer
,
2128 config_element_snapshot_mode
, 1);
2130 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2133 } else if (session
->live_timer
) {
2134 ret
= config_writer_write_element_unsigned_int(writer
,
2135 config_element_live_timer_interval
, session
->live_timer
);
2137 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2141 if (session
->rotate_timer_period
|| session
->rotate_size
) {
2142 ret
= save_session_rotation_schedules(writer
,
2145 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2151 ret
= config_writer_close_element(writer
);
2153 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2158 ret
= save_session_output(writer
, session
);
2164 ret
= config_writer_close_element(writer
);
2166 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2171 ret
= config_writer_close_element(writer
);
2173 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
2177 if (writer
&& config_writer_destroy(writer
)) {
2178 /* Preserve the original error code */
2179 ret
= ret
? ret
: LTTNG_ERR_SAVE_IO_FAIL
;
2182 /* Delete file in case of error */
2183 if (file_opened
&& unlink(config_file_path
)) {
2184 PERROR("Unlinking XML session configuration.");
2191 PERROR("Closing XML session configuration");
2198 int cmd_save_sessions(struct lttng_save_session_attr
*attr
,
2199 lttng_sock_cred
*creds
)
2202 const char *session_name
;
2203 struct ltt_session
*session
;
2205 session_lock_list();
2207 session_name
= lttng_save_session_attr_get_session_name(attr
);
2209 session
= session_find_by_name(session_name
);
2211 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
2215 session_lock(session
);
2216 ret
= save_session(session
, attr
, creds
);
2217 session_unlock(session
);
2222 struct ltt_session_list
*list
= session_get_list();
2224 cds_list_for_each_entry(session
, &list
->head
, list
) {
2225 session_lock(session
);
2226 ret
= save_session(session
, attr
, creds
);
2227 session_unlock(session
);
2229 /* Don't abort if we don't have the required permissions. */
2230 if (ret
&& ret
!= LTTNG_ERR_EPERM
) {
2238 session_unlock_list();