Serenity Operating System
1/*
2 * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/JsonArray.h>
8#include <AK/JsonObject.h>
9#include <LibCore/File.h>
10#include <LibCore/System.h>
11#include <LibMain/Main.h>
12
13ErrorOr<int> serenity_main(Main::Arguments)
14{
15 TRY(Core::System::pledge("stdio rpath"));
16 TRY(Core::System::unveil("/sys/kernel/jails", "r"));
17 TRY(Core::System::unveil(nullptr, nullptr));
18
19 auto jails_data = TRY(Core::File::open("/sys/kernel/jails"sv, Core::File::OpenMode::Read));
20
21 TRY(Core::System::pledge("stdio"));
22
23 outln("Index Name");
24 auto file_contents = TRY(jails_data->read_until_eof());
25 auto json = TRY(JsonValue::from_string(file_contents));
26 json.as_array().for_each([](auto& value) {
27 auto& jail = value.as_object();
28 auto index = jail.get_deprecated_string("index"sv).value_or({});
29 auto name = jail.get_deprecated_string("name"sv).value_or({});
30
31 outln("{:4} {:10}", index, name);
32 });
33
34 return 0;
35}