Fix: sessiond: double free on duplicate removal of tracer source
[lttng-tools.git] / src / bin / lttng-sessiond / agent.h
CommitLineData
022d91ba 1/*
ab5be9fa
MJ
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
022d91ba 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
022d91ba 6 *
022d91ba
DG
7 */
8
9#ifndef LTTNG_SESSIOND_AGENT_H
10#define LTTNG_SESSIOND_AGENT_H
11
022d91ba
DG
12#include <inttypes.h>
13
14#include <common/hashtable/hashtable.h>
15#include <lttng/lttng.h>
16
9474416f 17/* Agent protocol version that is verified during the agent registration. */
a0ba721c 18#define AGENT_MAJOR_VERSION 2
9474416f
DG
19#define AGENT_MINOR_VERSION 0
20
022d91ba
DG
21/*
22 * Hash table that contains the agent app created upon registration indexed by
7c1d2758 23 * socket. Global to the session daemon.
022d91ba 24 */
7c1d2758 25extern struct lttng_ht *agent_apps_ht_by_sock;
022d91ba
DG
26
27struct agent_ht_key {
28 const char *name;
2106efa0 29 int loglevel_value;
a9319624 30 enum lttng_loglevel_type loglevel_type;
6b10b3b0 31 char *filter_expression;
022d91ba
DG
32};
33
34/*
35 * Registration message payload from an agent application. The PID is used to
36 * find back the corresponding UST app object so both socket can be linked.
37 */
38struct agent_register_msg {
fefd409b
DG
39 /* This maps to a lttng_domain_type. */
40 uint32_t domain;
022d91ba 41 uint32_t pid;
9474416f
DG
42 uint32_t major_version;
43 uint32_t minor_version;
022d91ba
DG
44};
45
46/*
47 * Agent application object created after a successful registration. This
48 * object is linked to its associated UST app by their PID through hash table
49 * lookups.
50 */
51struct agent_app {
52 /*
d53e2992 53 * PID sent during registration of an agent application.
022d91ba
DG
54 */
55 pid_t pid;
56
fefd409b
DG
57 /* Domain of the application. */
58 enum lttng_domain_type domain;
59
022d91ba
DG
60 /*
61 * AGENT TCP socket that was created upon registration.
62 */
63 struct lttcomm_sock *sock;
64
65 /* Initialized with the AGENT sock value. */
66 struct lttng_ht_node_ulong node;
67};
68
69/*
70 * Agent event representation.
71 */
72struct agent_event {
73 /* Name of the event. */
74 char name[LTTNG_SYMBOL_NAME_LEN];
2106efa0 75 int loglevel_value;
022d91ba
DG
76 enum lttng_loglevel_type loglevel_type;
77
78 /*
79 * Tells if the event is enabled or not on the agent.
80 */
81 unsigned int enabled:1;
82
83 /* Hash table node of the agent domain object. */
84 struct lttng_ht_node_str node;
85
51755dc8 86 /* Filter associated with the event. NULL if none. */
022d91ba 87 struct lttng_filter_bytecode *filter;
51755dc8
JG
88 char *filter_expression;
89 struct lttng_event_exclusion *exclusion;
022d91ba
DG
90};
91
92/*
93 * Agent object containing events enabled/disabled for it.
94 */
95struct agent {
96 /*
97 * This indicates if that domain is being used meaning if at least one
98 * event has been at some point in time added to it. This is used so when
99 * listing domains for a session, we can tell or not if the agent is
100 * actually enabled.
101 */
102 unsigned int being_used:1;
fefd409b
DG
103
104 /* What domain this agent is. */
105 enum lttng_domain_type domain;
106
022d91ba
DG
107 /* Contains event indexed by name. */
108 struct lttng_ht *events;
fefd409b 109
bdf64013
JG
110 /* Application context list (struct agent_app_ctx). */
111 struct cds_list_head app_ctx_list;
112
fefd409b
DG
113 /* Node used for the hash table indexed by domain type. */
114 struct lttng_ht_node_u64 node;
022d91ba
DG
115};
116
6a4e4039
JG
117/* Allocate agent apps hash table */
118int agent_app_ht_alloc(void);
119/* Clean-up agent apps hash table */
120void agent_app_ht_clean(void);
022d91ba
DG
121
122/* Initialize an already allocated agent domain. */
123int agent_init(struct agent *agt);
fefd409b 124struct agent *agent_create(enum lttng_domain_type domain);
022d91ba 125void agent_destroy(struct agent *agt);
fefd409b 126void agent_add(struct agent *agt, struct lttng_ht *ht);
022d91ba
DG
127
128/* Agent event API. */
a9319624
PP
129struct agent_event *agent_create_event(const char *name,
130 enum lttng_loglevel_type loglevel_type, int loglevel_value,
51755dc8
JG
131 struct lttng_filter_bytecode *filter,
132 char *filter_expression);
022d91ba
DG
133void agent_add_event(struct agent_event *event, struct agent *agt);
134
a9319624
PP
135struct agent_event *agent_find_event(const char *name,
136 enum lttng_loglevel_type loglevel_type, int loglevel_value,
6b10b3b0 137 char *filter_expression, struct agent *agt);
e261a6cc
PP
138void agent_find_events_by_name(const char *name, struct agent *agt,
139 struct lttng_ht_iter* iter);
140void agent_event_next_duplicate(const char *name,
141 struct agent *agt, struct lttng_ht_iter* iter);
022d91ba
DG
142void agent_delete_event(struct agent_event *event, struct agent *agt);
143void agent_destroy_event(struct agent_event *event);
144
bdf64013 145/* Agent context API.*/
df4f5a87 146int agent_enable_context(const struct lttng_event_context *ctx,
bdf64013 147 enum lttng_domain_type domain);
df4f5a87
JG
148int agent_add_context(const struct lttng_event_context *ctx,
149 struct agent *agt);
bdf64013 150
022d91ba 151/* Agent app API. */
fefd409b
DG
152struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
153 struct lttcomm_sock *sock);
022d91ba
DG
154void agent_add_app(struct agent_app *app);
155void agent_delete_app(struct agent_app *app);
156struct agent_app *agent_find_app_by_sock(int sock);
157void agent_destroy_app(struct agent_app *app);
6a4e4039 158void agent_destroy_app_by_sock(int sock);
022d91ba
DG
159int agent_send_registration_done(struct agent_app *app);
160
161/* Agent action API */
fefd409b
DG
162int agent_enable_event(struct agent_event *event,
163 enum lttng_domain_type domain);
164int agent_disable_event(struct agent_event *event,
165 enum lttng_domain_type domain);
733c9165 166void agent_update(const struct agent *agt, const struct agent_app *app);
f60140a1
DG
167int agent_list_events(struct lttng_event **events,
168 enum lttng_domain_type domain);
022d91ba
DG
169
170#endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.050022 seconds and 4 git commands to generate.