lsirq: Port to LibMain

This commit is contained in:
Kenneth Myhra 2022-01-20 15:42:33 +01:00 committed by Andreas Kling
parent 4a69072c3a
commit 6a7ffcddba
Notes: sideshowbarker 2024-07-17 19:57:26 +09:00
2 changed files with 10 additions and 31 deletions

View file

@ -122,6 +122,7 @@ target_link_libraries(less LibMain)
target_link_libraries(ln LibMain)
target_link_libraries(logout LibMain)
target_link_libraries(ls LibMain)
target_link_libraries(lsirq LibMain)
target_link_libraries(lspci LibPCIDB LibMain)
target_link_libraries(lsusb LibUSBDB LibMain)
target_link_libraries(man LibMarkdown LibMain)

View file

@ -4,47 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#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"));
TRY(Core::System::unveil("/proc/interrupts", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
if (unveil("/proc/interrupts", "r") < 0) {
perror("unveil");
return 1;
}
auto proc_interrupts = TRY(Core::File::open("/proc/interrupts", Core::OpenMode::ReadOnly));
unveil(nullptr, nullptr);
auto proc_interrupts = Core::File::construct("/proc/interrupts");
if (!proc_interrupts->open(Core::OpenMode::ReadOnly)) {
warnln("Error: {}", proc_interrupts->error_string());
return 1;
}
if (pledge("stdio", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio"));
outln(" CPU0");
auto file_contents = proc_interrupts->read_all();
auto json_or_error = JsonValue::from_string(file_contents);
if (json_or_error.is_error()) {
warnln("Error: {}", json_or_error.error());
return 1;
}
auto json = json_or_error.release_value();
auto json = TRY(JsonValue::from_string(file_contents));
json.as_array().for_each([](auto& value) {
auto& handler = value.as_object();
auto purpose = handler.get("purpose").to_string();