From 66cfbb5da2daea10ac4791c05bc949ec4dc89c77 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 20 Sep 2020 00:12:18 +0200 Subject: [PATCH] ls instead hwinfo; update UI even mutex is locked --- include/reHDD.h | 7 +++++-- include/tui.h | 2 +- src/reHDD.cpp | 35 +++++++++++++++++------------------ src/tui.cpp | 9 +++++++-- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index f10f157..5bb3344 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -10,8 +10,6 @@ #define REHDD_VERSION "bV0.1.0" -//#define DRYRUN - // Drive handling Settings #define WORSE_HOURS 19200 //mark drive if at this limit or beyond #define WORSE_POWERUP 10000 //mark drive if at this limit or beyond @@ -25,6 +23,11 @@ #define SOFTWARE_VERSION "alpha" #define HARDWARE_VERSION "generic" +// Logic +//#define DRYRUN //donĀ“t touch the drives +#define FROZEN_ALERT //show alert if drive is frozen + + #define LOG_LEVEL_HIGH //log everything, like drive scann thread #ifndef LOG_LEVEL_HIGH #define LOG_LEVEL_LOW //log only user actions and tasks diff --git a/include/tui.h b/include/tui.h index 135ff0d..33f95b4 100644 --- a/include/tui.h +++ b/include/tui.h @@ -60,7 +60,7 @@ private: static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB); - static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial); + static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress); void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index e1f91bc..8405708 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -23,8 +23,6 @@ static uint8_t u8SelectedEntry; static fd_set selectSet; -//static struct TUI::MenuState menustate; - /** * \brief app constructor * \param void @@ -61,23 +59,27 @@ void reHDD::app_logic(void) FD_SET(fdShredInformPipe[0], &selectSet); select(FD_SETSIZE, &selectSet, NULL, NULL, NULL); - mxScannDrives.lock(); - if( FD_ISSET(fdNewDrivesInformPipe[0], &selectSet)) + + if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet)) { + mxScannDrives.lock(); char dummy; read (fdNewDrivesInformPipe[0],&dummy,1); filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector printDrives(&vecDrives); - + mxScannDrives.unlock(); } - - if (FD_ISSET(fdShredInformPipe[0], &selectSet)) + if(FD_ISSET(fdShredInformPipe[0], &selectSet)) { char dummy; read (fdShredInformPipe[0],&dummy,1); +#ifdef LOG_LEVEL_HIGH + Logger::logThis()->info("got progress signal from a shred task"); +#endif } + //mxScannDrives.lock(); ui->updateTUI(&vecDrives, u8SelectedEntry); - mxScannDrives.unlock(); + //mxScannDrives.unlock(); } //endless loop thDevices.join(); thUserInput.join(); @@ -112,8 +114,6 @@ void reHDD::ThreadScannDevices() } } - - void reHDD::ThreadCheckFrozenDrives() { while(true) @@ -127,7 +127,7 @@ void reHDD::ThreadCheckFrozenDrives() } } mxScannDrives.unlock(); - sleep(5); //sleep 5 sec + sleep(13); //sleep 13 sec } } @@ -284,18 +284,19 @@ void reHDD::searchDrives(vector * pvecDrives) char * cLine = NULL; size_t len = 0; - FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r"); + FILE* outputfileHwinfo = popen("ls -1 /dev/sd*", "r"); if (outputfileHwinfo == NULL) { + Logger::logThis()->error("Unable to scann attached drives"); exit(EXIT_FAILURE); } while ((getline(&cLine, &len, outputfileHwinfo)) != -1) { - if (string(cLine).find("/dev/sd") != string::npos) + if (string(cLine).length() == 9) { - Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); + Drive* tmpDrive = new Drive(string(cLine).substr(0, 8)); tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; pvecDrives->push_back(*tmpDrive); @@ -397,7 +398,7 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) void reHDD::printDrives(vector * pvecDrives) { #ifdef LOG_LEVEL_HIGH - Logger::logThis()->info("------------DRIVES---------------"); + Logger::logThis()->info("------------DRIVES START------------"); //cout << "------------DRIVES---------------" << endl; vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) @@ -416,11 +417,9 @@ void reHDD::printDrives(vector * pvecDrives) ostringstream address; address << (void const *)&pvecDrives->at(it - pvecDrives->begin()); - - Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str()); } - Logger::logThis()->info("---------------------------------"); + Logger::logThis()->info("------------DRIVES END--------------"); //cout << "---------------------------------" << endl; #endif } diff --git a/src/tui.cpp b/src/tui.cpp index 1f962cc..902f252 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -112,8 +112,11 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) } break; case Drive::FROZEN: - dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial()); +#ifdef FROZEN_ALERT + stream << fixed << setprecision(2) << (it->getTaskPercentage()); + dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%"); wrefresh(dialog); +#endif break; default: break; @@ -399,7 +402,7 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri return newWindow; } -WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial) +WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress) { WINDOW *newWindow; newWindow = newwin(iYSize, iXSize, iYStart, iXStart); @@ -409,6 +412,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar string sHeader = "Drive " + sPath + " is frozen"; string sLine01 = "Please detach this drive and check it manually:"; + string sShredState = "Shredding stopped after " + sProgress; string sLinePath = "Path: " +sPath; string sLineModelFamlily = "ModelFamily: " + sModelFamily; string sLineModelName = "ModelName: " + sModelName; @@ -429,6 +433,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar u16Line++; mvwaddstr(newWindow,u16Line++, 3, sLine02.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLine03.c_str()); + mvwaddstr(newWindow,u16Line++, 3, sShredState.c_str()); return newWindow; }