~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/shared/report/lttng/tracepoint_provider.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Lesser General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17
 
 */
18
 
 
19
 
#include "mir/report/lttng/tracepoint_provider.h"
20
 
 
21
 
#include <boost/throw_exception.hpp>
22
 
#include <stdexcept>
23
 
 
24
 
#include <dlfcn.h>
25
 
 
26
 
namespace
27
 
{
28
 
 
29
 
std::string const tracepoint_lib_install_path{MIR_TRACEPOINT_LIB_INSTALL_PATH};
30
 
 
31
 
void* open_tracepoint_lib(std::string const& lib_name)
32
 
{
33
 
    auto lib = dlopen(lib_name.c_str(), RTLD_NOW);
34
 
 
35
 
    if (lib == nullptr)
36
 
    {
37
 
        std::string path{tracepoint_lib_install_path + "/" + lib_name};
38
 
        lib = dlopen(path.c_str(), RTLD_NOW);
39
 
    }
40
 
 
41
 
    if (lib == nullptr)
42
 
    {
43
 
        std::string msg{"Failed to load tracepoint provider: "};
44
 
        msg += dlerror();
45
 
        BOOST_THROW_EXCEPTION(std::runtime_error(msg));
46
 
    }
47
 
 
48
 
    return lib;
49
 
}
50
 
 
51
 
}
52
 
 
53
 
mir::report::lttng::TracepointProvider::TracepointProvider(std::string const& lib_name)
54
 
    : lib{open_tracepoint_lib(lib_name)}
55
 
{
56
 
}
57
 
 
58
 
mir::report::lttng::TracepointProvider::~TracepointProvider() noexcept
59
 
{
60
 
    dlclose(lib);
61
 
}