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