Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
Merge pull request #304 from mihaibuzgau/1.6.x
Browse files Browse the repository at this point in the history
(maint) Merge-up 1.5.x -> 1.6.x
  • Loading branch information
GabrielNagy authored Sep 4, 2019
2 parents 11a942a + 151dd25 commit 170e094
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions execution/src/posix/execution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,26 @@ namespace leatherman { namespace execution {
#ifdef HAS_CLOSEFROM
closefrom(STDERR_FILENO + 1);
#else
for (uint64_t i = (STDERR_FILENO + 1); i < max_fd; ++i) {
close(i);
uint64_t fd;
const char* fdpath = "/proc/self/fd";
std::list<uint64_t> fd_list;

if (is_directory(fdpath)) {
for (const directory_entry& dent : directory_iterator(fdpath)) {
fd = atol(dent.path().filename().c_str());
if (fd >= (STDERR_FILENO + 1)) {
fd_list.push_back(fd);
}
}
for (auto fd : fd_list) {
close(fd);
}
} else {
for (uint64_t i = (STDERR_FILENO + 1); i < max_fd; ++i) {
close(i);
}
}
#endif
#endif // HAS_CLOSEFROM

// Execute the given program; this should not return if successful
execve(program, const_cast<char* const*>(argv), const_cast<char* const*>(envp));
Expand Down

0 comments on commit 170e094

Please sign in to comment.