diff --git a/.gitignore b/.gitignore index 9862cb4..68a7334 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,8 @@ reHDD -reHDD.log - +*.log +*.ods +*.txt ignoreDrives.conf diff --git a/ignoreDrives.conf b/ignoreDrives.conf index 06e17c4..b9453cc 100644 --- a/ignoreDrives.conf +++ b/ignoreDrives.conf @@ -1,2 +1,3 @@ 4673974d 2cb3dea4 +8ffbc421 diff --git a/src/drive.cpp b/src/drive.cpp index 35f934e..837b089 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -67,7 +67,6 @@ string Drive::sErrorCountToText() return to_string(getErrorCount()); } - string Drive::sPowerOnHoursToText() { double dDays = 0U; diff --git a/src/reHDD.cpp b/src/reHDD.cpp index dc2dd19..0b70e92 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -11,7 +11,7 @@ static int fdNewDrivesInformPipe[2];//File descriptor for pipe that informs if n static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wipe thread signals -static std::mutex mxScannDrives; +static std::mutex mxDrives; list listNewDrives; //store found drives that are updated every 5sec @@ -60,12 +60,12 @@ void reHDD::app_logic(void) if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet)) { - mxScannDrives.lock(); + mxDrives.lock(); char dummy; read (fdNewDrivesInformPipe[0],&dummy,1); filterNewDrives(&listDrives, &listNewDrives); //filter and copy to app logic vector printDrives(&listDrives); - mxScannDrives.unlock(); + mxDrives.unlock(); } if(FD_ISSET(fdShredInformPipe[0], &selectSet)) { @@ -101,12 +101,12 @@ void reHDD::ThreadScannDevices() { while(true) { - mxScannDrives.lock(); + mxDrives.lock(); listNewDrives.clear(); searchDrives(&listNewDrives); //search for new drives and store them in list filterIgnoredDrives(&listNewDrives); //filter out ignored drives addSMARTData(&listNewDrives); //add S.M.A.R.T. Data to the drives - mxScannDrives.unlock(); + mxDrives.unlock(); write(fdNewDrivesInformPipe[1], "A",1); sleep(5); //sleep 5 sec } @@ -116,7 +116,7 @@ void reHDD::ThreadCheckFrozenDrives() { while(true) { - mxScannDrives.lock(); + mxDrives.lock(); for(auto it = begin(listDrives); it != end(listDrives); ++it) { if(it->state == Drive::SHRED_ACTIVE) @@ -124,7 +124,7 @@ void reHDD::ThreadCheckFrozenDrives() it->checkFrozenDrive(); } } - mxScannDrives.unlock(); + mxDrives.unlock(); sleep(13); //sleep 13 sec } } @@ -156,7 +156,7 @@ void reHDD::ThreadUserInput() break; case TUI::UserInput::Delete: //cout << "Delete" << endl; - + mxDrives.lock(); if (getSelectedDrive() != nullptr) { if(getSelectedDrive()->state == Drive::NONE) @@ -164,11 +164,12 @@ void reHDD::ThreadUserInput() getSelectedDrive()->state = Drive::DELETE_SELECTED; } } + mxDrives.unlock(); ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::Shred: //cout << "Shred" << endl; - + mxDrives.lock(); if (getSelectedDrive() != nullptr) { if(getSelectedDrive()->state == Drive::NONE) @@ -176,10 +177,11 @@ void reHDD::ThreadUserInput() getSelectedDrive()->state = Drive::SHRED_SELECTED; } } + mxDrives.unlock(); ui->updateTUI(&listDrives, u8SelectedEntry); break; case TUI::UserInput::ShredAll: - cout << "ShredAll" << endl; + //cout << "ShredAll" << endl; startShredAllDrives(&listDrives); ui->updateTUI(&listDrives, u8SelectedEntry); break; @@ -251,7 +253,7 @@ void reHDD::filterNewDrives(list * plistOldDrives, list * plistNew //search offline drives and mark them for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld) { - itOld->bIsOffline = true; //set offline befor seachring in the new list + itOld->bIsOffline = true; //set offline before searching in the new list for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end();) { if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath())) @@ -390,16 +392,22 @@ void reHDD::filterIgnoredDrives(list * plistDrives) void reHDD::startShredAllDrives(list * plistDrives) { list ::iterator it; + mxDrives.lock(); for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { if(it->state == Drive::NONE) { - it->state = Drive::SHRED_ACTIVE; - Logger::logThis()->info("all start: " + it->getSerial()); Drive* pTmpDrive = iterator_to_pointer::iterator > (it); - thread(ThreadShred, std::ref(pTmpDrive)).detach(); +#ifdef LOG_LEVEL_HIGH + ostringstream address; + address << (void const *)&(*pTmpDrive); + Logger::logThis()->info("Started shred (all) for: " + pTmpDrive->getModelName() + "-" + pTmpDrive->getSerial() + " @" + address.str()); +#endif + pTmpDrive->state = Drive::TaskState::SHRED_ACTIVE; + thread(ThreadShred, pTmpDrive).detach(); } } + mxDrives.unlock(); } /** @@ -484,6 +492,7 @@ void reHDD::handleArrowKey(TUI::UserInput userInput) void reHDD::handleEnter() { + mxDrives.lock(); if (getSelectedDrive() != nullptr) { if(getSelectedDrive()->state == Drive::TaskState::SHRED_SELECTED) @@ -492,7 +501,7 @@ void reHDD::handleEnter() getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE; //task for drive is running --> donĀ“t show more task options Drive* pTmpDrive = getSelectedDrive(); - thread(ThreadShred, std::ref(pTmpDrive)).detach(); + thread(ThreadShred, pTmpDrive).detach(); } if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED) @@ -503,6 +512,7 @@ void reHDD::handleEnter() thread(ThreadDelete).detach(); } } + mxDrives.unlock(); } void reHDD::handleESC() diff --git a/src/shred.cpp b/src/shred.cpp index 258b526..b1281c3 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -24,9 +24,11 @@ Shred::~Shred() */ int Shred::shredDrive(Drive* drive, int* ipSignalFd) { + ostringstream address; + address << (void const *)&(*drive); + Logger::logThis()->info("Shred-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); #ifdef DRYRUN - Logger::logThis()->info("Shred-Task started - Drive: " + drive->getSerial()); for(int i = 0; i<=500; i++) { if(drive->state != Drive::SHRED_ACTIVE)