Skip to content

Commit

Permalink
Allow scopes to be initially empty. (#754)
Browse files Browse the repository at this point in the history
Allow an initially empty scope by skipping the add() call in the
constructor unless both key and value are non-empty.

Also, in get()/get_ref() log a warning if the scope-as-string is empty.
  • Loading branch information
mstemm authored and Luca Marturana committed Feb 21, 2017
1 parent 3153d27 commit c6eb34a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion userspace/libsinsp/user_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const std::string event_scope::KEY_FORMAT = "^[a-zA-Z0-9_/\\.-]*$";

event_scope::event_scope(const std::string& key, const std::string& value)
{
add(key, value, "");
if(!key.empty() && !value.empty())
{
add(key, value, "");
}
}

bool event_scope::add(const std::string& key, const std::string& value, const std::string& op)
Expand Down
11 changes: 11 additions & 0 deletions userspace/libsinsp/user_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,22 @@ class event_scope

inline const std::string& event_scope::get() const
{
if(m_scope.empty())
{
g_logger.log("Scope is empty--at least one key/value pair should be present",
sinsp_logger::SEV_WARNING);
}
return m_scope;
}

inline std::string& event_scope::get_ref()
{
if(m_scope.empty())
{
g_logger.log("Scope is empty--at least one key/value pair should be present",
sinsp_logger::SEV_WARNING);
}

return m_scope;
}

Expand Down

0 comments on commit c6eb34a

Please sign in to comment.