summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-23 15:44:17 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-23 15:44:59 +0100
commit6386b54746a6962cb9f986679842015e1eaa5c77 (patch)
treee91c4a6384576b7c11aadefcda758ca1b75b19c8 /Userland
parente6579e702959ca971b7bc70d03841a8b0bfcd602 (diff)
downloadserenity-6386b54746a6962cb9f986679842015e1eaa5c77.zip
dmesg: Port to LibMain :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/dmesg.cpp30
2 files changed, 10 insertions, 21 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 0a4fbf7e3c..00b62ffd80 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -61,6 +61,7 @@ target_link_libraries(config LibConfig)
target_link_libraries(copy LibGUI)
target_link_libraries(diff LibDiff)
target_link_libraries(disasm LibX86)
+target_link_libraries(dmesg LibMain)
target_link_libraries(expr LibRegex)
target_link_libraries(fdtdump LibDeviceTree)
target_link_libraries(file LibGfx LibIPC LibCompress)
diff --git a/Userland/Utilities/dmesg.cpp b/Userland/Utilities/dmesg.cpp
index 2e890004fc..7877ae9288 100644
--- a/Userland/Utilities/dmesg.cpp
+++ b/Userland/Utilities/dmesg.cpp
@@ -1,33 +1,21 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/File.h>
-#include <stdio.h>
-#include <unistd.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
-int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
+ErrorOr<int> serenity_main(Main::Arguments)
{
- if (pledge("stdio rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio rpath", nullptr));
+ TRY(Core::System::unveil("/proc/dmesg", "r"));
+ TRY(Core::System::unveil(nullptr, nullptr));
- if (unveil("/proc/dmesg", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- unveil(nullptr, nullptr);
-
- auto file = Core::File::construct("/proc/dmesg");
- if (!file->open(Core::OpenMode::ReadOnly)) {
- warnln("Failed to open {}: {}", file->name(), file->error_string());
- return 1;
- }
+ auto file = TRY(Core::File::open("/proc/dmesg", Core::OpenMode::ReadOnly));
auto buffer = file->read_all();
- out("{}", String::copy(buffer));
+ out("{}", StringView { buffer });
return 0;
}