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
23 #include <lttng/lttng-error.h>
24 #include <lttng/save.h>
25 #include <lttng/save-internal.h>
26 #include <common/sessiond-comm/sessiond-comm.h>
28 #include "lttng-ctl-helper.h"
30 struct lttng_save_session_attr
*lttng_save_session_attr_create(void)
32 return zmalloc(sizeof(struct lttng_save_session_attr
));
35 void lttng_save_session_attr_destroy(struct lttng_save_session_attr
*output
)
42 const char *lttng_save_session_attr_get_session_name(
43 struct lttng_save_session_attr
*attr
)
45 const char *ret
= NULL
;
47 if (attr
&& attr
->session_name
[0]) {
48 ret
= attr
->session_name
;
54 const char *lttng_save_session_attr_get_output_url(
55 struct lttng_save_session_attr
*attr
)
57 const char *ret
= NULL
;
59 if (attr
&& attr
->configuration_url
[0]) {
60 ret
= attr
->configuration_url
;
66 int lttng_save_session_attr_get_overwrite(
67 struct lttng_save_session_attr
*attr
)
69 return attr
? attr
->overwrite
: -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
>= NAME_MAX
) {
87 ret
= -LTTNG_ERR_INVALID
;
91 strncpy(attr
->session_name
, session_name
, len
);
93 attr
->session_name
[0] = '\0';
99 int lttng_save_session_attr_set_output_url(
100 struct lttng_save_session_attr
*attr
, const char *url
)
105 struct lttng_uri
*uris
= NULL
;
108 ret
= -LTTNG_ERR_INVALID
;
113 attr
->configuration_url
[0] = '\0';
119 if (len
>= PATH_MAX
) {
120 ret
= -LTTNG_ERR_INVALID
;
124 size
= uri_parse_str_urls(url
, NULL
, &uris
);
125 if (size
<= 0 || uris
[0].dtype
!= LTTNG_DST_PATH
) {
126 ret
= -LTTNG_ERR_INVALID
;
130 /* Copy string plus the NULL terminated byte. */
131 lttng_ctl_copy_string(attr
->configuration_url
, uris
[0].dst
.path
,
132 sizeof(attr
->configuration_url
));
140 int lttng_save_session_attr_set_overwrite(
141 struct lttng_save_session_attr
*attr
, int overwrite
)
146 ret
= -LTTNG_ERR_INVALID
;
150 attr
->overwrite
= !!overwrite
;
156 * The lttng-ctl API does not expose all the information needed to save the
157 * session configurations. Thus, we must send a save command to the session
158 * daemon which will, in turn, save its current session configuration.
160 int lttng_save_session(struct lttng_save_session_attr
*attr
)
162 struct lttcomm_session_msg lsm
;
166 ret
= -LTTNG_ERR_INVALID
;
170 memset(&lsm
, 0, sizeof(lsm
));
171 lsm
.cmd_type
= LTTNG_SAVE_SESSION
;
173 memcpy(&lsm
.u
.save_session
.attr
, attr
,
174 sizeof(struct lttng_save_session_attr
));
175 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
This page took 0.032117 seconds and 4 git commands to generate.