Skip to content

Commit

Permalink
fix(event): fix and simplify SigSet formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Grzegorz Nosek <[email protected]>
  • Loading branch information
gnosek authored and poiana committed Oct 18, 2024
1 parent 21ff658 commit 142041a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions falco_event/src/types/primitive/newtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,27 @@ newtype!(
SigSet(u32)
);

impl<F> Format<F> for SigSet {
impl<F> Format<F> for SigSet
where
SigType: Format<F>,
{
fn format(&self, fmt: &mut Formatter) -> std::fmt::Result {
<u32 as Format<format_type::PF_HEX>>::format(&self.0, fmt)?;
if self.0 != 0 {
write!(fmt, "(")?;
let mut first = false;
for sig in 0..32 {
if (self.0 & (1 << sig)) != 0 {
#[cfg(target_os = "linux")]
let sig_obj = nix::sys::signal::Signal::try_from(self.0 as i32);

#[cfg(not(target_os = "linux"))]
let sig_obj: Result<(), ()> = Err(());

if let Ok(sig) = sig_obj {
write!(fmt, "{sig:?}")?;
if first {
write!(fmt, "(")?;
first = false;
} else {
write!(fmt, "SIG{sig}")?;
write!(fmt, ",")?;
}
let sig_type = SigType(sig);
sig_type.format(fmt)?;
}
}
write!(fmt, ")")?;
}

Ok(())
Expand Down

0 comments on commit 142041a

Please sign in to comment.