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 | 10 | #include "ust-registry.hpp" |
c9e313bc SM |
11 | #include "lttng-sessiond.hpp" |
12 | #include "notification-thread-commands.hpp" | |
d7bfb9b0 | 13 | #include "ust-app.hpp" |
b0f2e8db JG |
14 | #include "ust-registry-session-pid.hpp" |
15 | #include "ust-registry-session-uid.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> | |
23 | #include <lttng/lttng.h> | |
10b56aef | 24 | |
d7bfb9b0 | 25 | #include <inttypes.h> |
3b016e58 | 26 | |
d7bfb9b0 JG |
27 | namespace ls = lttng::sessiond; |
28 | namespace lst = lttng::sessiond::trace; | |
29 | namespace lsu = lttng::sessiond::ust; | |
10b56aef | 30 | |
d0b96690 DG |
31 | /* |
32 | * Destroy event function call of the call RCU. | |
33 | */ | |
d7bfb9b0 | 34 | static void ust_registry_event_destroy_rcu(struct rcu_head *head) |
d0b96690 | 35 | { |
d7bfb9b0 JG |
36 | DIAGNOSTIC_PUSH |
37 | DIAGNOSTIC_IGNORE_INVALID_OFFSETOF | |
38 | lttng::sessiond::ust::registry_event *event = | |
f139a4f9 | 39 | lttng::utils::container_of(head, <tng::sessiond::ust::registry_event::_head); |
d7bfb9b0 JG |
40 | DIAGNOSTIC_POP |
41 | ||
42 | lttng::sessiond::ust::registry_event_destroy(event); | |
d0b96690 DG |
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 | */ | |
d7bfb9b0 JG |
49 | void ust_registry_channel_destroy_event(lsu::registry_channel *chan, |
50 | lttng::sessiond::ust::registry_event *event) | |
d0b96690 DG |
51 | { |
52 | int ret; | |
53 | struct lttng_ht_iter iter; | |
54 | ||
a0377dfe FD |
55 | LTTNG_ASSERT(chan); |
56 | LTTNG_ASSERT(event); | |
48b7cdc2 | 57 | ASSERT_RCU_READ_LOCKED(); |
d0b96690 DG |
58 | |
59 | /* Delete the node first. */ | |
f139a4f9 | 60 | iter.iter.node = &event->_node; |
d7bfb9b0 | 61 | ret = lttng_ht_del(chan->_events, &iter); |
a0377dfe | 62 | LTTNG_ASSERT(!ret); |
d0b96690 | 63 | |
f139a4f9 | 64 | call_rcu(&event->_head, ust_registry_event_destroy_rcu); |
d0b96690 DG |
65 | |
66 | return; | |
67 | } | |
68 | ||
b0f2e8db | 69 | lsu::registry_session *ust_registry_session_per_uid_create(const lttng::sessiond::trace::abi& abi, |
af6142cf | 70 | uint32_t major, |
d7ba1388 | 71 | uint32_t minor, |
3d071855 | 72 | const char *root_shm_path, |
d7ba1388 MD |
73 | const char *shm_path, |
74 | uid_t euid, | |
8de88061 JR |
75 | gid_t egid, |
76 | uint64_t tracing_id, | |
77 | uid_t tracing_uid) | |
d0b96690 | 78 | { |
aeeb48c6 | 79 | try { |
b0f2e8db | 80 | return new lsu::registry_session_per_uid(abi, major, minor, root_shm_path, shm_path, |
aeeb48c6 | 81 | euid, egid, tracing_id, tracing_uid); |
d7bfb9b0 | 82 | } catch (const std::exception& ex) { |
aeeb48c6 JG |
83 | ERR("Failed to create per-uid registry session: %s", ex.what()); |
84 | return nullptr; | |
d7ba1388 | 85 | } |
aeeb48c6 | 86 | } |
8de88061 | 87 | |
b0f2e8db | 88 | lsu::registry_session *ust_registry_session_per_pid_create(struct ust_app *app, |
d7bfb9b0 | 89 | const lttng::sessiond::trace::abi& abi, |
aeeb48c6 JG |
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 { | |
b0f2e8db | 99 | return new lsu::registry_session_per_pid(*app, abi, major, minor, root_shm_path, |
d7bfb9b0 JG |
100 | shm_path, euid, egid, tracing_id); |
101 | } catch (const std::exception& ex) { | |
aeeb48c6 JG |
102 | ERR("Failed to create per-pid registry session: %s", ex.what()); |
103 | return nullptr; | |
d0b96690 | 104 | } |
d0b96690 DG |
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 | */ | |
b0f2e8db | 111 | void ust_registry_session_destroy(lsu::registry_session *reg) |
d0b96690 | 112 | { |
aeeb48c6 | 113 | delete reg; |
d0b96690 | 114 | } |
d7bfb9b0 JG |
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 | } |