Skip to content

Commit 82247d2

Browse files
committed
Move SignalTerminationGuard to util
1 parent 432d56e commit 82247d2

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/backend/statefile.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! On-disk saved state.
22
33
use crate::model::SavedState;
4+
use crate::util::SignalTerminationGuard;
45
use anyhow::{bail, Context, Result};
56
use fn_error_context::context;
67
use fs2::FileExt;
@@ -9,25 +10,6 @@ use std::fs::File;
910
use std::io::prelude::*;
1011
use std::path::Path;
1112

12-
/// Suppress SIGTERM while active
13-
// TODO: In theory we could record if we got SIGTERM and exit
14-
// on drop, but in practice we don't care since we're going to exit anyways.
15-
#[derive(Debug)]
16-
struct SignalTerminationGuard(signal_hook_registry::SigId);
17-
18-
impl SignalTerminationGuard {
19-
pub(crate) fn new() -> Result<Self> {
20-
let signal = unsafe { signal_hook_registry::register(libc::SIGTERM, || {})? };
21-
Ok(Self(signal))
22-
}
23-
}
24-
25-
impl Drop for SignalTerminationGuard {
26-
fn drop(&mut self) {
27-
signal_hook_registry::unregister(self.0);
28-
}
29-
}
30-
3113
impl SavedState {
3214
/// System-wide bootupd write lock (relative to sysroot).
3315
const WRITE_LOCK_PATH: &'static str = "run/bootupd-lock";

src/util.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,22 @@ pub fn running_in_container() -> bool {
115115
}
116116
false
117117
}
118+
119+
/// Suppress SIGTERM while active
120+
// TODO: In theory we could record if we got SIGTERM and exit
121+
// on drop, but in practice we don't care since we're going to exit anyways.
122+
#[derive(Debug)]
123+
pub(crate) struct SignalTerminationGuard(signal_hook_registry::SigId);
124+
125+
impl SignalTerminationGuard {
126+
pub(crate) fn new() -> Result<Self> {
127+
let signal = unsafe { signal_hook_registry::register(libc::SIGTERM, || {})? };
128+
Ok(Self(signal))
129+
}
130+
}
131+
132+
impl Drop for SignalTerminationGuard {
133+
fn drop(&mut self) {
134+
signal_hook_registry::unregister(self.0);
135+
}
136+
}

0 commit comments

Comments
 (0)