-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from serpent-os/feat/ignore-signals-during-blit
moss: Ignore SIGINT during blit
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-FileCopyrightText: Copyright © 2020-2024 Serpent OS Developers | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//! Signal handling | ||
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet}; | ||
use thiserror::Error; | ||
|
||
pub use nix::sys::signal::Signal; | ||
|
||
/// Ignore the provided signals until [`Guard`] is dropped | ||
pub fn ignore(signals: impl IntoIterator<Item = Signal>) -> Result<Guard, Error> { | ||
Ok(Guard( | ||
signals | ||
.into_iter() | ||
.map(|signal| unsafe { | ||
let action = sigaction( | ||
signal, | ||
&SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty()), | ||
) | ||
.map_err(Error::Ignore)?; | ||
|
||
Ok(PrevHandler { signal, action }) | ||
}) | ||
.collect::<Result<_, Error>>()?, | ||
)) | ||
} | ||
|
||
/// A guard which restores the previous signal | ||
/// handlers when dropped | ||
pub struct Guard(Vec<PrevHandler>); | ||
|
||
impl Drop for Guard { | ||
fn drop(&mut self) { | ||
for PrevHandler { signal, action } in &self.0 { | ||
unsafe { | ||
let _ = sigaction(*signal, action); | ||
}; | ||
} | ||
} | ||
} | ||
|
||
struct PrevHandler { | ||
signal: Signal, | ||
action: SigAction, | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("ignore signal")] | ||
Ignore(#[source] nix::Error), | ||
} |