mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Utilities/logout: Refactor to use Core::SessionManagement::logout
This commit is contained in:
parent
2c3caa7e17
commit
1df4cc1926
Notes:
sideshowbarker
2024-07-17 06:24:24 +09:00
Author: https://github.com/petelliott Commit: https://github.com/SerenityOS/serenity/commit/1df4cc1926 Pull-request: https://github.com/SerenityOS/serenity/pull/15142 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/bgianfo
1 changed files with 2 additions and 29 deletions
|
@ -4,20 +4,11 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/ProcessStatisticsReader.h>
|
||||
#include <LibCore/SessionManagement.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <signal.h>
|
||||
|
||||
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<int> serenity_main(Main::Arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio proc rpath"));
|
||||
|
@ -25,25 +16,7 @@ ErrorOr<int> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue