From 7016308147c21ea2a34a74aad839712b2f4102dd Mon Sep 17 00:00:00 2001 From: Dmitry Savintsev Date: Wed, 25 Jan 2023 17:12:06 +0100 Subject: [PATCH] fix uprobe programs Signed-off-by: Dmitry Savintsev --- {{project-name}}/Cargo.toml | 2 ++ {{project-name}}/src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/{{project-name}}/Cargo.toml b/{{project-name}}/Cargo.toml index 937eac8..9b69d73 100644 --- a/{{project-name}}/Cargo.toml +++ b/{{project-name}}/Cargo.toml @@ -13,7 +13,9 @@ clap = { version = "4.1", features = ["derive"] } {{project-name}}-common = { path = "../{{project-name}}-common", features = ["user"] } anyhow = "1.0.68" env_logger = "0.10" +{%- if program_type == "uprobe" %} libc = "0.2" +{%- endif %} log = "0.4" tokio = { version = "1.24", features = ["macros", "rt", "rt-multi-thread", "net", "signal"] } diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index ebb3ad8..f9dc7b2 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -59,7 +59,7 @@ struct Opt { cgroup_path: String, {% elsif program_type == "uprobe" or program_type == "uretprobe" %} #[clap(short, long)] - pid: Option + pid: Option, {% endif -%} } @@ -105,7 +105,7 @@ async fn main() -> Result<(), anyhow::Error> { {%- when "uprobe", "uretprobe" -%} let program: &mut UProbe = bpf.program_mut("{{crate_name}}").unwrap().try_into()?; program.load()?; - program.attach(Some("{{uprobe_fn_name}}"), 0, "{{uprobe_target}}", opt.pid.try_into()?)?; + program.attach(Some("{{uprobe_fn_name}}"), 0, "{{uprobe_target}}", opt.pid)?; {%- when "sock_ops" -%} let program: &mut SockOps = bpf.program_mut("{{crate_name}}").unwrap().try_into()?; let cgroup = std::fs::File::open(opt.cgroup_path)?;