diff --git a/userspace/falco/CMakeLists.txt b/userspace/falco/CMakeLists.txt index 087b180c..946f26d4 100644 --- a/userspace/falco/CMakeLists.txt +++ b/userspace/falco/CMakeLists.txt @@ -16,7 +16,6 @@ configure_file(config_falco.h.in config_falco.h) set( FALCO_SOURCES app/app.cpp - app/state.cpp app/signals.cpp app/options.cpp app/actions/helpers_generic.cpp diff --git a/userspace/falco/app/actions/compute_syscall_buffer_size.cpp b/userspace/falco/app/actions/compute_syscall_buffer_size.cpp index 35d0c37b..f4f9009f 100644 --- a/userspace/falco/app/actions/compute_syscall_buffer_size.cpp +++ b/userspace/falco/app/actions/compute_syscall_buffer_size.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/create_requested_paths.cpp b/userspace/falco/app/actions/create_requested_paths.cpp index 93cea9d8..80487471 100644 --- a/userspace/falco/app/actions/create_requested_paths.cpp +++ b/userspace/falco/app/actions/create_requested_paths.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,28 +29,7 @@ limitations under the License. using namespace falco::app; using namespace falco::app::actions; -static int create_dir(const std::string &path) -{ - // Properly reset errno - errno = 0; - - std::istringstream f(path); - std::string path_until_token; - std::string s; - // Create all the subfolder stopping at last token (f.eof()); - // Examples: - // "/tmp/foo/bar" -> "", "tmp", "foo" -> mkdir("/") + mkdir("/tmp/") + midir("/tmp/foo/") - // "tmp/foo/bar" -> "tmp", "foo" -> mkdir("tmp/") + midir("tmp/foo/") - while (getline(f, s, *CPPPATH_SEP) && !f.eof()) { - path_until_token += s + CPPPATH_SEP; - int ret = mkdir(path_until_token.c_str(), 0600); - if (ret != 0 && errno != EEXIST) - { - return ret; - } - } - return 0; -} +static int create_dir(const std::string &path); falco::app::run_result falco::app::actions::create_requested_paths(falco::app::state& s) { @@ -111,3 +90,25 @@ falco::app::run_result falco::app::actions::create_requested_paths(falco::app::s return run_result::ok(); } +static int create_dir(const std::string &path) +{ + // Properly reset errno + errno = 0; + + std::istringstream f(path); + std::string path_until_token; + std::string s; + // Create all the subfolder stopping at last token (f.eof()); + // Examples: + // "/tmp/foo/bar" -> "", "tmp", "foo" -> mkdir("/") + mkdir("/tmp/") + midir("/tmp/foo/") + // "tmp/foo/bar" -> "tmp", "foo" -> mkdir("tmp/") + midir("tmp/foo/") + while (getline(f, s, *CPPPATH_SEP) && !f.eof()) { + path_until_token += s + CPPPATH_SEP; + int ret = mkdir(path_until_token.c_str(), 0600); + if (ret != 0 && errno != EEXIST) + { + return ret; + } + } + return 0; +} diff --git a/userspace/falco/app/actions/create_signal_handlers.cpp b/userspace/falco/app/actions/create_signal_handlers.cpp index 4929015c..621832cd 100644 --- a/userspace/falco/app/actions/create_signal_handlers.cpp +++ b/userspace/falco/app/actions/create_signal_handlers.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/daemonize.cpp b/userspace/falco/app/actions/daemonize.cpp index 817cd307..08ebf640 100644 --- a/userspace/falco/app/actions/daemonize.cpp +++ b/userspace/falco/app/actions/daemonize.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/helpers_inspector.cpp b/userspace/falco/app/actions/helpers_inspector.cpp index 85d36473..04db949d 100644 --- a/userspace/falco/app/actions/helpers_inspector.cpp +++ b/userspace/falco/app/actions/helpers_inspector.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/helpers_interesting_sets.cpp b/userspace/falco/app/actions/helpers_interesting_sets.cpp index c3dc8762..c0eddf65 100644 --- a/userspace/falco/app/actions/helpers_interesting_sets.cpp +++ b/userspace/falco/app/actions/helpers_interesting_sets.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/init_clients.cpp b/userspace/falco/app/actions/init_clients.cpp index ea1e8f8c..062f40a0 100644 --- a/userspace/falco/app/actions/init_clients.cpp +++ b/userspace/falco/app/actions/init_clients.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/init_falco_engine.cpp b/userspace/falco/app/actions/init_falco_engine.cpp index 28253c02..f802bd32 100644 --- a/userspace/falco/app/actions/init_falco_engine.cpp +++ b/userspace/falco/app/actions/init_falco_engine.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/init_inspectors.cpp b/userspace/falco/app/actions/init_inspectors.cpp index 980bfb84..500b3cf0 100644 --- a/userspace/falco/app/actions/init_inspectors.cpp +++ b/userspace/falco/app/actions/init_inspectors.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/init_outputs.cpp b/userspace/falco/app/actions/init_outputs.cpp index 3c1a0607..580c59ac 100644 --- a/userspace/falco/app/actions/init_outputs.cpp +++ b/userspace/falco/app/actions/init_outputs.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/list_fields.cpp b/userspace/falco/app/actions/list_fields.cpp index fa4d363d..e1bbd980 100644 --- a/userspace/falco/app/actions/list_fields.cpp +++ b/userspace/falco/app/actions/list_fields.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/list_plugins.cpp b/userspace/falco/app/actions/list_plugins.cpp index c9b023d6..3aee1d75 100644 --- a/userspace/falco/app/actions/list_plugins.cpp +++ b/userspace/falco/app/actions/list_plugins.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/load_config.cpp b/userspace/falco/app/actions/load_config.cpp index ca79e08a..152dd9ce 100644 --- a/userspace/falco/app/actions/load_config.cpp +++ b/userspace/falco/app/actions/load_config.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/load_plugins.cpp b/userspace/falco/app/actions/load_plugins.cpp index ff4ec1bf..04c8ac53 100644 --- a/userspace/falco/app/actions/load_plugins.cpp +++ b/userspace/falco/app/actions/load_plugins.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/load_rules_files.cpp b/userspace/falco/app/actions/load_rules_files.cpp index 278809ac..293a782d 100644 --- a/userspace/falco/app/actions/load_rules_files.cpp +++ b/userspace/falco/app/actions/load_rules_files.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_generated_gvisor_config.cpp b/userspace/falco/app/actions/print_generated_gvisor_config.cpp index 9f47a5dd..f12bb567 100644 --- a/userspace/falco/app/actions/print_generated_gvisor_config.cpp +++ b/userspace/falco/app/actions/print_generated_gvisor_config.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_ignored_events.cpp b/userspace/falco/app/actions/print_ignored_events.cpp index cdff823c..5bbf9b74 100644 --- a/userspace/falco/app/actions/print_ignored_events.cpp +++ b/userspace/falco/app/actions/print_ignored_events.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_page_size.cpp b/userspace/falco/app/actions/print_page_size.cpp index 86213901..bee0d3e9 100644 --- a/userspace/falco/app/actions/print_page_size.cpp +++ b/userspace/falco/app/actions/print_page_size.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_plugin_info.cpp b/userspace/falco/app/actions/print_plugin_info.cpp index 95574df6..f279cbea 100644 --- a/userspace/falco/app/actions/print_plugin_info.cpp +++ b/userspace/falco/app/actions/print_plugin_info.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_support.cpp b/userspace/falco/app/actions/print_support.cpp index 69abdfd9..d3e8c645 100644 --- a/userspace/falco/app/actions/print_support.cpp +++ b/userspace/falco/app/actions/print_support.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_syscall_events.cpp b/userspace/falco/app/actions/print_syscall_events.cpp index 17c91b7d..7a5e5a52 100644 --- a/userspace/falco/app/actions/print_syscall_events.cpp +++ b/userspace/falco/app/actions/print_syscall_events.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/print_version.cpp b/userspace/falco/app/actions/print_version.cpp index 2a3b530c..6aabbcee 100644 --- a/userspace/falco/app/actions/print_version.cpp +++ b/userspace/falco/app/actions/print_version.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/process_events.cpp b/userspace/falco/app/actions/process_events.cpp index 4a89e38d..392bcf65 100644 --- a/userspace/falco/app/actions/process_events.cpp +++ b/userspace/falco/app/actions/process_events.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/actions/select_event_sources.cpp b/userspace/falco/app/actions/select_event_sources.cpp index 318d72b4..82001b27 100644 --- a/userspace/falco/app/actions/select_event_sources.cpp +++ b/userspace/falco/app/actions/select_event_sources.cpp @@ -1,9 +1,12 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/userspace/falco/app/actions/start_grpc_server.cpp b/userspace/falco/app/actions/start_grpc_server.cpp index 43710348..7fb0b57d 100644 --- a/userspace/falco/app/actions/start_grpc_server.cpp +++ b/userspace/falco/app/actions/start_grpc_server.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -60,4 +60,3 @@ falco::app::run_result falco::app::actions::stop_grpc_server(falco::app::state& return run_result::ok(); } -#endif diff --git a/userspace/falco/app/actions/start_webserver.cpp b/userspace/falco/app/actions/start_webserver.cpp index d5f016f1..1f3fda0a 100644 --- a/userspace/falco/app/actions/start_webserver.cpp +++ b/userspace/falco/app/actions/start_webserver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -58,4 +58,3 @@ falco::app::run_result falco::app::actions::stop_webserver(falco::app::state& s) return run_result::ok(); } -#endif diff --git a/userspace/falco/app/actions/validate_rules_files.cpp b/userspace/falco/app/actions/validate_rules_files.cpp index ce490f3e..2b4851db 100644 --- a/userspace/falco/app/actions/validate_rules_files.cpp +++ b/userspace/falco/app/actions/validate_rules_files.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/userspace/falco/app/options.h b/userspace/falco/app/options.h index e4a5b548..a34690eb 100644 --- a/userspace/falco/app/options.h +++ b/userspace/falco/app/options.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2022 The Falco Authors. +Copyright (C) 2023 The Falco Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,11 +30,11 @@ namespace app { class options { public: options(); - virtual ~options(); - options(options&&) = default; - options& operator = (options&&) = default; - options(const options&) = default; - options& operator = (const options&) = default; + virtual ~options(); + options(options&&) = default; + options& operator = (options&&) = default; + options(const options&) = default; + options& operator = (const options&) = default; // Each of these maps directly to a command line option. bool help; diff --git a/userspace/falco/app/signals.cpp b/userspace/falco/app/signals.cpp index 1172d08f..0eb42fd6 100644 --- a/userspace/falco/app/signals.cpp +++ b/userspace/falco/app/signals.cpp @@ -22,7 +22,6 @@ std::atomic falco::app::g_terminate(APP_SIGNAL_NOT_SET); std::atomic falco::app::g_restart(APP_SIGNAL_NOT_SET); std::atomic falco::app::g_reopen_outputs(APP_SIGNAL_NOT_SET); - static inline bool should_take_action_to_signal(std::atomic& v) { // we expected the signal to be received, and we try to set action-taken flag diff --git a/userspace/falco/app/signals.h b/userspace/falco/app/signals.h index 4ba3f0da..18f92210 100644 --- a/userspace/falco/app/signals.h +++ b/userspace/falco/app/signals.h @@ -41,10 +41,12 @@ inline bool should_terminate() { return g_terminate.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET; } + inline bool should_restart() { return g_restart.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET; } + inline bool should_reopen_outputs() { return g_reopen_outputs.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET; diff --git a/userspace/falco/app/state.cpp b/userspace/falco/app/state.cpp deleted file mode 100644 index 5764cd0b..00000000 --- a/userspace/falco/app/state.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright (C) 2023 The Falco Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "state.h" - -falco::app::state::state() - : loaded_sources(), - enabled_sources(), - source_infos(), - plugin_configs(), - ppm_sc_of_interest(), - tp_of_interest(), - syscall_buffer_bytes_size(DEFAULT_DRIVER_BUFFER_BYTES_DIM) -{ - config = std::make_shared(); - engine = std::make_shared(); - offline_inspector = std::make_shared(); - outputs = nullptr; -} \ No newline at end of file diff --git a/userspace/falco/app/state.h b/userspace/falco/app/state.h index 9c2940ba..39f4cb8b 100644 --- a/userspace/falco/app/state.h +++ b/userspace/falco/app/state.h @@ -58,7 +58,20 @@ struct state std::shared_ptr inspector; }; - state(); + state(): + loaded_sources(), + enabled_sources(), + source_infos(), + plugin_configs(), + ppm_sc_of_interest(), + tp_of_interest(), + syscall_buffer_bytes_size(DEFAULT_DRIVER_BUFFER_BYTES_DIM) + { + config = std::make_shared(); + engine = std::make_shared(); + offline_inspector = std::make_shared(); + outputs = nullptr; + } ~state() = default; state(state&&) = default; state& operator = (state&&) = default; @@ -112,14 +125,14 @@ struct state #endif inline bool is_capture_mode() const - { - return !options.trace_filename.empty(); - } + { + return !options.trace_filename.empty(); + } - inline bool is_gvisor_enabled() const - { - return !options.gvisor_config.empty(); - } + inline bool is_gvisor_enabled() const + { + return !options.gvisor_config.empty(); + } }; }; // namespace app