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.
This commit is contained in:
Lucas CHOLLET 2022-06-16 11:44:30 +02:00 committed by Sam Atkins
parent 63d06458ca
commit 6f04a3778b
Notes: sideshowbarker 2024-07-17 09:34:16 +09:00

View file

@ -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, &current_flag);
posix_spawnattr_setflags(&spawn_attributes, static_cast<short>(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<char**>(argv), environ);
posix_spawn(&child, launcher_handler.details().executable.characters(), &spawn_actions, &spawn_attributes, const_cast<char**>(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<char**>(argv), environ);
posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, &spawn_attributes, const_cast<char**>(argv), environ);
if (disown(child) < 0)
perror("disown");
}