sort: add comments to wait_if_signal function and its usage

This commit is contained in:
Niyaz Nigmatullin 2022-08-10 15:31:03 +03:00
parent e43872d4c7
commit 898be12a33
2 changed files with 5 additions and 1 deletions

View file

@ -1268,6 +1268,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
settings.init_precomputed();
let result = exec(&mut files, &settings, output, &mut tmp_dir);
// Wait here if `SIGINT` was received,
// for signal handler to do its work and terminate the program.
tmp_dir.wait_if_signal();
result
}

View file

@ -45,7 +45,8 @@ impl TmpDirWrapper {
let path = self.temp_dir.as_ref().unwrap().path().to_owned();
let lock = self.lock.clone();
ctrlc::set_handler(move || {
// Take the lock so that `next_file_path` returns no new file path.
// Take the lock so that `next_file_path` returns no new file path,
// and the program doesn't terminate before the handler has finished
let _lock = lock.lock().unwrap();
if let Err(e) = remove_tmp_dir(&path) {
show_error!("failed to delete temporary directory: {}", e);
@ -70,6 +71,7 @@ impl TmpDirWrapper {
))
}
/// Function just waits if signal handler was called
pub fn wait_if_signal(&self) {
let _lock = self.lock.lock().unwrap();
}