Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move definitions to inner CMakeLists.txt(s) and correct add_user/add_group #361

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if(ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# NOTE: do not add `add_definition` in this file because consumers project won't import it.

if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(CMD_MAKE gmake)
else()
Expand Down Expand Up @@ -63,19 +65,6 @@ else() # MSVC

endif()

include(CheckIncludeFile)

check_include_file("pwd.h" HAVE_PWD_H)
if (HAVE_PWD_H)
add_definitions(-DHAVE_PWD_H)
endif()

check_include_file("grp.h" HAVE_GRP_H)
if (HAVE_GRP_H)
add_definitions(-DHAVE_GRP_H)
endif()


if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")
endif()
Expand Down
9 changes: 9 additions & 0 deletions userspace/libscap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../common")

option(USE_BUNDLED_DEPS "Enable bundled dependencies instead of using the system ones" ON)

if(NOT MSVC)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DHAS_CAPTURE)
endif()
else() # MSVC
# todo(leogr): this should be removed - double check
add_definitions(-DHAS_CAPTURE)
endif()

include(ExternalProject)

if(WIN32 OR NOT MINIMAL_BUILD)
Expand Down
21 changes: 21 additions & 0 deletions userspace/libsinsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ include_directories(./include)

option(USE_BUNDLED_DEPS "Enable bundled dependencies instead of using the system ones" ON)

if(NOT MSVC)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DHAS_CAPTURE)
endif()
else() # MSVC
# todo(leogr): this should be removed - double check
add_definitions(-DHAS_CAPTURE)
endif()

include(CheckIncludeFile)

check_include_file("pwd.h" HAVE_PWD_H)
if (HAVE_PWD_H)
add_definitions(-DHAVE_PWD_H)
endif()

check_include_file("grp.h" HAVE_GRP_H)
if (HAVE_GRP_H)
add_definitions(-DHAVE_GRP_H)
endif()

include(ExternalProject)

if(NOT WIN32 AND NOT APPLE)
Expand Down
1 change: 0 additions & 1 deletion userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,6 @@ void sinsp_parser::parse_clone_exit(sinsp_evt *evt)
}
ASSERT(parinfo->m_len == sizeof(int32_t));
tinfo->set_group(*(int32_t *)parinfo->m_val);
tinfo->m_user.gid = tinfo->m_group.gid;

//
// If we're in a container, vtid and vpid are
Expand Down
4 changes: 3 additions & 1 deletion userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ void sinsp_threadinfo::init(scap_threadinfo* pi)
ASSERT(m_inspector);
m_inspector->m_container_manager.resolve_container(this, !m_inspector->is_capture());

set_user(pi->uid);
set_group(pi->gid);
set_user(pi->uid);
set_loginuser((uint32_t)pi->loginuid);

//
Expand Down Expand Up @@ -537,6 +537,8 @@ void sinsp_threadinfo::set_group(uint32_t gid)
m_group.gid = gid;
strcpy(m_group.name, "<NA>");
}
// Force-sync user.gid and group id
m_user.gid = m_group.gid;
}

void sinsp_threadinfo::set_loginuser(uint32_t loginuid)
Expand Down
9 changes: 7 additions & 2 deletions userspace/libsinsp/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const string &container_id, uin
if (!usr)
{
#ifdef HAVE_PWD_H
struct passwd *p = nullptr;
if (container_id.empty() && !name)
{
// On Host, try to load info from db
auto *p = getpwuid(uid);
p = getpwuid(uid);
if (p)
{
name = p->pw_name;
Expand Down Expand Up @@ -186,6 +187,8 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const string &container_id, uin
{
notify_user_changed(&userlist[uid], container_id);
}

usr = &userlist[uid];
}
return usr;
}
Expand Down Expand Up @@ -217,10 +220,11 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, u
if (!gr)
{
#ifdef HAVE_GRP_H
struct group *p = nullptr;
if (container_id.empty() && !name)
{
// On Host, try to load info from db
auto *p = getgrgid(gid);
p = getgrgid(gid);
if (p)
{
name = p->gr_name;
Expand All @@ -241,6 +245,7 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, u
{
notify_group_changed(&grplist[gid], container_id, true);
}
gr = &grplist[gid];
}
return gr;
}
Expand Down