Skip to content

Commit

Permalink
usdt: Use ProcMountNS
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg authored and drzaeus77 committed Jun 30, 2017
1 parent 8600ffc commit 96c1b8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/cc/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ Location::Location(uint64_t addr, const char *arg_fmt) : address_(addr) {
}

Probe::Probe(const char *bin_path, const char *provider, const char *name,
uint64_t semaphore, const optional<int> &pid)
uint64_t semaphore, const optional<int> &pid, ProcMountNS *ns)
: bin_path_(bin_path),
provider_(provider),
name_(name),
semaphore_(semaphore),
pid_(pid) {}
pid_(pid),
mount_ns_(ns) {}

bool Probe::in_shared_object() {
if (!in_shared_object_)
if (!in_shared_object_) {
ProcMountNSGuard g(mount_ns_);
in_shared_object_ = bcc_elf_is_shared_obj(bin_path_.c_str());
}
return in_shared_object_.value();
}

Expand Down Expand Up @@ -205,6 +208,7 @@ int Context::_each_module(const char *modpath, uint64_t, uint64_t, bool, void *p
// executable region. We are going to parse the ELF on disk anyway, so we
// don't need these duplicates.
if (ctx->modules_.insert(modpath).second /*inserted new?*/) {
ProcMountNSGuard g(ctx->mount_ns_instance_.get());
bcc_elf_foreach_usdt(modpath, _each_probe, p);
}
return 0;
Expand All @@ -219,7 +223,8 @@ void Context::add_probe(const char *binpath, const struct bcc_elf_usdt *probe) {
}

probes_.emplace_back(
new Probe(binpath, probe->provider, probe->name, probe->semaphore, pid_));
new Probe(binpath, probe->provider, probe->name, probe->semaphore, pid_,
mount_ns_instance_.get()));
probes_.back()->add_location(probe->pc, probe->arg_fmt);
}

Expand Down Expand Up @@ -296,7 +301,8 @@ Context::Context(const std::string &bin_path) : loaded_(false) {
}
}

Context::Context(int pid) : pid_(pid), pid_stat_(pid), loaded_(false) {
Context::Context(int pid) : pid_(pid), pid_stat_(pid),
mount_ns_instance_(new ProcMountNS(pid)), loaded_(false) {
if (bcc_procutils_each_module(pid, _each_module, this) == 0)
loaded_ = true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/cc/usdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <unordered_map>
#include <vector>

#include "ns_guard.h"
#include "syms.h"
#include "vendor/optional.hpp"

Expand Down Expand Up @@ -149,6 +150,7 @@ class Probe {
std::vector<Location> locations_;

optional<int> pid_;
ProcMountNS *mount_ns_;
optional<bool> in_shared_object_;

optional<std::string> attached_to_;
Expand All @@ -163,7 +165,7 @@ class Probe {

public:
Probe(const char *bin_path, const char *provider, const char *name,
uint64_t semaphore, const optional<int> &pid);
uint64_t semaphore, const optional<int> &pid, ProcMountNS *ns);

size_t num_locations() const { return locations_.size(); }
size_t num_arguments() const { return locations_.front().arguments_.size(); }
Expand Down Expand Up @@ -195,6 +197,7 @@ class Context {

optional<int> pid_;
optional<ProcStat> pid_stat_;
std::unique_ptr<ProcMountNS> mount_ns_instance_;
bool loaded_;

static void _each_probe(const char *binpath, const struct bcc_elf_usdt *probe,
Expand Down

0 comments on commit 96c1b8e

Please sign in to comment.