protect lists with mutex
This commit is contained in:
parent
b6f0c5e89f
commit
70f5727eb3
|
@ -41,7 +41,8 @@
|
|||
|
||||
reHDD
|
||||
|
||||
reHDD.log
|
||||
|
||||
*.log
|
||||
*.ods
|
||||
*.txt
|
||||
|
||||
ignoreDrives.conf
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
4673974d
|
||||
2cb3dea4
|
||||
8ffbc421
|
||||
|
|
|
@ -67,7 +67,6 @@ string Drive::sErrorCountToText()
|
|||
return to_string(getErrorCount());
|
||||
}
|
||||
|
||||
|
||||
string Drive::sPowerOnHoursToText()
|
||||
{
|
||||
double dDays = 0U;
|
||||
|
|
|
@ -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 <Drive> 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 <Drive>* plistOldDrives, list <Drive>* 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 <Drive>* plistDrives)
|
|||
void reHDD::startShredAllDrives(list <Drive>* plistDrives)
|
||||
{
|
||||
list <Drive>::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<Drive, std::list<Drive>::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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue