summaryrefslogtreecommitdiff
path: root/Userland/Utilities/jail-attach.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-11-02 22:28:58 +0200
committerAndrew Kaster <andrewdkaster@gmail.com>2022-11-05 18:00:58 -0600
commit8d8b0d0a34f68ed850a96e1437084a2e07876f9b (patch)
tree80de6b017a7d08f461ab2470aee2cd64f8c26293 /Userland/Utilities/jail-attach.cpp
parent1d0066a5ccba8597c87bd5b9424388ca53a605c4 (diff)
downloadserenity-8d8b0d0a34f68ed850a96e1437084a2e07876f9b.zip
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.
Diffstat (limited to 'Userland/Utilities/jail-attach.cpp')
-rw-r--r--Userland/Utilities/jail-attach.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Utilities/jail-attach.cpp b/Userland/Utilities/jail-attach.cpp
new file mode 100644
index 0000000000..ba09dafc49
--- /dev/null
+++ b/Userland/Utilities/jail-attach.cpp
@@ -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;
+}