summaryrefslogtreecommitdiff
path: root/Userland/lsof.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-01-01 20:58:47 -0700
committerAndreas Kling <kling@serenityos.org>2021-01-03 22:12:19 +0100
commitcf89180c350e59a8c7cf012544a1988ca1149010 (patch)
tree377a4ad610b7795b257fa811f2bd7f9e92d4eb82 /Userland/lsof.cpp
parent754bf22da72bfdf160549713655acde26bee580c (diff)
downloadserenity-cf89180c350e59a8c7cf012544a1988ca1149010.zip
LibCore: Report error condition when reading process statistics failed
Diffstat (limited to 'Userland/lsof.cpp')
-rw-r--r--Userland/lsof.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/Userland/lsof.cpp b/Userland/lsof.cpp
index a9bf880078..26de05ea91 100644
--- a/Userland/lsof.cpp
+++ b/Userland/lsof.cpp
@@ -166,9 +166,11 @@ int main(int argc, char* argv[])
}
printf("%-28s %4s %4s %-10s %4s %s\n", "COMMAND", "PID", "PGID", "USER", "FD", "NAME");
+ auto processes = Core::ProcessStatisticsReader::get_all();
+ if (!processes.has_value())
+ return 1;
if (arg_pid == -1) {
- auto processes = Core::ProcessStatisticsReader::get_all();
- for (auto process : processes) {
+ for (auto process : processes.value()) {
if (process.key == 0)
continue;
auto open_files = get_open_files_by_pid(process.key);
@@ -187,14 +189,13 @@ int main(int argc, char* argv[])
}
}
} else {
- auto processes = Core::ProcessStatisticsReader::get_all();
auto open_files = get_open_files_by_pid(arg_pid);
if (open_files.is_empty())
return 0;
for (auto file : open_files) {
- display_entry(file, processes.get(arg_pid).value());
+ display_entry(file, processes.value().get(arg_pid).value());
}
}