Pārlūkot izejas kodu

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.
Lucas CHOLLET 3 gadi atpakaļ
vecāks
revīzija
6f04a3778b
1 mainītis faili ar 12 papildinājumiem un 2 dzēšanām
  1. 12 2
      Userland/Applications/FileManager/DirectoryView.cpp

+ 12 - 2
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, &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");
         }