Fix: lttng_trace_archive_location_serialize is called on freed memory
[lttng-tools.git] / include / lttng / location-internal.h
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_LOCATION_INTERNAL_H
9 #define LTTNG_LOCATION_INTERNAL_H
10
11 #include <lttng/location.h>
12 #include <common/dynamic-buffer.h>
13 #include <common/buffer-view.h>
14 #include <common/macros.h>
15 #include <sys/types.h>
16 #include <urcu/ref.h>
17
18 /*
19 * The public API assumes that trace archive locations are always
20 * provided as "constant". This means that the user of liblttng-ctl never
21 * has to destroy a trace archive location. Hence, users of liblttng-ctl
22 * have no visibility of the reference counting of archive locations.
23 */
24 struct lttng_trace_archive_location {
25 struct urcu_ref ref;
26 enum lttng_trace_archive_location_type type;
27 union {
28 struct {
29 char *absolute_path;
30 } local;
31 struct {
32 char *host;
33 enum lttng_trace_archive_location_relay_protocol_type protocol;
34 struct {
35 uint16_t control, data;
36 } ports;
37 char *relative_path;
38 } relay;
39 } types;
40 };
41
42 struct lttng_trace_archive_location_comm {
43 /* A value from enum lttng_trace_archive_location_type */
44 int8_t type;
45 union {
46 struct {
47 /* Includes the trailing \0. */
48 uint32_t absolute_path_len;
49 } LTTNG_PACKED local;
50 struct {
51 /* Includes the trailing \0. */
52 uint32_t hostname_len;
53 /*
54 * A value from
55 * enum lttng_trace_archive_location_relay_protocol_type.
56 */
57 int8_t protocol;
58 struct {
59 uint16_t control, data;
60 } ports;
61 /* Includes the trailing \0. */
62 uint32_t relative_path_len;
63 } LTTNG_PACKED relay;
64 } LTTNG_PACKED types;
65 /*
66 * Payload is composed of:
67 * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
68 * - absolute path, including \0
69 * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
70 * - hostname, including \0
71 * - relative path, including \0
72 */
73 char payload[];
74 } LTTNG_PACKED;
75
76
77 LTTNG_HIDDEN
78 struct lttng_trace_archive_location *lttng_trace_archive_location_local_create(
79 const char *path);
80
81 LTTNG_HIDDEN
82 struct lttng_trace_archive_location *lttng_trace_archive_location_relay_create(
83 const char *host,
84 enum lttng_trace_archive_location_relay_protocol_type protocol,
85 uint16_t control_port, uint16_t data_port,
86 const char *relative_path);
87
88 LTTNG_HIDDEN
89 ssize_t lttng_trace_archive_location_create_from_buffer(
90 const struct lttng_buffer_view *buffer,
91 struct lttng_trace_archive_location **location);
92
93 LTTNG_HIDDEN
94 ssize_t lttng_trace_archive_location_serialize(
95 const struct lttng_trace_archive_location *location,
96 struct lttng_dynamic_buffer *buffer);
97
98 LTTNG_HIDDEN
99 void lttng_trace_archive_location_get(
100 struct lttng_trace_archive_location *location);
101
102 LTTNG_HIDDEN
103 void lttng_trace_archive_location_put(
104 struct lttng_trace_archive_location *location);
105
106 #endif /* LTTNG_LOCATION_INTERNAL_H */
This page took 0.030476 seconds and 4 git commands to generate.