2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
11 #include <lttng/lttng-error.h>
12 #include <lttng/save.h>
13 #include <lttng/save-internal.hpp>
14 #include <common/sessiond-comm/sessiond-comm.hpp>
16 #include "lttng-ctl-helper.hpp"
18 struct lttng_save_session_attr
*lttng_save_session_attr_create(void)
20 return zmalloc
<lttng_save_session_attr
>();
23 void lttng_save_session_attr_destroy(struct lttng_save_session_attr
*output
)
30 const char *lttng_save_session_attr_get_session_name(
31 struct lttng_save_session_attr
*attr
)
33 const char *ret
= NULL
;
35 if (attr
&& attr
->session_name
[0]) {
36 ret
= attr
->session_name
;
42 const char *lttng_save_session_attr_get_output_url(
43 struct lttng_save_session_attr
*attr
)
45 const char *ret
= NULL
;
47 if (attr
&& attr
->configuration_url
[0]) {
48 ret
= attr
->configuration_url
;
54 int lttng_save_session_attr_get_overwrite(
55 struct lttng_save_session_attr
*attr
)
57 return attr
? attr
->overwrite
: -LTTNG_ERR_INVALID
;
60 int lttng_save_session_attr_get_omit_name(
61 struct lttng_save_session_attr
*attr
)
63 return attr
? attr
->omit_name
: -LTTNG_ERR_INVALID
;
66 int lttng_save_session_attr_get_omit_output(
67 struct lttng_save_session_attr
*attr
)
69 return attr
? attr
->omit_output
: -LTTNG_ERR_INVALID
;
72 int lttng_save_session_attr_set_session_name(
73 struct lttng_save_session_attr
*attr
, const char *session_name
)
78 ret
= -LTTNG_ERR_INVALID
;
85 len
= strlen(session_name
);
86 if (len
>= LTTNG_NAME_MAX
) {
87 ret
= -LTTNG_ERR_INVALID
;
91 ret
= lttng_strncpy(attr
->session_name
, session_name
,
92 sizeof(attr
->session_name
));
94 ret
= -LTTNG_ERR_INVALID
;
98 attr
->session_name
[0] = '\0';
104 int lttng_save_session_attr_set_output_url(
105 struct lttng_save_session_attr
*attr
, const char *url
)
110 struct lttng_uri
*uris
= NULL
;
113 ret
= -LTTNG_ERR_INVALID
;
118 attr
->configuration_url
[0] = '\0';
124 if (len
>= PATH_MAX
) {
125 ret
= -LTTNG_ERR_INVALID
;
129 size
= uri_parse_str_urls(url
, NULL
, &uris
);
130 if (size
<= 0 || uris
[0].dtype
!= LTTNG_DST_PATH
) {
131 ret
= -LTTNG_ERR_INVALID
;
135 /* Copy string plus the NULL terminated byte. */
136 ret
= lttng_strncpy(attr
->configuration_url
, uris
[0].dst
.path
,
137 sizeof(attr
->configuration_url
));
139 ret
= -LTTNG_ERR_INVALID
;
149 int lttng_save_session_attr_set_overwrite(
150 struct lttng_save_session_attr
*attr
, int overwrite
)
155 ret
= -LTTNG_ERR_INVALID
;
159 attr
->overwrite
= !!overwrite
;
164 int lttng_save_session_attr_set_omit_name(
165 struct lttng_save_session_attr
*attr
, int omit_name
)
170 ret
= -LTTNG_ERR_INVALID
;
174 attr
->omit_name
= !!omit_name
;
179 int lttng_save_session_attr_set_omit_output(
180 struct lttng_save_session_attr
*attr
, int omit_output
)
185 ret
= -LTTNG_ERR_INVALID
;
189 attr
->omit_output
= !!omit_output
;
195 * The lttng-ctl API does not expose all the information needed to save the
196 * session configurations. Thus, we must send a save command to the session
197 * daemon which will, in turn, save its current session configuration.
199 int lttng_save_session(struct lttng_save_session_attr
*attr
)
201 struct lttcomm_session_msg lsm
;
205 ret
= -LTTNG_ERR_INVALID
;
209 memset(&lsm
, 0, sizeof(lsm
));
210 lsm
.cmd_type
= LTTNG_SAVE_SESSION
;
212 memcpy(&lsm
.u
.save_session
.attr
, attr
,
213 sizeof(struct lttng_save_session_attr
));
214 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
This page took 0.034494 seconds and 4 git commands to generate.