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 /Applications/FileManager | |
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 'Applications/FileManager')
-rw-r--r-- | Applications/FileManager/main.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index c2d2547dc9..d82d711c51 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -58,6 +58,7 @@ #include <LibGUI/Window.h> #include <LibGfx/Palette.h> #include <signal.h> +#include <spawn.h> #include <stdio.h> #include <string.h> #include <unistd.h> @@ -337,16 +338,13 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio }); auto open_terminal_action = GUI::Action::create("Open Terminal here...", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](const GUI::Action&) { - if (!fork()) { - if (chdir(directory_view.path().characters()) < 0) { - perror("chdir"); - exit(1); - } - - if (execl("/bin/Terminal", "Terminal", nullptr) < 0) - perror("execl"); - exit(1); - } + posix_spawn_file_actions_t spawn_actions; + posix_spawn_file_actions_init(&spawn_actions); + posix_spawn_file_actions_addchdir(&spawn_actions, directory_view.path().characters()); + pid_t pid; + const char* argv[] = { "Terminal", nullptr }; + posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ); + posix_spawn_file_actions_destroy(&spawn_actions); }); RefPtr<GUI::Action> view_as_table_action; @@ -719,13 +717,10 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio }; auto open_in_text_editor_action = GUI::Action::create("Open in TextEditor...", Gfx::Bitmap::load_from_file("/res/icons/TextEditor16.png"), [&](auto&) { + pid_t child; for (auto& path : selected_file_paths()) { - if (!fork()) { - int rc = execl("/bin/TextEditor", "TextEditor", path.characters(), nullptr); - if (rc < 0) - perror("execl"); - exit(1); - } + const char* argv[] = { "TextEditor", path.characters(), nullptr }; + posix_spawn(&child, "/bin/TextEditor", nullptr, nullptr, const_cast<char**>(argv), environ); } }); |