fix uninlined_format_args clippy issues

pull/456/head
Dmitry Savintsev 2 years ago
parent 22340764a3
commit 055d94f58b

@ -148,7 +148,7 @@ impl SockOps {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("sockops/{}", name) format!("sockops/{name}")
} else { } else {
"sockops".to_owned() "sockops".to_owned()
}; };
@ -208,7 +208,7 @@ impl Xdp {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("xdp/{}", name) format!("xdp/{name}")
} else { } else {
"xdp".to_owned() "xdp".to_owned()
}; };
@ -240,7 +240,7 @@ impl SchedClassifier {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("classifier/{}", name) format!("classifier/{name}")
} else { } else {
"classifier".to_owned() "classifier".to_owned()
}; };
@ -272,7 +272,7 @@ impl CgroupSysctl {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("cgroup/sysctl/{}", name) format!("cgroup/sysctl/{name}")
} else { } else {
("cgroup/sysctl").to_owned() ("cgroup/sysctl").to_owned()
}; };
@ -349,12 +349,12 @@ impl CgroupSkb {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(attach) = &self.expected_attach_type { let section_name = if let Some(attach) = &self.expected_attach_type {
if let Some(name) = &self.name { if let Some(name) = &self.name {
format!("cgroup_skb/{}/{}", attach, name) format!("cgroup_skb/{attach}/{name}")
} else { } else {
format!("cgroup_skb/{}", attach) format!("cgroup_skb/{attach}")
} }
} else if let Some(name) = &self.name { } else if let Some(name) = &self.name {
format!("cgroup/skb/{}", name) format!("cgroup/skb/{name}")
} else { } else {
("cgroup/skb").to_owned() ("cgroup/skb").to_owned()
}; };
@ -432,12 +432,12 @@ impl CgroupSock {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
if let Some(attach_type) = &self.attach_type { if let Some(attach_type) = &self.attach_type {
format!("cgroup/{}/{}", attach_type, name) format!("cgroup/{attach_type}/{name}")
} else { } else {
format!("cgroup/sock/{}", name) format!("cgroup/sock/{name}")
} }
} else if let Some(attach_type) = &self.attach_type { } else if let Some(attach_type) = &self.attach_type {
format!("cgroup/{}", attach_type) format!("cgroup/{attach_type}")
} else { } else {
"cgroup/sock".to_string() "cgroup/sock".to_string()
}; };
@ -679,9 +679,9 @@ impl SkSkb {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let kind = &self.kind; let kind = &self.kind;
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("sk_skb/{}/{}", kind, name) format!("sk_skb/{kind}/{name}")
} else { } else {
format!("sk_skb/{}", kind) format!("sk_skb/{kind}")
}; };
let fn_name = &self.item.sig.ident; let fn_name = &self.item.sig.ident;
let item = &self.item; let item = &self.item;
@ -712,7 +712,7 @@ impl SocketFilter {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("socket/{}", name) format!("socket/{name}")
} else { } else {
"socket".to_owned() "socket".to_owned()
}; };
@ -802,7 +802,7 @@ impl SkLookup {
pub fn expand(&self) -> Result<TokenStream> { pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name { let section_name = if let Some(name) = &self.name {
format!("sk_lookup/{}", name) format!("sk_lookup/{name}")
} else { } else {
"sk_lookup".to_owned() "sk_lookup".to_owned()
}; };

@ -71,7 +71,7 @@ impl Parse for LogArgs {
} }
fn string_to_expr(s: String) -> Result<Expr> { fn string_to_expr(s: String) -> Result<Expr> {
parse_str(&format!("\"{}\"", s)) parse_str(&format!("\"{s}\""))
} }
fn hint_to_expr(hint: DisplayHint) -> Result<Expr> { fn hint_to_expr(hint: DisplayHint) -> Result<Expr> {
@ -108,7 +108,7 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
let fragments = parse(&format_string_val).map_err(|e| { let fragments = parse(&format_string_val).map_err(|e| {
Error::new( Error::new(
format_string.span(), format_string.span(),
format!("could not parse the format string: {}", e), format!("could not parse the format string: {e}"),
) )
})?; })?;

@ -61,7 +61,7 @@ fn parse_display_hint(s: &str) -> Result<DisplayHint, String> {
"ipv6" => DisplayHint::Ipv6, "ipv6" => DisplayHint::Ipv6,
"mac" => DisplayHint::LowerMac, "mac" => DisplayHint::LowerMac,
"MAC" => DisplayHint::UpperMac, "MAC" => DisplayHint::UpperMac,
_ => return Err(format!("unknown display hint: {:?}", s)), _ => return Err(format!("unknown display hint: {s:?}")),
}) })
} }
@ -83,7 +83,7 @@ fn parse_param(mut input: &str) -> Result<Parameter, String> {
hint = parse_display_hint(input)?; hint = parse_display_hint(input)?;
} else if !input.is_empty() { } else if !input.is_empty() {
return Err(format!("unexpected content {:?} in format string", input)); return Err(format!("unexpected content {input:?} in format string"));
} }
Ok(Parameter { hint }) Ok(Parameter { hint })

