mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
lsof: Port to Core::Stream
This commit is contained in:
parent
9e4689f4c8
commit
376b5731a2
1 changed files with 7 additions and 3 deletions
|
@ -11,8 +11,8 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
|
||||||
#include <LibCore/ProcessStatisticsReader.h>
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -65,14 +65,18 @@ static bool parse_name(StringView name, OpenFile& file)
|
||||||
|
|
||||||
static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
auto file = Core::File::open(String::formatted("/proc/{}/fds", pid), Core::OpenMode::ReadOnly);
|
auto file = Core::Stream::File::open(String::formatted("/proc/{}/fds", pid), Core::Stream::OpenMode::Read);
|
||||||
if (file.is_error()) {
|
if (file.is_error()) {
|
||||||
outln("lsof: PID {}: {}", pid, file.error());
|
outln("lsof: PID {}: {}", pid, file.error());
|
||||||
return Vector<OpenFile>();
|
return Vector<OpenFile>();
|
||||||
}
|
}
|
||||||
auto data = file.value()->read_all();
|
auto data = file.value()->read_all();
|
||||||
|
if (data.is_error()) {
|
||||||
|
outln("lsof: PID {}: {}", pid, data.error());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto json_or_error = JsonValue::from_string(data);
|
auto json_or_error = JsonValue::from_string(data.value());
|
||||||
if (json_or_error.is_error()) {
|
if (json_or_error.is_error()) {
|
||||||
outln("lsof: {}", json_or_error.error());
|
outln("lsof: {}", json_or_error.error());
|
||||||
return Vector<OpenFile>();
|
return Vector<OpenFile>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue