summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-23 16:07:18 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-24 00:25:22 +0100
commitca23644397025f041370a14e50928f186c2ff721 (patch)
treef555b0e4aab1a17aae60cb1a039fc79d589c4f75
parent8b7b726680313f17be50a9fbb577f14995c33218 (diff)
downloadserenity-ca23644397025f041370a14e50928f186c2ff721.zip
logout: Port to LibMain :^)
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/logout.cpp29
2 files changed, 9 insertions, 21 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 0801d34b83..83df36fe91 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -76,6 +76,7 @@ target_link_libraries(gzip LibCompress)
target_link_libraries(id LibMain)
target_link_libraries(js LibJS LibLine LibMain)
target_link_libraries(keymap LibKeyboard LibMain)
+target_link_libraries(logout LibMain)
target_link_libraries(lspci LibPCIDB)
target_link_libraries(lsusb LibUSBDB LibMain)
target_link_libraries(man LibMarkdown)
diff --git a/Userland/Utilities/logout.cpp b/Userland/Utilities/logout.cpp
index 0aedb63953..b9597c32ee 100644
--- a/Userland/Utilities/logout.cpp
+++ b/Userland/Utilities/logout.cpp
@@ -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;
}