@ -137,7 +137,7 @@ where
T: LowerHex, T: LowerHex,
{ {
fn format(v: T) -> String { fn format(v: T) -> String {
format!("{:x}", v) format!("{v:x}")
} }
} }
@ -147,7 +147,7 @@ where
T: UpperHex, T: UpperHex,
{ {
fn format(v: T) -> String { fn format(v: T) -> String {
format!("{:X}", v) format!("{v:X}")
} }
} }
@ -481,7 +481,7 @@ fn log_buf(mut buf: &[u8], logger: &dyn Log) -> Result<(), ()> {
logger.log( logger.log(
&Record::builder() &Record::builder()
.args(format_args!("{}", full_log_msg)) .args(format_args!("{full_log_msg}"))
.target(target.ok_or(())?) .target(target.ok_or(())?)
.level(level) .level(level)
.module_path(module) .module_path(module)
@ -529,7 +529,6 @@ mod test {
use super::*; use super::*;
use aya_log_common::{write_record_header, WriteToBuf}; use aya_log_common::{write_record_header, WriteToBuf};
use log::logger; use log::logger;
use testing_logger;
fn new_log(args: usize) -> Result<(usize, Vec<u8>), ()> { fn new_log(args: usize) -> Result<(usize, Vec<u8>), ()> {
let mut buf = vec![0; 8192]; let mut buf = vec![0; 8192];

@ -28,7 +28,7 @@ enum Command {
fn main() { fn main() {
if let Err(e) = try_main() { if let Err(e) = try_main() {
eprintln!("{:#}", e); eprintln!("{e:#}");
exit(1); exit(1);
} }
} }
@ -47,7 +47,7 @@ fn try_main() -> Result<(), anyhow::Error> {
} else { } else {
generate(InputFile::Btf(btf), &names, &bindgen_args)? generate(InputFile::Btf(btf), &names, &bindgen_args)?
}; };
println!("{}", bindings); println!("{bindings}");
} }
}; };

@ -490,7 +490,7 @@ impl Btf {
let mut ty = ty.clone(); let mut ty = ty.clone();
for (i, mut param) in ty.params.iter_mut().enumerate() { for (i, mut param) in ty.params.iter_mut().enumerate() {
if param.name_offset == 0 && param.btf_type != 0 { if param.name_offset == 0 && param.btf_type != 0 {
param.name_offset = self.add_string(format!("param{}", i)); param.name_offset = self.add_string(format!("param{i}"));
} }
} }
types.types[i] = BtfType::FuncProto(ty); types.types[i] = BtfType::FuncProto(ty);

@ -682,7 +682,7 @@ impl<'a> AccessSpec<'a> {
rel_kind => { rel_kind => {
return Err(RelocationError::InvalidRelocationKindForType { return Err(RelocationError::InvalidRelocationKindForType {
relocation_number: relocation.number, relocation_number: relocation.number,
relocation_kind: format!("{:?}", rel_kind), relocation_kind: format!("{rel_kind:?}"),
type_kind: format!("{:?}", ty.kind()), type_kind: format!("{:?}", ty.kind()),
error: "field relocation on a type that doesn't have fields" error: "field relocation on a type that doesn't have fields"
.to_string(), .to_string(),
@ -791,7 +791,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction { return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number, relocation_number: rel.number,
index: ins_index, index: ins_index,
error: format!("invalid src_reg={:x} expected {:x}", src_reg, BPF_K), error: format!("invalid src_reg={src_reg:x} expected {BPF_K:x}"),
} }
.into()); .into());
} }
@ -803,7 +803,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction { return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number, relocation_number: rel.number,
index: ins_index, index: ins_index,
error: format!("value `{}` overflows 16 bits offset field", target_value), error: format!("value `{target_value}` overflows 16 bits offset field"),
} }
.into()); .into());
} }
@ -844,7 +844,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction { return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number, relocation_number: rel.number,
index: ins_index, index: ins_index,
error: format!("invalid target size {}", size), error: format!("invalid target size {size}"),
} }
.into()) .into())
} }
@ -868,7 +868,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction { return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number, relocation_number: rel.number,
index: ins_index, index: ins_index,
error: format!("invalid instruction class {:x}", class), error: format!("invalid instruction class {class:x}"),
} }
.into()) .into())
} }
@ -938,7 +938,7 @@ impl ComputedRelocation {
let ty = spec.btf.type_by_id(accessor.type_id)?; let ty = spec.btf.type_by_id(accessor.type_id)?;
return Err(RelocationError::InvalidRelocationKindForType { return Err(RelocationError::InvalidRelocationKindForType {
relocation_number: rel.number, relocation_number: rel.number,
relocation_kind: format!("{:?}", rel_kind), relocation_kind: format!("{rel_kind:?}"),
type_kind: format!("{:?}", ty.kind()), type_kind: format!("{:?}", ty.kind()),
error: "invalid relocation kind for array type".to_string(), error: "invalid relocation kind for array type".to_string(),
} }

@ -1335,7 +1335,7 @@ mod tests {
let data2 = new.to_bytes(); let data2 = new.to_bytes();
assert_eq!(data, data2); assert_eq!(data, data2);
} }
Ok(t) => panic!("expected int type, got {:#?}", t), Ok(t) => panic!("expected int type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
} }
@ -1379,7 +1379,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Ptr(_)) => {} Ok(BtfType::Ptr(_)) => {}
Ok(t) => panic!("expected ptr type, got {:#?}", t), Ok(t) => panic!("expected ptr type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1396,7 +1396,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Array(_)) => {} Ok(BtfType::Array(_)) => {}
Ok(t) => panic!("expected array type, got {:#?}", t), Ok(t) => panic!("expected array type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1413,7 +1413,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Struct(_)) => {} Ok(BtfType::Struct(_)) => {}
Ok(t) => panic!("expected struct type, got {:#?}", t), Ok(t) => panic!("expected struct type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1430,7 +1430,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Union(_)) => {} Ok(BtfType::Union(_)) => {}
Ok(t) => panic!("expected union type, got {:#?}", t), Ok(t) => panic!("expected union type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1447,7 +1447,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Enum(_)) => {} Ok(BtfType::Enum(_)) => {}
Ok(t) => panic!("expected enum type, got {:#?}", t), Ok(t) => panic!("expected enum type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1463,7 +1463,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Fwd(_)) => {} Ok(BtfType::Fwd(_)) => {}
Ok(t) => panic!("expected fwd type, got {:#?}", t), Ok(t) => panic!("expected fwd type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1479,7 +1479,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Typedef(_)) => {} Ok(BtfType::Typedef(_)) => {}
Ok(t) => panic!("expected typedef type, got {:#?}", t), Ok(t) => panic!("expected typedef type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1495,7 +1495,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Volatile(_)) => {} Ok(BtfType::Volatile(_)) => {}
Ok(t) => panic!("expected volatile type, got {:#?}", t), Ok(t) => panic!("expected volatile type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1511,7 +1511,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Const(_)) => {} Ok(BtfType::Const(_)) => {}
Ok(t) => panic!("expected const type, got {:#?}", t), Ok(t) => panic!("expected const type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1527,7 +1527,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Restrict(_)) => {} Ok(BtfType::Restrict(_)) => {}
Ok(t) => panic!("expected restrict type gpt {:#?}", t), Ok(t) => panic!("expected restrict type gpt {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1543,7 +1543,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Func(_)) => {} Ok(BtfType::Func(_)) => {}
Ok(t) => panic!("expected func type gpt {:#?}", t), Ok(t) => panic!("expected func type gpt {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1560,7 +1560,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::FuncProto(_)) => {} Ok(BtfType::FuncProto(_)) => {}
Ok(t) => panic!("expected func_proto type, got {:#?}", t), Ok(t) => panic!("expected func_proto type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1578,7 +1578,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Var(_)) => {} Ok(BtfType::Var(_)) => {}
Ok(t) => panic!("expected var type, got {:#?}", t), Ok(t) => panic!("expected var type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
}; };
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1600,7 +1600,7 @@ mod tests {
assert_eq!(0, ty.entries[0].offset); assert_eq!(0, ty.entries[0].offset);
assert_eq!(4, ty.entries[0].size); assert_eq!(4, ty.entries[0].size);
} }
Ok(t) => panic!("expected datasec type, got {:#?}", t), Ok(t) => panic!("expected datasec type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1616,7 +1616,7 @@ mod tests {
let got = unsafe { BtfType::read(data, endianness) }; let got = unsafe { BtfType::read(data, endianness) };
match got { match got {
Ok(BtfType::Float(_)) => {} Ok(BtfType::Float(_)) => {}
Ok(t) => panic!("expected float type, got {:#?}", t), Ok(t) => panic!("expected float type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
let data2 = got.unwrap().to_bytes(); let data2 = got.unwrap().to_bytes();
@ -1642,7 +1642,7 @@ mod tests {
Ok(BtfType::FuncProto(fp)) => { Ok(BtfType::FuncProto(fp)) => {
assert_eq!(fp.params.len(), 2); assert_eq!(fp.params.len(), 2);
} }
Ok(t) => panic!("expected func proto type, got {:#?}", t), Ok(t) => panic!("expected func proto type, got {t:#?}"),
Err(_) => panic!("unexpected error"), Err(_) => panic!("unexpected error"),
} }
} }

@ -60,7 +60,7 @@ impl Lsm {
/// be attached to /// be attached to
pub fn load(&mut self, lsm_hook_name: &str, btf: &Btf) -> Result<(), ProgramError> { pub fn load(&mut self, lsm_hook_name: &str, btf: &Btf) -> Result<(), ProgramError> {
self.data.expected_attach_type = Some(BPF_LSM_MAC); self.data.expected_attach_type = Some(BPF_LSM_MAC);
let type_name = format!("bpf_lsm_{}", lsm_hook_name); let type_name = format!("bpf_lsm_{lsm_hook_name}");
self.data.attach_btf_id = self.data.attach_btf_id =
Some(btf.id_by_type_name_kind(type_name.as_str(), BtfKind::Func)?); Some(btf.id_by_type_name_kind(type_name.as_str(), BtfKind::Func)?);
load_program(BPF_PROG_TYPE_LSM, &mut self.data) load_program(BPF_PROG_TYPE_LSM, &mut self.data)

@ -154,8 +154,8 @@ fn create_probe_event(
offset offset
); );
let offset_suffix = match kind { let offset_suffix = match kind {
KProbe => format!("+{}", offset), KProbe => format!("+{offset}"),
UProbe => format!(":{:#x}", offset), UProbe => format!(":{offset:#x}"),
_ => "".to_string(), _ => "".to_string(),
}; };
let probe = format!( let probe = format!(
@ -193,7 +193,7 @@ fn delete_probe_event(kind: ProbeKind, event_alias: &str) -> Result<(), (String,
.open(&events_file_name) .open(&events_file_name)
.map_err(|e| (events_file_name.to_string(), e))?; .map_err(|e| (events_file_name.to_string(), e))?;
let rm = format!("-:{}\n", event_alias); let rm = format!("-:{event_alias}\n");
events_file events_file
.write_all(rm.as_bytes()) .write_all(rm.as_bytes())
@ -204,7 +204,7 @@ fn delete_probe_event(kind: ProbeKind, event_alias: &str) -> Result<(), (String,
} }
fn read_sys_fs_perf_type(pmu: &str) -> Result<u32, (String, io::Error)> { fn read_sys_fs_perf_type(pmu: &str) -> Result<u32, (String, io::Error)> {
let file = format!("/sys/bus/event_source/devices/{}/type", pmu); let file = format!("/sys/bus/event_source/devices/{pmu}/type");
let perf_ty = fs::read_to_string(&file).map_err(|e| (file.clone(), e))?; let perf_ty = fs::read_to_string(&file).map_err(|e| (file.clone(), e))?;
let perf_ty = perf_ty let perf_ty = perf_ty
@ -216,7 +216,7 @@ fn read_sys_fs_perf_type(pmu: &str) -> Result<u32, (String, io::Error)> {
} }
fn read_sys_fs_perf_ret_probe(pmu: &str) -> Result<u32, (String, io::Error)> { fn read_sys_fs_perf_ret_probe(pmu: &str) -> Result<u32, (String, io::Error)> {
let file = format!("/sys/bus/event_source/devices/{}/format/retprobe", pmu); let file = format!("/sys/bus/event_source/devices/{pmu}/format/retprobe");
let data = fs::read_to_string(&file).map_err(|e| (file.clone(), e))?; let data = fs::read_to_string(&file).map_err(|e| (file.clone(), e))?;

@ -58,7 +58,7 @@ impl BtfTracePoint {
/// * `btf` - btf information for the target system /// * `btf` - btf information for the target system
pub fn load(&mut self, tracepoint: &str, btf: &Btf) -> Result<(), ProgramError> { pub fn load(&mut self, tracepoint: &str, btf: &Btf) -> Result<(), ProgramError> {
self.data.expected_attach_type = Some(BPF_TRACE_RAW_TP); self.data.expected_attach_type = Some(BPF_TRACE_RAW_TP);
let type_name = format!("btf_trace_{}", tracepoint); let type_name = format!("btf_trace_{tracepoint}");
self.data.attach_btf_id = self.data.attach_btf_id =
Some(btf.id_by_type_name_kind(type_name.as_str(), BtfKind::Typedef)?); Some(btf.id_by_type_name_kind(type_name.as_str(), BtfKind::Typedef)?);
load_program(BPF_PROG_TYPE_TRACING, &mut self.data) load_program(BPF_PROG_TYPE_TRACING, &mut self.data)

@ -117,7 +117,7 @@ pub(crate) fn read_sys_fs_trace_point_id(
category: &str, category: &str,
name: &str, name: &str,
) -> Result<u32, TracePointError> { ) -> Result<u32, TracePointError> {
let file = format!("/sys/kernel/debug/tracing/events/{}/{}/id", category, name); let file = format!("/sys/kernel/debug/tracing/events/{category}/{name}/id");
let id = fs::read_to_string(&file).map_err(|io_error| TracePointError::FileError { let id = fs::read_to_string(&file).map_err(|io_error| TracePointError::FileError {
filename: file.clone(), filename: file.clone(),

@ -84,7 +84,7 @@ impl UProbe {
let mut path = if let Some(pid) = pid { let mut path = if let Some(pid) = pid {
find_lib_in_proc_maps(pid, target_str).map_err(|io_error| UProbeError::FileError { find_lib_in_proc_maps(pid, target_str).map_err(|io_error| UProbeError::FileError {
filename: format!("/proc/{}/maps", pid), filename: format!("/proc/{pid}/maps"),
io_error, io_error,
})? })?
} else { } else {
@ -187,7 +187,7 @@ pub enum UProbeError {
} }
fn proc_maps_libs(pid: pid_t) -> Result<Vec<(String, String)>, io::Error> { fn proc_maps_libs(pid: pid_t) -> Result<Vec<(String, String)>, io::Error> {
let maps_file = format!("/proc/{}/maps", pid); let maps_file = format!("/proc/{pid}/maps");
let data = fs::read_to_string(maps_file)?; let data = fs::read_to_string(maps_file)?;
Ok(data Ok(data

@ -23,7 +23,7 @@ pub fn online_cpus() -> Result<Vec<u32>, io::Error> {
parse_cpu_ranges(data.trim()).map_err(|_| { parse_cpu_ranges(data.trim()).map_err(|_| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
format!("unexpected {} format", ONLINE_CPUS), format!("unexpected {ONLINE_CPUS} format"),
) )
}) })
} }
@ -43,7 +43,7 @@ pub(crate) fn possible_cpus() -> Result<Vec<u32>, io::Error> {
parse_cpu_ranges(data.trim()).map_err(|_| { parse_cpu_ranges(data.trim()).map_err(|_| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
format!("unexpected {} format", POSSIBLE_CPUS), format!("unexpected {POSSIBLE_CPUS} format"),
) )
}) })
} }

@ -3,10 +3,10 @@ use std::env;
fn main() { fn main() {
println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH");
if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") {
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} else { } else {
let arch = env::var("HOST").unwrap(); let arch = env::var("HOST").unwrap();
let arch = arch.split_once('-').map_or(&*arch, |x| x.0); let arch = arch.split_once('-').map_or(&*arch, |x| x.0);
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} }
} }

@ -3,10 +3,10 @@ use std::env;
fn main() { fn main() {
println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH");
if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") {
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} else { } else {
let arch = env::var("HOST").unwrap(); let arch = env::var("HOST").unwrap();
let arch = arch.split_once('-').map_or(&*arch, |x| x.0); let arch = arch.split_once('-').map_or(&*arch, |x| x.0);
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} }
} }

@ -4,11 +4,11 @@ fn main() {
check_rust_version(); check_rust_version();
println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH");
if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") {
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} else { } else {
let arch = env::var("HOST").unwrap(); let arch = env::var("HOST").unwrap();
let arch = arch.split_once('-').map_or(&*arch, |x| x.0); let arch = arch.split_once('-').map_or(&*arch, |x| x.0);
println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} }
} }

@ -140,7 +140,7 @@ fn compile_with_clang<P: Clone + AsRef<Path>>(
.arg("-target") .arg("-target")
.arg("bpf") .arg("bpf")
.arg("-c") .arg("-c")
.arg(format!("-D__TARGET_ARCH_{}", arch)) .arg(format!("-D__TARGET_ARCH_{arch}"))
.arg(src.as_ref().as_os_str()) .arg(src.as_ref().as_os_str())
.arg("-o") .arg("-o")
.arg(out.as_ref().as_os_str()); .arg(out.as_ref().as_os_str());

@ -219,7 +219,7 @@ fn codegen_bindings(opts: &Options) -> Result<(), anyhow::Error> {
// write the bindings, with the original helpers removed // write the bindings, with the original helpers removed
write_to_file( write_to_file(
generated.join(format!("linux_bindings_{}.rs", arch)), generated.join(format!("linux_bindings_{arch}.rs")),
&bindings.to_string(), &bindings.to_string(),
)?; )?;
} }

@ -110,7 +110,7 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
// write the new helpers as expanded by expand_helpers() // write the new helpers as expanded by expand_helpers()
write_to_file_fmt( write_to_file_fmt(
generated.join("helpers.rs"), generated.join("helpers.rs"),
&format!("use super::bindings::*; {}", helpers), &format!("use super::bindings::*; {helpers}"),
)?; )?;
} }

@ -36,7 +36,7 @@ fn main() {
}; };
if let Err(e) = ret { if let Err(e) = ret {
eprintln!("{:#}", e); eprintln!("{e:#}");
exit(1); exit(1);
} }
} }

@ -52,7 +52,7 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> {
build(&opts).context("Error while building userspace application")?; build(&opts).context("Error while building userspace application")?;
// profile we are building (release or debug) // profile we are building (release or debug)
let profile = if opts.release { "release" } else { "debug" }; let profile = if opts.release { "release" } else { "debug" };
let bin_path = format!("target/{}/integration-test", profile); let bin_path = format!("target/{profile}/integration-test");
// arguments to pass to the application // arguments to pass to the application
let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect(); let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect();

Loading…
Cancel
Save