Skip to content

Commit

Permalink
cleanup(sinsp): rename scap_mode_t and its values
Browse files Browse the repository at this point in the history
scap_mode_t is now named sinsp_mode_t to reflect that it's not used
in libscap at all, and all the enum values are renamed from SCAP_MODE_*
to SINSP_MODE_*

Signed-off-by: Grzegorz Nosek <[email protected]>
  • Loading branch information
gnosek authored and poiana committed Oct 30, 2023
1 parent fb1226c commit cbab0d8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
32 changes: 16 additions & 16 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void sinsp::set_import_users(bool import_users)
/*=============================== OPEN METHODS ===============================*/

void sinsp::open_common(scap_open_args* oargs, const struct scap_vtable* vtable, struct scap_platform* platform,
scap_mode_t mode)
sinsp_mode_t mode)
{
g_logger.log("Trying to open the right engine!");

Expand Down Expand Up @@ -586,7 +586,7 @@ void sinsp::open_kmod(unsigned long driver_buffer_bytes_dim, const libsinsp::eve
linux_plat->m_linux_vtable = &scap_kmod_linux_vtable;
}

open_common(&oargs, &scap_kmod_engine, platform, SCAP_MODE_LIVE);
open_common(&oargs, &scap_kmod_engine, platform, SINSP_MODE_LIVE);
#else
throw sinsp_exception("KMOD engine is not supported in this build");
#endif
Expand All @@ -613,7 +613,7 @@ void sinsp::open_bpf(const std::string& bpf_path, unsigned long driver_buffer_by
oargs.engine_params = &params;

struct scap_platform* platform = scap_linux_alloc_platform(::on_new_entry_from_proc, this);
open_common(&oargs, &scap_bpf_engine, platform, SCAP_MODE_LIVE);
open_common(&oargs, &scap_bpf_engine, platform, SINSP_MODE_LIVE);
#else
throw sinsp_exception("BPF engine is not supported in this build");
#endif
Expand All @@ -625,7 +625,7 @@ void sinsp::open_udig()
scap_open_args oargs {};

struct scap_platform* platform = scap_linux_alloc_platform(::on_new_entry_from_proc, this);
open_common(&oargs, &scap_udig_engine, platform, SCAP_MODE_LIVE);
open_common(&oargs, &scap_udig_engine, platform, SINSP_MODE_LIVE);

#else
throw sinsp_exception("UDIG engine is not supported in this build");
Expand All @@ -651,7 +651,7 @@ void sinsp::open_nodriver(bool full_proc_scan)
platform = scap_generic_alloc_platform(::on_new_entry_from_proc, this);
}

open_common(&oargs, &scap_nodriver_engine, platform, SCAP_MODE_NODRIVER);
open_common(&oargs, &scap_nodriver_engine, platform, SINSP_MODE_NODRIVER);
#else
throw sinsp_exception("NODRIVER engine is not supported in this build");
#endif
Expand Down Expand Up @@ -697,13 +697,13 @@ void sinsp::open_savefile(const std::string& filename, int fd)

// AFAICT this is because tinfo==NULL when calling the callback in scap_read_fdlist
struct scap_platform* platform = scap_savefile_alloc_platform(nullptr, nullptr);
open_common(&oargs, &scap_savefile_engine, platform, SCAP_MODE_CAPTURE);
open_common(&oargs, &scap_savefile_engine, platform, SINSP_MODE_CAPTURE);
#else
throw sinsp_exception("SAVEFILE engine is not supported in this build");
#endif
}

void sinsp::open_plugin(const std::string& plugin_name, const std::string& plugin_open_params, scap_mode_t mode)
void sinsp::open_plugin(const std::string& plugin_name, const std::string& plugin_open_params, sinsp_mode_t mode)
{
#ifdef HAS_ENGINE_SOURCE_PLUGIN
scap_open_args oargs {};
Expand All @@ -716,10 +716,10 @@ void sinsp::open_plugin(const std::string& plugin_name, const std::string& plugi
struct scap_platform* platform;
switch(mode)
{
case SCAP_MODE_PLUGIN:
case SINSP_MODE_PLUGIN:
platform = scap_generic_alloc_platform(::on_new_entry_from_proc, this);
break;
case SCAP_MODE_LIVE:
case SINSP_MODE_LIVE:
platform = scap_linux_alloc_platform(::on_new_entry_from_proc, this);
break;
default:
Expand Down Expand Up @@ -748,7 +748,7 @@ void sinsp::open_gvisor(const std::string& config_path, const std::string& root_
oargs.engine_params = &params;

struct scap_platform* platform = scap_gvisor_alloc_platform(::on_new_entry_from_proc, this);
open_common(&oargs, &scap_gvisor_engine, platform, SCAP_MODE_LIVE);
open_common(&oargs, &scap_gvisor_engine, platform, SINSP_MODE_LIVE);

set_get_procs_cpu_from_driver(false);
#else
Expand All @@ -773,13 +773,13 @@ void sinsp::open_modern_bpf(unsigned long driver_buffer_bytes_dim, uint16_t cpus
oargs.engine_params = &params;

struct scap_platform* platform = scap_linux_alloc_platform(::on_new_entry_from_proc, this);
open_common(&oargs, &scap_modern_bpf_engine, platform, SCAP_MODE_LIVE);
open_common(&oargs, &scap_modern_bpf_engine, platform, SINSP_MODE_LIVE);
#else
throw sinsp_exception("MODERN_BPF engine is not supported in this build");
#endif
}

void sinsp::open_test_input(scap_test_input_data* data, scap_mode_t mode)
void sinsp::open_test_input(scap_test_input_data* data, sinsp_mode_t mode)
{
#ifdef HAS_ENGINE_TEST_INPUT
scap_open_args oargs {};
Expand All @@ -790,10 +790,10 @@ void sinsp::open_test_input(scap_test_input_data* data, scap_mode_t mode)
struct scap_platform* platform;
switch(mode)
{
case SCAP_MODE_TEST:
case SINSP_MODE_TEST:
platform = scap_test_input_alloc_platform(::on_new_entry_from_proc, this);
break;
case SCAP_MODE_LIVE:
case SINSP_MODE_LIVE:
platform = scap_linux_alloc_platform(::on_new_entry_from_proc, this);
break;
default:
Expand Down Expand Up @@ -928,7 +928,7 @@ void sinsp::close()
}

// unset the meta-event callback to all plugins that support it
if (!is_capture() && m_mode != SCAP_MODE_NONE)
if (!is_capture() && m_mode != SINSP_MODE_NONE)
{
std::string err;
// note(jasondellaluce,rohith-raju): for now the emscripten build does not support
Expand Down Expand Up @@ -956,7 +956,7 @@ void sinsp::close()
}
}

m_mode = SCAP_MODE_NONE;
m_mode = SINSP_MODE_NONE;
}

//
Expand Down
36 changes: 18 additions & 18 deletions userspace/libsinsp/sinsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,38 @@ class sinsp_proc_metainfo
};

/*!
\brief Scap possible modes
\brief Sinsp possible modes
*/
typedef enum
{
/*!
* Default value that mostly exists so that sinsp can have a valid value
* before it is initialized.
*/
SCAP_MODE_NONE = 0,
SINSP_MODE_NONE = 0,
/*!
* Read system call data from a capture file.
*/
SCAP_MODE_CAPTURE,
SINSP_MODE_CAPTURE,
/*!
* Read system call data from the underlying operating system.
*/
SCAP_MODE_LIVE,
SINSP_MODE_LIVE,
/*!
* Do not read system call data. If next is called, a dummy event is
* returned.
*/
SCAP_MODE_NODRIVER,
SINSP_MODE_NODRIVER,
/*!
* Do not read system call data. Events come from the configured input plugin.
*/
SCAP_MODE_PLUGIN,
SINSP_MODE_PLUGIN,
/*!
* Read system call and event data from the test event generator.
* Do not attempt to query the underlying system.
*/
SCAP_MODE_TEST,
} scap_mode_t;
SINSP_MODE_TEST,
} sinsp_mode_t;

/** @defgroup inspector Main library
@{
Expand Down Expand Up @@ -261,14 +261,14 @@ class SINSP_PUBLIC sinsp : public capture_stats_source
virtual void open_nodriver(bool full_proc_scan = false);
virtual void open_savefile(const std::string &filename, int fd = 0);
virtual void open_plugin(const std::string& plugin_name, const std::string& plugin_open_params,
scap_mode_t mode = SCAP_MODE_PLUGIN);
sinsp_mode_t mode = SINSP_MODE_PLUGIN);
virtual void open_gvisor(const std::string &config_path, const std::string &root_path, bool no_events = false, int epoll_timeout = -1);
/*[EXPERIMENTAL] This API could change between releases, we are trying to find the right configuration to deploy the modern bpf probe:
* `cpus_for_each_buffer` and `online_only` are the 2 experimental params. The first one allows associating more than one CPU to a single ring buffer.
* The last one allows allocating ring buffers only for online CPUs and not for all system-available CPUs.
*/
virtual void open_modern_bpf(unsigned long driver_buffer_bytes_dim = DEFAULT_DRIVER_BUFFER_BYTES_DIM, uint16_t cpus_for_each_buffer = DEFAULT_CPU_FOR_EACH_BUFFER, bool online_only = true, const libsinsp::events::set<ppm_sc_code> &ppm_sc_of_interest = {});
virtual void open_test_input(scap_test_input_data* data, scap_mode_t mode = SCAP_MODE_TEST);
virtual void open_test_input(scap_test_input_data* data, sinsp_mode_t mode = SINSP_MODE_TEST);

void fseek(uint64_t filepos)
{
Expand Down Expand Up @@ -644,39 +644,39 @@ class SINSP_PUBLIC sinsp : public capture_stats_source
*/
inline bool is_capture()
{
return m_mode == SCAP_MODE_CAPTURE;
return m_mode == SINSP_MODE_CAPTURE;
}

/*!
\brief Returns true if the current capture is offline
*/
inline bool is_offline()
{
return is_capture() || m_mode == SCAP_MODE_TEST;
return is_capture() || m_mode == SINSP_MODE_TEST;
}

/*!
\brief Returns true if the current capture is live
*/
inline bool is_live()
{
return m_mode == SCAP_MODE_LIVE;
return m_mode == SINSP_MODE_LIVE;
}

/*!
\brief Returns true if the kernel module is not loaded
*/
inline bool is_nodriver()
{
return m_mode == SCAP_MODE_NODRIVER;
return m_mode == SINSP_MODE_NODRIVER;
}

/*!
\brief Returns true if the current capture has a plugin producing events.
*/
inline bool is_plugin()
{
return m_mode == SCAP_MODE_PLUGIN && m_input_plugin != nullptr;
return m_mode == SINSP_MODE_PLUGIN && m_input_plugin != nullptr;
}

/*!
Expand Down Expand Up @@ -1061,7 +1061,7 @@ class SINSP_PUBLIC sinsp : public capture_stats_source

VISIBILITY_PROTECTED
bool add_thread(const sinsp_threadinfo *ptinfo);
void set_mode(scap_mode_t value)
void set_mode(sinsp_mode_t value)
{
m_mode = value;
}
Expand All @@ -1075,7 +1075,7 @@ VISIBILITY_PRIVATE

void set_input_plugin(const std::string& name, const std::string& params);
void open_common(scap_open_args* oargs, const struct scap_vtable* vtable, struct scap_platform* platform,
scap_mode_t mode);
sinsp_mode_t mode);
void init();
void deinit_state();
void consume_initialstate_events();
Expand Down Expand Up @@ -1128,7 +1128,7 @@ VISIBILITY_PRIVATE
scap_t* m_h;
uint64_t m_nevts;
int64_t m_filesize;
scap_mode_t m_mode = SCAP_MODE_NONE;
sinsp_mode_t m_mode = SINSP_MODE_NONE;

// If non-zero, reading from this fd and m_input_filename contains "fd
// <m_input_fd>". Otherwise, reading from m_input_filename.
Expand Down
10 changes: 5 additions & 5 deletions userspace/libsinsp/test/classes/sinsp_thread_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST(sinsp_thread_manager, create_thread_dependencies_null_pointer)
struct scap_test_input_data data;
data.event_count = 0;
data.thread_count = 0;
m_inspector.open_test_input(&data, SCAP_MODE_TEST);
m_inspector.open_test_input(&data, SINSP_MODE_TEST);

auto tinfo = std::make_shared<sinsp_threadinfo>();
tinfo.reset();
Expand All @@ -71,7 +71,7 @@ TEST(sinsp_thread_manager, create_thread_dependencies_invalid_tinfo)
struct scap_test_input_data data;
data.event_count = 0;
data.thread_count = 0;
m_inspector.open_test_input(&data, SCAP_MODE_TEST);
m_inspector.open_test_input(&data, SINSP_MODE_TEST);

auto tinfo = std::make_shared<sinsp_threadinfo>();
tinfo->m_tid = 4;
Expand All @@ -89,7 +89,7 @@ TEST(sinsp_thread_manager, create_thread_dependencies_tginfo_already_there)
struct scap_test_input_data data;
data.event_count = 0;
data.thread_count = 0;
m_inspector.open_test_input(&data, SCAP_MODE_TEST);
m_inspector.open_test_input(&data, SINSP_MODE_TEST);

auto tinfo = std::make_shared<sinsp_threadinfo>();
tinfo->m_tid = 4;
Expand All @@ -110,7 +110,7 @@ TEST(sinsp_thread_manager, create_thread_dependencies_new_tginfo)
struct scap_test_input_data data;
data.event_count = 0;
data.thread_count = 0;
m_inspector.open_test_input(&data, SCAP_MODE_TEST);
m_inspector.open_test_input(&data, SINSP_MODE_TEST);

auto tinfo = std::make_shared<sinsp_threadinfo>();
tinfo->m_tid = 51000;
Expand All @@ -131,7 +131,7 @@ TEST(sinsp_thread_manager, create_thread_dependencies_use_existing_tginfo)
struct scap_test_input_data data;
data.event_count = 0;
data.thread_count = 0;
m_inspector.open_test_input(&data, SCAP_MODE_TEST);
m_inspector.open_test_input(&data, SINSP_MODE_TEST);

auto tinfo = std::make_shared<sinsp_threadinfo>();
tinfo->m_tid = 51000;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/events_evt.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST_F(sinsp_with_test_input, event_hostname)

add_default_init_thread();

open_inspector(SCAP_MODE_LIVE);
open_inspector(SINSP_MODE_LIVE);
sinsp_evt *evt = NULL;

/* Toy event example from a previous test. */
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/sinsp_with_test_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class sinsp_with_test_input : public ::testing::Test {

sinsp m_inspector;

void open_inspector(scap_mode_t mode = SCAP_MODE_TEST) {
void open_inspector(sinsp_mode_t mode = SINSP_MODE_TEST) {
m_inspector.open_test_input(m_test_data.get(), mode);
}

Expand Down

0 comments on commit cbab0d8

Please sign in to comment.