mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
Merge pull request #3801 from niyaznigmatullin/sort_wait_for_signal_handling
sort: wait when SIGINT was raised for the program to finish properly
This commit is contained in:
commit
e304758f61
2 changed files with 12 additions and 2 deletions
|
@ -1267,7 +1267,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
settings.init_precomputed();
|
||||
|
||||
exec(&mut files, &settings, output, &mut tmp_dir)
|
||||
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
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> Command<'a> {
|
||||
|
|
|
@ -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);
|
||||
|
@ -69,6 +70,11 @@ impl TmpDirWrapper {
|
|||
path,
|
||||
))
|
||||
}
|
||||
|
||||
/// Function just waits if signal handler was called
|
||||
pub fn wait_if_signal(&self) {
|
||||
let _lock = self.lock.lock().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the directory at `path` by deleting its child files and then itself.
|
||||
|
|
Loading…
Reference in a new issue