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 <LibCore/ArgsParser.h>
8#include <LibCore/MappedFile.h>
9#include <LibCore/System.h>
10#include <LibELF/Image.h>
11#include <LibMain/Main.h>
12
13ErrorOr<int> serenity_main(Main::Arguments arguments)
14{
15 Vector<DeprecatedString> unveil_paths;
16 Vector<StringView> command;
17
18 Core::ArgsParser args_parser;
19 args_parser.set_stop_on_first_non_option(true);
20 args_parser.add_option(unveil_paths, "Path to unveil [permissions,path]", "path", 'u', "");
21 args_parser.add_positional_argument(command, "Command to execute", "command");
22 args_parser.parse(arguments);
23
24 if (unveil_paths.is_empty()) {
25 return Error::from_string_view("No unveil paths were specified."sv);
26 }
27
28 for (auto& path : unveil_paths) {
29 auto parts = path.split_view(',');
30 if (parts.size() != 2)
31 return Error::from_string_literal("Unveil path being specified is invalid.");
32 TRY(Core::System::unveil_after_exec(parts[1], parts[0]));
33 }
34
35 TRY(Core::System::exec(command[0], command, Core::System::SearchInPath::Yes));
36 return 0;
37}