mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
Userland: Add support for jails
This happens in two ways: 1. LibCore now has two new methods for creating Jails and attaching processes to a Jail. 2. We introduce 3 new utilities - lsjails, jail-create and jails-attach, which list jails, create jails and attach processes to a Jail, respectively.
This commit is contained in:
parent
1d0066a5cc
commit
8d8b0d0a34
9 changed files with 174 additions and 0 deletions
28
Userland/Utilities/jail-attach.cpp
Normal file
28
Userland/Utilities/jail-attach.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue