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(userspace/libsinsp): solve data race and segfault in logger #1643

Merged
merged 2 commits into from
Jan 25, 2024
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
8 changes: 2 additions & 6 deletions userspace/libsinsp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ const size_t ENCODE_LEN = sizeof(uint64_t);

} // end namespace

sinsp_logger* sinsp_logger::s_logger = nullptr;
sinsp_logger sinsp_logger::s_logger;

sinsp_logger* sinsp_logger::instance()
{
if(s_logger == nullptr)
{
s_logger = new sinsp_logger();
}
return s_logger;
return &s_logger;
}

const uint32_t sinsp_logger::OT_NONE = 0;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SINSP_PUBLIC sinsp_logger
sinsp_logger();
~sinsp_logger();

static sinsp_logger* s_logger;
static sinsp_logger s_logger;

/** Disable copy constructor and assignment operator */
sinsp_logger(const sinsp_logger&) = delete;
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const std::string &container_id
scap_userinfo *sinsp_usergroup_manager::add_host_user(uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify)
{
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"adding host user: name: %s", name);
"adding host user: name: %.*s", static_cast<int>(name.length()), name.data());

scap_userinfo *retval{nullptr};
if (name.data() != nullptr)
Expand Down Expand Up @@ -434,7 +434,7 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, i
scap_groupinfo *sinsp_usergroup_manager::add_host_group(uint32_t gid, std::string_view name, bool notify)
{
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"adding host group: name: %s", name);
"adding host group: name: %.*s", static_cast<int>(name.length()), name.data());

scap_groupinfo *gr = nullptr;
if (name.data())
Expand Down
Loading