Commit 5d5afa74 authored by Krzesimir Nowak's avatar Krzesimir Nowak

Support resolving cgroupid only if name_to_handle_at exists

Currently used image of alpine has a version of musl libc that does
not have name_to_handle_at function that is required to resolve the
cgroup id. In such case we just use an implementation that says that
resolving cgroupid is not supported.
parent 64abee2b
......@@ -60,6 +60,11 @@ add_flex_bison_dependency(flex_lexer bison_parser)
add_library(parser ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS})
target_include_directories(parser PUBLIC src src/ast ${CMAKE_BINARY_DIR})
include(CheckSymbolExists)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(name_to_handle_at "sys/types.h;sys/stat.h;fcntl.h" HAVE_NAME_TO_HANDLE_AT)
set(CMAKE_REQUIRED_DEFINITIONS)
find_package(LLVM REQUIRED)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
......
......@@ -13,6 +13,9 @@ add_executable(bpftrace
list.cpp
)
if(HAVE_NAME_TO_HANDLE_AT)
target_compile_definitions(bpftrace PRIVATE HAVE_NAME_TO_HANDLE_AT=1)
endif(HAVE_NAME_TO_HANDLE_AT)
target_link_libraries(bpftrace arch ast parser resources)
ExternalProject_Get_Property(bcc source_dir binary_dir)
......
......@@ -1287,6 +1287,8 @@ uint64_t BPFtrace::resolve_kname(const std::string &name)
return addr;
}
#ifdef HAVE_NAME_TO_HANDLE_AT
namespace
{
......@@ -1333,6 +1335,15 @@ uint64_t BPFtrace::resolve_cgroupid(const std::string &path)
return cfh.cgid;
}
#else
uint64_t BPFtrace::resolve_cgroupid(const std::string &path)
{
throw std::runtime_error("cgroupid is not supported on this system");
}
#endif
uint64_t BPFtrace::resolve_uname(const std::string &name, const std::string &path)
{
uint64_t addr = 0;
......
......@@ -24,6 +24,9 @@ add_executable(bpftrace_test
${CMAKE_SOURCE_DIR}/src/types.cpp
)
if(HAVE_NAME_TO_HANDLE_AT)
target_compile_definitions(bpftrace_test PRIVATE HAVE_NAME_TO_HANDLE_AT=1)
endif(HAVE_NAME_TO_HANDLE_AT)
target_link_libraries(bpftrace_test arch ast parser resources)
ExternalProject_Get_Property(bcc source_dir binary_dir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment