From 8f2d04a3c1123d62fac004d7c94d70c3c0bfde40 Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Wed, 13 Mar 2024 14:38:48 +0000 Subject: [PATCH] fix: alignment with libs api Signed-off-by: Roberto Scolaro --- CMakeLists.txt | 4 ++ .../falcosecurity-libs-repo/CMakeLists.txt | 1 - cmake/modules/falcosecurity-libs.cmake | 11 +++-- userspace/sinspui/cursescomponents.cpp | 21 ++++----- userspace/sinspui/cursescomponents.h | 2 +- userspace/sinspui/cursesspectro.cpp | 14 +++--- userspace/sinspui/cursestable.cpp | 12 +++--- userspace/sinspui/cursesui.cpp | 30 ++++++------- userspace/sinspui/cursesui.h | 5 ++- userspace/sysdig/CMakeLists.txt | 9 ---- userspace/sysdig/csysdig.cpp | 12 +++--- userspace/sysdig/sysdig.cpp | 43 ++++++++++--------- userspace/sysdig/utils/supported_fields.cpp | 2 +- 13 files changed, 75 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58876a7334..d331e57a6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,10 @@ endif() set(PACKAGE_NAME "sysdig") add_definitions(-DPLATFORM_NAME="${CMAKE_SYSTEM_NAME}") +if(NOT DEFINED CHISEL_TOOL_LIBRARY_NAME) + set(CHISEL_TOOL_LIBRARY_NAME "sysdig") +endif() +add_definitions(-DCHISEL_TOOL_LIBRARY_NAME="${CHISEL_TOOL_LIBRARY_NAME}") option(BUILD_WARNINGS_AS_ERRORS "Enable building with -Wextra -Werror flags") diff --git a/cmake/modules/falcosecurity-libs-repo/CMakeLists.txt b/cmake/modules/falcosecurity-libs-repo/CMakeLists.txt index 1896b79e85..eed2f34727 100644 --- a/cmake/modules/falcosecurity-libs-repo/CMakeLists.txt +++ b/cmake/modules/falcosecurity-libs-repo/CMakeLists.txt @@ -31,5 +31,4 @@ ExternalProject_Add( BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" - PATCH_COMMAND sh -c "patch -p1 <${CMAKE_SOURCE_DIR}/chisel.patch && patch -p1 <${CMAKE_SOURCE_DIR}/eof.patch" ) diff --git a/cmake/modules/falcosecurity-libs.cmake b/cmake/modules/falcosecurity-libs.cmake index 0c51042af0..6f5b32da1a 100644 --- a/cmake/modules/falcosecurity-libs.cmake +++ b/cmake/modules/falcosecurity-libs.cmake @@ -32,8 +32,8 @@ else() # In case you want to test against another falcosecurity/libs version (or branch, or commit) just pass the variable - # ie., `cmake -DFALCOSECURITY_LIBS_VERSION=dev ..` if(NOT FALCOSECURITY_LIBS_VERSION) - set(FALCOSECURITY_LIBS_VERSION "0.14.2") - set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=b4ae7bbf3ad031deee4a808145f9fd64b71c537406cc5a92f512823b2e52cdd5") + set(FALCOSECURITY_LIBS_VERSION "0.15.1") + set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=8c2596fec3c25e9718a8b357b0504450cd26efbe653b79afcd66a8405f0dc08c") endif() # cd /path/to/build && cmake /path/to/source @@ -57,10 +57,9 @@ endif() set(SCAP_HOST_ROOT_ENV_VAR_NAME "HOST_ROOT") -if(NOT LIBSCAP_DIR) - set(LIBSCAP_DIR "${FALCOSECURITY_LIBS_SOURCE_DIR}") -endif() -set(LIBSINSP_DIR "${FALCOSECURITY_LIBS_SOURCE_DIR}") +if(NOT LIBS_DIR) + set(LIBS_DIR "${FALCOSECURITY_LIBS_SOURCE_DIR}") + endif() # configure gVisor support set(BUILD_LIBSCAP_GVISOR ${BUILD_SYSDIG_GVISOR} CACHE BOOL "") diff --git a/userspace/sinspui/cursescomponents.cpp b/userspace/sinspui/cursescomponents.cpp index e730c9c8c4..e52e0d624a 100644 --- a/userspace/sinspui/cursescomponents.cpp +++ b/userspace/sinspui/cursescomponents.cpp @@ -33,15 +33,15 @@ limitations under the License. #include using namespace std; -#include "sinsp.h" -#include "sinsp_int.h" -#include "filter.h" -#include "filterchecks.h" +#include +#include +#include +#include -#include "chisel_table.h" +#include +#include #include "cursescomponents.h" #include "cursestable.h" -#include "chisel_viewinfo.h" #include "cursesui.h" #include "utils.h" @@ -150,7 +150,7 @@ const char* spy_text_renderer::process_event_spy(sinsp_evt* evt, int64_t* len) return NULL; } - sinsp_fdinfo_t* m_fdinfo = evt->get_fd_info(); + sinsp_fdinfo* m_fdinfo = evt->get_fd_info(); if(m_fdinfo == NULL) { return NULL; @@ -835,11 +835,6 @@ curses_textbox::~curses_textbox() delete m_searcher; } - if(m_filter != NULL) - { - delete m_filter; - } - if(m_text_renderer) { delete m_text_renderer; @@ -860,7 +855,7 @@ curses_textbox::~curses_textbox() void curses_textbox::set_filter(string filter) { sinsp_filter_compiler compiler(m_inspector, filter); - m_filter = compiler.compile(); + m_filter = std::move(compiler.compile()); } void curses_textbox::print_no_data() diff --git a/userspace/sinspui/cursescomponents.h b/userspace/sinspui/cursescomponents.h index 8f0cfb2c88..56df5e4da4 100644 --- a/userspace/sinspui/cursescomponents.h +++ b/userspace/sinspui/cursescomponents.h @@ -212,7 +212,7 @@ public sinsp_chart, public search_caller_interface ctext* m_ctext; sinsp_cursesui* m_parent; sinsp* m_inspector; - sinsp_filter* m_filter; + std::unique_ptr m_filter; uint32_t n_prints; bool m_paused; curses_table_sidemenu* m_sidemenu; diff --git a/userspace/sinspui/cursesspectro.cpp b/userspace/sinspui/cursesspectro.cpp index dd3dec2851..73a16cbc66 100644 --- a/userspace/sinspui/cursesspectro.cpp +++ b/userspace/sinspui/cursesspectro.cpp @@ -34,14 +34,14 @@ limitations under the License. #include using namespace std; -#include "sinsp.h" -#include "filter.h" -#include "filterchecks.h" +#include +#include +#include #ifndef NOCURSESUI #include -#include "chisel_table.h" +#include #include "ctext.h" #include "cursescomponents.h" #include "cursestable.h" @@ -463,7 +463,7 @@ chisel_table_action curses_spectro::handle_input(int ch) { if(m_last_mevent.bstate & BUTTON1_CLICKED) { - g_logger.format("mouse clicked"); + libsinsp_logger()->format("mouse clicked"); if(m_last_mevent.y == (int)m_h - 2) { @@ -517,8 +517,8 @@ chisel_table_action curses_spectro::handle_input(int ch) ") and (evt.latency>=" + to_string(start_latency) + " and evt.latency<" + to_string(end_latency) + ")"; - g_logger.format("spectrogram drill down"); - g_logger.format("filter: %s", m_selection_filter.c_str()); + libsinsp_logger()->format("spectrogram drill down"); + libsinsp_logger()->format("filter: %s", m_selection_filter.c_str()); m_selstart_x = -1; m_selstart_y = -1; diff --git a/userspace/sinspui/cursestable.cpp b/userspace/sinspui/cursestable.cpp index 5c2fee2f95..e39adc195f 100644 --- a/userspace/sinspui/cursestable.cpp +++ b/userspace/sinspui/cursestable.cpp @@ -32,15 +32,15 @@ limitations under the License. #include using namespace std; -#include "sinsp.h" -#include "sinsp_int.h" -#include "filter.h" -#include "filterchecks.h" +#include +#include +#include +#include #ifndef NOCURSESUI #include -#include "chisel_table.h" +#include #include "cursescomponents.h" #include "cursestable.h" #include "cursesui.h" @@ -261,7 +261,7 @@ void curses_table::print_line_centered(string line, int32_t off) for(uint32_t j = 0;; j++) { string ss = line.substr(spos, spos + m_parent->m_screenw); -glogf("2, %d %s\n", spos, ss.c_str()); + libsinsp_logger()->format("2, %d %s\n", spos, ss.c_str()); mvwprintw(m_tblwin, m_parent->m_screenh / 2 + off + j, diff --git a/userspace/sinspui/cursesui.cpp b/userspace/sinspui/cursesui.cpp index 32f4b23b15..76f2fb3d40 100644 --- a/userspace/sinspui/cursesui.cpp +++ b/userspace/sinspui/cursesui.cpp @@ -19,10 +19,10 @@ limitations under the License. #include #include -#include "sinsp.h" -#include "sinsp_int.h" -#include "filter.h" -#include "filterchecks.h" +#include +#include +#include +#include #ifndef _WIN32 #include @@ -30,7 +30,7 @@ limitations under the License. #include #define getch _getch #endif -#include "chisel_table.h" +#include #include "cursescomponents.h" #include "cursestable.h" #include "cursesspectro.h" @@ -86,11 +86,6 @@ json_spy_renderer::json_spy_renderer(sinsp* inspector, json_spy_renderer::~json_spy_renderer() { delete m_json_spy_renderer; - - if(m_filter != NULL) - { - delete m_filter; - } } void json_spy_renderer::set_filter(string filter) @@ -98,7 +93,7 @@ void json_spy_renderer::set_filter(string filter) if(filter != "") { sinsp_filter_compiler compiler(m_inspector, filter); - m_filter = compiler.compile(); + m_filter = std::move(compiler.compile()); } } @@ -2266,11 +2261,11 @@ chisel_table_action sinsp_cursesui::handle_textbox_input(int ch) if(*str != "") { sinsp_filter_compiler compiler(m_inspector, *str); - sinsp_filter* f; + std::unique_ptr f; try { - f = compiler.compile(); + f = std::move(compiler.compile()); } catch(const sinsp_exception& e) { @@ -2300,7 +2295,6 @@ chisel_table_action sinsp_cursesui::handle_textbox_input(int ch) break; } - delete f; } } @@ -2535,7 +2529,7 @@ chisel_table_action sinsp_cursesui::handle_input(int ch) { chisel_view_info* vinfo = get_selected_view(); - g_logger.format("running action %d %s", m_selected_action_sidemenu_entry, + libsinsp_logger()->format("running action %d %s", m_selected_action_sidemenu_entry, vinfo->m_name.c_str()); if(vinfo->m_actions.size() != 0) { @@ -3179,8 +3173,8 @@ void sinsp_cursesui::run_action(chisel_view_action_info* action) #endif // NOCURSESUI } - g_logger.format("original command: %s", action->m_command.c_str()); - g_logger.format("running command: %s", resolved_command.c_str()); + libsinsp_logger()->format("original command: %s", action->m_command.c_str()); + libsinsp_logger()->format("running command: %s", resolved_command.c_str()); #ifndef NOCURSESUI // @@ -3225,7 +3219,7 @@ void sinsp_cursesui::run_action(chisel_view_action_info* action) int sret = system(resolved_command.c_str()); if(sret == -1) { - g_logger.format("command failed"); + libsinsp_logger()->format("command failed"); } } diff --git a/userspace/sinspui/cursesui.h b/userspace/sinspui/cursesui.h index 4c77edfbe0..478e1f6053 100644 --- a/userspace/sinspui/cursesui.h +++ b/userspace/sinspui/cursesui.h @@ -21,6 +21,8 @@ limitations under the License. #include #endif +#include + #include "../sysdig/utils/sinsp_opener.h" #define UI_USER_INPUT_CHECK_PERIOD_NS 10000000 @@ -31,7 +33,6 @@ std::string combine_filters(std::string flt1, std::string flt2); class ctext; class sinsp_chart; class curses_spectro; -extern sinsp_logger g_logger; class sinsp_menuitem_info { @@ -350,7 +351,7 @@ class json_spy_renderer spy_text_renderer* m_json_spy_renderer; sinsp* m_inspector; Json::Value m_root; - sinsp_filter* m_filter; + std::unique_ptr m_filter; uint64_t m_linecnt; }; diff --git a/userspace/sysdig/CMakeLists.txt b/userspace/sysdig/CMakeLists.txt index 99da7a3f96..82c938112a 100644 --- a/userspace/sysdig/CMakeLists.txt +++ b/userspace/sysdig/CMakeLists.txt @@ -20,11 +20,6 @@ if(NOT WIN32) include(ncurses) endif() # NOT WIN32 -include(libscap) -include(libsinsp) -include(zlib) - -include_directories("${LIBSINSP_INCLUDE_DIRS}") include_directories("${PROJECT_BINARY_DIR}/userspace/sinspui") include_directories(../sinspui) include_directories("${PROJECT_BINARY_DIR}/userspace/sysdig") @@ -76,16 +71,12 @@ endif() target_include_directories( sysdig PUBLIC - "${LIBSCAP_INCLUDE_DIRS}" - "${LIBSINSP_INCLUDE_DIRS}" "${YAMLCPP_INCLUDE_DIR}" "${NJSON_INCLUDE_DIR}") target_include_directories( csysdig PUBLIC - "${LIBSCAP_INCLUDE_DIRS}" - "${LIBSINSP_INCLUDE_DIRS}" "${YAMLCPP_INCLUDE_DIR}" "${NJSON_INCLUDE_DIR}") diff --git a/userspace/sysdig/csysdig.cpp b/userspace/sysdig/csysdig.cpp index 68f077fe99..4b48f02561 100644 --- a/userspace/sysdig/csysdig.cpp +++ b/userspace/sysdig/csysdig.cpp @@ -28,7 +28,7 @@ limitations under the License. #include #include -#include +#include #ifdef HAS_CAPTURE #ifndef WIN32 #include "driver_config.h" @@ -36,11 +36,11 @@ limitations under the License. #endif // HAS_CAPTURE #include "sysdig.h" #ifdef HAS_CHISELS -#include "chisel.h" -#include "chisel_utils.h" +#include +#include #endif -#include "chisel_table.h" -#include "utils.h" +#include +#include #include "utils/plugin_utils.h" #include "utils/sinsp_opener.h" #include "utils/supported_fields.h" @@ -58,7 +58,7 @@ limitations under the License. #include "cursestable.h" #include "cursesui.h" #include "scap_open_exception.h" -#include "chisel_capture_interrupt_exception.h" +#include #define MOUSE_CAPABLE_TERM "xterm-1003" #define MOUSE_CAPABLE_TERM_COMPAT "xterm-1002" diff --git a/userspace/sysdig/sysdig.cpp b/userspace/sysdig/sysdig.cpp index 0c7a93f08c..f72975fdc3 100644 --- a/userspace/sysdig/sysdig.cpp +++ b/userspace/sysdig/sysdig.cpp @@ -30,9 +30,10 @@ limitations under the License. #include #include -#include +#include +#include #include "scap_open_exception.h" -#include "chisel_capture_interrupt_exception.h" +#include #ifdef HAS_CAPTURE #ifndef WIN32 #include "driver_config.h" @@ -40,9 +41,9 @@ limitations under the License. #endif // HAS_CAPTURE #include "sysdig.h" #ifdef HAS_CHISELS -#include "chisel.h" -#include "chisel_utils.h" -#include "chisel_fields_info.h" +#include +#include +#include #endif #include "utils.h" #include "plugin.h" @@ -542,7 +543,7 @@ static void initialize_chisels() // static void parse_chisel_args( sinsp_chisel* ch, - std::shared_ptr filter_factory, + std::shared_ptr filter_factory, int optind, int argc, char **argv, int32_t* n_filterargs) { uint32_t nargs = ch->get_n_args(); @@ -589,8 +590,7 @@ static void parse_chisel_args( try { sinsp_filter_compiler compiler(filter_factory, testflt); - sinsp_filter* s = compiler.compile(); - delete s; + std::unique_ptr s = compiler.compile(); } catch(...) { @@ -737,6 +737,7 @@ std::vector split_nextrun_args(std::string na) // Event processing loop // captureinfo do_inspect(sinsp* inspector, + sinsp_cycledumper* dumper, uint64_t cnt, uint64_t duration_to_tot_ns, bool quiet, @@ -744,7 +745,7 @@ captureinfo do_inspect(sinsp* inspector, bool do_flush, bool reset_colors, bool print_progress, - sinsp_filter* display_filter, + std::unique_ptr display_filter, std::vector &summary_table, sinsp_evt_formatter* syscall_evt_formatter, sinsp_evt_formatter* plugin_evt_formatter) @@ -785,6 +786,10 @@ captureinfo do_inspect(sinsp* inspector, break; } res = inspector->next(&ev); + if(dumper && ev && res != SCAP_EOF) + { + dumper->dump(ev); + } if(res == SCAP_TIMEOUT || res == SCAP_FILTERED_EVENT) { @@ -897,7 +902,7 @@ captureinfo do_inspect(sinsp* inspector, continue; } - if(display_filter && !display_filter->run(ev)) + if(display_filter.get() && !display_filter->run(ev)) { continue; } @@ -983,6 +988,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) { sysdig_init_res res; std::unique_ptr inspector; + std::unique_ptr dumper; std::vector infiles; std::string outfile; int op; @@ -995,7 +1001,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) std::string list_flds_source = ""; bool compress = false; sinsp_evt::param_fmt event_buffer_format = sinsp_evt::PF_NORMAL; - sinsp_filter* display_filter = NULL; + std::unique_ptr display_filter; double duration = 1; int duration_to_tot = 0; captureinfo cinfo; @@ -1024,7 +1030,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) std::string plugin_config_file = ""; sinsp_opener opener; std::unique_ptr filter_list; - std::shared_ptr filter_factory; + std::shared_ptr filter_factory; // These variables are for the cycle_writer engine int duration_seconds = 0; @@ -1543,7 +1549,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) fprintf(stderr, "invalid log level %s\n", optarg); return sysdig_init_res(EXIT_FAILURE); } - g_logger.add_stdout_log(); + libsinsp_logger()->add_stdout_log(); } else if (optname == "list-chisels") { std::vector chlist; @@ -1917,8 +1923,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) if(outfile != "") { - inspector->setup_cycle_writer(outfile, rollover_mb, duration_seconds, file_limit, event_limit, compress); - inspector->autodump_next_file(); + dumper = std::make_unique(inspector.get(), outfile, rollover_mb, duration_seconds, file_limit, event_limit, compress); } // @@ -1969,6 +1974,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) disable_tty_echo(); #endif cinfo = do_inspect(inspector.get(), + dumper.get(), cnt, uint64_t(duration_to_tot*ONE_SECOND_IN_NS), quiet, @@ -1976,7 +1982,7 @@ sysdig_init_res sysdig_init(int argc, char **argv) unbuf_flag, reset_colors, opener.options.print_progress, - display_filter, + std::move(display_filter), summary_table, &syscall_evt_formatter, &plugin_evt_formatter); @@ -2060,11 +2066,6 @@ sysdig_init_res sysdig_init(int argc, char **argv) // free_chisels(); - if(display_filter) - { - delete display_filter; - } - return res; } diff --git a/userspace/sysdig/utils/supported_fields.cpp b/userspace/sysdig/utils/supported_fields.cpp index e848feba12..03057e5081 100644 --- a/userspace/sysdig/utils/supported_fields.cpp +++ b/userspace/sysdig/utils/supported_fields.cpp @@ -28,7 +28,7 @@ limitations under the License. struct fields_info { std::set compatible_sources; - gen_event_filter_factory::filter_fieldclass_info class_info; + sinsp_filter_factory::filter_fieldclass_info class_info; }; void print_supported_fields(sinsp* inspector, plugin_utils& plugins, const std::string &source, bool verbose, bool markdown)