From 62a8e76205b944dc3590dd8cd060bc85909eb2cc Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Thu, 19 Mar 2020 21:09:02 +0000 Subject: [PATCH] Fix incorrect summary duration during shutdown If the system is shutdown while nwipe is still wiping, the duration calculation would be incorrect. This patch fixes that problem, so for instance if a UPS signals the system running nwipe to shutdown, nwipe typically traps that signal and exits in an orderly manner. The log summary is generated showing the wipe was aborted and the wipe duration shows a valid value i.e the elapsed time since the start of the wipe. --- src/logging.c | 22 ++++++++++++++-------- src/nwipe.c | 5 +++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/logging.c b/src/logging.c index 7919384..0c70d3b 100644 --- a/src/logging.c +++ b/src/logging.c @@ -627,15 +627,21 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected ) /* Add this devices throughput to the total throughput */ total_throughput += c[i]->throughput; - /* Retrieve the duration of the wipe in seconds and convert hours and minutes and seconds */ - /* WARNING More work needs doing on .. - * - * model - * serial no - * the footer - * testing under various fault situations ... WARNING */ + /* Retrieve the duration of the wipe in seconds and convert to hours and minutes and seconds */ - c[i]->duration = difftime( c[i]->end_time, c[i]->start_time ); + if( c[i]->start_time != 0 && c[i]->end_time != 0 ) + { + /* For a summary when the wipe has finished */ + c[i]->duration = difftime( c[i]->end_time, c[i]->start_time ); + } + else + { + if( c[i]->start_time != 0 && c[i]->end_time == 0 ) + { + /* For a summary in the event of a system shutdown */ + c[i]->duration = difftime( t, c[i]->start_time ); + } + } total_duration_seconds = (u64) c[i]->duration; diff --git a/src/nwipe.c b/src/nwipe.c index dc352f2..325caca 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -269,8 +269,13 @@ int main( int argc, char** argv ) /* A result buffer for the BLKGETSIZE64 ioctl. */ u64 size64; + /* Initialise the spinner character index */ c2[i]->spinner_idx = 0; + /* Initialise the start and end time of the wipe */ + c2[i]->start_time = 0; + c2[i]->end_time = 0; + /* Initialise the wipe_status flag, -1 = wipe not yet started */ c2[i]->wipe_status = -1;