From ec300d7c75485d5940c722c479d1469c219d59af Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 23 Aug 2020 10:42:03 +0200 Subject: [PATCH] kill shred thread after abort or offline drive --- shred_dummy.sh | 2 +- src/reHDD.cpp | 3 ++- src/shred.cpp | 23 +++++++++++++++-------- src/tui.cpp | 5 +++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/shred_dummy.sh b/shred_dummy.sh index 206624b..bbdfed9 100644 --- a/shred_dummy.sh +++ b/shred_dummy.sh @@ -2,7 +2,7 @@ echo "starting SHRED DUMMY" -for i in {0..100..20} +for i in {0..100..10} do echo "DUMMY shred $i%" sleep 1 diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 7539bb9..dd44883 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -182,7 +182,7 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN bOldDriveIsOffline = false; // copy old drive instance date in new instance itNew->state = itOld->state; //copy state - itNew->setTaskPercentage(itOld->getTaskPercentage()); //copy percentage + itNew->setTaskPercentage(itOld->getTaskPercentage()); //copy percentage itNew->bWasDeleteted = itOld->bWasDeleteted; //copy finished task delete itNew->bWasShredded = itOld->bWasShredded; //copy finished task shred } @@ -192,6 +192,7 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN { //cout << "offline drive found: " << itOld->getPath() << endl; //TODO kill task thread if running + itOld->state = Drive::NONE; } } diff --git a/src/shred.cpp b/src/shred.cpp index 65d0770..32fc92b 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -35,15 +35,22 @@ void Shred::shredDrive(Drive* drive, int* fdInformPipeWrite) while ((getline(&cLine, &len, shredCmdOutput)) != -1) { - string sLine = string(cLine); - string search("%"); - size_t found = sLine.find(search); - if (found!=string::npos) + if(drive->state == Drive::SHRED_ACTIVE) { - sLine.erase(0, sLine.find("%")-3); - sLine.erase(std::remove(sLine.begin(), sLine.end(), '\n'), sLine.end()); - drive->setTaskPercentage(stoi(sLine)); - write(*fdInformPipeWrite, "A",1); + string sLine = string(cLine); + string search("%"); + size_t found = sLine.find(search); + if (found!=string::npos) + { + sLine.erase(0, sLine.find("%")-3); + sLine.erase(std::remove(sLine.begin(), sLine.end(), '\n'), sLine.end()); + drive->setTaskPercentage(stoi(sLine)); + write(*fdInformPipeWrite, "A",1); + } + } + else + { + return; //end shredding task } } fclose(shredCmdOutput); diff --git a/src/tui.cpp b/src/tui.cpp index 2b1bd31..b6521bd 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -67,12 +67,15 @@ void TUI::updateTUI(vector * pvecDrives, int32_t i32SelectedEntry) systemview=createSystemStats((int)(stdscrX/3), 10, (stdscrY-11)); wrefresh(systemview); + delwin(detailview); + vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { string sModelFamily = it->getModelFamily(); string sModelName = it->getModelName(); string sCapacity = it->sCapacityToText(); + string sState = " "; bool bSelectedEntry = false; @@ -82,7 +85,6 @@ void TUI::updateTUI(vector * pvecDrives, int32_t i32SelectedEntry) displaySelectedDrive(pvecDrives->at(i32SelectedEntry), stdscrX, stdscrY); } - string sState = " "; switch (it->state) { @@ -298,7 +300,6 @@ WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart) WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate) { - WINDOW *newWindow; newWindow = newwin(iYSize, iXSize, iYStart, iXStart);