From 23e9e990bad6e988801898514b8c0f295dedb885 Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Fri, 16 Feb 2024 13:51:49 +0000 Subject: eBPF - Network Viewer (Move code) (#17018) --- src/collectors/ebpf.plugin/ebpf.c | 48 +++------------------------------------ 1 file changed, 3 insertions(+), 45 deletions(-) (limited to 'src/collectors/ebpf.plugin/ebpf.c') diff --git a/src/collectors/ebpf.plugin/ebpf.c b/src/collectors/ebpf.plugin/ebpf.c index c46688895f..5c2036394e 100644 --- a/src/collectors/ebpf.plugin/ebpf.c +++ b/src/collectors/ebpf.plugin/ebpf.c @@ -3050,48 +3050,6 @@ static inline void ebpf_load_thread_config() } } -/** - * Check Conditions - * - * This function checks kernel that plugin is running and permissions. - * - * @return It returns 0 on success and -1 otherwise - */ -int ebpf_check_conditions() -{ - if (!has_condition_to_run(running_on_kernel)) { - netdata_log_error("The current collector cannot run on this kernel."); - return -1; - } - - if (!am_i_running_as_root()) { - netdata_log_error( - "ebpf.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities..", - (unsigned int)getuid(), (unsigned int)geteuid()); - return -1; - } - - return 0; -} - -/** - * Adjust memory - * - * Adjust memory values to load eBPF programs. - * - * @return It returns 0 on success and -1 otherwise - */ -int ebpf_adjust_memory_limit() -{ - struct rlimit r = { RLIM_INFINITY, RLIM_INFINITY }; - if (setrlimit(RLIMIT_MEMLOCK, &r)) { - netdata_log_error("Setrlimit(RLIMIT_MEMLOCK)"); - return -1; - } - - return 0; -} - /** * Parse arguments given from user. * @@ -3324,7 +3282,7 @@ static void ebpf_parse_args(int argc, char **argv) case EBPF_OPTION_UNITTEST: { // if we cannot run until the end, we will cancel the unittest int exit_code = ECANCELED; - if (ebpf_check_conditions()) + if (ebpf_can_plugin_load_code(running_on_kernel, NETDATA_EBPF_PLUGIN_NAME)) goto unittest; if (ebpf_adjust_memory_limit()) @@ -4009,7 +3967,7 @@ static void ebpf_manage_pid(pid_t pid) int main(int argc, char **argv) { clocks_init(); - nd_log_initialize_for_external_plugins("ebpf.plugin"); + nd_log_initialize_for_external_plugins(NETDATA_EBPF_PLUGIN_NAME); main_thread_id = gettid(); @@ -4017,7 +3975,7 @@ int main(int argc, char **argv) ebpf_parse_args(argc, argv); ebpf_manage_pid(getpid()); - if (ebpf_check_conditions()) + if (ebpf_can_plugin_load_code(running_on_kernel, NETDATA_EBPF_PLUGIN_NAME)) return 2; if (ebpf_adjust_memory_limit()) -- cgit v1.2.3