Skip to content

Commit f51c068

Browse files
committed
Disable helper thread cleanup signals in miri
Miri doesn't support signals and the cleanup is best-effort anyway.
1 parent c0f920d commit f51c068

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/unix.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use std::mem::MaybeUninit;
88
use std::os::unix::prelude::*;
99
use std::path::Path;
1010
use std::process::Command;
11-
use std::ptr;
1211
use std::sync::{
1312
atomic::{AtomicBool, Ordering},
14-
Arc, Once,
13+
Arc,
1514
};
1615
use std::thread::{self, Builder, JoinHandle};
1716
use std::time::Duration;
@@ -379,19 +378,24 @@ pub(crate) fn spawn_helper(
379378
state: Arc<super::HelperState>,
380379
mut f: Box<dyn FnMut(io::Result<crate::Acquired>) + Send>,
381380
) -> io::Result<Helper> {
382-
static USR1_INIT: Once = Once::new();
383-
let mut err = None;
384-
USR1_INIT.call_once(|| unsafe {
385-
let mut new: libc::sigaction = mem::zeroed();
386-
new.sa_sigaction = sigusr1_handler as usize;
387-
new.sa_flags = libc::SA_SIGINFO as _;
388-
if libc::sigaction(libc::SIGUSR1, &new, ptr::null_mut()) != 0 {
389-
err = Some(io::Error::last_os_error());
390-
}
391-
});
381+
#[cfg(not(miri))]
382+
{
383+
use std::sync::Once;
384+
385+
static USR1_INIT: Once = Once::new();
386+
let mut err = None;
387+
USR1_INIT.call_once(|| unsafe {
388+
let mut new: libc::sigaction = mem::zeroed();
389+
new.sa_sigaction = sigusr1_handler as usize;
390+
new.sa_flags = libc::SA_SIGINFO as _;
391+
if libc::sigaction(libc::SIGUSR1, &new, std::ptr::null_mut()) != 0 {
392+
err = Some(io::Error::last_os_error());
393+
}
394+
});
392395

393-
if let Some(e) = err.take() {
394-
return Err(e);
396+
if let Some(e) = err.take() {
397+
return Err(e);
398+
}
395399
}
396400

397401
let state2 = state.clone();
@@ -436,6 +440,7 @@ impl Helper {
436440
if state.consumer_done {
437441
break;
438442
}
443+
#[cfg(not(miri))]
439444
unsafe {
440445
// Ignore the return value here of `pthread_kill`,
441446
// apparently on OSX if you kill a dead thread it will
@@ -538,6 +543,7 @@ fn cvt(t: c_int) -> io::Result<c_int> {
538543
}
539544
}
540545

546+
#[cfg(not(miri))]
541547
extern "C" fn sigusr1_handler(
542548
_signum: c_int,
543549
_info: *mut libc::siginfo_t,

0 commit comments

Comments
 (0)