diff --git a/Userland/Utilities/logout.cpp b/Userland/Utilities/logout.cpp index bafedc4de4..32f5679dfd 100644 --- a/Userland/Utilities/logout.cpp +++ b/Userland/Utilities/logout.cpp @@ -4,20 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include -static Core::ProcessStatistics const& get_proc(Core::AllProcessesStatistics const& stats, pid_t pid) -{ - for (auto& proc : stats.processes) { - if (proc.pid == pid) - return proc; - } - VERIFY_NOT_REACHED(); -} - ErrorOr serenity_main(Main::Arguments) { TRY(Core::System::pledge("stdio proc rpath")); @@ -25,25 +16,7 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::unveil("/etc/passwd", "r")); TRY(Core::System::unveil(nullptr, nullptr)); - // logout finds the highest session up all nested sessions, and kills it. - auto stats = Core::ProcessStatisticsReader::get_all(); - if (!stats.has_value()) { - warnln("couldn't get process statistics"); - return 1; - } - - pid_t sid = getsid(0); - while (true) { - pid_t parent = get_proc(stats.value(), sid).ppid; - pid_t parent_sid = get_proc(stats.value(), parent).sid; - - if (parent_sid == 0) - break; - - sid = parent_sid; - } - - TRY(Core::System::kill(-sid, SIGTERM)); + TRY(Core::SessionManagement::logout()); return 0; }