diff --git a/Userland/Utilities/w.cpp b/Userland/Utilities/w.cpp index 04f2fa5fcb..260b4a9bfc 100644 --- a/Userland/Utilities/w.cpp +++ b/Userland/Utilities/w.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ static ErrorOr tty_stat_to_pseudo_name(struct stat const& tty_stat) return Error::from_string_literal("Unknown TTY device type"); } -ErrorOr serenity_main(Main::Arguments) +ErrorOr serenity_main(Main::Arguments args) { TRY(Core::System::pledge("stdio rpath")); TRY(Core::System::unveil("/dev", "r")); @@ -44,6 +45,12 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::unveil("/sys/kernel/processes", "r")); 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_contents = TRY(file->read_until_eof()); auto json = TRY(JsonValue::from_string(file_contents)); @@ -72,6 +79,9 @@ ErrorOr serenity_main(Main::Arguments) else username = TRY(String::formatted("{}", uid)); + if (!username_to_filter_by.is_empty() && username_to_filter_by != username) + return {}; + StringBuilder builder; String idle_string = "n/a"_short_string; String what = "n/a"_short_string;