fix uprobe programs

Signed-off-by: Dmitry Savintsev <dsavints@gmail.com>
pull/75/head
Dmitry Savintsev 2 years ago
parent 8cd95c42ea
commit 7016308147

@ -13,7 +13,9 @@ clap = { version = "4.1", features = ["derive"] }
{{project-name}}-common = { path = "../{{project-name}}-common", features = ["user"] } {{project-name}}-common = { path = "../{{project-name}}-common", features = ["user"] }
anyhow = "1.0.68" anyhow = "1.0.68"
env_logger = "0.10" env_logger = "0.10"
{%- if program_type == "uprobe" %}
libc = "0.2" libc = "0.2"
{%- endif %}
log = "0.4" log = "0.4"
tokio = { version = "1.24", features = ["macros", "rt", "rt-multi-thread", "net", "signal"] } tokio = { version = "1.24", features = ["macros", "rt", "rt-multi-thread", "net", "signal"] }

@ -59,7 +59,7 @@ struct Opt {
cgroup_path: String, cgroup_path: String,
{% elsif program_type == "uprobe" or program_type == "uretprobe" %} {% elsif program_type == "uprobe" or program_type == "uretprobe" %}
#[clap(short, long)] #[clap(short, long)]
pid: Option<i32> pid: Option<i32>,
{% endif -%} {% endif -%}
} }
@ -105,7 +105,7 @@ async fn main() -> Result<(), anyhow::Error> {
{%- when "uprobe", "uretprobe" -%} {%- when "uprobe", "uretprobe" -%}
let program: &mut UProbe = bpf.program_mut("{{crate_name}}").unwrap().try_into()?; let program: &mut UProbe = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
program.load()?; 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" -%} {%- when "sock_ops" -%}
let program: &mut SockOps = bpf.program_mut("{{crate_name}}").unwrap().try_into()?; let program: &mut SockOps = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
let cgroup = std::fs::File::open(opt.cgroup_path)?; let cgroup = std::fs::File::open(opt.cgroup_path)?;

Loading…
Cancel
Save