From 3066a6b6f96b98327d37f969df5157980d055bb3 Mon Sep 17 00:00:00 2001 From: Georgy Moshkin <gmoshkin@picodata.io> Date: Wed, 27 Jul 2022 12:47:45 +0300 Subject: [PATCH] fix: exit with signal code if child was signaled --- src/main.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index bf3a7aeffb..de9b76fb4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use nix::sys::signal; use nix::sys::termios::{tcgetattr, tcsetattr, SetArg::TCSADRAIN}; -use nix::sys::wait::WaitStatus; +use nix::sys::wait::{waitpid, WaitStatus}; use nix::unistd::{self, fork, ForkResult}; use serde::{Deserialize, Serialize}; @@ -412,24 +412,14 @@ fn main_run(args: args::Run) -> ! { let msg = from_child.recv().ok(); - let mut rc: i32 = 0; - unsafe { - libc::waitpid( - child.into(), // pid_t - &mut rc as *mut libc::c_int, // int* - 0, // int options - ) - }; + let status = waitpid(child, None); // Restore termios configuration as planned if let Some(tcattr) = tcattr.as_ref() { tcsetattr(0, TCSADRAIN, tcattr).unwrap(); } - println!( - "[supervisor:{parent}] subprocess finished: {:?}", - WaitStatus::from_raw(child, rc) - ); + println!("[supervisor:{parent}] subprocess finished: {status:?}"); if let Some(msg) = msg { entrypoint = msg.next_entrypoint; @@ -438,7 +428,12 @@ fn main_run(args: args::Run) -> ! { rm_tarantool_files(&args.data_dir); } } else { - std::process::exit(libc::WEXITSTATUS(rc)); + let rc = match status.unwrap() { + WaitStatus::Exited(_, rc) => rc, + WaitStatus::Signaled(_, sig, _) => sig as _, + _ => unreachable!("unexpected exit status"), + }; + std::process::exit(rc); } } }; -- GitLab