Added: Try to restart secondary thread in case of stall and addiotional error checks for ifstream in Proc::collect()

This commit is contained in:
aristocratos 2021-10-15 08:32:37 +02:00
parent 832699ffe6
commit e20258ea9f
2 changed files with 11 additions and 6 deletions

View file

@ -541,9 +541,14 @@ namespace Runner {
void run(const string& box, const bool no_update, const bool force_redraw) {
atomic_wait_for(active, true, 5000);
if (active) {
Global::exit_error_msg = "Stall in Runner thread, quitting!";
Logger::error("Stall in Runner thread, restarting!");
active = false;
exit(1);
// exit(1);
pthread_cancel(Runner::runner_id);
if (pthread_create(&Runner::runner_id, NULL, &Runner::_runner, NULL) != 0) {
Global::exit_error_msg = "Failed to re-create _runner thread!";
exit(1);
}
}
if (stopping or Global::resized) return;

View file

@ -1354,7 +1354,7 @@ namespace Proc {
uid_user.clear();
pread.open(Shared::passwd_path);
if (pread.good()) {
while (not pread.eof()) {
while (pread.good()) {
getline(pread, r_user, ':');
pread.ignore(SSmax, ':');
getline(pread, r_uid, ':');
@ -1422,7 +1422,7 @@ namespace Proc {
if (not pread.good()) continue;
string uid;
string line;
while (not pread.eof()) {
while (pread.good()) {
getline(pread, line, ':');
if (line == "Uid") {
pread.ignore();
@ -1465,9 +1465,9 @@ namespace Proc {
uint64_t cpu_t = 0;
try {
for (;;) {
while (++x < next_x + offset) pread.ignore(SSmax, ' ');
getline(pread, short_str, ' ');
while (pread.good() and ++x < next_x + offset) pread.ignore(SSmax, ' ');
if (not pread.good()) break;
else getline(pread, short_str, ' ');
switch (x-offset) {
case 3: //? Process state