forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjail-attach.cpp
28 lines (25 loc) · 945 Bytes
/
jail-attach.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Copyright (c) 2022, Liav A. <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <unistd.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
unsigned jail_index = 0;
Vector<StringView> command;
Core::ArgsParser args_parser;
bool preserve_env = false;
args_parser.set_stop_on_first_non_option(true);
args_parser.add_option(preserve_env, "Preserve user environment when running command", "preserve-env", 'E');
args_parser.add_positional_argument(jail_index, "Jail Index", "jail index");
args_parser.add_positional_argument(command, "Command to execute", "command");
args_parser.parse(arguments);
TRY(Core::System::pledge("stdio rpath exec id jail tty"));
TRY(Core::System::join_jail(jail_index));
TRY(Core::System::exec_command(command, preserve_env));
return 0;
}