LCOV - code coverage report
Current view: top level - libs/utils/src - signals.rs (source / functions) Coverage Total Hit
Test: 53437f7e869ac68c86c7d3e4c20964c0156f158c.info Lines: 0.0 % 16 0
Test Date: 2024-09-20 16:14:12 Functions: 0.0 % 3 0

            Line data    Source code
       1              : use signal_hook::iterator::Signals;
       2              : 
       3              : pub use signal_hook::consts::{signal::*, TERM_SIGNALS};
       4              : 
       5              : pub enum Signal {
       6              :     Quit,
       7              :     Interrupt,
       8              :     Terminate,
       9              : }
      10              : 
      11              : impl Signal {
      12            0 :     pub fn name(&self) -> &'static str {
      13            0 :         match self {
      14            0 :             Signal::Quit => "SIGQUIT",
      15            0 :             Signal::Interrupt => "SIGINT",
      16            0 :             Signal::Terminate => "SIGTERM",
      17              :         }
      18            0 :     }
      19              : }
      20              : 
      21              : pub struct ShutdownSignals;
      22              : 
      23              : impl ShutdownSignals {
      24            0 :     pub fn handle(mut handler: impl FnMut(Signal) -> anyhow::Result<()>) -> anyhow::Result<()> {
      25            0 :         for raw_signal in Signals::new(TERM_SIGNALS)?.into_iter() {
      26            0 :             let signal = match raw_signal {
      27            0 :                 SIGINT => Signal::Interrupt,
      28            0 :                 SIGTERM => Signal::Terminate,
      29            0 :                 SIGQUIT => Signal::Quit,
      30            0 :                 other => panic!("unknown signal: {}", other),
      31              :             };
      32              : 
      33            0 :             handler(signal)?;
      34              :         }
      35              : 
      36            0 :         Ok(())
      37            0 :     }
      38              : }
        

Generated by: LCOV version 2.1-beta