Skip to content

Commit

Permalink
FileManager: Improve error handling when posix_spawn() fails
Browse files Browse the repository at this point in the history
Previously we'd try to disown() the newly created process even if
posix_spawn() had failed.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Nov 4, 2022
1 parent 59e87cc commit 0eb7d1e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Userland/Applications/FileManager/DirectoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,18 @@ void DirectoryView::launch(URL const&, LauncherHandler const& launcher_handler)
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, &spawn_attributes, const_cast<char**>(argv), environ);
if (disown(child) < 0)
errno = posix_spawn(&child, launcher_handler.details().executable.characters(), &spawn_actions, &spawn_attributes, const_cast<char**>(argv), environ);
if (errno) {
perror("posix_spawn");
} else if (disown(child) < 0) {
perror("disown");

}
posix_spawn_file_actions_destroy(&spawn_actions);
} 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, &spawn_attributes, const_cast<char**>(argv), environ);
if ((errno = posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, &spawn_attributes, const_cast<char**>(argv), environ)))
continue;
if (disown(child) < 0)
perror("disown");
}
Expand Down

0 comments on commit 0eb7d1e

Please sign in to comment.