Skip to content

Commit

Permalink
Fix parsing stat file for polkit
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Mar 29, 2024
1 parent 514afeb commit 60908d4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/gui/osutils/nixutils/NixUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,22 @@ quint64 NixUtils::getProcessStartTime() const
QString processStatInfo = processStatStream.readLine();
processStatFile.close();

auto startIndex = processStatInfo.indexOf(')', -1);
auto startIndex = processStatInfo.lastIndexOf(')');
if (startIndex != -1) {
auto tokens = processStatInfo.midRef(startIndex + 2).split(' ');
if (tokens.size() >= 20) {
return tokens[19].toULongLong();
bool ok;
auto time = tokens[19].toULongLong(&ok);
if (!ok) {
qDebug() << "nixutils: failed to convert " << tokens[19] << " to an integer in " << processStatPath;
return 0;
}
return time;
}
qDebug() << "nixutils: failed to find at least 20 values in " << processStatPath;
return 0;
}

qDebug() << "nixutils: failed to parse " << processStatPath;
qDebug() << "nixutils: failed to find ')' in " << processStatPath;
return 0;
}

0 comments on commit 60908d4

Please sign in to comment.