From 626ca3826c73895c0ea65eebf9683290ca02e90e Mon Sep 17 00:00:00 2001 From: PartialVolume <22084881+PartialVolume@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:39:50 +0000 Subject: [PATCH] Fix nwipe not auto exiting on completion in non gui mode. --- src/nwipe.c | 62 ++++++++++++++++++++++++++++++--------------------- src/version.c | 4 ++-- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/nwipe.c b/src/nwipe.c index e1eb71c..491060d 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -737,32 +737,6 @@ int main( int argc, char** argv ) } } - /* Kill the temperature update thread */ - if( nwipe_temperature_thread ) - { - if( nwipe_options.verbose ) - { - nwipe_log( NWIPE_LOG_INFO, "Cancelling the temperature thread." ); - } - - /* We don't want to use pthread_cancel as our temperature thread is aware of the control-c - * signal and will exit itself we just join the temperature thread and wait for confirmation - */ - r = pthread_join( nwipe_temperature_thread, NULL ); - if( r != 0 ) - { - nwipe_log( NWIPE_LOG_WARNING, - "main()>pthread_join():Error when waiting for temperature thread to cancel." ); - } - else - { - if( nwipe_options.verbose ) - { - nwipe_log( NWIPE_LOG_INFO, "temperature thread has been cancelled" ); - } - } - } - /* Release the gui. */ if( !nwipe_options.nogui ) { @@ -839,6 +813,42 @@ int main( int argc, char** argv ) thread_timeout_counter--; sleep( 1 ); } + + /* Now all the wipe threads have finished, we can issue a terminate_signal = 1 + * which will cause the temperature update thread to terminate, this is necessary + * because in gui mode the terminate_signal is set when the user presses a key to + * exit on completion of all the wipes, however in non gui mode that code isn't + * active (being in the gui section) so here we need to set the terminate signal + * specifically for a completed wipes/s just for non gui mode. + */ + terminate_signal = 1; + + /* Kill the temperature update thread */ + if( nwipe_temperature_thread ) + { + if( nwipe_options.verbose ) + { + nwipe_log( NWIPE_LOG_INFO, "Cancelling the temperature thread." ); + } + + /* We don't want to use pthread_cancel as our temperature thread is aware of the control-c + * signal and will exit itself we just join the temperature thread and wait for confirmation + */ + r = pthread_join( nwipe_temperature_thread, NULL ); + if( r != 0 ) + { + nwipe_log( NWIPE_LOG_WARNING, + "main()>pthread_join():Error when waiting for temperature thread to cancel." ); + } + else + { + if( nwipe_options.verbose ) + { + nwipe_log( NWIPE_LOG_INFO, "temperature thread has been cancelled" ); + } + } + } + if( nwipe_options.verbose ) { for( i = 0; i < nwipe_selected; i++ ) diff --git a/src/version.c b/src/version.c index 631ee30..798b76d 100644 --- a/src/version.c +++ b/src/version.c @@ -4,7 +4,7 @@ * used by configure to dynamically assign those values * to documentation files. */ -const char* version_string = "0.35.2"; +const char* version_string = "0.35.3"; const char* program_name = "nwipe"; const char* author_name = "Martijn van Brummelen"; const char* email_address = "git@brumit.nl"; @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley \n\ This is free software; see the source for copying conditions.\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ FOR A PARTICULAR PURPOSE.\n"; -const char* banner = "nwipe 0.35.2"; +const char* banner = "nwipe 0.35.3";