From 12927cf6992bc0f8b1e4221d48b34f4c0098b93d Mon Sep 17 00:00:00 2001 From: ajwerner Date: Wed, 28 Dec 2022 12:25:35 -0500 Subject: [PATCH] Don't panic in init when bpf programs don't log This was broken in d6cb1a16ad0f8df483e2234fb01ab55bdbeaa8b8. --- aya-log/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index 8ef1712a..4ba1d784 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -57,6 +57,8 @@ use std::{ sync::Arc, }; +const MAP_NAME: &str = "AYA_LOGS"; + use aya_log_common::{Argument, DisplayHint, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS}; use bytes::BytesMut; use log::{error, Level, Log, Record}; @@ -90,7 +92,10 @@ impl BpfLogger { logger: T, ) -> Result { let logger = Arc::new(logger); - let mut logs: AsyncPerfEventArray<_> = bpf.take_map("AYA_LOGS").unwrap().try_into()?; + let mut logs: AsyncPerfEventArray<_> = bpf + .take_map(MAP_NAME) + .ok_or(Error::MapNotFound)? + .try_into()?; for cpu_id in online_cpus().map_err(Error::InvalidOnlineCpu)? { let mut buf = logs.open(cpu_id, None)?; @@ -326,6 +331,9 @@ impl Log for DefaultLogger { #[derive(Error, Debug)] pub enum Error { + #[error("log event array {} doesn't exist", MAP_NAME)] + MapNotFound, + #[error("error opening log event array")] MapError(#[from] MapError),