diff options
author | Nico Weber <thakis@chromium.org> | 2020-06-28 13:40:10 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-29 12:04:27 +0200 |
commit | 12cbc4ad0d57b7f403e0a27b491b098f1431a283 (patch) | |
tree | efe3ef1bb3555c24b3173bbfad4d97c503e3f585 /Services/SystemMenu | |
parent | 301ac3c7e5d99f32ac9a70b51844ad7ce8c9d563 (diff) | |
download | serenity-12cbc4ad0d57b7f403e0a27b491b098f1431a283.zip |
Everywhere: Replace some uses of fork/exec with posix_spawn
It's less code, and it's potentially more efficient once
posix_spawn is a real syscall.
Diffstat (limited to 'Services/SystemMenu')
-rw-r--r-- | Services/SystemMenu/main.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Services/SystemMenu/main.cpp b/Services/SystemMenu/main.cpp index 871002e022..5de516eeab 100644 --- a/Services/SystemMenu/main.cpp +++ b/Services/SystemMenu/main.cpp @@ -36,6 +36,7 @@ #include <LibGUI/Menu.h> #include <LibGUI/WindowServerConnection.h> #include <LibGfx/Bitmap.h> +#include <spawn.h> //#define SYSTEM_MENU_DEBUG @@ -149,12 +150,11 @@ NonnullRefPtr<GUI::Menu> build_system_menu() auto parent_menu = g_app_category_menus.get(app.category).value_or(*system_menu); parent_menu->add_action(GUI::Action::create(app.name, icon.ptr(), [app_identifier](auto&) { dbg() << "Activated app with ID " << app_identifier; - if (fork() == 0) { - const auto& bin = g_apps[app_identifier].executable; - if (execl(bin.characters(), bin.characters(), nullptr) < 0) - perror("execl"); - ASSERT_NOT_REACHED(); - } + const auto& bin = g_apps[app_identifier].executable; + pid_t child_pid; + const char* argv[] = { bin.characters(), nullptr }; + if ((errno = posix_spawn(&child_pid, bin.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) + perror("posix_spawn"); })); ++app_identifier; } @@ -197,10 +197,9 @@ NonnullRefPtr<GUI::Menu> build_system_menu() system_menu->add_separator(); system_menu->add_action(GUI::Action::create("About...", Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"), [](auto&) { - if (fork() == 0) { - execl("/bin/About", "/bin/About", nullptr); - ASSERT_NOT_REACHED(); - } + pid_t child_pid; + const char* argv[] = { "/bin/About", nullptr }; + posix_spawn(&child_pid, "/bin/About", nullptr, nullptr, const_cast<char**>(argv), environ); })); system_menu->add_separator(); system_menu->add_action(GUI::Action::create("Exit...", [](auto&) { @@ -209,10 +208,8 @@ NonnullRefPtr<GUI::Menu> build_system_menu() if (command.size() == 0) return; - if (fork() == 0) { - execv(command[0], const_cast<char* const*>(command.data())); - ASSERT_NOT_REACHED(); - } + pid_t child_pid; + posix_spawn(&child_pid, command[0], nullptr, nullptr, const_cast<char**>(command.data()), environ); })); return system_menu; |