summaryrefslogtreecommitdiff
path: root/Userland/Utilities/dmesg.cpp
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/Utilities/dmesg.cpp
parente6579e702959ca971b7bc70d03841a8b0bfcd602 (diff)
downloadserenity-6386b54746a6962cb9f986679842015e1eaa5c77.zip
dmesg: Port to LibMain :^)
Diffstat (limited to 'Userland/Utilities/dmesg.cpp')
-rw-r--r--Userland/Utilities/dmesg.cpp30
1 files changed, 9 insertions, 21 deletions
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;
}