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 lttng_ctl_copy_string(attr
->configuration_url
, uris
[0].dst
.path
,
138 sizeof(attr
->configuration_url
));
146 int lttng_save_session_attr_set_overwrite(
147 struct lttng_save_session_attr
*attr
, int overwrite
)
152 ret
= -LTTNG_ERR_INVALID
;
156 attr
->overwrite
= !!overwrite
;
161 int lttng_save_session_attr_set_omit_name(
162 struct lttng_save_session_attr
*attr
, int omit_name
)
167 ret
= -LTTNG_ERR_INVALID
;
171 attr
->omit_name
= !!omit_name
;
176 int lttng_save_session_attr_set_omit_output(
177 struct lttng_save_session_attr
*attr
, int omit_output
)
182 ret
= -LTTNG_ERR_INVALID
;
186 attr
->omit_output
= !!omit_output
;
192 * The lttng-ctl API does not expose all the information needed to save the
193 * session configurations. Thus, we must send a save command to the session
194 * daemon which will, in turn, save its current session configuration.
196 int lttng_save_session(struct lttng_save_session_attr
*attr
)
198 struct lttcomm_session_msg lsm
;
202 ret
= -LTTNG_ERR_INVALID
;
206 memset(&lsm
, 0, sizeof(lsm
));
207 lsm
.cmd_type
= LTTNG_SAVE_SESSION
;
209 memcpy(&lsm
.u
.save_session
.attr
, attr
,
210 sizeof(struct lttng_save_session_attr
));
211 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
This page took 0.034359 seconds and 4 git commands to generate.