Skip to content

Commit

Permalink
do not close extern table when a module destructs
Browse files Browse the repository at this point in the history
  • Loading branch information
shodoco committed Dec 20, 2016
1 parent 35d6ff8 commit d4a3baf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ BPFModule::~BPFModule() {
ctx_.reset();
if (tables_) {
for (auto table : *tables_) {
if (table.is_shared)
if (table.is_shared) {
SharedTables::instance()->remove_fd(table.name);
else
} else if (!table.is_extern) {
close(table.fd);
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
++i;
}

bool is_extern = false;
bpf_map_type map_type = BPF_MAP_TYPE_UNSPEC;
if (A->getName() == "maps/hash") {
map_type = BPF_MAP_TYPE_HASH;
Expand Down Expand Up @@ -666,7 +665,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
} else if (A->getName() == "maps/stacktrace") {
map_type = BPF_MAP_TYPE_STACK_TRACE;
} else if (A->getName() == "maps/extern") {
is_extern = true;
table.is_extern = true;
table.fd = SharedTables::instance()->lookup_fd(table.name);
table.type = SharedTables::instance()->lookup_type(table.name);
} else if (A->getName() == "maps/export") {
Expand All @@ -687,7 +686,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
return true;
}

if (!is_extern) {
if (!table.is_extern) {
if (map_type == BPF_MAP_TYPE_UNSPEC) {
error(Decl->getLocStart(), "unsupported map type: %0") << A->getName();
return false;
Expand Down
1 change: 1 addition & 0 deletions src/cc/table_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct TableDesc {
llvm::Function *key_snprintf;
llvm::Function *leaf_snprintf;
bool is_shared;
bool is_extern;
};

} // namespace ebpf

0 comments on commit d4a3baf

Please sign in to comment.