Fix: sessiond: fix memory leak in receive_lttng_trigger
[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 */
412d7227 25extern struct lttng_ht *the_agent_apps_ht_by_sock;
022d91ba 26
44760c20
JR
27/*
28 * Hash table that contains the trigger agents by domain */
412d7227 29extern struct lttng_ht *the_trigger_agents_ht_by_domain;
44760c20 30
022d91ba
DG
31struct agent_ht_key {
32 const char *name;
2106efa0 33 int loglevel_value;
a9319624 34 enum lttng_loglevel_type loglevel_type;
44760c20 35 const char *filter_expression;
022d91ba
DG
36};
37
38/*
39 * Registration message payload from an agent application. The PID is used to
40 * find back the corresponding UST app object so both socket can be linked.
41 */
42struct agent_register_msg {
fefd409b
DG
43 /* This maps to a lttng_domain_type. */
44 uint32_t domain;
022d91ba 45 uint32_t pid;
9474416f
DG
46 uint32_t major_version;
47 uint32_t minor_version;
022d91ba
DG
48};
49
50/*
51 * Agent application object created after a successful registration. This
52 * object is linked to its associated UST app by their PID through hash table
53 * lookups.
54 */
55struct agent_app {
56 /*
d53e2992 57 * PID sent during registration of an agent application.
022d91ba
DG
58 */
59 pid_t pid;
60
fefd409b
DG
61 /* Domain of the application. */
62 enum lttng_domain_type domain;
63
022d91ba
DG
64 /*
65 * AGENT TCP socket that was created upon registration.
66 */
67 struct lttcomm_sock *sock;
68
69 /* Initialized with the AGENT sock value. */
70 struct lttng_ht_node_ulong node;
71};
72
73/*
74 * Agent event representation.
44760c20 75 * Accesses to this structure are protected by the session list lock.
022d91ba
DG
76 */
77struct agent_event {
78 /* Name of the event. */
79 char name[LTTNG_SYMBOL_NAME_LEN];
2106efa0 80 int loglevel_value;
022d91ba
DG
81 enum lttng_loglevel_type loglevel_type;
82
83 /*
44760c20
JR
84 * Tells if the event is enabled or not on the agent. While this can be
85 * implicitly tested as a boolean, it is in fact a reference count and
86 * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental
87 * comparisons to non-zero literals (e.g. '1').
88 *
89 * Multiple triggers and events can map to the same agent event as it
90 * is merely a "filter" in front of a user space tracer enabler.
91 *
92 * This count is updated to ensure an event is only disabled when all
93 * matching enablers are disabled.
022d91ba 94 */
44760c20 95 unsigned int enabled_count;
022d91ba
DG
96
97 /* Hash table node of the agent domain object. */
98 struct lttng_ht_node_str node;
99
51755dc8 100 /* Filter associated with the event. NULL if none. */
2b00d462 101 struct lttng_bytecode *filter;
51755dc8
JG
102 char *filter_expression;
103 struct lttng_event_exclusion *exclusion;
022d91ba
DG
104};
105
44760c20
JR
106#define AGENT_EVENT_IS_ENABLED(agent_event) (!!agent_event->enabled_count)
107
022d91ba 108/*
44760c20
JR
109 * Agent object containing events enabled/disabled for a given domain in a
110 * scope. The scope is typically a session, but can also be "global" in the
111 * context of event notifiers: see event_notifiers_find_agent().
022d91ba
DG
112 */
113struct agent {
114 /*
115 * This indicates if that domain is being used meaning if at least one
116 * event has been at some point in time added to it. This is used so when
117 * listing domains for a session, we can tell or not if the agent is
118 * actually enabled.
119 */
120 unsigned int being_used:1;
fefd409b
DG
121
122 /* What domain this agent is. */
123 enum lttng_domain_type domain;
124
022d91ba
DG
125 /* Contains event indexed by name. */
126 struct lttng_ht *events;
fefd409b 127
bdf64013
JG
128 /* Application context list (struct agent_app_ctx). */
129 struct cds_list_head app_ctx_list;
130
fefd409b
DG
131 /* Node used for the hash table indexed by domain type. */
132 struct lttng_ht_node_u64 node;
022d91ba
DG
133};
134
6a4e4039
JG
135/* Allocate agent apps hash table */
136int agent_app_ht_alloc(void);
137/* Clean-up agent apps hash table */
138void agent_app_ht_clean(void);
022d91ba
DG
139
140/* Initialize an already allocated agent domain. */
141int agent_init(struct agent *agt);
fefd409b 142struct agent *agent_create(enum lttng_domain_type domain);
022d91ba 143void agent_destroy(struct agent *agt);
fefd409b 144void agent_add(struct agent *agt, struct lttng_ht *ht);
022d91ba
DG
145
146/* Agent event API. */
a9319624
PP
147struct agent_event *agent_create_event(const char *name,
148 enum lttng_loglevel_type loglevel_type, int loglevel_value,
2b00d462 149 struct lttng_bytecode *filter,
51755dc8 150 char *filter_expression);
022d91ba
DG
151void agent_add_event(struct agent_event *event, struct agent *agt);
152
a9319624 153struct agent_event *agent_find_event(const char *name,
44760c20
JR
154 enum lttng_loglevel_type loglevel_type,
155 int loglevel_value,
156 const char *filter_expression,
157 struct agent *agt);
e261a6cc
PP
158void agent_find_events_by_name(const char *name, struct agent *agt,
159 struct lttng_ht_iter* iter);
160void agent_event_next_duplicate(const char *name,
161 struct agent *agt, struct lttng_ht_iter* iter);
022d91ba
DG
162void agent_delete_event(struct agent_event *event, struct agent *agt);
163void agent_destroy_event(struct agent_event *event);
164
bdf64013 165/* Agent context API.*/
df4f5a87 166int agent_enable_context(const struct lttng_event_context *ctx,
bdf64013 167 enum lttng_domain_type domain);
df4f5a87
JG
168int agent_add_context(const struct lttng_event_context *ctx,
169 struct agent *agt);
bdf64013 170
022d91ba 171/* Agent app API. */
fefd409b
DG
172struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
173 struct lttcomm_sock *sock);
022d91ba
DG
174void agent_add_app(struct agent_app *app);
175void agent_delete_app(struct agent_app *app);
176struct agent_app *agent_find_app_by_sock(int sock);
177void agent_destroy_app(struct agent_app *app);
6a4e4039 178void agent_destroy_app_by_sock(int sock);
022d91ba
DG
179int agent_send_registration_done(struct agent_app *app);
180
181/* Agent action API */
fefd409b
DG
182int agent_enable_event(struct agent_event *event,
183 enum lttng_domain_type domain);
184int agent_disable_event(struct agent_event *event,
185 enum lttng_domain_type domain);
733c9165 186void agent_update(const struct agent *agt, const struct agent_app *app);
f60140a1
DG
187int agent_list_events(struct lttng_event **events,
188 enum lttng_domain_type domain);
022d91ba 189
44760c20
JR
190struct agent_event *agent_find_event_by_trigger(
191 const struct lttng_trigger *trigger, struct agent *agt);
192
193/* Global event notifier per-domain agents. */
194struct agent *agent_find_by_event_notifier_domain(
195 enum lttng_domain_type domain_type);
196void agent_by_event_notifier_domain_ht_destroy(void);
197int agent_by_event_notifier_domain_ht_create(void);
198
022d91ba 199#endif /* LTTNG_SESSIOND_AGENT_H */
This page took 0.052662 seconds and 4 git commands to generate.