2 * Copyright (C) 2020 - EfficiOS, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program 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 General Public License for
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #include "buffer-view.h"
19 #include "dynamic-buffer.h"
20 #include "lttng/snapshot.h"
21 #include "lttng/snapshot-internal.h"
28 bool lttng_snapshot_output_validate(const struct lttng_snapshot_output
*output
)
34 * It is mandatory to have a ctrl_url. If there is only one output
35 * URL (in the net://, net6:// or file:// form), it will be in this
38 len
= lttng_strnlen(output
->ctrl_url
, sizeof(output
->ctrl_url
));
39 if (len
== 0 || len
>= sizeof(output
->ctrl_url
)) {
43 len
= lttng_strnlen(output
->data_url
, sizeof(output
->data_url
));
44 if (len
>= sizeof(output
->data_url
)) {
48 len
= lttng_strnlen(output
->name
, sizeof(output
->name
));
49 if (len
>= sizeof(output
->name
)) {
60 bool lttng_snapshot_output_is_equal(
61 const struct lttng_snapshot_output
*a
,
62 const struct lttng_snapshot_output
*b
)
69 if (a
->max_size
!= b
->max_size
) {
73 if (strcmp(a
->name
, b
->name
) != 0) {
77 if (strcmp(a
->ctrl_url
, b
->ctrl_url
) != 0) {
81 if (strcmp(a
->data_url
, b
->data_url
) != 0) {
92 * This is essentially the same as `struct lttng_snapshot_output`, but packed.
94 struct LTTNG_PACKED lttng_snapshot_output_comm
{
97 char name
[LTTNG_NAME_MAX
];
98 char ctrl_url
[PATH_MAX
];
99 char data_url
[PATH_MAX
];
103 int lttng_snapshot_output_serialize(
104 const struct lttng_snapshot_output
*output
,
105 struct lttng_dynamic_buffer
*buf
)
107 struct lttng_snapshot_output_comm comm
;
110 comm
.id
= output
->id
;
111 comm
.max_size
= output
->max_size
;
113 ret
= lttng_strncpy(comm
.name
, output
->name
, sizeof(comm
.name
));
118 ret
= lttng_strncpy(comm
.ctrl_url
, output
->ctrl_url
, sizeof(comm
.ctrl_url
));
123 ret
= lttng_strncpy(comm
.data_url
, output
->data_url
, sizeof(comm
.data_url
));
128 ret
= lttng_dynamic_buffer_append(buf
, &comm
, sizeof(comm
));
138 ssize_t
lttng_snapshot_output_create_from_buffer(
139 const struct lttng_buffer_view
*view
,
140 struct lttng_snapshot_output
**output_p
)
142 const struct lttng_snapshot_output_comm
*comm
;
143 struct lttng_snapshot_output
*output
= NULL
;
146 if (view
->size
!= sizeof(*comm
)) {
151 output
= lttng_snapshot_output_create();
157 comm
= (struct lttng_snapshot_output_comm
*) view
->data
;
159 output
->id
= comm
->id
;
160 output
->max_size
= comm
->max_size
;
162 ret
= lttng_strncpy(output
->name
, comm
->name
, sizeof(output
->name
));
167 ret
= lttng_strncpy(output
->ctrl_url
, comm
->ctrl_url
, sizeof(output
->ctrl_url
));
172 ret
= lttng_strncpy(output
->data_url
, comm
->data_url
, sizeof(output
->data_url
));
182 lttng_snapshot_output_destroy(output
);