From 898be12a33a223fd3bc179ff507fdcb8345a365e Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 10 Aug 2022 15:31:03 +0300 Subject: [PATCH] sort: add comments to wait_if_signal function and its usage --- src/uu/sort/src/sort.rs | 2 ++ src/uu/sort/src/tmp_dir.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index c72350228..7a0ac21d2 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -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 } diff --git a/src/uu/sort/src/tmp_dir.rs b/src/uu/sort/src/tmp_dir.rs index 628805717..3fc405244 100644 --- a/src/uu/sort/src/tmp_dir.rs +++ b/src/uu/sort/src/tmp_dir.rs @@ -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(); }