1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

logout: Port to LibMain :^)

This commit is contained in:
Andreas Kling 2021-11-23 16:07:18 +01:00
parent 8b7b726680
commit ca23644397
2 changed files with 9 additions and 21 deletions

View file

@ -5,6 +5,8 @@
*/
#include <LibCore/ProcessStatisticsReader.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)
@ -16,24 +18,12 @@ static Core::ProcessStatistics const& get_proc(Core::AllProcessesStatistics cons
VERIFY_NOT_REACHED();
}
int main(int, char**)
ErrorOr<int> serenity_main(Main::Arguments)
{
if (pledge("stdio proc rpath", nullptr) < 0) {
perror("pledge");
return 1;
}
if (unveil("/proc/all", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil("/etc/passwd", "r") < 0) {
perror("unveil");
return 1;
}
unveil(nullptr, nullptr);
TRY(Core::System::pledge("stdio proc rpath", nullptr));
TRY(Core::System::unveil("/proc/all", "r"));
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();
@ -53,10 +43,7 @@ int main(int, char**)
sid = parent_sid;
}
if (kill(-sid, SIGTERM) == -1) {
perror("kill(2)");
return 1;
}
TRY(Core::System::kill(-sid, SIGTERM));
return 0;
}