2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
12 #include <lttng/lttng-error.h>
13 #include <lttng/save.h>
14 #include <lttng/save-internal.h>
15 #include <common/sessiond-comm/sessiond-comm.h>
17 #include "lttng-ctl-helper.h"
19 struct lttng_save_session_attr
*lttng_save_session_attr_create(void)
21 return zmalloc(sizeof(struct lttng_save_session_attr
));
24 void lttng_save_session_attr_destroy(struct lttng_save_session_attr
*output
)
31 const char *lttng_save_session_attr_get_session_name(
32 struct lttng_save_session_attr
*attr
)
34 const char *ret
= NULL
;
36 if (attr
&& attr
->session_name
[0]) {
37 ret
= attr
->session_name
;
43 const char *lttng_save_session_attr_get_output_url(
44 struct lttng_save_session_attr
*attr
)
46 const char *ret
= NULL
;
48 if (attr
&& attr
->configuration_url
[0]) {
49 ret
= attr
->configuration_url
;
55 int lttng_save_session_attr_get_overwrite(
56 struct lttng_save_session_attr
*attr
)
58 return attr
? attr
->overwrite
: -LTTNG_ERR_INVALID
;
61 int lttng_save_session_attr_get_omit_name(
62 struct lttng_save_session_attr
*attr
)
64 return attr
? attr
->omit_name
: -LTTNG_ERR_INVALID
;
67 int lttng_save_session_attr_get_omit_output(
68 struct lttng_save_session_attr
*attr
)
70 return attr
? attr
->omit_output
: -LTTNG_ERR_INVALID
;
73 int lttng_save_session_attr_set_session_name(
74 struct lttng_save_session_attr
*attr
, const char *session_name
)
79 ret
= -LTTNG_ERR_INVALID
;
86 len
= strlen(session_name
);
87 if (len
>= LTTNG_NAME_MAX
) {
88 ret
= -LTTNG_ERR_INVALID
;
92 ret
= lttng_strncpy(attr
->session_name
, session_name
,
93 sizeof(attr
->session_name
));
95 ret
= -LTTNG_ERR_INVALID
;
99 attr
->session_name
[0] = '\0';
105 int lttng_save_session_attr_set_output_url(
106 struct lttng_save_session_attr
*attr
, const char *url
)
111 struct lttng_uri
*uris
= NULL
;
114 ret
= -LTTNG_ERR_INVALID
;
119 attr
->configuration_url
[0] = '\0';
125 if (len
>= PATH_MAX
) {
126 ret
= -LTTNG_ERR_INVALID
;
130 size
= uri_parse_str_urls(url
, NULL
, &uris
);
131 if (size
<= 0 || uris
[0].dtype
!= LTTNG_DST_PATH
) {
132 ret
= -LTTNG_ERR_INVALID
;
136 /* Copy string plus the NULL terminated byte. */
137 ret
= lttng_strncpy(attr
->configuration_url
, uris
[0].dst
.path
,
138 sizeof(attr
->configuration_url
));
140 ret
= -LTTNG_ERR_INVALID
;
150 int lttng_save_session_attr_set_overwrite(
151 struct lttng_save_session_attr
*attr
, int overwrite
)
156 ret
= -LTTNG_ERR_INVALID
;
160 attr
->overwrite
= !!overwrite
;
165 int lttng_save_session_attr_set_omit_name(
166 struct lttng_save_session_attr
*attr
, int omit_name
)
171 ret
= -LTTNG_ERR_INVALID
;
175 attr
->omit_name
= !!omit_name
;
180 int lttng_save_session_attr_set_omit_output(
181 struct lttng_save_session_attr
*attr
, int omit_output
)
186 ret
= -LTTNG_ERR_INVALID
;
190 attr
->omit_output
= !!omit_output
;
196 * The lttng-ctl API does not expose all the information needed to save the
197 * session configurations. Thus, we must send a save command to the session
198 * daemon which will, in turn, save its current session configuration.
200 int lttng_save_session(struct lttng_save_session_attr
*attr
)
202 struct lttcomm_session_msg lsm
;
206 ret
= -LTTNG_ERR_INVALID
;
210 memset(&lsm
, 0, sizeof(lsm
));
211 lsm
.cmd_type
= LTTNG_SAVE_SESSION
;
213 memcpy(&lsm
.u
.save_session
.attr
, attr
,
214 sizeof(struct lttng_save_session_attr
));
215 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
This page took 0.033689 seconds and 4 git commands to generate.