From d92edca851c59f080479027a923d498a0bbdfe8e Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Wed, 22 Jan 2020 10:17:53 +0000 Subject: [PATCH] disable racy killing till a portable workaround is found --- src/bin/constellation/main.rs | 15 ++++++--------- src/lib.rs | 20 ++++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/bin/constellation/main.rs b/src/bin/constellation/main.rs index beb5173..a92528b 100644 --- a/src/bin/constellation/main.rs +++ b/src/bin/constellation/main.rs @@ -376,8 +376,7 @@ fn main() { palaver::process::ForkResult::Parent(child) => child, }; unistd::close(process_listener).unwrap(); - let child = std::sync::Arc::new(child); - let x = pending.write().unwrap().insert(process_id, child.clone()); + let x = pending.write().unwrap().insert(process_id, ()); assert!(x.is_none()); trace.fabric(FabricOutputEvent::Init { pid: process_id, @@ -393,18 +392,16 @@ fn main() { break; } let _ = scope.spawn(abort_on_unwind_1(move |_scope| { + let child_pid = child.pid; match child.wait() { Ok(palaver::process::WaitStatus::Exited(0)) | Ok(palaver::process::WaitStatus::Signaled(signal::Signal::SIGKILL, _)) => (), wait_status => panic!("{:?}", wait_status), } - let x = pending.write().unwrap().remove(&process_id).unwrap(); - assert!(std::sync::Arc::ptr_eq(&child, &x)); - drop(x); - let child = std::sync::Arc::try_unwrap(child).unwrap(); + pending.write().unwrap().remove(&process_id).unwrap(); trace.fabric(FabricOutputEvent::Exit { pid: process_id, - system_pid: nix::libc::pid_t::from(child.pid).try_into().unwrap(), + system_pid: nix::libc::pid_t::from(child_pid).try_into().unwrap(), }); let _unchecked_error = bincode::serialize_into( *stream_write.lock().unwrap(), @@ -413,9 +410,9 @@ fn main() { .map_err(map_bincode_err); })); } - for (&_job, pid) in pending.read().unwrap().iter() { + for (&_job, _pid) in pending.read().unwrap().iter() { // TODO: this is racey - let _unchecked_error = pid.signal(signal::Signal::SIGKILL); + // let _unchecked_error = pid.signal(signal::Signal::SIGKILL); } }) .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 3063f9c..ba158c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -914,17 +914,12 @@ fn monitor_process( // trace!("forking"); // No threads spawned between init and here so we're good assert_eq!(palaver::thread::count(), 1); // TODO: balks on 32 bit due to procinfo using usize that reflects target not host - let old = unsafe { - signal::sigaction( - signal::SIGCHLD, - &signal::SigAction::new( - signal::SigHandler::SigDfl, - signal::SaFlags::empty(), - signal::SigSet::empty(), - ), - ) - .unwrap() - }; + let new = signal::SigAction::new( + signal::SigHandler::SigDfl, + signal::SaFlags::empty(), + signal::SigSet::empty(), + ); + let old = unsafe { signal::sigaction(signal::SIGCHLD, &new).unwrap() }; if let palaver::process::ForkResult::Parent(child) = palaver::process::fork(false).unwrap() { unistd::close(reader).unwrap(); unistd::close(monitor_writer).unwrap(); @@ -1138,7 +1133,8 @@ fn monitor_process( unistd::close(stderr_reader.unwrap()).unwrap(); } unistd::close(stdout_reader).unwrap(); - let _ = unsafe { signal::sigaction(signal::SIGCHLD, &old).unwrap() }; + let new2 = unsafe { signal::sigaction(signal::SIGCHLD, &old).unwrap() }; + assert_eq!(new.handler(), new2.handler()); trace!("awaiting ready"); let err = unistd::read(reader, &mut [0]).unwrap(); assert_eq!(err, 0);