]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "common/TracepointProvider.h" | |
5 | #include "common/config.h" | |
6 | ||
7 | TracepointProvider::TracepointProvider(CephContext *cct, const char *library, | |
8 | const char *config_key) | |
11fdf7f2 TL |
9 | : m_cct(cct), m_library(library), m_config_keys{config_key, NULL} |
10 | { | |
11 | m_cct->_conf.add_observer(this); | |
7c673cae FG |
12 | verify_config(m_cct->_conf); |
13 | } | |
14 | ||
15 | TracepointProvider::~TracepointProvider() { | |
11fdf7f2 | 16 | m_cct->_conf.remove_observer(this); |
7c673cae FG |
17 | if (m_handle) { |
18 | dlclose(m_handle); | |
19 | } | |
20 | } | |
21 | ||
22 | void TracepointProvider::handle_conf_change( | |
11fdf7f2 | 23 | const ConfigProxy& conf, const std::set<std::string> &changed) { |
7c673cae FG |
24 | if (changed.count(m_config_keys[0])) { |
25 | verify_config(conf); | |
26 | } | |
27 | } | |
28 | ||
11fdf7f2 TL |
29 | void TracepointProvider::verify_config(const ConfigProxy& conf) { |
30 | std::lock_guard locker(m_lock); | |
7c673cae FG |
31 | if (m_handle) { |
32 | return; | |
33 | } | |
34 | ||
35 | char buf[10]; | |
36 | char *pbuf = buf; | |
11fdf7f2 | 37 | if (conf.get_val(m_config_keys[0], &pbuf, sizeof(buf)) != 0 || |
7c673cae FG |
38 | strncmp(buf, "true", 5) != 0) { |
39 | return; | |
40 | } | |
41 | ||
42 | m_handle = dlopen(m_library.c_str(), RTLD_NOW | RTLD_NODELETE); | |
11fdf7f2 | 43 | ceph_assert(m_handle); |
7c673cae FG |
44 | } |
45 |