From 779316d468734d092acf4be64982ec225aeeb762 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 6 Aug 2021 01:05:32 +0200 Subject: Userland: Use Core::Process::spawn() instead of posix_spawn() in places This replaces a bunch of very basic uses of posix_spawn() with the new Core::Process::spawn(). --- Userland/Applications/Settings/main.cpp | 14 ++------------ Userland/Applications/Terminal/main.cpp | 12 ++---------- Userland/Applications/Welcome/WelcomeWidget.cpp | 11 ++--------- 3 files changed, 6 insertions(+), 31 deletions(-) (limited to 'Userland/Applications') diff --git a/Userland/Applications/Settings/main.cpp b/Userland/Applications/Settings/main.cpp index 90ce8a1ca2..90fc4222dc 100644 --- a/Userland/Applications/Settings/main.cpp +++ b/Userland/Applications/Settings/main.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include #include @@ -108,17 +108,7 @@ int main(int argc, char** argv) auto launch_origin_rect = icon_view.to_widget_rect(icon_view.content_rect(index)).translated(icon_view.screen_relative_rect().location()); setenv("__libgui_launch_origin_rect", String::formatted("{},{},{},{}", launch_origin_rect.x(), launch_origin_rect.y(), launch_origin_rect.width(), launch_origin_rect.height()).characters(), 1); - - pid_t child_pid; - const char* argv[] = { executable.characters(), nullptr }; - - if ((errno = posix_spawn(&child_pid, executable.characters(), nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - return; - } - - if (disown(child_pid) < 0) - perror("disown"); + Core::Process::spawn(executable); }; auto& statusbar = main_widget.add(); diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 6d64f64349..2dcd416e9e 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -37,9 +38,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -379,14 +378,7 @@ int main(int argc, char** argv) auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::Action::create("Open New &Terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) { - pid_t child; - const char* argv[] = { "Terminal", nullptr }; - if ((errno = posix_spawn(&child, "/bin/Terminal", nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/Terminal"); })); file_menu.add_action(open_settings_action); diff --git a/Userland/Applications/Welcome/WelcomeWidget.cpp b/Userland/Applications/Welcome/WelcomeWidget.cpp index 623cdb65b1..24931b28c0 100644 --- a/Userland/Applications/Welcome/WelcomeWidget.cpp +++ b/Userland/Applications/Welcome/WelcomeWidget.cpp @@ -7,6 +7,7 @@ #include "WelcomeWidget.h" #include #include +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include #include WelcomeWidget::WelcomeWidget() @@ -52,14 +52,7 @@ WelcomeWidget::WelcomeWidget() m_help_button = *find_descendant_of_type_named("help_button"); m_help_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book-open.png")); m_help_button->on_click = [](auto) { - pid_t pid; - const char* argv[] = { "Help", nullptr }; - if ((errno = posix_spawn(&pid, "/bin/Help", nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(pid) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/Help"sv); }; m_new_button = *find_descendant_of_type_named("new_button"); -- cgit v1.2.3