Kaynağa Gözat

logout: Port to LibMain :^)

Andreas Kling 3 yıl önce
ebeveyn
işleme
ca23644397

+ 1 - 0
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)

+ 8 - 21
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;
 }