mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
LibCore: Report error condition when reading process statistics failed
This commit is contained in:
parent
754bf22da7
commit
cf89180c35
12 changed files with 94 additions and 74 deletions
|
@ -37,7 +37,7 @@ namespace Core {
|
|||
|
||||
HashMap<uid_t, String> ProcessStatisticsReader::s_usernames;
|
||||
|
||||
HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all()
|
||||
Optional<HashMap<pid_t, Core::ProcessStatistics>> ProcessStatisticsReader::get_all()
|
||||
{
|
||||
auto file = Core::File::construct("/proc/all");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
|
@ -49,7 +49,8 @@ HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all()
|
|||
|
||||
auto file_contents = file->read_all();
|
||||
auto json = JsonValue::from_string(file_contents);
|
||||
ASSERT(json.has_value());
|
||||
if (!json.has_value())
|
||||
return {};
|
||||
json.value().as_array().for_each([&](auto& value) {
|
||||
const JsonObject& process_object = value.as_object();
|
||||
Core::ProcessStatistics process;
|
||||
|
|
|
@ -86,7 +86,7 @@ struct ProcessStatistics {
|
|||
|
||||
class ProcessStatisticsReader {
|
||||
public:
|
||||
static HashMap<pid_t, Core::ProcessStatistics> get_all();
|
||||
static Optional<HashMap<pid_t, Core::ProcessStatistics>> get_all();
|
||||
|
||||
private:
|
||||
static String username_from_uid(uid_t);
|
||||
|
|
|
@ -50,14 +50,15 @@ void RunningProcessesModel::update()
|
|||
|
||||
Core::ProcessStatisticsReader reader;
|
||||
auto processes = reader.get_all();
|
||||
|
||||
for (auto& it : processes) {
|
||||
Process process;
|
||||
process.pid = it.value.pid;
|
||||
process.uid = it.value.uid;
|
||||
process.icon = FileIconProvider::icon_for_executable(it.value.executable).bitmap_for_size(16);
|
||||
process.name = it.value.name;
|
||||
m_processes.append(move(process));
|
||||
if (processes.has_value()) {
|
||||
for (auto& it : processes.value()) {
|
||||
Process process;
|
||||
process.pid = it.value.pid;
|
||||
process.uid = it.value.uid;
|
||||
process.icon = FileIconProvider::icon_for_executable(it.value.executable).bitmap_for_size(16);
|
||||
process.name = it.value.name;
|
||||
m_processes.append(move(process));
|
||||
}
|
||||
}
|
||||
|
||||
did_update();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue