From 6f04a3778b179ca5f2c2e81fb808abcfe48aea9e Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 16 Jun 2022 11:44:30 +0200 Subject: [PATCH] FileManager: Change PGID of spawned processes Processes spawned by FileManager (e.g. through double-click) now set their PGID to that of the session leader. It allows the filemanage instance to be killed without propagating the signal to the new process. --- .../Applications/FileManager/DirectoryView.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 08eaea3feaf..c0bbbd61bdc 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -478,13 +478,23 @@ void DirectoryView::set_should_show_dotfiles(bool show_dotfiles) void DirectoryView::launch(URL const&, LauncherHandler const& launcher_handler) const { pid_t child; + + posix_spawnattr_t spawn_attributes; + posix_spawnattr_init(&spawn_attributes); + + posix_spawnattr_setpgroup(&spawn_attributes, getsid(0)); + + short current_flag; + posix_spawnattr_getflags(&spawn_attributes, ¤t_flag); + posix_spawnattr_setflags(&spawn_attributes, static_cast(current_flag | POSIX_SPAWN_SETPGROUP)); + if (launcher_handler.details().launcher_type == Desktop::Launcher::LauncherType::Application) { posix_spawn_file_actions_t spawn_actions; posix_spawn_file_actions_init(&spawn_actions); posix_spawn_file_actions_addchdir(&spawn_actions, path().characters()); char const* argv[] = { launcher_handler.details().name.characters(), nullptr }; - posix_spawn(&child, launcher_handler.details().executable.characters(), &spawn_actions, nullptr, const_cast(argv), environ); + posix_spawn(&child, launcher_handler.details().executable.characters(), &spawn_actions, &spawn_attributes, const_cast(argv), environ); if (disown(child) < 0) perror("disown"); @@ -492,7 +502,7 @@ void DirectoryView::launch(URL const&, LauncherHandler const& launcher_handler) } else { for (auto& path : selected_file_paths()) { char const* argv[] = { launcher_handler.details().name.characters(), path.characters(), nullptr }; - posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast(argv), environ); + posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, &spawn_attributes, const_cast(argv), environ); if (disown(child) < 0) perror("disown"); }