mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
Utilities/w: Add the ability to filter by username
This commit is contained in:
parent
d2ec82d4f9
commit
9596346528
1 changed files with 11 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
#include <LibCore/Account.h>
|
#include <LibCore/Account.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/ProcessStatisticsReader.h>
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
|
@ -33,7 +34,7 @@ static ErrorOr<String> tty_stat_to_pseudo_name(struct stat const& tty_stat)
|
||||||
return Error::from_string_literal("Unknown TTY device type");
|
return Error::from_string_literal("Unknown TTY device type");
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments)
|
ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
{
|
{
|
||||||
TRY(Core::System::pledge("stdio rpath"));
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
TRY(Core::System::unveil("/dev", "r"));
|
TRY(Core::System::unveil("/dev", "r"));
|
||||||
|
@ -44,6 +45,12 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
TRY(Core::System::unveil("/sys/kernel/processes", "r"));
|
TRY(Core::System::unveil("/sys/kernel/processes", "r"));
|
||||||
TRY(Core::System::unveil(nullptr, nullptr));
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
|
|
||||||
|
StringView username_to_filter_by;
|
||||||
|
|
||||||
|
Core::ArgsParser args_parser;
|
||||||
|
args_parser.add_positional_argument(username_to_filter_by, "Only show information about the specified user", "user", Core::ArgsParser::Required::No);
|
||||||
|
args_parser.parse(args);
|
||||||
|
|
||||||
auto file = TRY(Core::File::open("/var/run/utmp"sv, Core::File::OpenMode::Read));
|
auto file = TRY(Core::File::open("/var/run/utmp"sv, Core::File::OpenMode::Read));
|
||||||
auto file_contents = TRY(file->read_until_eof());
|
auto file_contents = TRY(file->read_until_eof());
|
||||||
auto json = TRY(JsonValue::from_string(file_contents));
|
auto json = TRY(JsonValue::from_string(file_contents));
|
||||||
|
@ -72,6 +79,9 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
else
|
else
|
||||||
username = TRY(String::formatted("{}", uid));
|
username = TRY(String::formatted("{}", uid));
|
||||||
|
|
||||||
|
if (!username_to_filter_by.is_empty() && username_to_filter_by != username)
|
||||||
|
return {};
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
String idle_string = "n/a"_short_string;
|
String idle_string = "n/a"_short_string;
|
||||||
String what = "n/a"_short_string;
|
String what = "n/a"_short_string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue