diff --git a/Cargo.toml b/Cargo.toml index 8b9668c..052413c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,11 @@ default-members = ["{{project-name}}", "{{project-name}}-common"] license = "MIT OR Apache-2.0" [workspace.dependencies] -aya = { version = "0.13.1", default-features = false } -aya-build = { version = "0.1.2", default-features = false } -aya-ebpf = { version = "0.1.1", default-features = false } -aya-log = { version = "0.2.1", default-features = false } -aya-log-ebpf = { version = "0.1.1", default-features = false } +aya = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-build = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-log = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-log-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false } anyhow = { version = "1", default-features = false } # `std` feature is currently required to build `clap`. diff --git a/{{project-name}}-ebpf/src/main.rs b/{{project-name}}-ebpf/src/main.rs index b9eb9cf..916cdf2 100644 --- a/{{project-name}}-ebpf/src/main.rs +++ b/{{project-name}}-ebpf/src/main.rs @@ -325,6 +325,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} } -#[link_section = "license"] -#[no_mangle] +#[unsafe(link_section = "license")] +#[unsafe(no_mangle)] static LICENSE: [u8; 13] = *b"Dual MIT/GPL\0"; diff --git a/{{project-name}}/build.rs b/{{project-name}}/build.rs index 2e7e132..d26b199 100644 --- a/{{project-name}}/build.rs +++ b/{{project-name}}/build.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Context as _}; -use aya_build::cargo_metadata; +use aya_build::{cargo_metadata, Toolchain}; fn main() -> anyhow::Result<()> { let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new() @@ -8,7 +8,7 @@ fn main() -> anyhow::Result<()> { .context("MetadataCommand::exec")?; let ebpf_package = packages .into_iter() - .find(|cargo_metadata::Package { name, .. }| name == "{{project-name}}-ebpf") + .find(|cargo_metadata::Package { name, .. }| name.as_str() == "aya-test-crate-ebpf") .ok_or_else(|| anyhow!("{{project-name}}-ebpf package not found"))?; - aya_build::build_ebpf([ebpf_package]) + aya_build::build_ebpf([ebpf_package], Toolchain::default()) } diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index c1d3483..ecce827 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -96,9 +96,22 @@ async fn main() -> anyhow::Result<()> { env!("OUT_DIR"), "/{{project-name}}" )))?; - if let Err(e) = aya_log::EbpfLogger::init(&mut ebpf) { - // This can happen if you remove all log statements from your eBPF program. - warn!("failed to initialize eBPF logger: {e}"); + match aya_log::EbpfLogger::init(&mut ebpf) { + Err(e) => { + // This can happen if you remove all log statements from your eBPF program. + warn!("failed to initialize eBPF logger: {e}"); + } + Ok(logger) => { + let mut logger = + tokio::io::unix::AsyncFd::with_interest(logger, tokio::io::Interest::READABLE)?; + tokio::task::spawn(async move { + loop { + let mut guard = logger.readable_mut().await.unwrap(); + guard.get_inner_mut().flush(); + guard.clear_ready(); + } + }); + } } {%- case program_type -%} {%- when "kprobe", "kretprobe" %} @@ -119,7 +132,7 @@ async fn main() -> anyhow::Result<()> { let Opt { pid } = opt; let program: &mut UProbe = ebpf.program_mut("{{crate_name}}").unwrap().try_into()?; program.load()?; - program.attach(Some("{{uprobe_fn_name}}"), 0, "{{uprobe_target}}", pid)?; + program.attach("{{uprobe_fn_name}}", "{{uprobe_target}}", pid, None /* cookie */)?; {%- when "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt" %} let Opt { cgroup_path } = opt; let cgroup =