diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-12 20:40:32 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-11 21:09:42 +0200 |
commit | 3971f712351f5ccab0bc100ca968c4ebbb99cca4 (patch) | |
tree | 6588f588c432588b5bc4d448e90aef5c9e4cd7d7 /Userland/Applications/Terminal/main.cpp | |
parent | 5a47b74227d41bdf8af1f2da7e232002f6ad06a2 (diff) | |
download | serenity-3971f712351f5ccab0bc100ca968c4ebbb99cca4.zip |
Terminal: Use Core::System::exec()
Diffstat (limited to 'Userland/Applications/Terminal/main.cpp')
-rw-r--r-- | Userland/Applications/Terminal/main.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index d94066e156..f080476489 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/FixedArray.h> #include <AK/QuickSort.h> #include <AK/URL.h> #include <LibConfig/Client.h> @@ -132,7 +133,7 @@ static void utmp_update(String const& tty, pid_t pid, bool create) } } -static void run_command(String command, bool keep_open) +static ErrorOr<void> run_command(String command, bool keep_open) { String shell = "/bin/Shell"; auto* pw = getpwuid(getuid()); @@ -141,20 +142,16 @@ static void run_command(String command, bool keep_open) } endpwent(); - char const* args[5] = { shell.characters(), nullptr, nullptr, nullptr, nullptr }; + Vector<StringView> arguments; + arguments.append(shell); if (!command.is_empty()) { - int arg_index = 1; if (keep_open) - args[arg_index++] = "--keep-open"; - args[arg_index++] = "-c"; - args[arg_index++] = command.characters(); - } - char const* envs[] = { "TERM=xterm", "PAGER=more", "PATH=/usr/local/bin:/usr/bin:/bin", nullptr }; - int rc = execve(shell.characters(), const_cast<char**>(args), const_cast<char**>(envs)); - if (rc < 0) { - perror("execve"); - exit(1); + arguments.append("--keep-open"); + arguments.append("-c"); + arguments.append(command); } + auto env = TRY(FixedArray<StringView>::try_create({ "TERM=xterm", "PAGER=more", "PATH=/usr/local/bin:/usr/bin:/bin" })); + TRY(Core::System::exec(shell, arguments, Core::System::SearchInPath::No, env.span())); VERIFY_NOT_REACHED(); } @@ -270,9 +267,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (shell_pid == 0) { close(ptm_fd); if (command_to_execute) - run_command(command_to_execute, keep_open); + TRY(run_command(command_to_execute, keep_open)); else - run_command(Config::read_string("Terminal", "Startup", "Command", ""), false); + TRY(run_command(Config::read_string("Terminal", "Startup", "Command", ""), false)); VERIFY_NOT_REACHED(); } |