diff --git a/aya/src/programs/mod.rs b/aya/src/programs/mod.rs index d903cca7..561b3a1a 100644 --- a/aya/src/programs/mod.rs +++ b/aya/src/programs/mod.rs @@ -999,12 +999,14 @@ impl Iterator for ProgramsIter { io_error, }) .and_then(|fd| { - bpf_prog_get_info_by_fd(fd) + let info = bpf_prog_get_info_by_fd(fd) .map_err(|io_error| ProgramError::SyscallError { call: "bpf_prog_get_info_by_fd".to_owned(), io_error, }) - .map(ProgramInfo) + .map(ProgramInfo); + unsafe { libc::close(fd) }; + info }), ) } diff --git a/test/integration-test/src/tests/load.rs b/test/integration-test/src/tests/load.rs index 9aa21bb5..f78f3f73 100644 --- a/test/integration-test/src/tests/load.rs +++ b/test/integration-test/src/tests/load.rs @@ -1,11 +1,11 @@ -use std::{convert::TryInto, process::Command, thread, time}; +use std::{convert::TryInto as _, thread, time}; use aya::{ include_bytes_aligned, maps::Array, programs::{ links::{FdLink, PinnedLink}, - KProbe, TracePoint, Xdp, XdpFlags, + loaded_programs, KProbe, TracePoint, Xdp, XdpFlags, }, Bpf, }; @@ -58,20 +58,10 @@ fn multiple_btf_maps() { assert_eq!(val_2, 42); } -fn is_loaded(name: &str) -> bool { - let output = Command::new("bpftool").args(["prog"]).output(); - let output = match output { - Err(e) => panic!("Failed to run 'bpftool prog': {e}"), - Ok(out) => out, - }; - let stdout = String::from_utf8(output.stdout).unwrap(); - stdout.contains(name) -} - macro_rules! assert_loaded { ($name:literal, $loaded:expr) => { for i in 0..(MAX_RETRIES + 1) { - let state = is_loaded($name); + let state = loaded_programs().any(|prog| prog.unwrap().name() == $name.as_bytes()); if state == $loaded { break; } diff --git a/test/run.sh b/test/run.sh index 46caf224..67056c83 100755 --- a/test/run.sh +++ b/test/run.sh @@ -193,7 +193,7 @@ EOF exec_vm sudo dnf config-manager --set-enabled updates-testing exec_vm sudo dnf config-manager --set-enabled updates-testing-modular echo "Installing dependencies" - exec_vm sudo dnf install -qy bpftool llvm llvm-devel clang clang-devel zlib-devel + exec_vm sudo dnf install -qy llvm llvm-devel clang clang-devel zlib-devel exec_vm 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ -y --profile minimal --default-toolchain nightly --component rust-src --component clippy' exec_vm 'echo source ~/.cargo/env >> ~/.bashrc' diff --git a/xtask/src/run.rs b/xtask/src/run.rs index c433c3f7..eb48f7ad 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -36,8 +36,13 @@ fn build(opts: &Options) -> Result<(), anyhow::Error> { .args(&args) .status() .expect("failed to build userspace"); - assert!(status.success()); - Ok(()) + match status.code() { + Some(code) => match code { + 0 => Ok(()), + code => Err(anyhow::anyhow!("exited with status code: {code}")), + }, + None => Err(anyhow::anyhow!("process terminated by signal")), + } } /// Build and run the project