From f8639db35a96a580bdf3e9268227d3ed425ee144 Mon Sep 17 00:00:00 2001 From: pdliyan Date: Sun, 25 Jun 2023 21:41:38 +0800 Subject: [PATCH] add memlock remove. --- {{project-name}}/Cargo.toml | 1 + {{project-name}}/src/main.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/{{project-name}}/Cargo.toml b/{{project-name}}/Cargo.toml index d06a00f..9f6cdd2 100644 --- a/{{project-name}}/Cargo.toml +++ b/{{project-name}}/Cargo.toml @@ -18,6 +18,7 @@ libc = "0.2" {%- endif %} log = "0.4" tokio = { version = "1.25", features = ["macros", "rt", "rt-multi-thread", "net", "signal"] } +rlimit = "0.9.1" [[bin]] name = "{{project-name}}" diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index 5ef5328..7f16d7d 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -46,6 +46,7 @@ use aya_log::BpfLogger; use clap::Parser; {% endif -%} use log::{info, warn}; +use rlimit::Resource; use tokio::signal; {% if program_types_with_opts contains program_type -%} @@ -71,6 +72,14 @@ async fn main() -> Result<(), anyhow::Error> { {% endif %} env_logger::init(); + if !Resource::MEMLOCK + .set(rlimit::INFINITY, rlimit::INFINITY) + .is_ok() + { + warn!("cannot remove mem lock"); + } + + // This will include your eBPF object file as raw bytes at compile-time and load it at // runtime. This approach is recommended for most real-world use cases. If you would // like to specify the eBPF program at runtime rather than at compile-time, you can