a6ceece9882dad64dfd20606eb2148446bad05e4
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.cpp
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #define _LGPL_SOURCE
9
10 #include "ust-registry.hpp"
11 #include "lttng-sessiond.hpp"
12 #include "notification-thread-commands.hpp"
13 #include "ust-app.hpp"
14 #include "ust-registry-session-pid.hpp"
15 #include "ust-registry-session-uid.hpp"
16 #include "utils.hpp"
17
18 #include <common/common.hpp>
19 #include <common/exception.hpp>
20 #include <common/format.hpp>
21 #include <common/hashtable/utils.hpp>
22 #include <common/make-unique-wrapper.hpp>
23 #include <lttng/lttng.h>
24
25 #include <inttypes.h>
26
27 namespace ls = lttng::sessiond;
28 namespace lst = lttng::sessiond::trace;
29 namespace lsu = lttng::sessiond::ust;
30
31 /*
32 * Destroy event function call of the call RCU.
33 */
34 static void ust_registry_event_destroy_rcu(struct rcu_head *head)
35 {
36 DIAGNOSTIC_PUSH
37 DIAGNOSTIC_IGNORE_INVALID_OFFSETOF
38 lttng::sessiond::ust::registry_event *event =
39 lttng::utils::container_of(head, &lttng::sessiond::ust::registry_event::_head);
40 DIAGNOSTIC_POP
41
42 lttng::sessiond::ust::registry_event_destroy(event);
43 }
44
45 /*
46 * For a given event in a registry, delete the entry and destroy the event.
47 * This MUST be called within a RCU read side lock section.
48 */
49 void ust_registry_channel_destroy_event(lsu::registry_channel *chan,
50 lttng::sessiond::ust::registry_event *event)
51 {
52 int ret;
53 struct lttng_ht_iter iter;
54
55 LTTNG_ASSERT(chan);
56 LTTNG_ASSERT(event);
57 ASSERT_RCU_READ_LOCKED();
58
59 /* Delete the node first. */
60 iter.iter.node = &event->_node;
61 ret = lttng_ht_del(chan->_events, &iter);
62 LTTNG_ASSERT(!ret);
63
64 call_rcu(&event->_head, ust_registry_event_destroy_rcu);
65
66 return;
67 }
68
69 lsu::registry_session *ust_registry_session_per_uid_create(const lttng::sessiond::trace::abi& abi,
70 uint32_t major,
71 uint32_t minor,
72 const char *root_shm_path,
73 const char *shm_path,
74 uid_t euid,
75 gid_t egid,
76 uint64_t tracing_id,
77 uid_t tracing_uid)
78 {
79 try {
80 return new lsu::registry_session_per_uid(abi, major, minor, root_shm_path, shm_path,
81 euid, egid, tracing_id, tracing_uid);
82 } catch (const std::exception& ex) {
83 ERR("Failed to create per-uid registry session: %s", ex.what());
84 return nullptr;
85 }
86 }
87
88 lsu::registry_session *ust_registry_session_per_pid_create(struct ust_app *app,
89 const lttng::sessiond::trace::abi& abi,
90 uint32_t major,
91 uint32_t minor,
92 const char *root_shm_path,
93 const char *shm_path,
94 uid_t euid,
95 gid_t egid,
96 uint64_t tracing_id)
97 {
98 try {
99 return new lsu::registry_session_per_pid(*app, abi, major, minor, root_shm_path,
100 shm_path, euid, egid, tracing_id);
101 } catch (const std::exception& ex) {
102 ERR("Failed to create per-pid registry session: %s", ex.what());
103 return nullptr;
104 }
105 }
106
107 /*
108 * Destroy session registry. This does NOT free the given pointer since it
109 * might get passed as a reference. The registry lock should NOT be acquired.
110 */
111 void ust_registry_session_destroy(lsu::registry_session *reg)
112 {
113 delete reg;
114 }
115
116 lsu::registry_enum::registry_enum(
117 std::string in_name, enum lst::integer_type::signedness in_signedness) :
118 name{std::move(in_name)}, signedness{in_signedness}
119 {
120 cds_lfht_node_init(&this->node.node);
121 this->rcu_head = {};
122 }
123
124 bool lsu::operator==(const lsu::registry_enum& lhs, const lsu::registry_enum& rhs) noexcept
125 {
126 if (lhs.signedness != rhs.signedness) {
127 return false;
128 }
129
130 return lhs._is_equal(rhs);
131 }
This page took 0.031326 seconds and 4 git commands to generate.