diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-06 01:05:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-06 01:06:42 +0200 |
commit | 779316d468734d092acf4be64982ec225aeeb762 (patch) | |
tree | dfdf4f1fae454c24b2c72eb2bf1654fba2b713de | |
parent | 6e65b36973cf97e7fcfe4cc4f731e441bc2e69f4 (diff) | |
download | serenity-779316d468734d092acf4be64982ec225aeeb762.zip |
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().
-rw-r--r-- | Userland/Applications/Settings/main.cpp | 14 | ||||
-rw-r--r-- | Userland/Applications/Terminal/main.cpp | 12 | ||||
-rw-r--r-- | Userland/Applications/Welcome/WelcomeWidget.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibDesktop/AppFile.cpp | 14 | ||||
-rw-r--r-- | Userland/Services/Taskbar/ClockWidget.cpp | 12 | ||||
-rw-r--r-- | Userland/Services/Taskbar/main.cpp | 36 |
6 files changed, 16 insertions, 83 deletions
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 <LibCore/Process.h> #include <LibDesktop/AppFile.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> @@ -14,7 +15,6 @@ #include <LibGUI/Statusbar.h> #include <LibGUI/Window.h> #include <serenity.h> -#include <spawn.h> #include <stdio.h> #include <unistd.h> @@ -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<char**>(argv), environ))) { - perror("posix_spawn"); - return; - } - - if (disown(child_pid) < 0) - perror("disown"); + Core::Process::spawn(executable); }; auto& statusbar = main_widget.add<GUI::Statusbar>(); 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 <LibCore/ConfigFile.h> #include <LibCore/DirIterator.h> #include <LibCore/File.h> +#include <LibCore/Process.h> #include <LibDesktop/Launcher.h> #include <LibGUI/Action.h> #include <LibGUI/ActionGroup.h> @@ -37,9 +38,7 @@ #include <errno.h> #include <pty.h> #include <pwd.h> -#include <serenity.h> #include <signal.h> -#include <spawn.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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<char**>(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 <Applications/Welcome/WelcomeWindowGML.h> #include <LibCore/File.h> +#include <LibCore/Process.h> #include <LibGUI/Application.h> #include <LibGUI/Button.h> #include <LibGUI/Label.h> @@ -16,7 +17,6 @@ #include <LibMarkdown/Document.h> #include <LibWeb/OutOfProcessWebView.h> #include <serenity.h> -#include <spawn.h> #include <time.h> WelcomeWidget::WelcomeWidget() @@ -52,14 +52,7 @@ WelcomeWidget::WelcomeWidget() m_help_button = *find_descendant_of_type_named<GUI::Button>("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<char**>(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<GUI::Button>("new_button"); diff --git a/Userland/Libraries/LibDesktop/AppFile.cpp b/Userland/Libraries/LibDesktop/AppFile.cpp index de24b80c73..7c7386293f 100644 --- a/Userland/Libraries/LibDesktop/AppFile.cpp +++ b/Userland/Libraries/LibDesktop/AppFile.cpp @@ -9,10 +9,8 @@ #include <AK/Vector.h> #include <LibCore/ConfigFile.h> #include <LibCore/DirIterator.h> +#include <LibCore/Process.h> #include <LibDesktop/AppFile.h> -#include <errno.h> -#include <serenity.h> -#include <spawn.h> namespace Desktop { @@ -134,15 +132,9 @@ bool AppFile::spawn() const if (!is_valid()) return false; - pid_t child_pid; - const char* argv[] = { executable().characters(), nullptr }; - if ((errno = posix_spawn(&child_pid, executable().characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); + auto pid = Core::Process::spawn(executable()); + if (pid < 0) return false; - } else if (disown(child_pid) < 0) { - perror("disown"); - return false; - } return true; } diff --git a/Userland/Services/Taskbar/ClockWidget.cpp b/Userland/Services/Taskbar/ClockWidget.cpp index bb1fe1c4b9..287c02636f 100644 --- a/Userland/Services/Taskbar/ClockWidget.cpp +++ b/Userland/Services/Taskbar/ClockWidget.cpp @@ -5,13 +5,12 @@ */ #include "ClockWidget.h" +#include <LibCore/Process.h> #include <LibGUI/Painter.h> #include <LibGUI/SeparatorWidget.h> #include <LibGUI/Window.h> #include <LibGfx/FontDatabase.h> #include <LibGfx/Palette.h> -#include <serenity.h> -#include <spawn.h> namespace Taskbar { @@ -158,14 +157,7 @@ ClockWidget::ClockWidget() m_calendar_launcher->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-calendar.png")); m_calendar_launcher->set_tooltip("Calendar"); m_calendar_launcher->on_click = [](auto) { - pid_t pid; - const char* argv[] = { "Calendar", nullptr }; - if ((errno = posix_spawn(&pid, "/bin/Calendar", nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(pid) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/Calendar"sv); }; } diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index f46eb552ac..f76ac5f2db 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -12,6 +12,7 @@ #include <LibCore/ConfigFile.h> #include <LibCore/DirIterator.h> #include <LibCore/EventLoop.h> +#include <LibCore/Process.h> #include <LibCore/StandardPaths.h> #include <LibDesktop/AppFile.h> #include <LibGUI/ActionGroup.h> @@ -113,14 +114,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu() auto system_menu = GUI::Menu::construct("\xE2\x9A\xA1"); // HIGH VOLTAGE SIGN system_menu->add_action(GUI::Action::create("About SerenityOS", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladyball.png"), [](auto&) { - pid_t child_pid; - const char* argv[] = { "/bin/About", nullptr }; - if ((errno = posix_spawn(&child_pid, "/bin/About", nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child_pid) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/About"sv); })); system_menu->add_separator(); @@ -248,26 +242,12 @@ NonnullRefPtr<GUI::Menu> build_system_menu() } system_menu->add_action(GUI::Action::create("Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-settings.png"), [](auto&) { - pid_t child_pid; - const char* argv[] = { "/bin/Settings", nullptr }; - if ((errno = posix_spawn(&child_pid, "/bin/Settings", nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child_pid) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/Settings"sv); })); system_menu->add_separator(); system_menu->add_action(GUI::Action::create("Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png"), [](auto&) { - pid_t child_pid; - const char* argv[] = { "/bin/Help", nullptr }; - if ((errno = posix_spawn(&child_pid, "/bin/Help", nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child_pid) < 0) - perror("disown"); - } + Core::Process::spawn("/bin/Help"sv); })); system_menu->add_action(GUI::Action::create("Run...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-run.png"), [](auto&) { posix_spawn_file_actions_t spawn_actions; @@ -293,13 +273,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu() if (command.size() == 0) return; - pid_t child_pid; - if ((errno = posix_spawn(&child_pid, command[0], nullptr, nullptr, const_cast<char**>(command.data()), environ))) { - perror("posix_spawn"); - } else { - if (disown(child_pid) < 0) - perror("disown"); - } + Core::Process::spawn(command[0]); })); return system_menu; |