mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
dmesg: Port to LibMain :^)
This commit is contained in:
parent
e6579e7029
commit
6386b54746
2 changed files with 10 additions and 21 deletions
|
@ -61,6 +61,7 @@ target_link_libraries(config LibConfig)
|
||||||
target_link_libraries(copy LibGUI)
|
target_link_libraries(copy LibGUI)
|
||||||
target_link_libraries(diff LibDiff)
|
target_link_libraries(diff LibDiff)
|
||||||
target_link_libraries(disasm LibX86)
|
target_link_libraries(disasm LibX86)
|
||||||
|
target_link_libraries(dmesg LibMain)
|
||||||
target_link_libraries(expr LibRegex)
|
target_link_libraries(expr LibRegex)
|
||||||
target_link_libraries(fdtdump LibDeviceTree)
|
target_link_libraries(fdtdump LibDeviceTree)
|
||||||
target_link_libraries(file LibGfx LibIPC LibCompress)
|
target_link_libraries(file LibGfx LibIPC LibCompress)
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <LibCore/System.h>
|
||||||
#include <unistd.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) {
|
TRY(Core::System::pledge("stdio rpath", nullptr));
|
||||||
perror("pledge");
|
TRY(Core::System::unveil("/proc/dmesg", "r"));
|
||||||
return 1;
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil("/proc/dmesg", "r") < 0) {
|
auto file = TRY(Core::File::open("/proc/dmesg", Core::OpenMode::ReadOnly));
|
||||||
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 buffer = file->read_all();
|
auto buffer = file->read_all();
|
||||||
out("{}", String::copy(buffer));
|
out("{}", StringView { buffer });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue