Skip to content

Commit

Permalink
Merge #68
Browse files Browse the repository at this point in the history
68: revise exit handling r=stlankes a=stlankes

A valid exit code means that a thread calls the system call `exit`. In this case, we have to terminate all threads like the behaviour of `exit`. This current version is the reason that PR `hermit-os/kernel#160` doesn't pass all tests.

Co-authored-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
  • Loading branch information
bors[bot] and stlankes committed Jan 23, 2021
2 parents 92f914c + 95161bb commit 793edf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
status:
patch: off
45 changes: 21 additions & 24 deletions src/bin/uhyve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[macro_use]
extern crate log;

#[macro_use]
extern crate clap;

Expand Down Expand Up @@ -29,9 +28,18 @@ const DEFAULT_GUEST_SIZE: usize = 64 * 1024 * 1024;
// as a result destructors are not run and cleanup may not happen.
fn main() {
#[cfg(feature = "instrument")]
let events = rftrace_frontend::init(1000000, true);
#[cfg(feature = "instrument")]
rftrace_frontend::enable();
{
let events = Box::new(rftrace_frontend::init(1000000, true));
rftrace_frontend::enable();
let exit_closure = || {
rftrace_frontend::dump_full_uftrace(*events, "uhyve_trace", "uhyve", true)
.expect("Saving trace failed");
};

unsafe {
libc::atexit(std::mem::transmute(exit_closure));
}
}

env_logger::init();

Expand Down Expand Up @@ -281,32 +289,21 @@ fn main() {
match result {
Err(x) => {
error!("CPU {} crashes! {}", tid, x);
None
std::process::exit(libc::EXIT_FAILURE);
}
Ok(exit_code) => {
if let Some(code) = exit_code {
std::process::exit(code);
} else {
std::process::exit(libc::EXIT_FAILURE);
}
}
Ok(exit_code) => exit_code,
}
})
})
.collect();

let mut exit_code: Option<i32> = None;
for t in threads {
let exit_code_tid = t.join().unwrap();

if exit_code_tid.is_some() {
if exit_code.is_some() {
debug!("Found multiple exit code. Taking the laste one");
}
exit_code = exit_code_tid;
}
}

#[cfg(feature = "instrument")]
rftrace_frontend::dump_full_uftrace(events, "uhyve_trace", "uhyve", true)
.expect("Saving trace failed");

match exit_code {
Some(a) => std::process::exit(a),
None => std::process::exit(0),
t.join().unwrap();
}
}

0 comments on commit 793edf7

Please sign in to comment.