2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library 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 Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <lttng/lttng-error.h>
23 #include <lttng/save.h>
24 #include <lttng/save-internal.h>
25 #include <common/sessiond-comm/sessiond-comm.h>
27 #include "lttng-ctl-helper.h"
29 struct lttng_save_session_attr
*lttng_save_session_attr_create(void)
31 return zmalloc(sizeof(struct lttng_save_session_attr
));
34 void lttng_save_session_attr_destroy(struct lttng_save_session_attr
*output
)
41 const char *lttng_save_session_attr_get_session_name(
42 struct lttng_save_session_attr
*attr
)
44 const char *ret
= NULL
;
46 if (attr
&& attr
->session_name
[0]) {
47 ret
= attr
->session_name
;
53 const char *lttng_save_session_attr_get_output_url(
54 struct lttng_save_session_attr
*attr
)
56 const char *ret
= NULL
;
58 if (attr
&& attr
->configuration_url
[0]) {
59 ret
= attr
->configuration_url
;
65 int lttng_save_session_attr_get_overwrite(
66 struct lttng_save_session_attr
*attr
)
68 return attr
? attr
->overwrite
: -LTTNG_ERR_INVALID
;
71 int lttng_save_session_attr_get_omit_name(
72 struct lttng_save_session_attr
*attr
)
74 return attr
? attr
->omit_name
: -LTTNG_ERR_INVALID
;
77 int lttng_save_session_attr_get_omit_output(
78 struct lttng_save_session_attr
*attr
)
80 return attr
? attr
->omit_output
: -LTTNG_ERR_INVALID
;
83 int lttng_save_session_attr_set_session_name(
84 struct lttng_save_session_attr
*attr
, const char *session_name
)
89 ret
= -LTTNG_ERR_INVALID
;
96 len
= strlen(session_name
);
97 if (len
>= LTTNG_NAME_MAX
) {
98 ret
= -LTTNG_ERR_INVALID
;
102 strncpy(attr
->session_name
, session_name
, len
);
104 attr
->session_name
[0] = '\0';
110 int lttng_save_session_attr_set_output_url(
111 struct lttng_save_session_attr
*attr
, const char *url
)
116 struct lttng_uri
*uris
= NULL
;
119 ret
= -LTTNG_ERR_INVALID
;
124 attr
->configuration_url
[0] = '\0';
130 if (len
>= PATH_MAX
) {
131 ret
= -LTTNG_ERR_INVALID
;
135 size
= uri_parse_str_urls(url
, NULL
, &uris
);
136 if (size
<= 0 || uris
[0].dtype
!= LTTNG_DST_PATH
) {
137 ret
= -LTTNG_ERR_INVALID
;
141 /* Copy string plus the NULL terminated byte. */
142 lttng_ctl_copy_string(attr
->configuration_url
, uris
[0].dst
.path
,
143 sizeof(attr
->configuration_url
));
151 int lttng_save_session_attr_set_overwrite(
152 struct lttng_save_session_attr
*attr
, int overwrite
)
157 ret
= -LTTNG_ERR_INVALID
;
161 attr
->overwrite
= !!overwrite
;
166 int lttng_save_session_attr_set_omit_name(
167 struct lttng_save_session_attr
*attr
, int omit_name
)
172 ret
= -LTTNG_ERR_INVALID
;
176 attr
->omit_name
= !!omit_name
;
181 int lttng_save_session_attr_set_omit_output(
182 struct lttng_save_session_attr
*attr
, int omit_output
)
187 ret
= -LTTNG_ERR_INVALID
;
191 attr
->omit_output
= !!omit_output
;
197 * The lttng-ctl API does not expose all the information needed to save the
198 * session configurations. Thus, we must send a save command to the session
199 * daemon which will, in turn, save its current session configuration.
201 int lttng_save_session(struct lttng_save_session_attr
*attr
)
203 struct lttcomm_session_msg lsm
;
207 ret
= -LTTNG_ERR_INVALID
;
211 memset(&lsm
, 0, sizeof(lsm
));
212 lsm
.cmd_type
= LTTNG_SAVE_SESSION
;
214 memcpy(&lsm
.u
.save_session
.attr
, attr
,
215 sizeof(struct lttng_save_session_attr
));
216 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
This page took 0.034726 seconds and 4 git commands to generate.